From 1d730c968da4f39eefe807de9f37064a2a5ea444 Mon Sep 17 00:00:00 2001 From: Peter Date: Mon, 20 Mar 2017 18:34:28 +0300 Subject: [PATCH] no message --- .../AccountStateManagementUtils.swift | 63 +++++++++++--- TelegramCore/AccountStateManager.swift | 70 ++++++++++++++-- TelegramCore/AccountViewTracker.swift | 83 +++++++++++++++++-- .../ApplyMaxReadIndexInteractively.swift | 4 +- TelegramCore/ApplyUpdateMessage.swift | 2 +- .../ManagedSecretChatOutgoingOperations.swift | 4 +- ...essageContentAsConsumedInteractively.swift | 4 +- TelegramCore/PendingMessageManager.swift | 10 +-- .../PendingMessageUploadedContent.swift | 2 +- 9 files changed, 206 insertions(+), 36 deletions(-) diff --git a/TelegramCore/AccountStateManagementUtils.swift b/TelegramCore/AccountStateManagementUtils.swift index 2bfc24b758..daf175aa74 100644 --- a/TelegramCore/AccountStateManagementUtils.swift +++ b/TelegramCore/AccountStateManagementUtils.swift @@ -987,7 +987,7 @@ private func finalStateWithUpdates(account: Account, state: AccountMutableState, } } - var pollChannelSignals: [Signal<(AccountMutableState, Bool), NoError>] = [] + var pollChannelSignals: [Signal<(AccountMutableState, Bool, Int32?), NoError>] = [] for peerId in channelsToPoll { if let peer = updatedState.peers[peerId] { pollChannelSignals.append(pollChannel(account, peer: peer, state: updatedState.branch())) @@ -999,7 +999,7 @@ private func finalStateWithUpdates(account: Account, state: AccountMutableState, return combineLatest(pollChannelSignals) |> mapToSignal { states -> Signal in var finalState = updatedState var hadError = false - for (state, success) in states { + for (state, success, _) in states { finalState.merge(state) if !success { hadError = true @@ -1123,7 +1123,42 @@ private func resolveMissingPeerNotificationSettings(account: Account, state: Acc } } -private func pollChannel(_ account: Account, peer: Peer, state: AccountMutableState) -> Signal<(AccountMutableState, Bool), NoError> { +func keepPollingChannel(account: Account, peerId: PeerId, stateManager: AccountStateManager) -> Signal { + return account.postbox.modify { modifier -> Signal in + if let accountState = (modifier.getState() as? AuthorizedAccountState)?.state, let peer = modifier.getPeer(peerId) { + var channelStates: [PeerId: ChannelState] = [:] + if let channelState = modifier.getPeerChatState(peerId) as? ChannelState { + channelStates[peerId] = channelState + } + let initialPeers: [PeerId: Peer] = [peerId: peer] + var peerNotificationSettings: [PeerId: TelegramPeerNotificationSettings] = [:] + if let notificationSettings = modifier.getPeerNotificationSettings(peerId) as? TelegramPeerNotificationSettings { + peerNotificationSettings[peerId] = notificationSettings + } + let initialState = AccountMutableState(initialState: AccountInitialState(state: accountState, peerIds: Set(), messageIds: Set(), peerIdsWithNewMessages: Set(), channelStates: channelStates, peerNotificationSettings: peerNotificationSettings, locallyGeneratedMessageTimestamps: [:]), initialPeers: initialPeers, initialStoredMessages: Set(), initialReadInboxMaxIds: [:], storedMessagesByPeerIdAndTimestamp: [:]) + return pollChannel(account, peer: peer, state: initialState) + |> mapToSignal { (finalState, _, timeout) -> Signal in + return resolveAssociatedMessages(account: account, state: finalState) + |> mapToSignal { resultingState -> Signal in + return resolveMissingPeerNotificationSettings(account: account, state: resultingState) + |> map { resultingState -> AccountFinalState in + return AccountFinalState(state: resultingState, shouldPoll: false, incomplete: false) + } + } + |> mapToSignal { finalState -> Signal in + return stateManager.addReplayAsynchronouslyBuiltFinalState(finalState) + |> mapToSignal { _ -> Signal in + return .complete() |> delay(Double(timeout ?? 30), queue: Queue.concurrentDefaultQueue()) + } + } + } + } else { + return .complete() |> delay(30.0, queue: Queue.concurrentDefaultQueue()) + } + } |> switchToLatest |> restart +} + +private func pollChannel(_ account: Account, peer: Peer, state: AccountMutableState) -> Signal<(AccountMutableState, Bool, Int32?), NoError> { if let inputChannel = apiInputChannel(peer) { return (account.network.request(Api.functions.updates.getChannelDifference(flags: 0, channel: inputChannel, filter: .channelMessagesFilterEmpty, pts: state.channelStates[peer.id]?.pts ?? 1, limit: 20)) |> map { Optional($0) } @@ -1135,11 +1170,13 @@ private func pollChannel(_ account: Account, peer: Peer, state: AccountMutableSt } }) |> retryRequest - |> map { difference -> (AccountMutableState, Bool) in + |> map { difference -> (AccountMutableState, Bool, Int32?) in var updatedState = state + var apiTimeout: Int32? if let difference = difference { switch difference { - case let .channelDifference(_, pts, _, newMessages, otherUpdates, chats, users): + case let .channelDifference(_, pts, timeout, newMessages, otherUpdates, chats, users): + apiTimeout = timeout let channelState: ChannelState if let previousState = updatedState.channelStates[peer.id] { channelState = previousState.setPts(pts) @@ -1170,7 +1207,9 @@ private func pollChannel(_ account: Account, peer: Peer, state: AccountMutableSt break } } - case let .channelDifferenceEmpty(_, pts, _): + case let .channelDifferenceEmpty(_, pts, timeout): + apiTimeout = timeout + let channelState: ChannelState if let previousState = updatedState.channelStates[peer.id] { channelState = previousState.setPts(pts) @@ -1178,7 +1217,9 @@ private func pollChannel(_ account: Account, peer: Peer, state: AccountMutableSt channelState = ChannelState(pts: pts) } updatedState.updateChannelState(peer.id, state: channelState) - case let .channelDifferenceTooLong(_, pts, _, topMessage, readInboxMaxId, readOutboxMaxId, unreadCount, messages, chats, users): + case let .channelDifferenceTooLong(_, pts, timeout, topMessage, readInboxMaxId, readOutboxMaxId, unreadCount, messages, chats, users): + apiTimeout = timeout + let channelState: ChannelState if let previousState = updatedState.channelStates[peer.id] { channelState = previousState.setPts(pts) @@ -1213,11 +1254,11 @@ private func pollChannel(_ account: Account, peer: Peer, state: AccountMutableSt updatedState.resetReadState(peer.id, namespace: Namespaces.Message.Cloud, maxIncomingReadId: readInboxMaxId, maxOutgoingReadId: readOutboxMaxId, maxKnownId: topMessage, count: unreadCount) } } - return (updatedState, difference != nil) + return (updatedState, difference != nil, apiTimeout) } } else { Logger.shared.log("State", "can't poll channel \(peer.id): can't create inputChannel") - return single((state, true), NoError.self) + return single((state, true, nil), NoError.self) } } @@ -1387,7 +1428,7 @@ func replayFinalState(accountPeerId: PeerId, mediaBox: MediaBox, modifier: Modif case let .DeleteMessages(ids): modifier.deleteMessages(ids) case let .EditMessage(id, message): - modifier.updateMessage(id, update: { _ in message }) + modifier.updateMessage(id, update: { _ in .update(message) }) case let .UpdateMedia(id, media): modifier.updateMedia(id, update: media) if let media = media as? TelegramMediaWebpage { @@ -1507,7 +1548,7 @@ func replayFinalState(accountPeerId: PeerId, mediaBox: MediaBox, modifier: Modif break loop } } - return StoreMessage(id: currentMessage.id, globallyUniqueId: currentMessage.globallyUniqueId, timestamp: currentMessage.timestamp, flags: StoreMessageFlags(currentMessage.flags), tags: currentMessage.tags, forwardInfo: storeForwardInfo, authorId: currentMessage.author?.id, text: currentMessage.text, attributes: attributes, media: currentMessage.media) + return .update(StoreMessage(id: currentMessage.id, globallyUniqueId: currentMessage.globallyUniqueId, timestamp: currentMessage.timestamp, flags: StoreMessageFlags(currentMessage.flags), tags: currentMessage.tags, forwardInfo: storeForwardInfo, authorId: currentMessage.author?.id, text: currentMessage.text, attributes: attributes, media: currentMessage.media)) }) case let .UpdateInstalledStickerPacks(operation): stickerPackOperations.append(operation) diff --git a/TelegramCore/AccountStateManager.swift b/TelegramCore/AccountStateManager.swift index 9287c6c75d..78853b1daa 100644 --- a/TelegramCore/AccountStateManager.swift +++ b/TelegramCore/AccountStateManager.swift @@ -16,6 +16,7 @@ private enum AccountStateManagerOperation { case custom(Int32, Signal) case pollCompletion(Int32, [MessageId], [(Int32, ([MessageId]) -> Void)]) case processEvents(Int32, AccountFinalStateEvents) + case replayAsynchronouslyBuiltFinalState(AccountFinalState, () -> Void) } #if os(macOS) @@ -117,7 +118,7 @@ public final class AccountStateManager { self.queue.async { if let last = self.operations.last { switch last { - case .pollDifference, .processUpdateGroups, .custom, .pollCompletion, .processEvents: + case .pollDifference, .processUpdateGroups, .custom, .pollCompletion, .processEvents, .replayAsynchronouslyBuiltFinalState: self.operations.append(.collectUpdateGroups(groups, 0.0)) case let .collectUpdateGroups(currentGroups, timestamp): if timestamp.isEqual(to: 0.0) { @@ -134,6 +135,22 @@ public final class AccountStateManager { } } + func addReplayAsynchronouslyBuiltFinalState(_ finalState: AccountFinalState) -> Signal { + return Signal { subscriber in + self.queue.async { + let begin = self.operations.isEmpty + self.operations.append(.replayAsynchronouslyBuiltFinalState(finalState, { + subscriber.putNext(true) + subscriber.putCompletion() + })) + if begin { + self.startFirstOperation() + } + } + return EmptyDisposable + } + } + func addCustomOperation(_ f: Signal) -> Signal { let pipe = ValuePipe>() return Signal { subscriber in @@ -169,13 +186,17 @@ public final class AccountStateManager { private func replaceOperations(with operation: AccountStateManagerOperation) { var collectedMessageIds: [MessageId] = [] var collectedPollCompletionSubscribers: [(Int32, ([MessageId]) -> Void)] = [] + var collectedReplayAsynchronouslyBuiltFinalState: [(AccountFinalState, () -> Void)] = [] - if !self.operations.isEmpty { - for operation in self.operations { - if case let .pollCompletion(_, messageIds, subscribers) = operation { + for operation in self.operations { + switch operation { + case let .pollCompletion(_, messageIds, subscribers): collectedMessageIds.append(contentsOf: messageIds) collectedPollCompletionSubscribers.append(contentsOf: subscribers) - } + case let .replayAsynchronouslyBuiltFinalState(finalState, completion): + collectedReplayAsynchronouslyBuiltFinalState.append((finalState, completion)) + default: + break } } @@ -185,6 +206,10 @@ public final class AccountStateManager { if !collectedPollCompletionSubscribers.isEmpty || !collectedMessageIds.isEmpty { self.operations.append(.pollCompletion(self.getNextId(), collectedMessageIds, collectedPollCompletionSubscribers)) } + + for (finalState, completion) in collectedReplayAsynchronouslyBuiltFinalState { + self.operations.append(.replayAsynchronouslyBuiltFinalState(finalState, completion)) + } } private func addOperation(_ operation: AccountStateManagerOperation) { @@ -477,6 +502,41 @@ public final class AccountStateManager { completed() }) } + case let .replayAsynchronouslyBuiltFinalState(finalState, completion): + if !finalState.state.preCachedResources.isEmpty { + for (resource, data) in finalState.state.preCachedResources { + self.account.postbox.mediaBox.storeResourceData(resource.id, data: data) + } + } + + let accountPeerId = self.account.peerId + let mediaBox = self.account.postbox.mediaBox + let signal = self.account.postbox.modify { modifier -> AccountReplayedFinalState? in + return replayFinalState(accountPeerId: accountPeerId, mediaBox: mediaBox, modifier: modifier, finalState: finalState) + } + |> map({ ($0, finalState) }) + |> deliverOn(self.queue) + + let _ = signal.start(next: { [weak self] replayedState, finalState in + if let strongSelf = self { + if case .replayAsynchronouslyBuiltFinalState = strongSelf.operations.removeFirst() { + if let replayedState = replayedState { + let events = AccountFinalStateEvents(state: replayedState) + if !events.isEmpty { + strongSelf.insertProcessEvents(events) + } + } + strongSelf.startFirstOperation() + } else { + assertionFailure() + } + completion() + } + }, error: { _ in + assertionFailure() + Logger.shared.log("AccountStateManager", "processUpdateGroups signal completed with error") + completion() + }) } } diff --git a/TelegramCore/AccountViewTracker.swift b/TelegramCore/AccountViewTracker.swift index c5dbf9b003..98e0343416 100644 --- a/TelegramCore/AccountViewTracker.swift +++ b/TelegramCore/AccountViewTracker.swift @@ -132,6 +132,15 @@ private final class CachedChannelParticipantsContext { } } +private final class ChannelPollingContext { + var subscribers = Bag() + let disposable = MetaDisposable() + + deinit { + self.disposable.dispose() + } +} + public final class AccountViewTracker { weak var account: Account? private let queue = Queue() @@ -148,6 +157,8 @@ public final class AccountViewTracker { private var cachedDataContexts: [PeerId: PeerCachedDataContext] = [:] private var cachedChannelParticipantsContexts: [PeerId: CachedChannelParticipantsContext] = [:] + private var channelPollingContexts: [PeerId: ChannelPollingContext] = [:] + init(account: Account) { self.account = account } @@ -216,7 +227,7 @@ public final class AccountViewTracker { } } - public func updatedViewCountMessageIds(messageIds: Set) { + public func updateViewCountForMessageIds(messageIds: Set) { self.queue.async { var addedMessageIds: [MessageId] = [] let timestamp = Int32(CFAbsoluteTimeGetCurrent()) @@ -253,11 +264,14 @@ public final class AccountViewTracker { var attributes = currentMessage.attributes loop: for j in 0 ..< attributes.count { if let attribute = attributes[j] as? ViewCountMessageAttribute { + if attribute.count >= Int(viewCounts[i]) { + return .skip + } attributes[j] = ViewCountMessageAttribute(count: max(attribute.count, Int(viewCounts[i]))) break loop } } - return StoreMessage(id: currentMessage.id, globallyUniqueId: currentMessage.globallyUniqueId, timestamp: currentMessage.timestamp, flags: StoreMessageFlags(currentMessage.flags), tags: currentMessage.tags, forwardInfo: storeForwardInfo, authorId: currentMessage.author?.id, text: currentMessage.text, attributes: attributes, media: currentMessage.media) + return .update(StoreMessage(id: currentMessage.id, globallyUniqueId: currentMessage.globallyUniqueId, timestamp: currentMessage.timestamp, flags: StoreMessageFlags(currentMessage.flags), tags: currentMessage.tags, forwardInfo: storeForwardInfo, authorId: currentMessage.author?.id, text: currentMessage.text, attributes: attributes, media: currentMessage.media)) }) } } @@ -323,8 +337,44 @@ public final class AccountViewTracker { } } - func wrappedMessageHistorySignal(_ signal: Signal<(MessageHistoryView, ViewUpdateType, InitialMessageHistoryData?), NoError>) -> Signal<(MessageHistoryView, ViewUpdateType, InitialMessageHistoryData?), NoError> { - return withState(signal, { [weak self] () -> Int32 in + private func polledChannel(peerId: PeerId) -> Signal { + return Signal { subscriber in + let disposable = MetaDisposable() + self.queue.async { + let context: ChannelPollingContext + if let current = self.channelPollingContexts[peerId] { + context = current + } else { + context = ChannelPollingContext() + self.channelPollingContexts[peerId] = context + } + + if context.subscribers.isEmpty { + if let account = self.account { + context.disposable.set(keepPollingChannel(account: account, peerId: peerId, stateManager: account.stateManager).start()) + } + } + + let index = context.subscribers.add(Void()) + + disposable.set(ActionDisposable { + self.queue.async { + if let context = self.channelPollingContexts[peerId] { + context.subscribers.remove(index) + if context.subscribers.isEmpty { + context.disposable.set(nil) + } + } + } + }) + } + + return disposable + } + } + + func wrappedMessageHistorySignal(peerId: PeerId, signal: Signal<(MessageHistoryView, ViewUpdateType, InitialMessageHistoryData?), NoError>) -> Signal<(MessageHistoryView, ViewUpdateType, InitialMessageHistoryData?), NoError> { + let history = withState(signal, { [weak self] () -> Int32 in if let strongSelf = self { return OSAtomicIncrement32(&strongSelf.nextViewId) } else { @@ -340,12 +390,31 @@ public final class AccountViewTracker { strongSelf.updatePendingWebpages(viewId: viewId, messageIds: []) } }) + + if peerId.namespace == Namespaces.Peer.CloudChannel { + return Signal { subscriber in + let disposable = history.start(next: { next in + subscriber.putNext(next) + }, error: { error in + subscriber.putError(error) + }, completed: { + subscriber.putCompletion() + }) + let polled = self.polledChannel(peerId: peerId).start() + return ActionDisposable { + disposable.dispose() + polled.dispose() + } + } + } else { + return history + } } public func aroundUnreadMessageHistoryViewForPeerId(_ peerId: PeerId, count: Int, tagMask: MessageTags? = nil, additionalData: [AdditionalMessageHistoryViewData] = []) -> Signal<(MessageHistoryView, ViewUpdateType, InitialMessageHistoryData?), NoError> { if let account = self.account { let signal = account.postbox.aroundUnreadMessageHistoryViewForPeerId(peerId, count: count, topTaggedMessageIdNamespaces: [Namespaces.Message.Cloud], tagMask: tagMask, additionalData: additionalData) - return wrappedMessageHistorySignal(signal) + return wrappedMessageHistorySignal(peerId: peerId, signal: signal) } else { return .never() } @@ -354,7 +423,7 @@ public final class AccountViewTracker { public func aroundIdMessageHistoryViewForPeerId(_ peerId: PeerId, count: Int, messageId: MessageId, tagMask: MessageTags? = nil, additionalData: [AdditionalMessageHistoryViewData] = []) -> Signal<(MessageHistoryView, ViewUpdateType, InitialMessageHistoryData?), NoError> { if let account = self.account { let signal = account.postbox.aroundIdMessageHistoryViewForPeerId(peerId, count: count, messageId: messageId, topTaggedMessageIdNamespaces: [Namespaces.Message.Cloud], tagMask: tagMask, additionalData: additionalData) - return wrappedMessageHistorySignal(signal) + return wrappedMessageHistorySignal(peerId: peerId, signal: signal) } else { return .never() } @@ -363,7 +432,7 @@ public final class AccountViewTracker { public func aroundMessageHistoryViewForPeerId(_ peerId: PeerId, index: MessageIndex, count: Int, anchorIndex: MessageIndex, fixedCombinedReadState: CombinedPeerReadState?, tagMask: MessageTags? = nil, additionalData: [AdditionalMessageHistoryViewData] = []) -> Signal<(MessageHistoryView, ViewUpdateType, InitialMessageHistoryData?), NoError> { if let account = self.account { let signal = account.postbox.aroundMessageHistoryViewForPeerId(peerId, index: index, count: count, anchorIndex: anchorIndex, fixedCombinedReadState: fixedCombinedReadState, topTaggedMessageIdNamespaces: [Namespaces.Message.Cloud], tagMask: tagMask, additionalData: additionalData) - return wrappedMessageHistorySignal(signal) + return wrappedMessageHistorySignal(peerId: peerId, signal: signal) } else { return .never() } diff --git a/TelegramCore/ApplyMaxReadIndexInteractively.swift b/TelegramCore/ApplyMaxReadIndexInteractively.swift index cfb04a20bc..79e4ae701d 100644 --- a/TelegramCore/ApplyMaxReadIndexInteractively.swift +++ b/TelegramCore/ApplyMaxReadIndexInteractively.swift @@ -29,7 +29,7 @@ public func applyMaxReadIndexInteractively(postbox: Postbox, network: Network, i return currentAttribute } }) - return StoreMessage(id: currentMessage.id, globallyUniqueId: currentMessage.globallyUniqueId, timestamp: currentMessage.timestamp, flags: StoreMessageFlags(currentMessage.flags), tags: currentMessage.tags, forwardInfo: storeForwardInfo, authorId: currentMessage.author?.id, text: currentMessage.text, attributes: updatedAttributes, media: currentMessage.media) + return .update(StoreMessage(id: currentMessage.id, globallyUniqueId: currentMessage.globallyUniqueId, timestamp: currentMessage.timestamp, flags: StoreMessageFlags(currentMessage.flags), tags: currentMessage.tags, forwardInfo: storeForwardInfo, authorId: currentMessage.author?.id, text: currentMessage.text, attributes: updatedAttributes, media: currentMessage.media)) }) modifier.addTimestampBasedMessageAttribute(tag: 0, timestamp: timestamp + attribute.timeout, messageId: id) } @@ -62,7 +62,7 @@ func applyOutgoingReadMaxIndex(modifier: Modifier, index: MessageIndex, beginAt return currentAttribute } }) - return StoreMessage(id: currentMessage.id, globallyUniqueId: currentMessage.globallyUniqueId, timestamp: currentMessage.timestamp, flags: StoreMessageFlags(currentMessage.flags), tags: currentMessage.tags, forwardInfo: storeForwardInfo, authorId: currentMessage.author?.id, text: currentMessage.text, attributes: updatedAttributes, media: currentMessage.media) + return .update(StoreMessage(id: currentMessage.id, globallyUniqueId: currentMessage.globallyUniqueId, timestamp: currentMessage.timestamp, flags: StoreMessageFlags(currentMessage.flags), tags: currentMessage.tags, forwardInfo: storeForwardInfo, authorId: currentMessage.author?.id, text: currentMessage.text, attributes: updatedAttributes, media: currentMessage.media)) }) modifier.addTimestampBasedMessageAttribute(tag: 0, timestamp: timestamp + attribute.timeout, messageId: id) } diff --git a/TelegramCore/ApplyUpdateMessage.swift b/TelegramCore/ApplyUpdateMessage.swift index 7d94a1e34f..514efe1396 100644 --- a/TelegramCore/ApplyUpdateMessage.swift +++ b/TelegramCore/ApplyUpdateMessage.swift @@ -115,7 +115,7 @@ func applyUpdateMessage(postbox: Postbox, stateManager: AccountStateManager, mes } } - return StoreMessage(id: updatedId, globallyUniqueId: nil, timestamp: updatedTimestamp ?? currentMessage.timestamp, flags: [], tags: tagsForStoreMessage(media: media, textEntities: entitiesAttribute?.entities), forwardInfo: storeForwardInfo, authorId: currentMessage.author?.id, text: text, attributes: attributes, media: media) + return .update(StoreMessage(id: updatedId, globallyUniqueId: nil, timestamp: updatedTimestamp ?? currentMessage.timestamp, flags: [], tags: tagsForStoreMessage(media: media, textEntities: entitiesAttribute?.entities), forwardInfo: storeForwardInfo, authorId: currentMessage.author?.id, text: text, attributes: attributes, media: media)) }) if let updatedTimestamp = updatedTimestamp { modifier.offsetPendingMessagesTimestamps(lowerBound: message.id, timestamp: updatedTimestamp) diff --git a/TelegramCore/ManagedSecretChatOutgoingOperations.swift b/TelegramCore/ManagedSecretChatOutgoingOperations.swift index 6cdbcb9702..2c85f95bab 100644 --- a/TelegramCore/ManagedSecretChatOutgoingOperations.swift +++ b/TelegramCore/ManagedSecretChatOutgoingOperations.swift @@ -669,7 +669,7 @@ private func sendMessage(postbox: Postbox, network: Network, messageId: MessageI if let forwardInfo = currentMessage.forwardInfo { storeForwardInfo = StoreMessageForwardInfo(authorId: forwardInfo.author.id, sourceId: forwardInfo.source?.id, sourceMessageId: forwardInfo.sourceMessageId, date: forwardInfo.date) } - return StoreMessage(id: currentMessage.id, globallyUniqueId: currentMessage.globallyUniqueId, timestamp: timestamp, flags: flags, tags: currentMessage.tags, forwardInfo: storeForwardInfo, authorId: currentMessage.author?.id, text: currentMessage.text, attributes: currentMessage.attributes, media: currentMessage.media) + return .update(StoreMessage(id: currentMessage.id, globallyUniqueId: currentMessage.globallyUniqueId, timestamp: timestamp, flags: flags, tags: currentMessage.tags, forwardInfo: storeForwardInfo, authorId: currentMessage.author?.id, text: currentMessage.text, attributes: currentMessage.attributes, media: currentMessage.media)) }) } } @@ -711,7 +711,7 @@ private func sendServiceActionMessage(postbox: Postbox, network: Network, peerId if let forwardInfo = currentMessage.forwardInfo { storeForwardInfo = StoreMessageForwardInfo(authorId: forwardInfo.author.id, sourceId: forwardInfo.source?.id, sourceMessageId: forwardInfo.sourceMessageId, date: forwardInfo.date) } - return StoreMessage(id: currentMessage.id, globallyUniqueId: currentMessage.globallyUniqueId, timestamp: timestamp, flags: flags, tags: currentMessage.tags, forwardInfo: storeForwardInfo, authorId: currentMessage.author?.id, text: currentMessage.text, attributes: currentMessage.attributes, media: currentMessage.media) + return .update(StoreMessage(id: currentMessage.id, globallyUniqueId: currentMessage.globallyUniqueId, timestamp: timestamp, flags: flags, tags: currentMessage.tags, forwardInfo: storeForwardInfo, authorId: currentMessage.author?.id, text: currentMessage.text, attributes: currentMessage.attributes, media: currentMessage.media)) }) } } diff --git a/TelegramCore/MarkMessageContentAsConsumedInteractively.swift b/TelegramCore/MarkMessageContentAsConsumedInteractively.swift index 754fa0cca7..8044e46d2a 100644 --- a/TelegramCore/MarkMessageContentAsConsumedInteractively.swift +++ b/TelegramCore/MarkMessageContentAsConsumedInteractively.swift @@ -66,7 +66,7 @@ public func markMessageContentAsConsumedInteractively(postbox: Postbox, network: if let forwardInfo = currentMessage.forwardInfo { storeForwardInfo = StoreMessageForwardInfo(authorId: forwardInfo.author.id, sourceId: forwardInfo.source?.id, sourceMessageId: forwardInfo.sourceMessageId, date: forwardInfo.date) } - return StoreMessage(id: currentMessage.id, globallyUniqueId: currentMessage.globallyUniqueId, timestamp: currentMessage.timestamp, flags: StoreMessageFlags(currentMessage.flags), tags: currentMessage.tags, forwardInfo: storeForwardInfo, authorId: currentMessage.author?.id, text: currentMessage.text, attributes: updatedAttributes, media: currentMessage.media) + return .update(StoreMessage(id: currentMessage.id, globallyUniqueId: currentMessage.globallyUniqueId, timestamp: currentMessage.timestamp, flags: StoreMessageFlags(currentMessage.flags), tags: currentMessage.tags, forwardInfo: storeForwardInfo, authorId: currentMessage.author?.id, text: currentMessage.text, attributes: updatedAttributes, media: currentMessage.media)) }) } } @@ -108,7 +108,7 @@ func markMessageContentAsConsumedRemotely(modifier: Modifier, messageId: Message if let forwardInfo = currentMessage.forwardInfo { storeForwardInfo = StoreMessageForwardInfo(authorId: forwardInfo.author.id, sourceId: forwardInfo.source?.id, sourceMessageId: forwardInfo.sourceMessageId, date: forwardInfo.date) } - return StoreMessage(id: currentMessage.id, globallyUniqueId: currentMessage.globallyUniqueId, timestamp: currentMessage.timestamp, flags: StoreMessageFlags(currentMessage.flags), tags: currentMessage.tags, forwardInfo: storeForwardInfo, authorId: currentMessage.author?.id, text: currentMessage.text, attributes: updatedAttributes, media: currentMessage.media) + return .update(StoreMessage(id: currentMessage.id, globallyUniqueId: currentMessage.globallyUniqueId, timestamp: currentMessage.timestamp, flags: StoreMessageFlags(currentMessage.flags), tags: currentMessage.tags, forwardInfo: storeForwardInfo, authorId: currentMessage.author?.id, text: currentMessage.text, attributes: updatedAttributes, media: currentMessage.media)) }) } } diff --git a/TelegramCore/PendingMessageManager.swift b/TelegramCore/PendingMessageManager.swift index 646640ef7f..41ad4a7ab7 100644 --- a/TelegramCore/PendingMessageManager.swift +++ b/TelegramCore/PendingMessageManager.swift @@ -270,7 +270,7 @@ public final class PendingMessageManager { if let forwardInfo = currentMessage.forwardInfo { storeForwardInfo = StoreMessageForwardInfo(authorId: forwardInfo.author.id, sourceId: forwardInfo.source?.id, sourceMessageId: forwardInfo.sourceMessageId, date: forwardInfo.date) } - return StoreMessage(id: currentMessage.id, globallyUniqueId: currentMessage.globallyUniqueId, timestamp: currentMessage.timestamp, flags: flags, tags: currentMessage.tags, forwardInfo: storeForwardInfo, authorId: currentMessage.author?.id, text: currentMessage.text, attributes: currentMessage.attributes, media: currentMessage.media) + return .update(StoreMessage(id: currentMessage.id, globallyUniqueId: currentMessage.globallyUniqueId, timestamp: currentMessage.timestamp, flags: flags, tags: currentMessage.tags, forwardInfo: storeForwardInfo, authorId: currentMessage.author?.id, text: currentMessage.text, attributes: currentMessage.attributes, media: currentMessage.media)) }) } break @@ -291,7 +291,7 @@ public final class PendingMessageManager { if let forwardInfo = currentMessage.forwardInfo { storeForwardInfo = StoreMessageForwardInfo(authorId: forwardInfo.author.id, sourceId: forwardInfo.source?.id, sourceMessageId: forwardInfo.sourceMessageId, date: forwardInfo.date) } - return StoreMessage(id: currentMessage.id, globallyUniqueId: currentMessage.globallyUniqueId, timestamp: currentMessage.timestamp, flags: flags, tags: currentMessage.tags, forwardInfo: storeForwardInfo, authorId: currentMessage.author?.id, text: currentMessage.text, attributes: currentMessage.attributes, media: currentMessage.media) + return .update(StoreMessage(id: currentMessage.id, globallyUniqueId: currentMessage.globallyUniqueId, timestamp: currentMessage.timestamp, flags: flags, tags: currentMessage.tags, forwardInfo: storeForwardInfo, authorId: currentMessage.author?.id, text: currentMessage.text, attributes: currentMessage.attributes, media: currentMessage.media)) }) } } else { @@ -300,7 +300,7 @@ public final class PendingMessageManager { if let forwardInfo = currentMessage.forwardInfo { storeForwardInfo = StoreMessageForwardInfo(authorId: forwardInfo.author.id, sourceId: forwardInfo.source?.id, sourceMessageId: forwardInfo.sourceMessageId, date: forwardInfo.date) } - return StoreMessage(id: message.id, globallyUniqueId: currentMessage.globallyUniqueId, timestamp: currentMessage.timestamp, flags: [.Failed], tags: currentMessage.tags, forwardInfo: storeForwardInfo, authorId: currentMessage.author?.id, text: currentMessage.text, attributes: currentMessage.attributes, media: currentMessage.media) + return .update(StoreMessage(id: message.id, globallyUniqueId: currentMessage.globallyUniqueId, timestamp: currentMessage.timestamp, flags: [.Failed], tags: currentMessage.tags, forwardInfo: storeForwardInfo, authorId: currentMessage.author?.id, text: currentMessage.text, attributes: currentMessage.attributes, media: currentMessage.media)) }) } return .complete() @@ -383,7 +383,7 @@ public final class PendingMessageManager { if let forwardInfo = currentMessage.forwardInfo { storeForwardInfo = StoreMessageForwardInfo(authorId: forwardInfo.author.id, sourceId: forwardInfo.source?.id, sourceMessageId: forwardInfo.sourceMessageId, date: forwardInfo.date) } - return StoreMessage(id: message.id, globallyUniqueId: currentMessage.globallyUniqueId, timestamp: currentMessage.timestamp, flags: [.Failed], tags: currentMessage.tags, forwardInfo: storeForwardInfo, authorId: currentMessage.author?.id, text: currentMessage.text, attributes: currentMessage.attributes, media: currentMessage.media) + return .update(StoreMessage(id: message.id, globallyUniqueId: currentMessage.globallyUniqueId, timestamp: currentMessage.timestamp, flags: [.Failed], tags: currentMessage.tags, forwardInfo: storeForwardInfo, authorId: currentMessage.author?.id, text: currentMessage.text, attributes: currentMessage.attributes, media: currentMessage.media)) }) } @@ -396,7 +396,7 @@ public final class PendingMessageManager { if let forwardInfo = currentMessage.forwardInfo { storeForwardInfo = StoreMessageForwardInfo(authorId: forwardInfo.author.id, sourceId: forwardInfo.source?.id, sourceMessageId: forwardInfo.sourceMessageId, date: forwardInfo.date) } - return StoreMessage(id: message.id, globallyUniqueId: currentMessage.globallyUniqueId, timestamp: currentMessage.timestamp, flags: [.Failed], tags: currentMessage.tags, forwardInfo: storeForwardInfo, authorId: currentMessage.author?.id, text: currentMessage.text, attributes: currentMessage.attributes, media: currentMessage.media) + return .update(StoreMessage(id: message.id, globallyUniqueId: currentMessage.globallyUniqueId, timestamp: currentMessage.timestamp, flags: [.Failed], tags: currentMessage.tags, forwardInfo: storeForwardInfo, authorId: currentMessage.author?.id, text: currentMessage.text, attributes: currentMessage.attributes, media: currentMessage.media)) }) } } diff --git a/TelegramCore/PendingMessageUploadedContent.swift b/TelegramCore/PendingMessageUploadedContent.swift index 7c2314c607..3501f31115 100644 --- a/TelegramCore/PendingMessageUploadedContent.swift +++ b/TelegramCore/PendingMessageUploadedContent.swift @@ -195,7 +195,7 @@ private func uploadedMediaFileContent(network: Network, postbox: Postbox, transf } else { updatedAttributes.append(OutgoingMessageInfoAttribute(uniqueId: arc4random64(), flags: [.transformedMedia])) } - return StoreMessage(id: currentMessage.id, globallyUniqueId: currentMessage.globallyUniqueId, timestamp: currentMessage.timestamp, flags: StoreMessageFlags(currentMessage.flags), tags: currentMessage.tags, forwardInfo: storeForwardInfo, authorId: currentMessage.author?.id, text: currentMessage.text, attributes: updatedAttributes, media: currentMessage.media) + return .update(StoreMessage(id: currentMessage.id, globallyUniqueId: currentMessage.globallyUniqueId, timestamp: currentMessage.timestamp, flags: StoreMessageFlags(currentMessage.flags), tags: currentMessage.tags, forwardInfo: storeForwardInfo, authorId: currentMessage.author?.id, text: currentMessage.text, attributes: updatedAttributes, media: currentMessage.media)) }) } return .done(media)