Support refreshDueToExternalTransaction in more views

This commit is contained in:
Ali
2021-11-04 21:09:34 +04:00
parent 9290df840d
commit ddb0999af0
36 changed files with 407 additions and 15 deletions

View File

@@ -36,6 +36,43 @@ final class MutablePeerNotificationSettingsView: MutablePostboxView {
return false
}
}
func refreshDueToExternalTransaction(postbox: PostboxImpl) -> Bool {
var notificationSettings: [PeerId: PeerNotificationSettings] = [:]
for peerId in self.peerIds {
var notificationPeerId = peerId
if let peer = postbox.peerTable.get(peerId), let associatedPeerId = peer.associatedPeerId {
notificationPeerId = associatedPeerId
}
if let settings = postbox.peerNotificationSettingsTable.getEffective(notificationPeerId) {
notificationSettings[peerId] = settings
}
}
var updated = false
if self.notificationSettings.count != notificationSettings.count {
updated = true
} else {
for (key, value) in self.notificationSettings {
if let other = notificationSettings[key] {
if !other.isEqual(to: value) {
updated = true
break
}
} else {
updated = true
break
}
}
}
if updated {
self.notificationSettings = notificationSettings
return true
} else {
return false
}
}
func immutableView() -> PostboxView {
return PeerNotificationSettingsView(self)