mirror of
https://github.com/Swiftgram/Telegram-iOS.git
synced 2025-06-16 05:55:20 +00:00
30 lines
1.4 KiB
Swift
30 lines
1.4 KiB
Swift
import Foundation
|
|
import Postbox
|
|
|
|
import SyncCore
|
|
|
|
func addSynchronizeChatInputStateOperation(transaction: Transaction, peerId: PeerId) {
|
|
var updateLocalIndex: Int32?
|
|
let tag: PeerOperationLogTag = OperationLogTags.SynchronizeChatInputStates
|
|
|
|
var previousOperation: SynchronizeChatInputStateOperation?
|
|
transaction.operationLogEnumerateEntries(peerId: peerId, tag: tag, { entry in
|
|
updateLocalIndex = entry.tagLocalIndex
|
|
if let operation = entry.contents as? SynchronizeChatInputStateOperation {
|
|
previousOperation = operation
|
|
}
|
|
return false
|
|
})
|
|
var previousState: SynchronizeableChatInputState?
|
|
if let previousOperation = previousOperation {
|
|
previousState = previousOperation.previousState
|
|
} else if let peerChatInterfaceState = transaction.getPeerChatInterfaceState(peerId) as? SynchronizeableChatInterfaceState {
|
|
previousState = peerChatInterfaceState.synchronizeableInputState
|
|
}
|
|
let operationContents = SynchronizeChatInputStateOperation(previousState: previousState)
|
|
if let updateLocalIndex = updateLocalIndex {
|
|
let _ = transaction.operationLogRemoveEntry(peerId: peerId, tag: tag, tagLocalIndex: updateLocalIndex)
|
|
}
|
|
transaction.operationLogAddEntry(peerId: peerId, tag: tag, tagLocalIndex: .automatic, tagMergedIndex: .automatic, contents: operationContents)
|
|
}
|