Skip to content

Commit

Permalink
For review updates #3.
Browse files Browse the repository at this point in the history
  • Loading branch information
buh committed Mar 11, 2020
1 parent 36c9f0b commit 6218c51
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 9 deletions.
10 changes: 5 additions & 5 deletions Sources/Client/Client/Client+UnreadCount.swift
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ extension Client {
if updatedChannelsUnreadCount != -1 {
user.channelsUnreadCountAtomic.set(updatedChannelsUnreadCount)
user.messagesUnreadCountAtomic.set(updatedMssagesUnreadCount)
userDidUpdate?(user)
onUserUpdate?(user)
}
}

Expand All @@ -58,7 +58,7 @@ extension Client {
if case .notificationMarkRead(let notificationChannel, let unreadCount, _, _, _) = event,
notificationChannel?.cid == channel.cid {
channel.unreadCountAtomic.set(unreadCount)
channel.didUpdate?(channel)
channel.onUpdate?(channel)
}

return
Expand All @@ -73,14 +73,14 @@ extension Client {
channel.mentionedUnreadCountAtomic += 1
}

channel.didUpdate?(channel)
channel.onUpdate?(channel)
return
}

if case .messageRead(let messageRead, _, _) = event, messageRead.user.isCurrent {
channel.unreadCountAtomic.set(0)
channel.mentionedUnreadCountAtomic.set(0)
channel.didUpdate?(channel)
channel.onUpdate?(channel)
updateUserUnreadCountForChannelUpdate(channelsDiff: oldUnreadCount > 0 ? -1 : 0, messagesDiff: -oldUnreadCount)
return
}
Expand All @@ -93,7 +93,7 @@ extension Client {
}

user.messagesUnreadCountAtomic += messages
userDidUpdate?(user)
onUserUpdate?(user)
}
}

4 changes: 2 additions & 2 deletions Sources/Client/Client/Client.swift
Original file line number Diff line number Diff line change
Expand Up @@ -76,11 +76,11 @@ public final class Client {
let logOptions: ClientLogger.Options

/// An observable user.
public var userDidUpdate: DidUpdate<User>?
public var onUserUpdate: OnUpdate<User>?

private(set) lazy var userAtomic = Atomic<User> { [unowned self] newValue, _ in
if let user = newValue {
self.userDidUpdate?(user)
self.onUserUpdate?(user)
}
}

Expand Down
2 changes: 1 addition & 1 deletion Sources/Client/Extensions/Functions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
//

/// A did update block type.
public typealias DidUpdate<T> = (T) -> Void
public typealias OnUpdate<T> = (T) -> Void

/// A tuple for unread counts of channels and messages.
public struct UnreadCount: Hashable {
Expand Down
2 changes: 1 addition & 1 deletion Sources/Client/Model/Channel/Channel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ public final class Channel: Codable {
public var isDirectMessage: Bool { id.hasPrefix("!members") && members.count == 2 }

/// An event when the channel was updated.
public var didUpdate: DidUpdate<Channel>?
public var onUpdate: OnUpdate<Channel>?

/// Init a channel 1-by-1 (direct message) with another member.
/// - Parameters:
Expand Down

0 comments on commit 6218c51

Please sign in to comment.