From 20c4c02f63b36c59a63feba4d801c863508dd5f8 Mon Sep 17 00:00:00 2001 From: Avently <7953703+avently@users.noreply.github.com> Date: Fri, 1 Nov 2024 14:59:38 +0700 Subject: [PATCH] fix --- .../commonMain/kotlin/chat/simplex/common/model/ChatModel.kt | 4 ++++ .../kotlin/chat/simplex/common/views/chat/ChatSections.kt | 2 +- .../kotlin/chat/simplex/common/views/chat/ChatView.kt | 2 +- 3 files changed, 6 insertions(+), 2 deletions(-) diff --git a/apps/multiplatform/common/src/commonMain/kotlin/chat/simplex/common/model/ChatModel.kt b/apps/multiplatform/common/src/commonMain/kotlin/chat/simplex/common/model/ChatModel.kt index 04fd64c6a4..b2426de8b2 100644 --- a/apps/multiplatform/common/src/commonMain/kotlin/chat/simplex/common/model/ChatModel.kt +++ b/apps/multiplatform/common/src/commonMain/kotlin/chat/simplex/common/model/ChatModel.kt @@ -2309,6 +2309,10 @@ fun MutableState>.removeAt(index: Int): T { return res } +fun MutableState>.removeRange(fromIndex: Int, toIndex: Int) { + value = SnapshotStateList().apply { addAll(value); removeRange(fromIndex, toIndex) } +} + fun MutableState>.removeLast() { value = SnapshotStateList().apply { addAll(value); removeLast() } } diff --git a/apps/multiplatform/common/src/commonMain/kotlin/chat/simplex/common/views/chat/ChatSections.kt b/apps/multiplatform/common/src/commonMain/kotlin/chat/simplex/common/views/chat/ChatSections.kt index d564810095..e55be0a57a 100644 --- a/apps/multiplatform/common/src/commonMain/kotlin/chat/simplex/common/views/chat/ChatSections.kt +++ b/apps/multiplatform/common/src/commonMain/kotlin/chat/simplex/common/views/chat/ChatSections.kt @@ -218,7 +218,7 @@ fun List.dropTemporarySections() { if (bottomSection != null) { val items = chatModel.chatItems.value val itemsOutsideOfSection = items.size - 1 - bottomSection.boundary.maxIndex - chatModel.chatItems.value.removeRange(fromIndex = 0, toIndex = itemsOutsideOfSection + bottomSection.excessItemCount()) + chatModel.chatItems.removeRange(fromIndex = 0, toIndex = itemsOutsideOfSection + bottomSection.excessItemCount()) chatModel.chatItemsSectionArea = mutableMapOf().also { it.putAll(items.associate { it.id to ChatSectionArea.Bottom }) } } } diff --git a/apps/multiplatform/common/src/commonMain/kotlin/chat/simplex/common/views/chat/ChatView.kt b/apps/multiplatform/common/src/commonMain/kotlin/chat/simplex/common/views/chat/ChatView.kt index 9f5fb74b48..b26756711d 100644 --- a/apps/multiplatform/common/src/commonMain/kotlin/chat/simplex/common/views/chat/ChatView.kt +++ b/apps/multiplatform/common/src/commonMain/kotlin/chat/simplex/common/views/chat/ChatView.kt @@ -1072,7 +1072,7 @@ fun BoxScope.ChatItemsList( itemsToDrop.forEach { chatModel.chatItemsSectionArea.remove(it.id) } - chatModel.chatItems.value.removeIf { chatModel.chatItemsSectionArea[it.id] == null } + chatModel.chatItems.removeAll { chatModel.chatItemsSectionArea[it.id] == null } val newIdx = reversedChatItems.value.indexOfFirst { it.id == itemId } listState.scrollToItem(scrollPosition.value(newIdx), -maxHeight.value) }