From c65cd8ac72ebba51bad961712fe322b53ee8ffae Mon Sep 17 00:00:00 2001 From: Diogo Date: Mon, 20 Jan 2025 16:06:50 +0000 Subject: [PATCH] changes --- .../simplex/common/views/chat/ChatInfoView.kt | 19 ++++++++++++++----- .../common/views/chat/ChatItemsLoader.kt | 7 ++++++- .../views/chat/group/GroupChatInfoView.kt | 8 ++++---- 3 files changed, 24 insertions(+), 10 deletions(-) diff --git a/apps/multiplatform/common/src/commonMain/kotlin/chat/simplex/common/views/chat/ChatInfoView.kt b/apps/multiplatform/common/src/commonMain/kotlin/chat/simplex/common/views/chat/ChatInfoView.kt index badb278d4f..f52372b37c 100644 --- a/apps/multiplatform/common/src/commonMain/kotlin/chat/simplex/common/views/chat/ChatInfoView.kt +++ b/apps/multiplatform/common/src/commonMain/kotlin/chat/simplex/common/views/chat/ChatInfoView.kt @@ -190,7 +190,7 @@ fun ChatInfoView( }, close = close, onSearchClicked = onSearchClicked, - enabled = remember { derivedStateOf { !progressIndicator.value } } + disabled = progressIndicator ) if (progressIndicator.value) { @@ -544,7 +544,7 @@ fun ChatInfoLayout( verifyClicked: () -> Unit, close: () -> Unit, onSearchClicked: () -> Unit, - enabled: State + disabled: State ) { val cStats = connStats.value val scrollState = rememberScrollState() @@ -552,7 +552,7 @@ fun ChatInfoLayout( KeyChangeEffect(chat.id) { scope.launch { scrollState.scrollTo(0) } } - ColumnWithScrollBar(Modifier.alpha(if (enabled.value) 1f else 0.6f)) { + ColumnWithScrollBar(Modifier.alpha(if (disabled.value) 0.6f else 1f)) { Row( Modifier.fillMaxWidth(), horizontalArrangement = Arrangement.Center @@ -1394,7 +1394,16 @@ private fun afterSetChatTTL(m: ChatModel, chatInfo: ChatInfo, progressIndicator: withApi { try { // this is using current remote host on purpose - if it changes during update, it will load correct chats - apiLoadMessages(m.remoteHostId(), chatInfo.chatType, chatInfo.apiId, contentTag = null, pagination = ChatPagination.Initial(ChatPagination.INITIAL_COUNT), replaceChat = true) + // redirectDisabled is set to true to prevent redirecting the current chat/chat items in case the chat changes while messages were updating + apiLoadMessages( + m.remoteHostId(), + chatInfo.chatType, + chatInfo.apiId, + contentTag = null, + pagination = ChatPagination.Initial(ChatPagination.INITIAL_COUNT), + replaceChat = true, + redirectDisabled = true + ) } catch (e: Exception) { Log.e(TAG, "apiGetChat error: ${e.message}") } finally { @@ -1436,7 +1445,7 @@ fun PreviewChatInfoLayout() { verifyClicked = {}, close = {}, onSearchClicked = {}, - enabled = remember { mutableStateOf(true) } + disabled = remember { mutableStateOf(true) } ) } } diff --git a/apps/multiplatform/common/src/commonMain/kotlin/chat/simplex/common/views/chat/ChatItemsLoader.kt b/apps/multiplatform/common/src/commonMain/kotlin/chat/simplex/common/views/chat/ChatItemsLoader.kt index 562df42a19..849e2016f7 100644 --- a/apps/multiplatform/common/src/commonMain/kotlin/chat/simplex/common/views/chat/ChatItemsLoader.kt +++ b/apps/multiplatform/common/src/commonMain/kotlin/chat/simplex/common/views/chat/ChatItemsLoader.kt @@ -29,7 +29,8 @@ suspend fun apiLoadMessages( pagination: ChatPagination, search: String = "", visibleItemIndexesNonReversed: () -> IntRange = { 0 .. 0 }, - replaceChat: Boolean = false + replaceChat: Boolean = false, + redirectDisabled: Boolean = false ) = coroutineScope { val (chat, navInfo) = chatModel.controller.apiGetChat(rhId, chatType, apiId, contentTag, pagination, search) ?: return@coroutineScope // For .initial allow the chatItems to be empty as well as chatModel.chatId to not match this chat because these values become set after .initial finishes @@ -57,6 +58,10 @@ suspend fun apiLoadMessages( } } withChats(contentTag) { + if (redirectDisabled && chatModel.chatId.value != chat.id) { + // redirect is disabled, but the chat is not the current one, so don't update it + return@withChats + } chatItemStatuses.clear() chatItems.replaceAll(chat.chatItems) chatModel.chatId.value = chat.chatInfo.id diff --git a/apps/multiplatform/common/src/commonMain/kotlin/chat/simplex/common/views/chat/group/GroupChatInfoView.kt b/apps/multiplatform/common/src/commonMain/kotlin/chat/simplex/common/views/chat/group/GroupChatInfoView.kt index c478c3f005..43f4137089 100644 --- a/apps/multiplatform/common/src/commonMain/kotlin/chat/simplex/common/views/chat/group/GroupChatInfoView.kt +++ b/apps/multiplatform/common/src/commonMain/kotlin/chat/simplex/common/views/chat/group/GroupChatInfoView.kt @@ -141,7 +141,7 @@ fun ModalData.GroupChatInfoView(chatModel: ChatModel, rhId: Long?, chatId: Strin ModalManager.end.showModal { GroupLinkView(chatModel, rhId, groupInfo, groupLink, groupLinkMemberRole, onGroupLinkUpdated) } }, onSearchClicked = onSearchClicked, - enabled = remember { derivedStateOf { !progressIndicator.value } } + disabled = progressIndicator ) if (progressIndicator.value) { @@ -323,7 +323,7 @@ fun ModalData.GroupChatInfoLayout( manageGroupLink: () -> Unit, close: () -> Unit = { ModalManager.closeAllModalsEverywhere()}, onSearchClicked: () -> Unit, - enabled: State + disabled: State ) { val listState = remember { appBarHandler.listState } val scope = rememberCoroutineScope() @@ -337,7 +337,7 @@ fun ModalData.GroupChatInfoLayout( if (s.isEmpty()) members else members.filter { m -> m.anyNameContains(s) } } } - Box(Modifier.alpha(if (enabled.value) 1f else 0.6f)) { + Box(Modifier.alpha(if (disabled.value) 0.6f else 1f)) { val oneHandUI = remember { appPrefs.oneHandUI.state } LazyColumnWithScrollBar( state = listState, @@ -811,7 +811,7 @@ fun PreviewGroupChatInfoLayout() { onLocalAliasChanged = {}, groupLink = null, scrollToItemId = remember { mutableStateOf(null) }, - addMembers = {}, showMemberInfo = {}, editGroupProfile = {}, addOrEditWelcomeMessage = {}, openPreferences = {}, deleteGroup = {}, clearChat = {}, leaveGroup = {}, manageGroupLink = {}, onSearchClicked = {}, enabled = remember { mutableStateOf(true) } + addMembers = {}, showMemberInfo = {}, editGroupProfile = {}, addOrEditWelcomeMessage = {}, openPreferences = {}, deleteGroup = {}, clearChat = {}, leaveGroup = {}, manageGroupLink = {}, onSearchClicked = {}, disabled = remember { mutableStateOf(true) } ) } }