diff --git a/submodules/TelegramCore/Sources/AccountStateManager.swift b/submodules/TelegramCore/Sources/AccountStateManager.swift index 3a7a952951..88236272f1 100644 --- a/submodules/TelegramCore/Sources/AccountStateManager.swift +++ b/submodules/TelegramCore/Sources/AccountStateManager.swift @@ -296,6 +296,7 @@ public final class AccountStateManager { var collectedPollCompletionSubscribers: [(Int32, ([MessageId]) -> Void)] = [] var collectedReplayAsynchronouslyBuiltFinalState: [(AccountFinalState, () -> Void)] = [] var processEvents: [(Int32, AccountFinalStateEvents)] = [] + var customOperations: [(Int32, Signal)] = [] var replacedOperations: [AccountStateManagerOperation] = [] @@ -313,6 +314,8 @@ public final class AccountStateManager { collectedReplayAsynchronouslyBuiltFinalState.append((finalState, completion)) case let .processEvents(operationId, events): processEvents.append((operationId, events)) + case let .custom(operationId, customSignal): + customOperations.append((operationId, customSignal)) default: break } @@ -335,6 +338,10 @@ public final class AccountStateManager { replacedOperations.append(AccountStateManagerOperation(content: .processEvents(operationId, events))) } + for (operationId, customSignal) in customOperations { + replacedOperations.append(AccountStateManagerOperation(content: .custom(operationId, customSignal))) + } + self.operations.removeAll() self.operations.append(contentsOf: replacedOperations) } diff --git a/submodules/TelegramCore/Sources/SynchronizePeerReadState.swift b/submodules/TelegramCore/Sources/SynchronizePeerReadState.swift index d9cfa28a6c..5f55a1bce3 100644 --- a/submodules/TelegramCore/Sources/SynchronizePeerReadState.swift +++ b/submodules/TelegramCore/Sources/SynchronizePeerReadState.swift @@ -60,40 +60,6 @@ private func dialogTopMessage(network: Network, postbox: Postbox, peerId: PeerId } } -func fetchPeerCloudReadState(network: Network, postbox: Postbox, peerId: PeerId, inputPeer: Api.InputPeer) -> Signal { - return network.request(Api.functions.messages.getPeerDialogs(peers: [.inputDialogPeer(peer: inputPeer)])) - |> map { result -> PeerReadState? in - switch result { - case let .peerDialogs(dialogs, _, _, _, _): - if let dialog = dialogs.filter({ $0.peerId == peerId }).first { - let apiTopMessage: Int32 - let apiReadInboxMaxId: Int32 - let apiReadOutboxMaxId: Int32 - let apiUnreadCount: Int32 - let apiMarkedUnread: Bool - switch dialog { - case let .dialog(flags, _, topMessage, readInboxMaxId, readOutboxMaxId, unreadCount, _, _, _, _, _): - apiTopMessage = topMessage - apiReadInboxMaxId = readInboxMaxId - apiReadOutboxMaxId = readOutboxMaxId - apiUnreadCount = unreadCount - apiMarkedUnread = (flags & (1 << 3)) != 0 - case .dialogFolder: - assertionFailure() - return nil - } - - return .idBased(maxIncomingReadId: apiReadInboxMaxId, maxOutgoingReadId: apiReadOutboxMaxId, maxKnownId: apiTopMessage, count: apiUnreadCount, markedUnread: apiMarkedUnread) - } else { - return nil - } - } - } - |> `catch` { _ -> Signal in - return .single(nil) - } -} - private func dialogReadState(network: Network, postbox: Postbox, peerId: PeerId) -> Signal<(PeerReadState, PeerReadStateMarker), PeerReadStateValidationError> { return dialogTopMessage(network: network, postbox: postbox, peerId: peerId) |> mapToSignal { topMessage -> Signal<(PeerReadState, PeerReadStateMarker), PeerReadStateValidationError> in