ui: drop the page-merge application of kept updates

This commit is contained in:
Narasimha-sc committed 2026-10-19 19:24:23 +00:00
1 parent 21ea35030b
commit 5dda3cc2cd
5 files changed
+23 -30

No files matched your search

-7
View File
@@ -102,13 +102,6 @@ class ItemsModel: ObservableObject {
chatState.splits.isEmpty || chatState.splits.first != reversedChatItems.first?.id
}
func withDroppedUpdates(_ chatId: ChatId, _ items: [ChatItem]) -> [ChatItem] {
if droppedUpdates.isEmpty || droppedUpdatesChatId != chatId { return items }
return items.map { item in
if let kept = droppedUpdates.removeValue(forKey: item.id), kept.meta.updatedAt > item.meta.updatedAt { kept } else { item }
}
}
func clearDroppedUpdates() {
droppedUpdatesChatId = nil
droppedUpdates.removeAll()
@@ -50,7 +50,7 @@ func apiLoadMessages(
chatModel.addChat(chat)
}
await MainActor.run {
im.reversedChatItems = im.withDroppedUpdates(chat.id, chat.chatItems.reversed())
im.reversedChatItems = chat.chatItems.reversed()
if im.secondaryIMFilter == nil {
chatModel.updateChatInfo(chat.chatInfo)
}
@@ -80,7 +80,7 @@ func apiLoadMessages(
let newReversed: [ChatItem] = newItems.reversed()
await MainActor.run {
if chatWasSwitched(chat, pagination, openAroundItemId) { return }
im.reversedChatItems = im.withDroppedUpdates(chat.id, newReversed)
im.reversedChatItems = newReversed
im.chatState.splits = modifiedSplits.newSplits
im.chatState.moveUnreadAfterItem(modifiedSplits.oldUnreadSplitIndex, modifiedSplits.newUnreadSplitIndex, oldItems)
}
@@ -101,7 +101,7 @@ func apiLoadMessages(
let newReversed: [ChatItem] = newItems.reversed()
await MainActor.run {
if chatWasSwitched(chat, pagination, openAroundItemId) { return }
im.reversedChatItems = im.withDroppedUpdates(chat.id, newReversed)
im.reversedChatItems = newReversed
im.chatState.splits = newSplits
im.chatState.moveUnreadAfterItem(im.chatState.splits.first ?? new.last!.id, new)
// loading clear bottom area, updating number of unread items after the newest loaded item
@@ -125,7 +125,7 @@ func apiLoadMessages(
let orderedSplits = newSplits
await MainActor.run {
if chatWasSwitched(chat, pagination, openAroundItemId) { return }
im.reversedChatItems = im.withDroppedUpdates(chat.id, newReversed)
im.reversedChatItems = newReversed
im.chatState.splits = orderedSplits
im.chatState.unreadAfterItemId = chat.chatItems.last!.id
im.chatState.totalAfter = navInfo.afterTotal
@@ -151,7 +151,7 @@ func apiLoadMessages(
let items = newItems
await MainActor.run {
if chatWasSwitched(chat, pagination, openAroundItemId) { return }
im.reversedChatItems = im.withDroppedUpdates(chat.id, items.reversed())
im.reversedChatItems = items.reversed()
im.chatState.splits = newSplits
if im.secondaryIMFilter == nil {
chatModel.updateChatInfo(chat.chatInfo)
@@ -737,13 +737,6 @@ object ChatModel {
return itemAdded
}
fun withDroppedUpdates(rhId: Long?, chatId: String, items: List<ChatItem>): List<ChatItem> =
if (droppedUpdates.isEmpty() || droppedUpdatesChat != (rhId to chatId)) {
items
} else {
items.map { item -> droppedUpdates.remove(item.id)?.takeIf { it.meta.updatedAt > item.meta.updatedAt } ?: item }
}
fun clearDroppedUpdates() {
droppedUpdatesChat = null
droppedUpdates.clear()
@@ -77,7 +77,7 @@ suspend fun processLoadedChat(
}
}
withContext(Dispatchers.Main) {
chatsCtx.chatItems.replaceAll(chatsCtx.withDroppedUpdates(chat.remoteHostId, chat.id, chat.chatItems))
chatsCtx.chatItems.replaceAll(chat.chatItems)
chatModel.chatId.value = chat.id
splits.value = newSplits
if (chat.chatItems.isNotEmpty()) {
@@ -103,7 +103,7 @@ suspend fun processLoadedChat(
newItems.addAll(insertAt, chat.chatItems)
withContext(Dispatchers.Main) {
if (chatWasSwitched(chat, pagination, openAroundItemId)) return@withContext
chatsCtx.chatItems.replaceAll(chatsCtx.withDroppedUpdates(chat.remoteHostId, chat.id, newItems))
chatsCtx.chatItems.replaceAll(newItems)
splits.value = newSplits
chatState.moveUnreadAfterItem(oldUnreadSplitIndex, newUnreadSplitIndex, oldItems)
}
@@ -123,7 +123,7 @@ suspend fun processLoadedChat(
newItems.addAll(indexToAdd, chat.chatItems)
withContext(Dispatchers.Main) {
if (chatWasSwitched(chat, pagination, openAroundItemId)) return@withContext
chatsCtx.chatItems.replaceAll(chatsCtx.withDroppedUpdates(chat.remoteHostId, chat.id, newItems))
chatsCtx.chatItems.replaceAll(newItems)
splits.value = newSplits
chatState.moveUnreadAfterItem(splits.value.firstOrNull() ?: newItems.last().id, newItems)
// loading clear bottom area, updating number of unread items after the newest loaded item
@@ -146,7 +146,7 @@ suspend fun processLoadedChat(
withContext(Dispatchers.Main) {
if (chatWasSwitched(chat, pagination, openAroundItemId)) return@withContext
chatsCtx.chatItems.replaceAll(chatsCtx.withDroppedUpdates(chat.remoteHostId, chat.id, newItems))
chatsCtx.chatItems.replaceAll(newItems)
splits.value = newSplits
unreadAfterItemId.value = chat.chatItems.last().id
totalAfter.value = navInfo.afterTotal
@@ -170,7 +170,7 @@ suspend fun processLoadedChat(
newItems.addAll(chat.chatItems)
withContext(Dispatchers.Main) {
if (chatWasSwitched(chat, pagination, openAroundItemId)) return@withContext
chatsCtx.chatItems.replaceAll(chatsCtx.withDroppedUpdates(chat.remoteHostId, chat.id, newItems))
chatsCtx.chatItems.replaceAll(newItems)
chatState.splits.value = newSplits
unreadAfterNewestLoaded.value = 0
}