mirror of
https://github.com/Swiftgram/Telegram-iOS.git
synced 2025-12-23 06:35:51 +00:00
Thread draft synchronization
This commit is contained in:
@@ -1,27 +1,41 @@
|
||||
import Foundation
|
||||
import Postbox
|
||||
|
||||
func addSynchronizeChatInputStateOperation(transaction: Transaction, peerId: PeerId) {
|
||||
var updateLocalIndex: Int32?
|
||||
func addSynchronizeChatInputStateOperation(transaction: Transaction, peerId: PeerId, threadId: Int64?) {
|
||||
var removeLocalIndices: [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
|
||||
if operation.threadId == threadId {
|
||||
previousOperation = operation
|
||||
removeLocalIndices.append(entry.tagLocalIndex)
|
||||
return false
|
||||
}
|
||||
} else {
|
||||
removeLocalIndices.append(entry.tagLocalIndex)
|
||||
}
|
||||
return false
|
||||
return true
|
||||
})
|
||||
var previousState: SynchronizeableChatInputState?
|
||||
if let previousOperation = previousOperation {
|
||||
previousState = previousOperation.previousState
|
||||
} else if let peerChatInterfaceState = transaction.getPeerChatInterfaceState(peerId), let data = peerChatInterfaceState.data {
|
||||
previousState = (try? AdaptedPostboxDecoder().decode(InternalChatInterfaceState.self, from: data))?.synchronizeableInputState
|
||||
} else {
|
||||
let peerChatInterfaceState: StoredPeerChatInterfaceState?
|
||||
if let threadId = threadId {
|
||||
peerChatInterfaceState = transaction.getPeerChatThreadInterfaceState(peerId, threadId: threadId)
|
||||
} else {
|
||||
peerChatInterfaceState = transaction.getPeerChatInterfaceState(peerId)
|
||||
}
|
||||
|
||||
if let peerChatInterfaceState = peerChatInterfaceState, let data = peerChatInterfaceState.data {
|
||||
previousState = (try? AdaptedPostboxDecoder().decode(InternalChatInterfaceState.self, from: data))?.synchronizeableInputState
|
||||
}
|
||||
}
|
||||
let operationContents = SynchronizeChatInputStateOperation(previousState: previousState)
|
||||
if let updateLocalIndex = updateLocalIndex {
|
||||
let _ = transaction.operationLogRemoveEntry(peerId: peerId, tag: tag, tagLocalIndex: updateLocalIndex)
|
||||
let operationContents = SynchronizeChatInputStateOperation(previousState: previousState, threadId: threadId)
|
||||
for index in removeLocalIndices {
|
||||
let _ = transaction.operationLogRemoveEntry(peerId: peerId, tag: tag, tagLocalIndex: index)
|
||||
}
|
||||
transaction.operationLogAddEntry(peerId: peerId, tag: tag, tagLocalIndex: .automatic, tagMergedIndex: .automatic, contents: operationContents)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user