mirror of
https://github.com/Swiftgram/Telegram-iOS.git
synced 2025-12-22 22:25:57 +00:00
refactor and cleanup [skip ci]
This commit is contained in:
@@ -0,0 +1,54 @@
|
||||
import Foundation
|
||||
|
||||
final class MutablePeerNotificationSettingsView: MutablePostboxView {
|
||||
let peerIds: Set<PeerId>
|
||||
var notificationSettings: [PeerId: PeerNotificationSettings]
|
||||
|
||||
init(postbox: Postbox, peerIds: Set<PeerId>) {
|
||||
self.peerIds = peerIds
|
||||
self.notificationSettings = [:]
|
||||
for peerId in peerIds {
|
||||
var notificationPeerId = peerId
|
||||
if let peer = postbox.peerTable.get(peerId), let associatedPeerId = peer.associatedPeerId {
|
||||
notificationPeerId = associatedPeerId
|
||||
}
|
||||
if let settings = postbox.peerNotificationSettingsTable.getEffective(notificationPeerId) {
|
||||
self.notificationSettings[peerId] = settings
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func replay(postbox: Postbox, transaction: PostboxTransaction) -> Bool {
|
||||
if !transaction.currentUpdatedPeerNotificationSettings.isEmpty {
|
||||
var updated = false
|
||||
for peerId in self.peerIds {
|
||||
var notificationPeerId = peerId
|
||||
if let peer = postbox.peerTable.get(peerId), let associatedPeerId = peer.associatedPeerId {
|
||||
notificationPeerId = associatedPeerId
|
||||
}
|
||||
if let settings = transaction.currentUpdatedPeerNotificationSettings[notificationPeerId] {
|
||||
self.notificationSettings[peerId] = settings
|
||||
updated = true
|
||||
}
|
||||
}
|
||||
return updated
|
||||
} else {
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
func immutableView() -> PostboxView {
|
||||
return PeerNotificationSettingsView(self)
|
||||
}
|
||||
}
|
||||
|
||||
public final class PeerNotificationSettingsView: PostboxView {
|
||||
public let peerIds: Set<PeerId>
|
||||
public let notificationSettings: [PeerId: PeerNotificationSettings]
|
||||
|
||||
init(_ view: MutablePeerNotificationSettingsView) {
|
||||
self.peerIds = view.peerIds
|
||||
self.notificationSettings = view.notificationSettings
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user