From 14941cd07522cbe48be23c2e2322c489c5d1a16d Mon Sep 17 00:00:00 2001 From: Peter Date: Tue, 9 May 2017 20:50:23 +0300 Subject: [PATCH] no message --- .../AccountStateManagementUtils.swift | 4 +- TelegramCore/AccountViewTracker.swift | 2 +- .../ApplyMaxReadIndexInteractively.swift | 4 +- TelegramCore/ApplyUpdateMessage.swift | 2 +- TelegramCore/CallSessionManager.swift | 96 +++++++++++-------- TelegramCore/EnqueueMessage.swift | 4 +- .../ManagedSecretChatOutgoingOperations.swift | 4 +- ...essageContentAsConsumedInteractively.swift | 4 +- TelegramCore/MessageUtils.swift | 2 +- TelegramCore/PendingMessageManager.swift | 10 +- .../PendingMessageUploadedContent.swift | 2 +- ...ecretChatIncomingDecryptedOperations.swift | 12 +-- TelegramCore/StoreMessage_Telegram.swift | 8 +- 13 files changed, 89 insertions(+), 65 deletions(-) diff --git a/TelegramCore/AccountStateManagementUtils.swift b/TelegramCore/AccountStateManagementUtils.swift index 7085f095ef..a6ac0b82a3 100644 --- a/TelegramCore/AccountStateManagementUtils.swift +++ b/TelegramCore/AccountStateManagementUtils.swift @@ -786,7 +786,7 @@ private func finalStateWithUpdates(account: Account, state: AccountMutableState, medias.append(mediaValue) } - let message = StoreMessage(peerId: peerId, namespace: Namespaces.Message.Local, globallyUniqueId: nil, timestamp: date, flags: [.Incoming], tags: [], forwardInfo: nil, authorId: peerId, text: messageText, attributes: attributes, media: []) + let message = StoreMessage(peerId: peerId, namespace: Namespaces.Message.Local, globallyUniqueId: nil, timestamp: date, flags: [.Incoming], tags: [], globalTags: [], forwardInfo: nil, authorId: peerId, text: messageText, attributes: attributes, media: []) updatedState.addMessages([message], location: .UpperHistoryBlock) } } @@ -1564,7 +1564,7 @@ func replayFinalState(accountPeerId: PeerId, mediaBox: MediaBox, modifier: Modif break loop } } - 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)) + return .update(StoreMessage(id: currentMessage.id, globallyUniqueId: currentMessage.globallyUniqueId, timestamp: currentMessage.timestamp, flags: StoreMessageFlags(currentMessage.flags), tags: currentMessage.tags, globalTags: currentMessage.globalTags, 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/AccountViewTracker.swift b/TelegramCore/AccountViewTracker.swift index 88cfddf6d6..db7119a230 100644 --- a/TelegramCore/AccountViewTracker.swift +++ b/TelegramCore/AccountViewTracker.swift @@ -282,7 +282,7 @@ public final class AccountViewTracker { break loop } } - 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)) + return .update(StoreMessage(id: currentMessage.id, globallyUniqueId: currentMessage.globallyUniqueId, timestamp: currentMessage.timestamp, flags: StoreMessageFlags(currentMessage.flags), tags: currentMessage.tags, globalTags: currentMessage.globalTags, forwardInfo: storeForwardInfo, authorId: currentMessage.author?.id, text: currentMessage.text, attributes: attributes, media: currentMessage.media)) }) } } diff --git a/TelegramCore/ApplyMaxReadIndexInteractively.swift b/TelegramCore/ApplyMaxReadIndexInteractively.swift index 79e4ae701d..5975f31646 100644 --- a/TelegramCore/ApplyMaxReadIndexInteractively.swift +++ b/TelegramCore/ApplyMaxReadIndexInteractively.swift @@ -29,7 +29,7 @@ public func applyMaxReadIndexInteractively(postbox: Postbox, network: Network, i return currentAttribute } }) - 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 .update(StoreMessage(id: currentMessage.id, globallyUniqueId: currentMessage.globallyUniqueId, timestamp: currentMessage.timestamp, flags: StoreMessageFlags(currentMessage.flags), tags: currentMessage.tags, globalTags: currentMessage.globalTags, 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 .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 .update(StoreMessage(id: currentMessage.id, globallyUniqueId: currentMessage.globallyUniqueId, timestamp: currentMessage.timestamp, flags: StoreMessageFlags(currentMessage.flags), tags: currentMessage.tags, globalTags: currentMessage.globalTags, 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 633323d359..39c652c234 100644 --- a/TelegramCore/ApplyUpdateMessage.swift +++ b/TelegramCore/ApplyUpdateMessage.swift @@ -122,7 +122,7 @@ func applyUpdateMessage(postbox: Postbox, stateManager: AccountStateManager, mes } } - 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)) + return .update(StoreMessage(id: updatedId, globallyUniqueId: nil, timestamp: updatedTimestamp ?? currentMessage.timestamp, flags: [], tags: tagsForStoreMessage(media: media, textEntities: entitiesAttribute?.entities), globalTags: globalTagsForStoreMessage(media: media), 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/CallSessionManager.swift b/TelegramCore/CallSessionManager.swift index 85bc0f79dd..f06f04db4b 100644 --- a/TelegramCore/CallSessionManager.swift +++ b/TelegramCore/CallSessionManager.swift @@ -33,12 +33,22 @@ enum CallSessionInternalState { case terminated(reason: CallSessionTerminationReason, reportRating: Bool) } -public typealias CallSessionInternalId = Int64 +public typealias CallSessionInternalId = UUID typealias CallSessionStableId = Int64 -public struct CallSessionRingingState { +public struct CallSessionRingingState: Equatable { public let id: CallSessionInternalId public let peerId: PeerId + + public static func ==(lhs: CallSessionRingingState, rhs: CallSessionRingingState) -> Bool { + return lhs.id == rhs.id && lhs.peerId == rhs.peerId + } +} + +public enum DropCallReason { + case hangUp + case busy + case disconnect } public enum CallSessionState { @@ -70,6 +80,7 @@ public enum CallSessionState { } public struct CallSession { + public let id: CallSessionInternalId public let isOutgoing: Bool public let state: CallSessionState } @@ -126,9 +137,8 @@ private final class CallSessionManagerContext { private let addUpdates: (Api.Updates) -> Void private let ringingSubscribers = Bag<([CallSessionRingingState]) -> Void>() - private var nextId: CallSessionInternalId = 0 private var contexts: [CallSessionInternalId: CallSessionContext] = [:] - private var contextIdByStableId: [CallSessionStableId: Int64] = [:] + private var contextIdByStableId: [CallSessionStableId: CallSessionInternalId] = [:] private let disposables = DisposableSet() @@ -153,6 +163,7 @@ private final class CallSessionManagerContext { let index = strongSelf.ringingSubscribers.add { next in subscriber.putNext(next) } + subscriber.putNext(strongSelf.ringingStatesValue()) disposable.set(ActionDisposable { queue.async { if let strongSelf = self { @@ -175,7 +186,7 @@ private final class CallSessionManagerContext { let index = context.subscribers.add { next in subscriber.putNext(next) } - subscriber.putNext(CallSession(isOutgoing: context.isOutgoing, state: CallSessionState(context))) + subscriber.putNext(CallSession(id: internalId, isOutgoing: context.isOutgoing, state: CallSessionState(context))) disposable.set(ActionDisposable { queue.async { if let strongSelf = self, let context = strongSelf.contexts[internalId] { @@ -192,21 +203,26 @@ private final class CallSessionManagerContext { } } - private func ringingStatesUpdated() { + private func ringingStatesValue() -> [CallSessionRingingState] { var ringingContexts: [CallSessionRingingState] = [] for (id, context) in self.contexts { if case .ringing = context.state { ringingContexts.append(CallSessionRingingState(id: id, peerId: context.peerId)) } } + return ringingContexts + } + + private func ringingStatesUpdated() { + let states = self.ringingStatesValue() for subscriber in self.ringingSubscribers.copyItems() { - subscriber(ringingContexts) + subscriber(states) } } private func contextUpdated(internalId: CallSessionInternalId) { if let context = self.contexts[internalId] { - let session = CallSession(isOutgoing: context.isOutgoing, state: CallSessionState(context)) + let session = CallSession(id: internalId, isOutgoing: context.isOutgoing, state: CallSessionState(context)) for subscriber in context.subscribers.copyItems() { subscriber(session) } @@ -218,39 +234,40 @@ private final class CallSessionManagerContext { return } - self.nextId += 1 - let bBytes = malloc(256)! let randomStatus = SecRandomCopyBytes(nil, 256, bBytes.assumingMemoryBound(to: UInt8.self)) let b = Data(bytesNoCopy: bBytes, count: 256, deallocator: .free) if randomStatus == 0 { - let internalId = self.nextId + let internalId = CallSessionInternalId() self.contexts[internalId] = CallSessionContext(peerId: peerId, isOutgoing: false, state: .ringing(id: stableId, accessHash: accessHash, gAHash: gAHash, b: b)) self.contextIdByStableId[stableId] = internalId self.contextUpdated(internalId: internalId) self.ringingStatesUpdated() - - self.queue.after(3.0, { [weak self] in - self?.accept(internalId: internalId) - }) } } - func drop(internalId: CallSessionInternalId) { + func drop(internalId: CallSessionInternalId, reason: DropCallReason) { if let context = self.contexts[internalId] { var dropData: (CallSessionStableId, Int64, DropCallSessionReason)? var wasRinging = false switch context.state { case let .ringing(id, accessHash, _, _): wasRinging = true - dropData = (id, accessHash, .abort) + dropData = (id, accessHash, .busy) case let .accepting(id, accessHash, _, _, disposable): dropData = (id, accessHash, .abort) disposable.dispose() case let .active(id, accessHash, beginTimestamp, _, _, _, _): let duration = max(0, Int32(CFAbsoluteTimeGetCurrent()) - beginTimestamp) - dropData = (id, accessHash, .hangUp(duration)) + let internalReason: DropCallSessionReason + switch reason { + case .busy, .hangUp: + internalReason = .hangUp(duration) + case .disconnect: + internalReason = .disconnect + } + dropData = (id, accessHash, internalReason) case .dropping, .terminated: break case let .awaitingConfirmation(id, accessHash, _, _, _): @@ -290,10 +307,10 @@ private final class CallSessionManagerContext { } } - func drop(stableId: CallSessionStableId) { + func drop(stableId: CallSessionStableId, reason: DropCallReason) { if let internalId = self.contextIdByStableId[stableId] { self.contextIdByStableId.removeValue(forKey: stableId) - self.drop(internalId: internalId) + self.drop(internalId: internalId, reason: reason) } } @@ -306,7 +323,7 @@ private final class CallSessionManagerContext { if case .accepting = context.state { switch result { case .failed: - strongSelf.drop(internalId: internalId) + strongSelf.drop(internalId: internalId, reason: .disconnect) case let .success(call): switch call { case let .waiting(config): @@ -317,7 +334,7 @@ private final class CallSessionManagerContext { context.state = .active(id: id, accessHash: accessHash, beginTimestamp: timestamp, key: key, keyId: keyId, keyVisualHash: keyVisualHash, connections: connections) strongSelf.contextUpdated(internalId: internalId) } else { - strongSelf.drop(internalId: internalId) + strongSelf.drop(internalId: internalId, reason: .disconnect) } } } @@ -365,13 +382,13 @@ private final class CallSessionManagerContext { if let updatedCall = updatedCall { strongSelf.updateSession(updatedCall) } else { - strongSelf.drop(internalId: internalId) + strongSelf.drop(internalId: internalId, reason: .disconnect) } } })) self.contextUpdated(internalId: internalId) default: - self.drop(internalId: internalId) + self.drop(internalId: internalId, reason: .disconnect) } } else { assertionFailure() @@ -408,7 +425,7 @@ private final class CallSessionManagerContext { break } } else { - assertionFailure() + //assertionFailure() } } case let .phoneCall(id, _, _, _, _, gAOrB, keyFingerprint, _, connection, alternativeConnections, startDate): @@ -423,10 +440,10 @@ private final class CallSessionManagerContext { context.state = .active(id: id, accessHash: accessHash, beginTimestamp: startDate, key: key, keyId: calculatedKeyId, keyVisualHash: keyVisualHash, connections: parseConnectionSet(primary: connection, alternative: alternativeConnections)) self.contextUpdated(internalId: internalId) } else { - self.drop(internalId: internalId) + self.drop(internalId: internalId, reason: .disconnect) } } else { - self.drop(internalId: internalId) + self.drop(internalId: internalId, reason: .disconnect) } case let .confirming(id, accessHash, key, keyId, keyVisualHash, _): context.state = .active(id: id, accessHash: accessHash, beginTimestamp: startDate, key: key, keyId: keyId, keyVisualHash: keyVisualHash, connections: parseConnectionSet(primary: connection, alternative: alternativeConnections)) @@ -486,14 +503,11 @@ private final class CallSessionManagerContext { return (key, keyId, keyVisualHash) } - func request(peerId: PeerId) -> CallSessionInternalId? { + func request(peerId: PeerId, internalId: CallSessionInternalId) -> CallSessionInternalId? { let aBytes = malloc(256)! let randomStatus = SecRandomCopyBytes(nil, 256, aBytes.assumingMemoryBound(to: UInt8.self)) let a = Data(bytesNoCopy: aBytes, count: 256, deallocator: .free) if randomStatus == 0 { - self.nextId += 1 - - let internalId = self.nextId self.contexts[internalId] = CallSessionContext(peerId: peerId, isOutgoing: true, state: .requesting(a: a, disposable: (requestCallSession(postbox: self.postbox, network: self.network, peerId: peerId, a: a) |> deliverOn(queue)).start(next: { [weak self] result in if let strongSelf = self, let context = strongSelf.contexts[internalId] { if case .requesting = context.state { @@ -557,30 +571,30 @@ public final class CallSessionManager { } } - public func drop(internalId: CallSessionInternalId) { + public func drop(internalId: CallSessionInternalId, reason: DropCallReason) { self.withContext { context in - context.drop(internalId: internalId) + context.drop(internalId: internalId, reason: reason) } } - func drop(stableId: CallSessionStableId) { + func drop(stableId: CallSessionStableId, reason: DropCallReason) { self.withContext { context in - context.drop(stableId: stableId) + context.drop(stableId: stableId, reason: reason) } } - func accept(internalId: CallSessionInternalId) { + public func accept(internalId: CallSessionInternalId) { self.withContext { context in context.accept(internalId: internalId) } } - public func request(peerId: PeerId) -> Signal { + public func request(peerId: PeerId, internalId: CallSessionInternalId = CallSessionInternalId()) -> Signal { return Signal { [weak self] subscriber in let disposable = MetaDisposable() self?.withContext { context in - if let internalId = context.request(peerId: peerId) { + if let internalId = context.request(peerId: peerId, internalId: internalId) { subscriber.putNext(internalId) subscriber.putCompletion() } @@ -749,6 +763,8 @@ private func confirmCallSession(network: Network, stableId: CallSessionStableId, private enum DropCallSessionReason { case abort case hangUp(Int32) + case busy + case disconnect } private func dropCallSession(network: Network, addUpdates: @escaping (Api.Updates) -> Void, stableId: CallSessionStableId, accessHash: Int64, reason: DropCallSessionReason) -> Signal { @@ -760,6 +776,10 @@ private func dropCallSession(network: Network, addUpdates: @escaping (Api.Update case let .hangUp(value): duration = value mappedReason = .phoneCallDiscardReasonHangup + case .busy: + mappedReason = .phoneCallDiscardReasonBusy + case .disconnect: + mappedReason = .phoneCallDiscardReasonDisconnect } return network.request(Api.functions.phone.discardCall(peer: Api.InputPhoneCall.inputPhoneCall(id: stableId, accessHash: accessHash), duration: duration, reason: mappedReason, connectionId: 0)) |> map { Optional($0) } diff --git a/TelegramCore/EnqueueMessage.swift b/TelegramCore/EnqueueMessage.swift index 5b80c37e6f..4be6f8ceb1 100644 --- a/TelegramCore/EnqueueMessage.swift +++ b/TelegramCore/EnqueueMessage.swift @@ -211,7 +211,7 @@ func enqueueMessages(modifier: Modifier, account: Account, peerId: PeerId, messa authorId = account.peerId } - storeMessages.append(StoreMessage(peerId: peerId, namespace: Namespaces.Message.Local, globallyUniqueId: randomId, timestamp: timestamp, flags: flags, tags: tagsForStoreMessage(media: mediaList, textEntities: entitiesAttribute?.entities), forwardInfo: nil, authorId: authorId, text: text, attributes: attributes, media: mediaList)) + storeMessages.append(StoreMessage(peerId: peerId, namespace: Namespaces.Message.Local, globallyUniqueId: randomId, timestamp: timestamp, flags: flags, tags: tagsForStoreMessage(media: mediaList, textEntities: entitiesAttribute?.entities), globalTags: globalTagsForStoreMessage(media: mediaList), forwardInfo: nil, authorId: authorId, text: text, attributes: attributes, media: mediaList)) case let .forward(source): if let sourceMessage = modifier.getMessage(source), let author = sourceMessage.author ?? sourceMessage.peers[sourceMessage.id.peerId] { if let peer = peer as? TelegramSecretChat { @@ -255,7 +255,7 @@ func enqueueMessages(modifier: Modifier, account: Account, peerId: PeerId, messa } } - storeMessages.append(StoreMessage(peerId: peerId, namespace: Namespaces.Message.Local, globallyUniqueId: randomId, timestamp: timestamp, flags: flags, tags: tagsForStoreMessage(media: sourceMessage.media, textEntities: entitiesAttribute?.entities), forwardInfo: forwardInfo, authorId: account.peerId, text: sourceMessage.text, attributes: attributes, media: sourceMessage.media)) + storeMessages.append(StoreMessage(peerId: peerId, namespace: Namespaces.Message.Local, globallyUniqueId: randomId, timestamp: timestamp, flags: flags, tags: tagsForStoreMessage(media: sourceMessage.media, textEntities: entitiesAttribute?.entities), globalTags: globalTagsForStoreMessage(media: sourceMessage.media), forwardInfo: forwardInfo, authorId: account.peerId, text: sourceMessage.text, attributes: attributes, media: sourceMessage.media)) } } } diff --git a/TelegramCore/ManagedSecretChatOutgoingOperations.swift b/TelegramCore/ManagedSecretChatOutgoingOperations.swift index f0bace05b5..e7e5eee411 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 .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)) + return .update(StoreMessage(id: currentMessage.id, globallyUniqueId: currentMessage.globallyUniqueId, timestamp: timestamp, flags: flags, tags: currentMessage.tags, globalTags: currentMessage.globalTags, 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 .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)) + return .update(StoreMessage(id: currentMessage.id, globallyUniqueId: currentMessage.globallyUniqueId, timestamp: timestamp, flags: flags, tags: currentMessage.tags, globalTags: currentMessage.globalTags, 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 374451d714..e6ce9f524a 100644 --- a/TelegramCore/MarkMessageContentAsConsumedInteractively.swift +++ b/TelegramCore/MarkMessageContentAsConsumedInteractively.swift @@ -66,7 +66,7 @@ public func markMessageContentAsConsumedInteractively(postbox: Postbox, messageI if let forwardInfo = currentMessage.forwardInfo { storeForwardInfo = StoreMessageForwardInfo(authorId: forwardInfo.author.id, sourceId: forwardInfo.source?.id, sourceMessageId: forwardInfo.sourceMessageId, date: forwardInfo.date) } - 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 .update(StoreMessage(id: currentMessage.id, globallyUniqueId: currentMessage.globallyUniqueId, timestamp: currentMessage.timestamp, flags: StoreMessageFlags(currentMessage.flags), tags: currentMessage.tags, globalTags: currentMessage.globalTags,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 .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 .update(StoreMessage(id: currentMessage.id, globallyUniqueId: currentMessage.globallyUniqueId, timestamp: currentMessage.timestamp, flags: StoreMessageFlags(currentMessage.flags), tags: currentMessage.tags, globalTags: currentMessage.globalTags, forwardInfo: storeForwardInfo, authorId: currentMessage.author?.id, text: currentMessage.text, attributes: updatedAttributes, media: currentMessage.media)) }) } } diff --git a/TelegramCore/MessageUtils.swift b/TelegramCore/MessageUtils.swift index f677287493..27fd726f68 100644 --- a/TelegramCore/MessageUtils.swift +++ b/TelegramCore/MessageUtils.swift @@ -106,5 +106,5 @@ func locallyRenderedMessage(message: StoreMessage, peers: [PeerId: Peer]) -> Mes messagePeers[peer.id] = peer } - return Message(stableId: 0, stableVersion: 0, id: id, globallyUniqueId: nil, timestamp: message.timestamp, flags: MessageFlags(message.flags), tags: message.tags, forwardInfo: nil, author: author, text: message.text, attributes: message.attributes, media: message.media, peers: messagePeers, associatedMessages: SimpleDictionary(), associatedMessageIds: []) + return Message(stableId: 0, stableVersion: 0, id: id, globallyUniqueId: nil, timestamp: message.timestamp, flags: MessageFlags(message.flags), tags: message.tags, globalTags: message.globalTags, forwardInfo: nil, author: author, text: message.text, attributes: message.attributes, media: message.media, peers: messagePeers, associatedMessages: SimpleDictionary(), associatedMessageIds: []) } diff --git a/TelegramCore/PendingMessageManager.swift b/TelegramCore/PendingMessageManager.swift index 9c57f0431e..bbcd2f3183 100644 --- a/TelegramCore/PendingMessageManager.swift +++ b/TelegramCore/PendingMessageManager.swift @@ -388,7 +388,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 .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)) + return .update(StoreMessage(id: currentMessage.id, globallyUniqueId: currentMessage.globallyUniqueId, timestamp: currentMessage.timestamp, flags: flags, tags: currentMessage.tags, globalTags: currentMessage.globalTags, forwardInfo: storeForwardInfo, authorId: currentMessage.author?.id, text: currentMessage.text, attributes: currentMessage.attributes, media: currentMessage.media)) }) } break @@ -409,7 +409,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 .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)) + return .update(StoreMessage(id: currentMessage.id, globallyUniqueId: currentMessage.globallyUniqueId, timestamp: currentMessage.timestamp, flags: flags, tags: currentMessage.tags, globalTags: currentMessage.globalTags, forwardInfo: storeForwardInfo, authorId: currentMessage.author?.id, text: currentMessage.text, attributes: currentMessage.attributes, media: currentMessage.media)) }) } } else { @@ -418,7 +418,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 .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 .update(StoreMessage(id: message.id, globallyUniqueId: currentMessage.globallyUniqueId, timestamp: currentMessage.timestamp, flags: [.Failed], tags: currentMessage.tags, globalTags: currentMessage.globalTags, forwardInfo: storeForwardInfo, authorId: currentMessage.author?.id, text: currentMessage.text, attributes: currentMessage.attributes, media: currentMessage.media)) }) } return .complete() @@ -503,7 +503,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 .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 .update(StoreMessage(id: message.id, globallyUniqueId: currentMessage.globallyUniqueId, timestamp: currentMessage.timestamp, flags: [.Failed], tags: currentMessage.tags, globalTags: currentMessage.globalTags, forwardInfo: storeForwardInfo, authorId: currentMessage.author?.id, text: currentMessage.text, attributes: currentMessage.attributes, media: currentMessage.media)) }) } @@ -516,7 +516,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 .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 .update(StoreMessage(id: message.id, globallyUniqueId: currentMessage.globallyUniqueId, timestamp: currentMessage.timestamp, flags: [.Failed], tags: currentMessage.tags, globalTags: currentMessage.globalTags, 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 aa1af5ebcd..20974027fe 100644 --- a/TelegramCore/PendingMessageUploadedContent.swift +++ b/TelegramCore/PendingMessageUploadedContent.swift @@ -228,7 +228,7 @@ private func uploadedMediaFileContent(network: Network, postbox: Postbox, transf } else { updatedAttributes.append(OutgoingMessageInfoAttribute(uniqueId: arc4random64(), flags: [.transformedMedia])) } - 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 .update(StoreMessage(id: currentMessage.id, globallyUniqueId: currentMessage.globallyUniqueId, timestamp: currentMessage.timestamp, flags: StoreMessageFlags(currentMessage.flags), tags: currentMessage.tags, globalTags: currentMessage.globalTags, forwardInfo: storeForwardInfo, authorId: currentMessage.author?.id, text: currentMessage.text, attributes: updatedAttributes, media: currentMessage.media)) }) } return .done(media) diff --git a/TelegramCore/ProcessSecretChatIncomingDecryptedOperations.swift b/TelegramCore/ProcessSecretChatIncomingDecryptedOperations.swift index a0ca3c14c9..929b6d78c4 100644 --- a/TelegramCore/ProcessSecretChatIncomingDecryptedOperations.swift +++ b/TelegramCore/ProcessSecretChatIncomingDecryptedOperations.swift @@ -382,7 +382,7 @@ extension StoreMessage { convenience init?(peerId: PeerId, authorId: PeerId, tagLocalIndex: Int32, timestamp: Int32, apiMessage: SecretApi8.DecryptedMessage, file: SecretChatFileReference?) { switch apiMessage { case let .decryptedMessage(randomId, _, message, media): - self.init(id: MessageId(peerId: peerId, namespace: Namespaces.Message.SecretIncoming, id: tagLocalIndex), globallyUniqueId: randomId, timestamp: timestamp, flags: [.Incoming], tags: [], forwardInfo: nil, authorId: authorId, text: message, attributes: [], media: []) + self.init(id: MessageId(peerId: peerId, namespace: Namespaces.Message.SecretIncoming, id: tagLocalIndex), globallyUniqueId: randomId, timestamp: timestamp, flags: [.Incoming], tags: [], globalTags: [], forwardInfo: nil, authorId: authorId, text: message, attributes: [], media: []) case let .decryptedMessageService(randomId, _, action): switch action { case let .decryptedMessageActionDeleteMessages(randomIds): @@ -394,9 +394,9 @@ extension StoreMessage { case let .decryptedMessageActionReadMessages(randomIds): return nil case .decryptedMessageActionScreenshotMessages: - self.init(id: MessageId(peerId: peerId, namespace: Namespaces.Message.SecretIncoming, id: tagLocalIndex), globallyUniqueId: randomId, timestamp: timestamp, flags: [.Incoming], tags: [], forwardInfo: nil, authorId: authorId, text: "", attributes: [], media: [TelegramMediaAction(action: .historyScreenshot)]) + self.init(id: MessageId(peerId: peerId, namespace: Namespaces.Message.SecretIncoming, id: tagLocalIndex), globallyUniqueId: randomId, timestamp: timestamp, flags: [.Incoming], tags: [], globalTags: [], forwardInfo: nil, authorId: authorId, text: "", attributes: [], media: [TelegramMediaAction(action: .historyScreenshot)]) case let .decryptedMessageActionSetMessageTTL(ttlSeconds): - self.init(id: MessageId(peerId: peerId, namespace: Namespaces.Message.SecretIncoming, id: tagLocalIndex), globallyUniqueId: randomId, timestamp: timestamp, flags: [.Incoming], tags: [], forwardInfo: nil, authorId: authorId, text: "", attributes: [], media: [TelegramMediaAction(action: .messageAutoremoveTimeoutUpdated(ttlSeconds))]) + self.init(id: MessageId(peerId: peerId, namespace: Namespaces.Message.SecretIncoming, id: tagLocalIndex), globallyUniqueId: randomId, timestamp: timestamp, flags: [.Incoming], tags: [], globalTags: [], forwardInfo: nil, authorId: authorId, text: "", attributes: [], media: [TelegramMediaAction(action: .messageAutoremoveTimeoutUpdated(ttlSeconds))]) } } } @@ -532,7 +532,7 @@ private func parseMessage(peerId: PeerId, authorId: PeerId, tagLocalIndex: Int32 } } - return (StoreMessage(id: MessageId(peerId: peerId, namespace: Namespaces.Message.SecretIncoming, id: tagLocalIndex), globallyUniqueId: randomId, timestamp: timestamp, flags: [.Incoming], tags: tagsForStoreMessage(media: parsedMedia, textEntities: entitiesAttribute?.entities), forwardInfo: nil, authorId: authorId, text: text, attributes: attributes, media: parsedMedia), resources) + return (StoreMessage(id: MessageId(peerId: peerId, namespace: Namespaces.Message.SecretIncoming, id: tagLocalIndex), globallyUniqueId: randomId, timestamp: timestamp, flags: [.Incoming], tags: tagsForStoreMessage(media: parsedMedia, textEntities: entitiesAttribute?.entities), globalTags: [], forwardInfo: nil, authorId: authorId, text: text, attributes: attributes, media: parsedMedia), resources) case let .decryptedMessageService(randomId, action): switch action { case let .decryptedMessageActionDeleteMessages(randomIds): @@ -544,9 +544,9 @@ private func parseMessage(peerId: PeerId, authorId: PeerId, tagLocalIndex: Int32 case .decryptedMessageActionReadMessages: return nil case .decryptedMessageActionScreenshotMessages: - return (StoreMessage(id: MessageId(peerId: peerId, namespace: Namespaces.Message.SecretIncoming, id: tagLocalIndex), globallyUniqueId: randomId, timestamp: timestamp, flags: [.Incoming], tags: [], forwardInfo: nil, authorId: authorId, text: "", attributes: [], media: [TelegramMediaAction(action: .historyScreenshot)]), []) + return (StoreMessage(id: MessageId(peerId: peerId, namespace: Namespaces.Message.SecretIncoming, id: tagLocalIndex), globallyUniqueId: randomId, timestamp: timestamp, flags: [.Incoming], tags: [], globalTags: [], forwardInfo: nil, authorId: authorId, text: "", attributes: [], media: [TelegramMediaAction(action: .historyScreenshot)]), []) case let .decryptedMessageActionSetMessageTTL(ttlSeconds): - return (StoreMessage(id: MessageId(peerId: peerId, namespace: Namespaces.Message.SecretIncoming, id: tagLocalIndex), globallyUniqueId: randomId, timestamp: timestamp, flags: [.Incoming], tags: [], forwardInfo: nil, authorId: authorId, text: "", attributes: [], media: [TelegramMediaAction(action: .messageAutoremoveTimeoutUpdated(ttlSeconds))]), []) + return (StoreMessage(id: MessageId(peerId: peerId, namespace: Namespaces.Message.SecretIncoming, id: tagLocalIndex), globallyUniqueId: randomId, timestamp: timestamp, flags: [.Incoming], tags: [], globalTags: [], forwardInfo: nil, authorId: authorId, text: "", attributes: [], media: [TelegramMediaAction(action: .messageAutoremoveTimeoutUpdated(ttlSeconds))]), []) case let .decryptedMessageActionResend(startSeqNo, endSeqNo): return nil case let .decryptedMessageActionRequestKey(exchangeId, gA): diff --git a/TelegramCore/StoreMessage_Telegram.swift b/TelegramCore/StoreMessage_Telegram.swift index 746f10cd40..d0913b7dfb 100644 --- a/TelegramCore/StoreMessage_Telegram.swift +++ b/TelegramCore/StoreMessage_Telegram.swift @@ -54,6 +54,10 @@ public func tagsForStoreMessage(media: [Media], textEntities: [MessageTextEntity return tags } +public func globalTagsForStoreMessage(media: [Media]) -> GlobalMessageTags { + return [] +} + extension Api.Message { var peerId: PeerId? { switch self { @@ -421,7 +425,7 @@ extension StoreMessage { storeFlags.insert(.Personal) } - self.init(id: MessageId(peerId: peerId, namespace: Namespaces.Message.Cloud, id: id), globallyUniqueId: nil, timestamp: date, flags: storeFlags, tags: tagsForStoreMessage(media: medias, textEntities: entitiesAttribute?.entities), forwardInfo: forwardInfo, authorId: authorId, text: messageText, attributes: attributes, media: medias) + self.init(id: MessageId(peerId: peerId, namespace: Namespaces.Message.Cloud, id: id), globallyUniqueId: nil, timestamp: date, flags: storeFlags, tags: tagsForStoreMessage(media: medias, textEntities: entitiesAttribute?.entities), globalTags: globalTagsForStoreMessage(media: medias), forwardInfo: forwardInfo, authorId: authorId, text: messageText, attributes: attributes, media: medias) case .messageEmpty: return nil case let .messageService(flags, id, fromId, toId, replyToMsgId, date, action): @@ -470,7 +474,7 @@ extension StoreMessage { media.append(action) } - self.init(id: MessageId(peerId: peerId, namespace: Namespaces.Message.Cloud, id: id), globallyUniqueId: nil, timestamp: date, flags: storeFlags, tags: [], forwardInfo: nil, authorId: authorId, text: "", attributes: attributes, media: media) + self.init(id: MessageId(peerId: peerId, namespace: Namespaces.Message.Cloud, id: id), globallyUniqueId: nil, timestamp: date, flags: storeFlags, tags: [], globalTags: globalTagsForStoreMessage(media: media), forwardInfo: nil, authorId: authorId, text: "", attributes: attributes, media: media) } } }