From e238c4ec0a18293f951b390b25ff1af453002ebd Mon Sep 17 00:00:00 2001 From: Ali <> Date: Sun, 5 Apr 2020 12:57:17 +0400 Subject: [PATCH] Debug chat list entries --- .../Postbox/Sources/ChatListViewState.swift | 29 +++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/submodules/Postbox/Sources/ChatListViewState.swift b/submodules/Postbox/Sources/ChatListViewState.swift index 2ad7c5fc25..92fe5a1eeb 100644 --- a/submodules/Postbox/Sources/ChatListViewState.swift +++ b/submodules/Postbox/Sources/ChatListViewState.swift @@ -138,6 +138,8 @@ private final class ChatListViewSpaceState { self.halfLimit = halfLimit self.orderedEntries = OrderedChatListViewEntries(anchorIndex: anchorIndex.index, lowerOrAtAnchor: [], higherThanAnchor: []) self.fillSpace(postbox: postbox) + + self.checkEntries(postbox: postbox) } private func fillSpace(postbox: Postbox) { @@ -790,9 +792,36 @@ private final class ChatListViewSpaceState { if hadRemovals { self.fillSpace(postbox: postbox) } + + self.checkEntries(postbox: postbox) + return hasUpdates } + private func checkEntries(postbox: Postbox) { + #if DEBUG + if case .group(.root, .includePinned, nil) = self.space { + let allEntries = self.orderedEntries.lowerOrAtAnchor + self.orderedEntries.higherThanAnchor + if !allEntries.isEmpty { + assert(allEntries.sorted(by: { $0.index < $1.index }) == allEntries) + + func mapEntry(_ entry: ChatListIntermediateEntry) -> MutableChatListEntry { + switch entry { + case let .message(index, messageIndex): + return .IntermediateMessageEntry(index: index, messageIndex: messageIndex) + case let .hole(hole): + return .HoleEntry(hole) + } + } + + let loadedEntries = postbox.chatListTable.entries(groupId: .root, from: (allEntries[0].index.predecessor, true), to: (allEntries[allEntries.count - 1].index.successor, true), peerChatInterfaceStateTable: postbox.peerChatInterfaceStateTable, count: 1000, predicate: nil).map(mapEntry) + + assert(loadedEntries.map({ $0.index }) == allEntries.map({ $0.index })) + } + } + #endif + } + private func add(entry: MutableChatListEntry) -> Bool { if self.anchorIndex >= entry.entryIndex { let insertionIndex = binaryInsertionIndex(self.orderedEntries.lowerOrAtAnchor, extract: { $0.entryIndex }, searchItem: entry.entryIndex)