diff --git a/TelegramCore/AccountStateManagementUtils.swift b/TelegramCore/AccountStateManagementUtils.swift index 83c428e832..fd042b3f66 100644 --- a/TelegramCore/AccountStateManagementUtils.swift +++ b/TelegramCore/AccountStateManagementUtils.swift @@ -2545,7 +2545,12 @@ func replayFinalState(accountManager: AccountManager, postbox: Postbox, accountP } for messageId in holesFromPreviousStateMeessageIds { - let upperId = topUpperHistoryBlockMessages[PeerIdAndMessageNamespace(peerId: messageId.peerId, namespace: messageId.namespace)] ?? Int32.max + let upperId: MessageId.Id + if let value = topUpperHistoryBlockMessages[PeerIdAndMessageNamespace(peerId: messageId.peerId, namespace: messageId.namespace)], value < Int32.max { + upperId = value - 1 + } else { + upperId = Int32.max + } if upperId > messageId.id { transaction.addHole(peerId: messageId.peerId, namespace: messageId.namespace, space: .everywhere, range: messageId.id ... upperId) } diff --git a/TelegramCore/AddPeerMember.swift b/TelegramCore/AddPeerMember.swift index 5524bcd50b..42bb21f8aa 100644 --- a/TelegramCore/AddPeerMember.swift +++ b/TelegramCore/AddPeerMember.swift @@ -194,8 +194,9 @@ public func addChannelMembers(account: Account, peerId: PeerId, memberIds: [Peer return .single(Void()) } - } |> introduceError(AddChannelMemberError.self) - - return signal |> switchToLatest + } + |> introduceError(AddChannelMemberError.self) + return signal + |> switchToLatest } diff --git a/TelegramCore/ApplyUpdateMessage.swift b/TelegramCore/ApplyUpdateMessage.swift index f4a00de1b0..c8fdca3071 100644 --- a/TelegramCore/ApplyUpdateMessage.swift +++ b/TelegramCore/ApplyUpdateMessage.swift @@ -33,8 +33,23 @@ func applyMediaResourceChanges(from: Media, to: Media, postbox: Postbox) { func applyUpdateMessage(postbox: Postbox, stateManager: AccountStateManager, message: Message, result: Api.Updates) -> Signal { return postbox.transaction { transaction -> Void in - let messageId = result.rawMessageIds.first - let apiMessage = result.messages.first + let messageId: Int32? + var apiMessage: Api.Message? + + for resultMessage in result.messages { + if let id = resultMessage.id { + if id.peerId == message.id.peerId { + apiMessage = resultMessage + break + } + } + } + + if let apiMessage = apiMessage, let id = apiMessage.id { + messageId = id.id + } else { + messageId = result.rawMessageIds.first + } var updatedTimestamp: Int32? if let apiMessage = apiMessage { diff --git a/TelegramCore/EnqueueMessage.swift b/TelegramCore/EnqueueMessage.swift index a0640ea276..23619413e2 100644 --- a/TelegramCore/EnqueueMessage.swift +++ b/TelegramCore/EnqueueMessage.swift @@ -365,7 +365,7 @@ func enqueueMessages(transaction: Transaction, account: Account, peerId: PeerId, } let authorId: PeerId? - if let peer = peer as? TelegramChannel, case let .broadcast(info) = peer.info, !info.flags.contains(.messagesShouldHaveSignatures) { + if let peer = peer as? TelegramChannel, case let .broadcast(info) = peer.info { authorId = peer.id } else { authorId = account.peerId @@ -486,7 +486,7 @@ func enqueueMessages(transaction: Transaction, account: Account, peerId: PeerId, } let authorId: PeerId? - if let peer = peer as? TelegramChannel, case let .broadcast(info) = peer.info, !info.flags.contains(.messagesShouldHaveSignatures) { + if let peer = peer as? TelegramChannel, case .broadcast = peer.info { authorId = peer.id } else { authorId = account.peerId