Swiftgram/submodules/Postbox/Postbox/PeerPresencesView.swift
Peter 4459dc5b47 Add 'submodules/Postbox/' from commit '534443c710e63ff4ea595b5dc7be94550c467734'
git-subtree-dir: submodules/Postbox
git-subtree-mainline: 373769682ef152a8d5ef41ccb064a8387b2ca6f0
git-subtree-split: 534443c710e63ff4ea595b5dc7be94550c467734
2019-06-11 18:56:39 +01:00

42 lines
1.1 KiB
Swift

import Foundation
final class MutablePeerPresencesView: MutablePostboxView {
fileprivate let ids: Set<PeerId>
fileprivate var presences: [PeerId: PeerPresence] = [:]
init(postbox: Postbox, ids: Set<PeerId>) {
self.ids = ids
for id in ids {
if let presence = postbox.peerPresenceTable.get(id) {
self.presences[id] = presence
}
}
}
func replay(postbox: Postbox, transaction: PostboxTransaction) -> Bool {
var updated = false
if !transaction.currentUpdatedPeerPresences.isEmpty {
for (id, presence) in transaction.currentUpdatedPeerPresences {
if self.ids.contains(id) {
self.presences[id] = presence
updated = true
}
}
}
return updated
}
func immutableView() -> PostboxView {
return PeerPresencesView(self)
}
}
public final class PeerPresencesView: PostboxView {
public let presences: [PeerId: PeerPresence]
init(_ view: MutablePeerPresencesView) {
self.presences = view.presences
}
}