From ea444a2f2df85c6508ee2380518332da974eaabd Mon Sep 17 00:00:00 2001 From: Ali <> Date: Fri, 2 Jul 2021 22:34:31 +0400 Subject: [PATCH] Fix chat history loading --- .../Sources/State/AccountViewTracker.swift | 21 +++++++++---------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/submodules/TelegramCore/Sources/State/AccountViewTracker.swift b/submodules/TelegramCore/Sources/State/AccountViewTracker.swift index 8d32c69bee..929893732b 100644 --- a/submodules/TelegramCore/Sources/State/AccountViewTracker.swift +++ b/submodules/TelegramCore/Sources/State/AccountViewTracker.swift @@ -1420,29 +1420,26 @@ public final class AccountViewTracker { addHole = true pollingCompleted = .single(true) } - let isAutomaticallyTracked = Promise(false) - if addHole { - let _ = (self.account!.postbox.transaction { transaction -> Bool in - if transaction.getPeerChatListIndex(peerId) == nil { + let isAutomaticallyTracked = self.account!.postbox.transaction { transaction -> Bool in + if transaction.getPeerChatListIndex(peerId) == nil { + if addHole { transaction.addHole(peerId: peerId, namespace: Namespaces.Message.Cloud, space: .everywhere, range: 1 ... (Int32.max - 1)) - return false - } else { - return true } + return false + } else { + return true } - |> deliverOn(self.queue)).start(next: { isTracked in - isAutomaticallyTracked.set(.single(isTracked)) - }) } let historyIsValid = combineLatest(queue: self.queue, pollingCompleted, - isAutomaticallyTracked.get() + isAutomaticallyTracked ) |> map { lhs, rhs -> Bool in return lhs || rhs } + var loaded = false let validHistory = historyIsValid |> distinctUntilChanged |> take(until: { next in @@ -1454,6 +1451,8 @@ public final class AccountViewTracker { }) |> mapToSignal { isValid -> Signal<(MessageHistoryView, ViewUpdateType, InitialMessageHistoryData?), NoError> in if isValid { + assert(!loaded) + loaded = true return history } else { let view = MessageHistoryView(tagMask: nil, namespaces: .all, entries: [], holeEarlier: true, holeLater: true, isLoading: true)