mirror of
https://github.com/Swiftgram/Telegram-iOS.git
synced 2025-12-23 22:55:00 +00:00
refactor and cleanup [skip ci]
This commit is contained in:
39
submodules/Postbox/Sources/UnsentMessageHistoryView.swift
Normal file
39
submodules/Postbox/Sources/UnsentMessageHistoryView.swift
Normal file
@@ -0,0 +1,39 @@
|
||||
import Foundation
|
||||
|
||||
final class UnsentMessageHistoryView {
|
||||
var ids: Set<MessageId>
|
||||
|
||||
init(ids: [MessageId]) {
|
||||
self.ids = Set(ids)
|
||||
}
|
||||
|
||||
func refreshDueToExternalTransaction(fetchUnsentMessageIds: () -> [MessageId]) -> Bool {
|
||||
let ids = Set(fetchUnsentMessageIds())
|
||||
if ids != self.ids {
|
||||
self.ids = ids
|
||||
return true
|
||||
} else {
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
func replay(_ operations: [IntermediateMessageHistoryUnsentOperation]) -> Bool {
|
||||
var updated = false
|
||||
for operation in operations {
|
||||
switch operation {
|
||||
case let .Insert(id):
|
||||
if !self.ids.contains(id) {
|
||||
self.ids.insert(id)
|
||||
updated = true
|
||||
}
|
||||
case let .Remove(id):
|
||||
if self.ids.contains(id) {
|
||||
self.ids.remove(id)
|
||||
updated = true
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return updated
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user