mirror of
https://github.com/Swiftgram/Telegram-iOS.git
synced 2025-12-23 22:55:00 +00:00
Refactoring
This commit is contained in:
@@ -1,33 +1,47 @@
|
||||
import Foundation
|
||||
|
||||
final class MutableContactPeersView {
|
||||
final class MutableContactPeersView: MutablePostboxView {
|
||||
fileprivate var peers: [PeerId: Peer]
|
||||
fileprivate var peerPresences: [PeerId: PeerPresence]
|
||||
fileprivate var peerIds: Set<PeerId>
|
||||
fileprivate var accountPeer: Peer?
|
||||
private let includePresences: Bool
|
||||
|
||||
init(peers: [PeerId: Peer], peerPresences: [PeerId: PeerPresence], accountPeer: Peer?, includePresences: Bool) {
|
||||
init(postbox: PostboxImpl, accountPeerId: PeerId?, includePresences: Bool) {
|
||||
var peers: [PeerId: Peer] = [:]
|
||||
var peerPresences: [PeerId: PeerPresence] = [:]
|
||||
|
||||
for peerId in postbox.contactsTable.get() {
|
||||
if let peer = postbox.peerTable.get(peerId) {
|
||||
peers[peerId] = peer
|
||||
}
|
||||
if includePresences {
|
||||
if let presence = postbox.peerPresenceTable.get(peerId) {
|
||||
peerPresences[peerId] = presence
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
self.peers = peers
|
||||
self.peerIds = Set<PeerId>(peers.map { $0.0 })
|
||||
self.peerPresences = peerPresences
|
||||
self.accountPeer = accountPeer
|
||||
self.accountPeer = accountPeerId.flatMap(postbox.peerTable.get)
|
||||
self.includePresences = includePresences
|
||||
}
|
||||
|
||||
func replay(postbox: PostboxImpl, replacePeerIds: Set<PeerId>?, updatedPeerPresences: [PeerId: PeerPresence]) -> Bool {
|
||||
|
||||
func replay(postbox: PostboxImpl, transaction: PostboxTransaction) -> Bool {
|
||||
var updated = false
|
||||
if let replacePeerIds = replacePeerIds {
|
||||
if let replacePeerIds = transaction.replaceContactPeerIds {
|
||||
let removedPeerIds = self.peerIds.subtracting(replacePeerIds)
|
||||
let addedPeerIds = replacePeerIds.subtracting(self.peerIds)
|
||||
|
||||
|
||||
self.peerIds = replacePeerIds
|
||||
|
||||
|
||||
for peerId in removedPeerIds {
|
||||
let _ = self.peers.removeValue(forKey: peerId)
|
||||
let _ = self.peerPresences.removeValue(forKey: peerId)
|
||||
}
|
||||
|
||||
|
||||
for peerId in addedPeerIds {
|
||||
if let peer = postbox.peerTable.get(peerId) {
|
||||
self.peers[peerId] = peer
|
||||
@@ -38,26 +52,30 @@ final class MutableContactPeersView {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if !removedPeerIds.isEmpty || !addedPeerIds.isEmpty {
|
||||
updated = true
|
||||
}
|
||||
}
|
||||
|
||||
if self.includePresences, !updatedPeerPresences.isEmpty {
|
||||
|
||||
if self.includePresences, !transaction.currentUpdatedPeerPresences.isEmpty {
|
||||
for peerId in self.peerIds {
|
||||
if let presence = updatedPeerPresences[peerId] {
|
||||
if let presence = transaction.currentUpdatedPeerPresences[peerId] {
|
||||
updated = true
|
||||
self.peerPresences[peerId] = presence
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return updated
|
||||
}
|
||||
|
||||
func immutableView() -> PostboxView {
|
||||
return ContactPeersView(self)
|
||||
}
|
||||
}
|
||||
|
||||
public final class ContactPeersView {
|
||||
public final class ContactPeersView: PostboxView {
|
||||
public let peers: [Peer]
|
||||
public let peerPresences: [PeerId: PeerPresence]
|
||||
public let accountPeer: Peer?
|
||||
|
||||
Reference in New Issue
Block a user