mirror of
https://github.com/Swiftgram/Telegram-iOS.git
synced 2025-11-29 03:21:29 +00:00
Fix chat list entry anchors
This commit is contained in:
parent
a0685b5250
commit
aab43f0b0a
@ -215,7 +215,7 @@ private final class ChatListViewSpaceState {
|
|||||||
if let lastMessage = lowerOrAtAnchorMessages.min(by: { $0.entryIndex < $1.entryIndex }) {
|
if let lastMessage = lowerOrAtAnchorMessages.min(by: { $0.entryIndex < $1.entryIndex }) {
|
||||||
nextLowerIndex = lastMessage.entryIndex
|
nextLowerIndex = lastMessage.entryIndex
|
||||||
} else {
|
} else {
|
||||||
nextLowerIndex = resolvedAnchorIndex
|
nextLowerIndex = resolvedAnchorIndex.predecessor
|
||||||
}
|
}
|
||||||
let loadedLowerMessages = postbox.chatListTable.entries(groupId: groupId, from: (nextLowerIndex.index, nextLowerIndex.isMessage), to: (lowerBound.index, lowerBound.isMessage), peerChatInterfaceStateTable: postbox.peerChatInterfaceStateTable, count: self.halfLimit - lowerOrAtAnchorMessages.count, predicate: filterPredicate.flatMap { mappedChatListFilterPredicate(postbox: postbox, groupId: groupId, predicate: $0) }).map(mapEntry)
|
let loadedLowerMessages = postbox.chatListTable.entries(groupId: groupId, from: (nextLowerIndex.index, nextLowerIndex.isMessage), to: (lowerBound.index, lowerBound.isMessage), peerChatInterfaceStateTable: postbox.peerChatInterfaceStateTable, count: self.halfLimit - lowerOrAtAnchorMessages.count, predicate: filterPredicate.flatMap { mappedChatListFilterPredicate(postbox: postbox, groupId: groupId, predicate: $0) }).map(mapEntry)
|
||||||
lowerOrAtAnchorMessages.append(contentsOf: loadedLowerMessages)
|
lowerOrAtAnchorMessages.append(contentsOf: loadedLowerMessages)
|
||||||
@ -223,7 +223,7 @@ private final class ChatListViewSpaceState {
|
|||||||
if higherThanAnchorMessages.count < self.halfLimit {
|
if higherThanAnchorMessages.count < self.halfLimit {
|
||||||
var nextHigherIndex: MutableChatListEntryIndex
|
var nextHigherIndex: MutableChatListEntryIndex
|
||||||
if let lastMessage = higherThanAnchorMessages.max(by: { $0.entryIndex < $1.entryIndex }) {
|
if let lastMessage = higherThanAnchorMessages.max(by: { $0.entryIndex < $1.entryIndex }) {
|
||||||
nextHigherIndex = lastMessage.entryIndex.successor
|
nextHigherIndex = lastMessage.entryIndex
|
||||||
} else {
|
} else {
|
||||||
nextHigherIndex = resolvedAnchorIndex
|
nextHigherIndex = resolvedAnchorIndex
|
||||||
}
|
}
|
||||||
@ -238,7 +238,25 @@ private final class ChatListViewSpaceState {
|
|||||||
assert(higherThanAnchorMessages.count <= self.halfLimit)
|
assert(higherThanAnchorMessages.count <= self.halfLimit)
|
||||||
|
|
||||||
let allIndices = (lowerOrAtAnchorMessages + higherThanAnchorMessages).map { $0.entryIndex }
|
let allIndices = (lowerOrAtAnchorMessages + higherThanAnchorMessages).map { $0.entryIndex }
|
||||||
assert(Set(allIndices).count == allIndices.count)
|
if Set(allIndices).count != allIndices.count {
|
||||||
|
var existingIndices = Set<MutableChatListEntryIndex>()
|
||||||
|
for i in (0 ..< lowerOrAtAnchorMessages.count).reversed() {
|
||||||
|
if !existingIndices.contains(lowerOrAtAnchorMessages[i].entryIndex) {
|
||||||
|
existingIndices.insert(lowerOrAtAnchorMessages[i].entryIndex)
|
||||||
|
} else {
|
||||||
|
lowerOrAtAnchorMessages.remove(at: i)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for i in (0 ..< higherThanAnchorMessages.count).reversed() {
|
||||||
|
if !existingIndices.contains(higherThanAnchorMessages[i].entryIndex) {
|
||||||
|
existingIndices.insert(higherThanAnchorMessages[i].entryIndex)
|
||||||
|
} else {
|
||||||
|
higherThanAnchorMessages.remove(at: i)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
assert(false)
|
||||||
|
}
|
||||||
|
|
||||||
assert(allIndices.sorted() == allIndices)
|
assert(allIndices.sorted() == allIndices)
|
||||||
|
|
||||||
let entries = OrderedChatListViewEntries(anchorIndex: self.anchorIndex.index, lowerOrAtAnchor: lowerOrAtAnchorMessages, higherThanAnchor: higherThanAnchorMessages)
|
let entries = OrderedChatListViewEntries(anchorIndex: self.anchorIndex.index, lowerOrAtAnchor: lowerOrAtAnchorMessages, higherThanAnchor: higherThanAnchorMessages)
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user