mirror of
https://github.com/Swiftgram/Telegram-iOS.git
synced 2025-08-17 11:00:07 +00:00
38 lines
1.4 KiB
Swift
38 lines
1.4 KiB
Swift
import Foundation
|
|
#if os(macOS)
|
|
import PostboxMac
|
|
#else
|
|
import Postbox
|
|
#endif
|
|
|
|
final class SynchronizePinnedChatsOperation: Coding {
|
|
let previousPeerIds: [PeerId]
|
|
|
|
init(previousPeerIds: [PeerId]) {
|
|
self.previousPeerIds = previousPeerIds
|
|
}
|
|
|
|
init(decoder: Decoder) {
|
|
self.previousPeerIds = PeerId.decodeArrayFromBuffer(decoder.decodeBytesForKey("p")!)
|
|
}
|
|
|
|
func encode(_ encoder: Encoder) {
|
|
let buffer = WriteBuffer()
|
|
PeerId.encodeArrayToBuffer(self.previousPeerIds, buffer: buffer)
|
|
encoder.encodeBytes(buffer, forKey: "p")
|
|
}
|
|
}
|
|
|
|
func addSynchronizePinnedChatsOperation(modifier: Modifier) {
|
|
var updateLocalIndex: Int32?
|
|
modifier.operationLogEnumerateEntries(peerId: PeerId(namespace: 0, id: 0), tag: OperationLogTags.SynchronizePinnedChats, { entry in
|
|
updateLocalIndex = entry.tagLocalIndex
|
|
return false
|
|
})
|
|
let operationContents = SynchronizePinnedChatsOperation(previousPeerIds: modifier.getPinnedPeerIds())
|
|
if let updateLocalIndex = updateLocalIndex {
|
|
let _ = modifier.operationLogRemoveEntry(peerId: PeerId(namespace: 0, id: 0), tag: OperationLogTags.SynchronizePinnedChats, tagLocalIndex: updateLocalIndex)
|
|
}
|
|
modifier.operationLogAddEntry(peerId: PeerId(namespace: 0, id: 0), tag: OperationLogTags.SynchronizePinnedChats, tagLocalIndex: .automatic, tagMergedIndex: .automatic, contents: operationContents)
|
|
}
|