Fix message index ordering

This commit is contained in:
Ali
2021-03-26 23:01:16 +04:00
parent e4fb095cc2
commit e30e4dd22f
3 changed files with 83 additions and 5 deletions

View File

@@ -242,11 +242,13 @@ private final class ChatListViewSpaceState {
let allIndices = (lowerOrAtAnchorMessages + higherThanAnchorMessages).map { $0.entryIndex }
let allEntityIds = (lowerOrAtAnchorMessages + higherThanAnchorMessages).map { $0.entityId }
if Set(allIndices).count != allIndices.count {
var debugRepeatedIndices = Set<MutableChatListEntryIndex>()
var existingIndices = Set<MutableChatListEntryIndex>()
for i in (0 ..< lowerOrAtAnchorMessages.count).reversed() {
if !existingIndices.contains(lowerOrAtAnchorMessages[i].entryIndex) {
existingIndices.insert(lowerOrAtAnchorMessages[i].entryIndex)
} else {
debugRepeatedIndices.insert(lowerOrAtAnchorMessages[i].entryIndex)
lowerOrAtAnchorMessages.remove(at: i)
}
}
@@ -254,10 +256,11 @@ private final class ChatListViewSpaceState {
if !existingIndices.contains(higherThanAnchorMessages[i].entryIndex) {
existingIndices.insert(higherThanAnchorMessages[i].entryIndex)
} else {
debugRepeatedIndices.insert(higherThanAnchorMessages[i].entryIndex)
higherThanAnchorMessages.remove(at: i)
}
}
postboxLog("allIndices not unique: \(allIndices)")
postboxLog("allIndices not unique, repeated: \(debugRepeatedIndices)")
assert(false)
//preconditionFailure()