Swiftgram/submodules/Postbox/Postbox/SynchronizeGroupMessageStatsView.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.5 KiB
Swift

import Foundation
final class MutableSynchronizeGroupMessageStatsView: MutablePostboxView {
fileprivate var groupsAndNamespaces: Set<PeerGroupAndNamespace>
init(postbox: Postbox) {
self.groupsAndNamespaces = postbox.synchronizeGroupMessageStatsTable.get()
}
func replay(postbox: Postbox, transaction: PostboxTransaction) -> Bool {
var updated = false
if !transaction.currentUpdatedGroupSummarySynchronizeOperations.isEmpty {
for (groupIdAndNamespace, value) in transaction.currentUpdatedGroupSummarySynchronizeOperations {
if value {
if !self.groupsAndNamespaces.contains(groupIdAndNamespace) {
self.groupsAndNamespaces.insert(groupIdAndNamespace)
updated = true
}
} else {
if self.groupsAndNamespaces.contains(groupIdAndNamespace) {
self.groupsAndNamespaces.remove(groupIdAndNamespace)
updated = true
}
}
}
}
return updated
}
func immutableView() -> PostboxView {
return SynchronizeGroupMessageStatsView(self)
}
}
public final class SynchronizeGroupMessageStatsView: PostboxView {
public let groupsAndNamespaces: Set<PeerGroupAndNamespace>
init(_ view: MutableSynchronizeGroupMessageStatsView) {
self.groupsAndNamespaces = view.groupsAndNamespaces
}
}