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

@@ -29,6 +29,41 @@ final class MutableTopChatMessageView: MutablePostboxView {
return updated
}
func refreshDueToExternalTransaction(postbox: PostboxImpl) -> Bool {
var messages: [PeerId: Message] = [:]
for peerId in self.peerIds {
if let index = postbox.chatListIndexTable.get(peerId: peerId).topMessageIndex {
messages[peerId] = postbox.getMessage(index.id)
}
}
var updated = false
if self.messages.count != messages.count {
updated = true
} else {
for (key, value) in self.messages {
if let other = messages[key] {
if other.stableId != value.stableId || other.stableVersion != value.stableVersion {
updated = true
break
}
} else {
updated = true
break
}
}
}
if updated {
self.messages = messages
return true
} else {
return false
}
}
func immutableView() -> PostboxView {
return TopChatMessageView(self)