From e4f5eaf404abe6b8867ed3cc01b2c8d1d7da4f17 Mon Sep 17 00:00:00 2001 From: Narasimha-sc <166327228+Narasimha-sc@users.noreply.github.com> Date: Sat, 17 Oct 2026 13:38:46 +0000 Subject: [PATCH] desktop: don't show another chat's info while the shown chat loads When the info pane showed a chat other than the one its values were loaded for, it reloaded them, but until the reload returned it showed the previous chat's values: "Verify security code" opened the previous contact's code, and a group showed the previous group's link, so "Group link" opened and shared another group's link. Start the contact info, security code and group link empty when they belong to another chat. Hide the "Create group link" / "Group link" row and disable the channel "Link" button until the link is loaded: with no link yet, both open the link page, which creates a link when it gets none, and for a group that already has one the core creates a server queue before failing with a duplicate link error. --- .../chat/simplex/common/views/chat/ChatView.kt | 10 ++++++---- .../common/views/chat/group/GroupChatInfoView.kt | 13 +++++++++---- 2 files changed, 15 insertions(+), 8 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 71761acb38..a07d989650 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 @@ -425,8 +425,8 @@ fun ChatView( ModalView(close, cardScreen = true, appBar = appBar.value) { val chatInfo = remember { activeChat }.value?.chatInfo if (chatInfo is ChatInfo.Direct) { - var contactInfo: Pair? by remember { mutableStateOf(preloadedContactInfo) } - var code: String? by remember { mutableStateOf(preloadedCode) } + var contactInfo: Pair? by remember(chatInfo.id) { mutableStateOf(if (chatInfo.id == preloadedChatId) preloadedContactInfo else null) } + var code: String? by remember(chatInfo.id) { mutableStateOf(if (chatInfo.id == preloadedChatId) preloadedCode else null) } LaunchedEffect(chatInfo.id) { if (chatInfo.id == preloadedChatId) return@LaunchedEffect preloadedChatId = null @@ -440,16 +440,18 @@ fun ChatView( showSearch.value = true } } else if (chatInfo is ChatInfo.Group) { - var link: GroupLink? by remember(chatInfo.id) { mutableStateOf(preloadedLink) } + var link: GroupLink? by remember(chatInfo.id) { mutableStateOf(if (chatInfo.id == preloadedChatId) preloadedLink else null) } + var linkLoaded by remember(chatInfo.id) { mutableStateOf(chatInfo.id == preloadedChatId) } LaunchedEffect(chatInfo.id) { if (chatInfo.id == preloadedChatId) return@LaunchedEffect preloadedChatId = null setGroupMembers(chatRh, chatInfo.groupInfo, chatModel) link = chatModel.controller.apiGetGroupLink(chatRh, chatInfo.groupInfo.groupId) + linkLoaded = true preloadedLink = link preloadedChatId = chatInfo.id } - GroupChatInfoView(chatsCtx, chatRh, chatInfo.id, link, selectedItems, appBar, scrollToItemId, { + GroupChatInfoView(chatsCtx, chatRh, chatInfo.id, link, linkLoaded, selectedItems, appBar, scrollToItemId, { link = it preloadedLink = it }, close, { showSearch.value = true }) 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 973b684d38..db99b5df44 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 @@ -63,6 +63,7 @@ fun ModalData.GroupChatInfoView( rhId: Long?, chatId: String, groupLink: GroupLink?, + groupLinkLoaded: Boolean, selectedItems: MutableState?>, appBar: MutableState<@Composable (BoxScope.() -> Unit)?>, scrollToItemId: MutableState, @@ -109,6 +110,7 @@ fun ModalData.GroupChatInfoView( developerTools, onLocalAliasChanged = { setGroupAlias(chat, it, chatModel) }, groupLink, + groupLinkLoaded, selectedItems, appBar, scrollToItemId, @@ -462,14 +464,15 @@ fun AddGroupMembersButton( fun ChannelLinkActionButton( modifier: Modifier, groupInfo: GroupInfo, + groupLinkLoaded: Boolean, manageGroupLink: () -> Unit ) { InfoViewActionButton( modifier = modifier, icon = painterResource(MR.images.ic_link), title = stringResource(MR.strings.action_button_channel_link), - disabled = !groupInfo.ready, - disabledLook = !groupInfo.ready, + disabled = !groupInfo.ready || !groupLinkLoaded, + disabledLook = !groupInfo.ready || !groupLinkLoaded, onClick = manageGroupLink ) } @@ -521,6 +524,7 @@ fun ModalData.GroupChatInfoLayout( developerTools: Boolean, onLocalAliasChanged: (String) -> Unit, groupLink: GroupLink?, + groupLinkLoaded: Boolean, selectedItems: MutableState?>, appBar: MutableState<@Composable (BoxScope.() -> Unit)?>, scrollToItemId: MutableState, @@ -606,7 +610,7 @@ fun ModalData.GroupChatInfoLayout( ) { if (groupInfo.useRelays && groupInfo.isOwner) { SearchButton(modifier = Modifier.fillMaxWidth(0.33f), chat, groupInfo, close, onSearchClicked) - ChannelLinkActionButton(modifier = Modifier.fillMaxWidth(0.5f), groupInfo, manageGroupLink) + ChannelLinkActionButton(modifier = Modifier.fillMaxWidth(0.5f), groupInfo, groupLinkLoaded, manageGroupLink) MuteButton(modifier = Modifier.fillMaxWidth(1f), chat, groupInfo) } else if (!groupInfo.useRelays && groupInfo.canAddMembers) { SearchButton(modifier = Modifier.fillMaxWidth(0.33f), chat, groupInfo, close, onSearchClicked) @@ -681,7 +685,7 @@ fun ModalData.GroupChatInfoLayout( } } else { SectionView { - if (groupInfo.canAddMembers && groupInfo.businessChat == null) { + if (groupInfo.canAddMembers && groupInfo.businessChat == null && groupLinkLoaded) { anyTopSectionRowShow = true if (groupLink == null) { CreateGroupLinkButton(manageGroupLink) @@ -1460,6 +1464,7 @@ fun PreviewGroupChatInfoLayout() { developerTools = false, onLocalAliasChanged = {}, groupLink = null, + groupLinkLoaded = true, selectedItems = remember { mutableStateOf(null) }, appBar = remember { mutableStateOf(null) }, scrollToItemId = remember { mutableStateOf(null) },