From c270a1531d303009f4b18ae069a8e7b28ec3e35d Mon Sep 17 00:00:00 2001 From: Narasimha-sc <166327228+Narasimha-sc@users.noreply.github.com> Date: Mon, 3 Aug 2026 16:12:10 +0000 Subject: [PATCH] android, desktop: extract profile selection from the picker row handler ActiveProfilePicker performed the whole profile change - connection reassignment, switch, alerts, close - inside the row's onSelected lambda, where nothing else can reach it. Lift it to selectProfile(user), called by the row. Pure move: the body is unchanged apart from indentation, so picking a profile behaves exactly as before. It gives the next commit a way to take the same path for a newly created profile rather than duplicating it. --- .../common/views/newchat/NewChatView.kt | 90 ++++++++++--------- 1 file changed, 46 insertions(+), 44 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 d3bca178aa..c2efeccd4f 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 @@ -314,6 +314,51 @@ fun ActiveProfilePicker( } } + fun selectProfile(user: User) { + switchingProfile.value = true + withApi { + try { + appPreferences.incognito.set(false) + var updatedConn: PendingContactConnection? = null; + + if (contactConnection != null) { + updatedConn = controller.apiChangeConnectionUser(rhId, contactConnection.pccConnId, user.userId) + if (updatedConn != null) { + withContext(Dispatchers.Main) { + chatModel.chatsContext.updateContactConnection(rhId, updatedConn) + updateShownConnection(updatedConn) + } + } + } + + if ((contactConnection != null && updatedConn != null) || contactConnection == null) { + controller.changeActiveUser_( + rhId = user.remoteHostId, + toUserId = user.userId, + viewPwd = if (user.hidden) searchTextOrPassword.value else null + ) + + if (chatModel.currentUser.value?.userId != user.userId) { + AlertManager.shared.showAlertMsg(generalGetString( + MR.strings.switching_profile_error_title), + String.format(generalGetString(MR.strings.switching_profile_error_message), user.chatViewName) + ) + } + } + + if (updatedConn != null) { + withContext(Dispatchers.Main) { + chatModel.chatsContext.updateContactConnection(user.remoteHostId, updatedConn) + } + } + + close() + } finally { + switchingProfile.value = false + } + } + } + @Composable fun ProfilePickerUserOption(user: User) { val selected = selectedProfile?.userId == user.userId && !incognito @@ -322,50 +367,7 @@ fun ActiveProfilePicker( title = user.chatViewName, disabled = switchingProfile.value || selected, selected = selected, - onSelected = { - switchingProfile.value = true - withApi { - try { - appPreferences.incognito.set(false) - var updatedConn: PendingContactConnection? = null; - - if (contactConnection != null) { - updatedConn = controller.apiChangeConnectionUser(rhId, contactConnection.pccConnId, user.userId) - if (updatedConn != null) { - withContext(Dispatchers.Main) { - chatModel.chatsContext.updateContactConnection(rhId, updatedConn) - updateShownConnection(updatedConn) - } - } - } - - if ((contactConnection != null && updatedConn != null) || contactConnection == null) { - controller.changeActiveUser_( - rhId = user.remoteHostId, - toUserId = user.userId, - viewPwd = if (user.hidden) searchTextOrPassword.value else null - ) - - if (chatModel.currentUser.value?.userId != user.userId) { - AlertManager.shared.showAlertMsg(generalGetString( - MR.strings.switching_profile_error_title), - String.format(generalGetString(MR.strings.switching_profile_error_message), user.chatViewName) - ) - } - } - - if (updatedConn != null) { - withContext(Dispatchers.Main) { - chatModel.chatsContext.updateContactConnection(user.remoteHostId, updatedConn) - } - } - - close() - } finally { - switchingProfile.value = false - } - } - }, + onSelected = { selectProfile(user) }, image = { ProfileImage(size = 42.dp, image = user.image) }, badge = user.profile.localBadge )