From 27f0e133acfc0893eb08a53d673354d8ef35e683 Mon Sep 17 00:00:00 2001 From: Narasimha-sc <166327228+Narasimha-sc@users.noreply.github.com> Date: Sat, 5 Sep 2026 11:16:14 +0000 Subject: [PATCH] ui: don't switch profile when the prepared chat failed to move ComposeContextProfilePickerView.changeProfile called changeActiveUser_ outside both 'updated != null' branches, so when apiChangePreparedContactUser or apiChangePreparedGroupUser returned null the chat stayed on the old profile but the active user was switched anyway: the API showed "Error changing profile", and then the profile switched regardless. The prepared chat is then left behind on a profile the user is no longer on. Kotlin only: the iOS twin throws instead of returning null, so its outer catch already skips the switch. --- .../common/views/chat/ComposeContextProfilePickerView.kt | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/apps/multiplatform/common/src/commonMain/kotlin/chat/simplex/common/views/chat/ComposeContextProfilePickerView.kt b/apps/multiplatform/common/src/commonMain/kotlin/chat/simplex/common/views/chat/ComposeContextProfilePickerView.kt index 80940bf631..960e2eb997 100644 --- a/apps/multiplatform/common/src/commonMain/kotlin/chat/simplex/common/views/chat/ComposeContextProfilePickerView.kt +++ b/apps/multiplatform/common/src/commonMain/kotlin/chat/simplex/common/views/chat/ComposeContextProfilePickerView.kt @@ -79,6 +79,7 @@ fun ComposeContextProfilePickerView( fun changeProfile(newUser: User) { withApi { + var chatMoved = false if (chat.chatInfo is ChatInfo.Direct) { val updatedContact = chatModel.controller.apiChangePreparedContactUser(rhId, chat.chatInfo.contact.contactId, newUser.userId) if (updatedContact != null) { @@ -86,6 +87,7 @@ fun ComposeContextProfilePickerView( chatModel.controller.appPrefs.incognito.set(false) listExpanded.value = false chatModel.chatsContext.updateContact(rhId, updatedContact) + chatMoved = true } } else if (chat.chatInfo is ChatInfo.Group) { val updatedGroup = chatModel.controller.apiChangePreparedGroupUser(rhId, chat.chatInfo.groupInfo.groupId, newUser.userId) @@ -94,8 +96,10 @@ fun ComposeContextProfilePickerView( chatModel.controller.appPrefs.incognito.set(false) listExpanded.value = false chatModel.chatsContext.updateGroup(rhId, updatedGroup) + chatMoved = true } } + if (!chatMoved) return@withApi chatModel.controller.changeActiveUser_( rhId = newUser.remoteHostId, toUserId = newUser.userId,