mirror of
https://github.com/Swiftgram/Telegram-iOS.git
synced 2025-08-18 19:40:19 +00:00
40 lines
1.1 KiB
Swift
40 lines
1.1 KiB
Swift
import Foundation
|
|
|
|
final class UnsentMessageHistoryView {
|
|
var indices: Set<MessageIndex>
|
|
|
|
init(indices: [MessageIndex]) {
|
|
self.indices = Set(indices)
|
|
}
|
|
|
|
func refreshDueToExternalTransaction(fetchUnsendMessageIndices: () -> [MessageIndex]) -> Bool {
|
|
let indices = Set(fetchUnsendMessageIndices())
|
|
if indices != self.indices {
|
|
self.indices = indices
|
|
return true
|
|
} else {
|
|
return false
|
|
}
|
|
}
|
|
|
|
func replay(_ operations: [IntermediateMessageHistoryUnsentOperation]) -> Bool {
|
|
var updated = false
|
|
for operation in operations {
|
|
switch operation {
|
|
case let .Insert(index):
|
|
if !self.indices.contains(index) {
|
|
self.indices.insert(index)
|
|
updated = true
|
|
}
|
|
case let .Remove(index):
|
|
if self.indices.contains(index) {
|
|
self.indices.remove(index)
|
|
updated = true
|
|
}
|
|
}
|
|
}
|
|
|
|
return updated
|
|
}
|
|
}
|