mirror of
https://github.com/Swiftgram/Telegram-iOS.git
synced 2025-11-07 09:20:08 +00:00
Scheduled messages fixes
This commit is contained in:
parent
9b190d7e6b
commit
233eaec213
@ -924,7 +924,7 @@ public final class AccountViewTracker {
|
|||||||
strongSelf.queue.async {
|
strongSelf.queue.async {
|
||||||
let (messageIds, localWebpages) = pendingWebpages(entries: next.0.entries)
|
let (messageIds, localWebpages) = pendingWebpages(entries: next.0.entries)
|
||||||
strongSelf.updatePendingWebpages(viewId: viewId, messageIds: messageIds, localWebpages: localWebpages)
|
strongSelf.updatePendingWebpages(viewId: viewId, messageIds: messageIds, localWebpages: localWebpages)
|
||||||
strongSelf.historyViewStateValidationContexts.updateView(id: viewId, view: next.0)
|
strongSelf.historyViewStateValidationContexts.updateView(id: viewId, view: next.0, location: chatLocation)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}, disposed: { [weak self] viewId in
|
}, disposed: { [weak self] viewId in
|
||||||
|
|||||||
@ -145,7 +145,7 @@ final class HistoryViewStateValidationContexts {
|
|||||||
self.accountPeerId = accountPeerId
|
self.accountPeerId = accountPeerId
|
||||||
}
|
}
|
||||||
|
|
||||||
func updateView(id: Int32, view: MessageHistoryView?) {
|
func updateView(id: Int32, view: MessageHistoryView?, location: ChatLocation? = nil) {
|
||||||
assert(self.queue.isCurrent())
|
assert(self.queue.isCurrent())
|
||||||
guard let view = view, view.tagMask == nil || view.tagMask == MessageTags.unseenPersonalMessage else {
|
guard let view = view, view.tagMask == nil || view.tagMask == MessageTags.unseenPersonalMessage else {
|
||||||
if self.contexts[id] != nil {
|
if self.contexts[id] != nil {
|
||||||
@ -262,35 +262,27 @@ final class HistoryViewStateValidationContexts {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else if view.namespaces.contains(Namespaces.Message.ScheduledCloud) {
|
} else if view.namespaces.contains(Namespaces.Message.ScheduledCloud) {
|
||||||
let context: HistoryStateValidationContext
|
if let _ = self.contexts[id] {
|
||||||
if let current = self.contexts[id] {
|
} else if let location = location, case let .peer(peerId) = location {
|
||||||
context = current
|
let context = HistoryStateValidationContext()
|
||||||
} else {
|
|
||||||
context = HistoryStateValidationContext()
|
|
||||||
self.contexts[id] = context
|
self.contexts[id] = context
|
||||||
}
|
|
||||||
|
|
||||||
let disposable = MetaDisposable()
|
let disposable = MetaDisposable()
|
||||||
let batch = HistoryStateValidationBatch(disposable: disposable)
|
let batch = HistoryStateValidationBatch(disposable: disposable)
|
||||||
context.batch = batch
|
context.batch = batch
|
||||||
|
|
||||||
disposable.set((validateScheduledMessagesBatch(postbox: self.postbox, network: self.network, accountPeerId: self.accountPeerId, tag: nil, messages: [], historyState: .scheduledMessages(self.accountPeerId))
|
let messages: [Message] = view.entries.map { $0.message }
|
||||||
|> deliverOn(self.queue)).start(completed: { [weak self, weak batch] in
|
|
||||||
if let strongSelf = self, let context = strongSelf.contexts[id], let batch = batch {
|
disposable.set((validateScheduledMessagesBatch(postbox: self.postbox, network: self.network, accountPeerId: peerId, tag: nil, messages: messages, historyState: .scheduledMessages(peerId))
|
||||||
var completedMessageIds: [MessageId] = []
|
|> deliverOn(self.queue)).start(completed: { [weak self] in
|
||||||
for (messageId, messageBatch) in context.batchReferences {
|
if let strongSelf = self, let context = strongSelf.contexts[id] {
|
||||||
if messageBatch === batch {
|
context.batch = nil
|
||||||
completedMessageIds.append(messageId)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
for messageId in completedMessageIds {
|
|
||||||
context.batchReferences.removeValue(forKey: messageId)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}))
|
}))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private func hashForMessages(_ messages: [Message], withChannelIds: Bool) -> Int32 {
|
private func hashForMessages(_ messages: [Message], withChannelIds: Bool) -> Int32 {
|
||||||
var acc: UInt32 = 0
|
var acc: UInt32 = 0
|
||||||
@ -404,7 +396,7 @@ private func validateChannelMessagesBatch(postbox: Postbox, network: Network, ac
|
|||||||
signal = .complete()
|
signal = .complete()
|
||||||
}
|
}
|
||||||
|
|
||||||
return validateBatch(postbox: postbox, network: network, transaction: transaction, accountPeerId: accountPeerId, tag: tag, historyState: historyState, signal: signal, previous: previous)
|
return validateBatch(postbox: postbox, network: network, transaction: transaction, accountPeerId: accountPeerId, tag: tag, historyState: historyState, signal: signal, previous: previous, messageNamespace: Namespaces.Message.Cloud)
|
||||||
} |> switchToLatest
|
} |> switchToLatest
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -429,7 +421,7 @@ private func validateScheduledMessagesBatch(postbox: Postbox, network: Network,
|
|||||||
messages = apiMessages
|
messages = apiMessages
|
||||||
chats = apiChats
|
chats = apiChats
|
||||||
users = apiUsers
|
users = apiUsers
|
||||||
case let .channelMessages(_, pts, _, apiMessages, apiChats, apiUsers):
|
case let .channelMessages(_, _, _, apiMessages, apiChats, apiUsers):
|
||||||
messages = apiMessages
|
messages = apiMessages
|
||||||
chats = apiChats
|
chats = apiChats
|
||||||
users = apiUsers
|
users = apiUsers
|
||||||
@ -444,11 +436,15 @@ private func validateScheduledMessagesBatch(postbox: Postbox, network: Network,
|
|||||||
default:
|
default:
|
||||||
signal = .complete()
|
signal = .complete()
|
||||||
}
|
}
|
||||||
return validateBatch(postbox: postbox, network: network, transaction: transaction, accountPeerId: accountPeerId, tag: tag, historyState: historyState, signal: signal, previous: [:])
|
var previous: [MessageId: Message] = [:]
|
||||||
|
for message in messages {
|
||||||
|
previous[message.id] = message
|
||||||
|
}
|
||||||
|
return validateBatch(postbox: postbox, network: network, transaction: transaction, accountPeerId: accountPeerId, tag: tag, historyState: historyState, signal: signal, previous: previous, messageNamespace: Namespaces.Message.ScheduledCloud)
|
||||||
} |> switchToLatest
|
} |> switchToLatest
|
||||||
}
|
}
|
||||||
|
|
||||||
private func validateBatch(postbox: Postbox, network: Network, transaction: Transaction, accountPeerId: PeerId, tag: MessageTags?, historyState: HistoryState, signal: Signal<ValidatedMessages, MTRpcError>, previous: [MessageId: Message]) -> Signal<Void, NoError> {
|
private func validateBatch(postbox: Postbox, network: Network, transaction: Transaction, accountPeerId: PeerId, tag: MessageTags?, historyState: HistoryState, signal: Signal<ValidatedMessages, MTRpcError>, previous: [MessageId: Message], messageNamespace: MessageId.Namespace) -> Signal<Void, NoError> {
|
||||||
return signal
|
return signal
|
||||||
|> map(Optional.init)
|
|> map(Optional.init)
|
||||||
|> `catch` { _ -> Signal<ValidatedMessages?, NoError> in
|
|> `catch` { _ -> Signal<ValidatedMessages?, NoError> in
|
||||||
@ -463,7 +459,7 @@ private func validateBatch(postbox: Postbox, network: Network, transaction: Tran
|
|||||||
var storeMessages: [StoreMessage] = []
|
var storeMessages: [StoreMessage] = []
|
||||||
|
|
||||||
for message in messages {
|
for message in messages {
|
||||||
if let storeMessage = StoreMessage(apiMessage: message) {
|
if let storeMessage = StoreMessage(apiMessage: message, namespace: messageNamespace) {
|
||||||
var attributes = storeMessage.attributes
|
var attributes = storeMessage.attributes
|
||||||
if let channelPts = channelPts {
|
if let channelPts = channelPts {
|
||||||
attributes.append(ChannelMessageStateVersionAttribute(pts: channelPts))
|
attributes.append(ChannelMessageStateVersionAttribute(pts: channelPts))
|
||||||
@ -658,13 +654,8 @@ private func validateBatch(postbox: Postbox, network: Network, transaction: Tran
|
|||||||
return .update(StoreMessage(id: currentMessage.id, globallyUniqueId: currentMessage.globallyUniqueId, groupingKey: currentMessage.groupingKey, timestamp: currentMessage.timestamp, flags: StoreMessageFlags(currentMessage.flags), tags: updatedTags, globalTags: currentMessage.globalTags, localTags: currentMessage.localTags, forwardInfo: storeForwardInfo, authorId: currentMessage.author?.id, text: currentMessage.text, attributes: attributes, media: currentMessage.media))
|
return .update(StoreMessage(id: currentMessage.id, globallyUniqueId: currentMessage.globallyUniqueId, groupingKey: currentMessage.groupingKey, timestamp: currentMessage.timestamp, flags: StoreMessageFlags(currentMessage.flags), tags: updatedTags, globalTags: currentMessage.globalTags, localTags: currentMessage.localTags, forwardInfo: storeForwardInfo, authorId: currentMessage.author?.id, text: currentMessage.text, attributes: attributes, media: currentMessage.media))
|
||||||
})
|
})
|
||||||
} else {
|
} else {
|
||||||
switch historyState {
|
|
||||||
case .channel:
|
|
||||||
deleteMessages(transaction: transaction, mediaBox: postbox.mediaBox, ids: [id])
|
deleteMessages(transaction: transaction, mediaBox: postbox.mediaBox, ids: [id])
|
||||||
Logger.shared.log("HistoryValidation", "deleting message \(id) in \(id.peerId)")
|
Logger.shared.log("HistoryValidation", "deleting message \(id) in \(id.peerId)")
|
||||||
default:
|
|
||||||
break
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -296,7 +296,7 @@ class ChatScheduleTimeControllerNode: ViewControllerTracingNode, UIScrollViewDel
|
|||||||
let buttonHeight = self.doneButton.updateLayout(width: contentFrame.width - buttonInset * 2.0, transition: transition)
|
let buttonHeight = self.doneButton.updateLayout(width: contentFrame.width - buttonInset * 2.0, transition: transition)
|
||||||
transition.updateFrame(node: self.doneButton, frame: CGRect(x: buttonInset, y: contentHeight - buttonHeight - insets.bottom - 10.0, width: contentFrame.width, height: buttonHeight))
|
transition.updateFrame(node: self.doneButton, frame: CGRect(x: buttonInset, y: contentHeight - buttonHeight - insets.bottom - 10.0, width: contentFrame.width, height: buttonHeight))
|
||||||
|
|
||||||
self.pickerView.frame = CGRect(origin: CGPoint(x: 0.0, y: 54.0), size: CGSize(width: contentFrame.width, height: contentHeight))
|
self.pickerView.frame = CGRect(origin: CGPoint(x: 0.0, y: 54.0), size: CGSize(width: contentFrame.width, height: pickerHeight))
|
||||||
|
|
||||||
transition.updateFrame(node: self.contentContainerNode, frame: contentContainerFrame)
|
transition.updateFrame(node: self.contentContainerNode, frame: contentContainerFrame)
|
||||||
transition.updateFrame(node: self.separatorNode, frame: CGRect(origin: CGPoint(x: 0.0, y: titleHeight), size: CGSize(width: contentContainerFrame.size.width, height: UIScreenPixel)))
|
transition.updateFrame(node: self.separatorNode, frame: CGRect(origin: CGPoint(x: 0.0, y: titleHeight), size: CGSize(width: contentContainerFrame.size.width, height: UIScreenPixel)))
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user