mirror of
https://github.com/Swiftgram/Telegram-iOS.git
synced 2025-07-16 16:21:11 +00:00

git-subtree-dir: submodules/TelegramCore git-subtree-mainline: 971273e8f8f49a47f14b251d2f35e3445a61fc3f git-subtree-split: 9561227540acef69894e6546395ab223a6233600
48 lines
1.6 KiB
Swift
48 lines
1.6 KiB
Swift
import Foundation
|
|
#if os(macOS)
|
|
import PostboxMac
|
|
import SwiftSignalKitMac
|
|
#else
|
|
import Postbox
|
|
import SwiftSignalKit
|
|
#endif
|
|
|
|
final class SynchronizeMarkAllUnseenPersonalMessagesOperation: PostboxCoding {
|
|
let maxId: MessageId.Id
|
|
|
|
init(maxId: MessageId.Id) {
|
|
self.maxId = maxId
|
|
}
|
|
|
|
init(decoder: PostboxDecoder) {
|
|
self.maxId = decoder.decodeInt32ForKey("maxId", orElse: Int32.min + 1)
|
|
}
|
|
|
|
func encode(_ encoder: PostboxEncoder) {
|
|
encoder.encodeInt32(self.maxId, forKey: "maxId")
|
|
}
|
|
}
|
|
|
|
func addSynchronizeMarkAllUnseenPersonalMessagesOperation(transaction: Transaction, peerId: PeerId, maxId: MessageId.Id) {
|
|
let tag: PeerOperationLogTag = OperationLogTags.SynchronizeMarkAllUnseenPersonalMessages
|
|
|
|
var topLocalIndex: Int32?
|
|
var currentMaxId: MessageId.Id?
|
|
transaction.operationLogEnumerateEntries(peerId: peerId, tag: tag, { entry in
|
|
topLocalIndex = entry.tagLocalIndex
|
|
if let operation = entry.contents as? SynchronizeMarkAllUnseenPersonalMessagesOperation {
|
|
currentMaxId = operation.maxId
|
|
}
|
|
return false
|
|
})
|
|
|
|
if let topLocalIndex = topLocalIndex {
|
|
if let currentMaxId = currentMaxId, currentMaxId >= maxId {
|
|
return
|
|
}
|
|
let _ = transaction.operationLogRemoveEntry(peerId: peerId, tag: tag, tagLocalIndex: topLocalIndex)
|
|
}
|
|
|
|
transaction.operationLogAddEntry(peerId: peerId, tag: tag, tagLocalIndex: .automatic, tagMergedIndex: .automatic, contents: SynchronizeMarkAllUnseenPersonalMessagesOperation(maxId: maxId))
|
|
}
|