mirror of
https://github.com/Swiftgram/Telegram-iOS.git
synced 2025-07-26 13:10:43 +00:00

git-subtree-dir: submodules/TelegramCore git-subtree-mainline: 971273e8f8f49a47f14b251d2f35e3445a61fc3f git-subtree-split: 9561227540acef69894e6546395ab223a6233600
40 lines
1.6 KiB
Swift
40 lines
1.6 KiB
Swift
import Foundation
|
|
#if os(macOS)
|
|
import PostboxMac
|
|
#else
|
|
import Postbox
|
|
#endif
|
|
|
|
final class SynchronizeConsumeMessageContentsOperation: PostboxCoding {
|
|
let messageIds: [MessageId]
|
|
|
|
init(messageIds: [MessageId]) {
|
|
self.messageIds = messageIds
|
|
}
|
|
|
|
init(decoder: PostboxDecoder) {
|
|
self.messageIds = MessageId.decodeArrayFromBuffer(decoder.decodeBytesForKeyNoCopy("i")!)
|
|
}
|
|
|
|
func encode(_ encoder: PostboxEncoder) {
|
|
let buffer = WriteBuffer()
|
|
MessageId.encodeArrayToBuffer(self.messageIds, buffer: buffer)
|
|
encoder.encodeBytes(buffer, forKey: "i")
|
|
}
|
|
}
|
|
|
|
func addSynchronizeConsumeMessageContentsOperation(transaction: Transaction, messageIds: [MessageId]) {
|
|
for (peerId, messageIds) in messagesIdsGroupedByPeerId(Set(messageIds)) {
|
|
var updateLocalIndex: Int32?
|
|
/*transaction.operationLogEnumerateEntries(peerId: peerId, tag: OperationLogTags.SynchronizeConsumeMessageContents, { entry in
|
|
updateLocalIndex = entry.tagLocalIndex
|
|
return false
|
|
})*/
|
|
let operationContents = SynchronizeConsumeMessageContentsOperation(messageIds: messageIds)
|
|
if let updateLocalIndex = updateLocalIndex {
|
|
let _ = transaction.operationLogRemoveEntry(peerId: peerId, tag: OperationLogTags.SynchronizeConsumeMessageContents, tagLocalIndex: updateLocalIndex)
|
|
}
|
|
transaction.operationLogAddEntry(peerId: peerId, tag: OperationLogTags.SynchronizeConsumeMessageContents, tagLocalIndex: .automatic, tagMergedIndex: .automatic, contents: operationContents)
|
|
}
|
|
}
|