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 2b4c21c7e5..94c44b3883 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 @@ -474,14 +474,17 @@ object ChatModel { } fun removeLastChatItems() { - val removed: Triple + val remIndex: Int + val rem: ChatItem? chatItems.value = SnapshotStateList().apply { addAll(chatItems.value) - val remIndex = lastIndex - val rem = removeLast() - removed = Triple(rem.id, remIndex, rem.isRcvNew) + remIndex = lastIndex + rem = removeLastOrNull() + } + if (rem != null) { + val removed = Triple(rem.id, remIndex, rem.isRcvNew) + chatState.itemsRemoved(listOf(removed), chatItems.value) } - chatState.itemsRemoved(listOf(removed), chatItems.value) } suspend fun addChatItem(rhId: Long?, chatInfo: ChatInfo, cItem: ChatItem) { diff --git a/apps/multiplatform/common/src/commonMain/kotlin/chat/simplex/common/platform/AppCommon.kt b/apps/multiplatform/common/src/commonMain/kotlin/chat/simplex/common/platform/AppCommon.kt index 780f8c25b4..7a96bd99d2 100644 --- a/apps/multiplatform/common/src/commonMain/kotlin/chat/simplex/common/platform/AppCommon.kt +++ b/apps/multiplatform/common/src/commonMain/kotlin/chat/simplex/common/platform/AppCommon.kt @@ -32,7 +32,7 @@ val databaseBackend: String = if (appPlatform == AppPlatform.ANDROID) "sqlite" e class FifoQueue(private var capacity: Int) : LinkedList() { override fun add(element: E): Boolean { - if(size > capacity) removeFirst() + if (size > capacity) removeFirstOrNull() return super.add(element) } }