mirror of
https://github.com/simplex-chat/simplex-chat.git
synced 2026-11-04 17:17:39 +00:00
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.
This commit is contained in:
1 parent
d9e5f49685
commit
e4f5eaf404
2 files changed
+15
-8
No files matched your search
+6
-4
@@ -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<ConnectionStats?, Profile?>? by remember { mutableStateOf(preloadedContactInfo) }
|
||||
var code: String? by remember { mutableStateOf(preloadedCode) }
|
||||
var contactInfo: Pair<ConnectionStats?, Profile?>? 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 })
|
||||
|
||||
+9
-4
@@ -63,6 +63,7 @@ fun ModalData.GroupChatInfoView(
|
||||
rhId: Long?,
|
||||
chatId: String,
|
||||
groupLink: GroupLink?,
|
||||
groupLinkLoaded: Boolean,
|
||||
selectedItems: MutableState<Set<Long>?>,
|
||||
appBar: MutableState<@Composable (BoxScope.() -> Unit)?>,
|
||||
scrollToItemId: MutableState<Long?>,
|
||||
@@ -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<Set<Long>?>,
|
||||
appBar: MutableState<@Composable (BoxScope.() -> Unit)?>,
|
||||
scrollToItemId: MutableState<Long?>,
|
||||
@@ -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) },
|
||||
|
||||
Reference in new issue
Block a user