mirror of
https://github.com/Swiftgram/Telegram-iOS.git
synced 2025-12-23 22:55:00 +00:00
refactor and cleanup [skip ci]
This commit is contained in:
41
submodules/Postbox/Sources/PeerPresencesView.swift
Normal file
41
submodules/Postbox/Sources/PeerPresencesView.swift
Normal file
@@ -0,0 +1,41 @@
|
||||
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
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user