From 10b88a02cb2949dbdd45528791575a302478d4f5 Mon Sep 17 00:00:00 2001 From: Narasimha-sc <166327228+Narasimha-sc@users.noreply.github.com> Date: Fri, 4 Sep 2026 17:29:48 +0000 Subject: [PATCH] ui: don't commit profile picker state when the change failed ActiveProfilePicker wrote the app-wide incognito preference before the call that can fail, and never rolled it back, in both directions: - selecting a profile set incognito=false, then, if apiChangeConnectionUser returned null, left the connection incognito while the preference said otherwise - selecting Incognito set incognito=true before apiSetConnectionIncognito, and undid nothing when it returned null Neither is visible at the time: the row reads the connection first (showingInvitation.value?.conn?.incognito), which was not changed. It surfaces on the next connection started with showingInvitation null, which falls through to the preference. Selecting a profile also closed the picker unconditionally, so a failed apiChangeConnectionUser left the connection on the old profile with the picker dismissed as if it had worked. Both APIs alert on error, so the failure was reported - but the picker still closed. Move all three inside the branch that runs only when the change landed. --- .../simplex/common/views/newchat/NewChatView.kt | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/apps/multiplatform/common/src/commonMain/kotlin/chat/simplex/common/views/newchat/NewChatView.kt b/apps/multiplatform/common/src/commonMain/kotlin/chat/simplex/common/views/newchat/NewChatView.kt index f3006d221b..59567e5f35 100644 --- a/apps/multiplatform/common/src/commonMain/kotlin/chat/simplex/common/views/newchat/NewChatView.kt +++ b/apps/multiplatform/common/src/commonMain/kotlin/chat/simplex/common/views/newchat/NewChatView.kt @@ -326,7 +326,6 @@ fun ActiveProfilePicker( switchingProfile.value = true withApi { try { - appPreferences.incognito.set(false) var updatedConn: PendingContactConnection? = null; if (contactConnection != null) { @@ -340,6 +339,7 @@ fun ActiveProfilePicker( } if ((contactConnection != null && updatedConn != null) || contactConnection == null) { + appPreferences.incognito.set(false) controller.changeActiveUser_( rhId = user.remoteHostId, toUserId = user.userId, @@ -352,15 +352,15 @@ fun ActiveProfilePicker( String.format(generalGetString(MR.strings.switching_profile_error_message), user.chatViewName) ) } - } - if (updatedConn != null) { - withContext(Dispatchers.Main) { - chatModel.chatsContext.updateContactConnection(user.remoteHostId, updatedConn) + if (updatedConn != null) { + withContext(Dispatchers.Main) { + chatModel.chatsContext.updateContactConnection(user.remoteHostId, updatedConn) + } } - } - close() + close() + } } finally { switchingProfile.value = false } @@ -383,9 +383,9 @@ fun ActiveProfilePicker( switchingProfile.value = true withApi { try { - appPreferences.incognito.set(true) val conn = controller.apiSetConnectionIncognito(rhId, contactConnection.pccConnId, true) if (conn != null) { + appPreferences.incognito.set(true) withContext(Dispatchers.Main) { chatModel.chatsContext.updateContactConnection(rhId, conn) updateShownConnection(conn)