From 239653141454ede606d25c91b9636b3ead2b1f24 Mon Sep 17 00:00:00 2001 From: Avently <7953703+avently@users.noreply.github.com> Date: Mon, 4 Nov 2024 12:35:34 +0700 Subject: [PATCH] refactor --- .../simplex/common/views/chat/ChatView.kt | 56 +++++++++---------- 1 file changed, 25 insertions(+), 31 deletions(-) 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 1942843f1d..67ab008904 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 @@ -292,41 +292,35 @@ fun ChatView(staleChatId: State, onComposed: suspend (chatId: String) - } }, loadMessages = { chatId, scrollDirection, (itemId, idx, area) -> - val c = chatModel.getChat(chatId) + val c = chatModel.getChat(chatId) ?: return@ChatLayout if (chatModel.chatId.value != chatId) return@ChatLayout - when (scrollDirection) { - ScrollDirection.Up -> { - if (c != null) { - withBGApi { - val chatSectionLoader = ChatSectionLoader(idx, area) - apiLoadMessages( - rhId = c.remoteHostId, - chatInfo = c.chatInfo, - chatModel = chatModel, - itemId = itemId, - search = "", - chatSectionLoader = chatSectionLoader, - ) - } + withBGApi { + when (scrollDirection) { + ScrollDirection.Up -> { + val chatSectionLoader = ChatSectionLoader(idx, area) + apiLoadMessages( + rhId = c.remoteHostId, + chatInfo = c.chatInfo, + chatModel = chatModel, + itemId = itemId, + search = "", + chatSectionLoader = chatSectionLoader, + ) } - } - ScrollDirection.Down -> { - if (c != null) { - withBGApi { - val chatSectionLoader = ChatSectionLoader(idx + 1, area) - apiLoadMessages( - rhId = c.remoteHostId, - chatInfo = c.chatInfo, - chatModel = chatModel, - itemId = itemId, - search = "", - chatSectionLoader = chatSectionLoader, - pagination = ChatPagination.After(itemId, ChatPagination.PRELOAD_COUNT) - ) - } + ScrollDirection.Down -> { + val chatSectionLoader = ChatSectionLoader(idx + 1, area) + apiLoadMessages( + rhId = c.remoteHostId, + chatInfo = c.chatInfo, + chatModel = chatModel, + itemId = itemId, + search = "", + chatSectionLoader = chatSectionLoader, + pagination = ChatPagination.After(itemId, ChatPagination.PRELOAD_COUNT) + ) } + else -> {} } - else -> {} } }, deleteMessage = { itemId, mode ->