From 7c6f046b5843bf69cd4ebd341a20c9050ca49089 Mon Sep 17 00:00:00 2001 From: Narasimha-sc <166327228+Narasimha-sc@users.noreply.github.com> Date: Thu, 30 Jul 2026 16:31:58 +0000 Subject: [PATCH] android, desktop: parameterise create-profile form's submit action CreateProfile hardcoded what happens after submission, choosing between createProfileInProfiles and createProfileInNoProfileSetup inside the button handler. That conditional is a hidden premise: two call sites invoke the composable and neither can see from the call that submission behaves differently for them. Lift the choice to the callers. The callback passes raw fields rather than a Profile because the two paths do not build the same one - the no-profile-setup path drops shortDescr and passes a null remote host id - so a Profile-shaped callback would silently change its behaviour. The chatModel parameter was redundant besides: UserPicker passed the platform-level chatModel global, which the parameter merely shadowed. No behaviour change - the conditional moves verbatim into createProfileFromForm, which both call sites invoke, rather than being copied into each. --- .../chat/simplex/common/views/WelcomeView.kt | 21 ++++++++++++------- .../common/views/chatlist/UserPicker.kt | 5 ++++- .../views/usersettings/UserProfilesView.kt | 5 ++++- 3 files changed, 21 insertions(+), 10 deletions(-) diff --git a/apps/multiplatform/common/src/commonMain/kotlin/chat/simplex/common/views/WelcomeView.kt b/apps/multiplatform/common/src/commonMain/kotlin/chat/simplex/common/views/WelcomeView.kt index 843bacecec..32cb6919ad 100644 --- a/apps/multiplatform/common/src/commonMain/kotlin/chat/simplex/common/views/WelcomeView.kt +++ b/apps/multiplatform/common/src/commonMain/kotlin/chat/simplex/common/views/WelcomeView.kt @@ -58,7 +58,7 @@ fun bioFitsLimit(bio: String): Boolean { } @Composable -fun CreateProfile(chatModel: ChatModel, close: () -> Unit) { +fun CreateProfile(onSubmit: (displayName: String, shortDescr: String, image: String?) -> Unit) { val scope = rememberCoroutineScope() val scrollState = rememberScrollState() val keyboardState by getKeyboardState() @@ -160,13 +160,7 @@ fun CreateProfile(chatModel: ChatModel, close: () -> Unit) { disabled = !canCreateProfile(displayName.value) || !bioFitsLimit(shortDescr.value), textColor = MaterialTheme.colors.primary, iconColor = MaterialTheme.colors.primary, - click = { - if (chatModel.localUserCreated.value == true) { - createProfileInProfiles(chatModel, displayName.value, shortDescr.value, profileImage.value, close) - } else { - createProfileInNoProfileSetup(displayName.value, profileImage.value, close) - } - }, + click = { onSubmit(displayName.value, shortDescr.value, profileImage.value) }, ) SectionTextFooter(generalGetString(MR.strings.your_profile_is_stored_on_your_device)) SectionTextFooter(generalGetString(MR.strings.profile_is_only_shared_with_your_contacts)) @@ -353,6 +347,17 @@ private fun CreateFirstProfileDesktop(chatModel: ChatModel, close: () -> Unit) { } } +// The two ordinary "add a profile" paths, where the new profile becomes the active +// one. Creating one for an invitation takes neither, which is why the form itself +// no longer chooses. +fun createProfileFromForm(chatModel: ChatModel, displayName: String, shortDescr: String, image: String?, close: () -> Unit) { + if (chatModel.localUserCreated.value == true) { + createProfileInProfiles(chatModel, displayName, shortDescr, image, close) + } else { + createProfileInNoProfileSetup(displayName, image, close) + } +} + fun createProfileInNoProfileSetup(displayName: String, image: String? = null, close: () -> Unit) { withBGApi { val user = controller.apiCreateActiveUser(null, Profile(displayName.trim(), "", null, image)) ?: return@withBGApi diff --git a/apps/multiplatform/common/src/commonMain/kotlin/chat/simplex/common/views/chatlist/UserPicker.kt b/apps/multiplatform/common/src/commonMain/kotlin/chat/simplex/common/views/chatlist/UserPicker.kt index 81a6b31323..45cbdf78cf 100644 --- a/apps/multiplatform/common/src/commonMain/kotlin/chat/simplex/common/views/chatlist/UserPicker.kt +++ b/apps/multiplatform/common/src/commonMain/kotlin/chat/simplex/common/views/chatlist/UserPicker.kt @@ -30,6 +30,7 @@ import chat.simplex.common.ui.theme.* import chat.simplex.common.views.helpers.* import chat.simplex.common.platform.* import chat.simplex.common.views.CreateProfile +import chat.simplex.common.views.createProfileFromForm import chat.simplex.common.views.localauth.VerticalDivider import chat.simplex.common.views.remote.* import chat.simplex.common.views.usersettings.* @@ -259,7 +260,9 @@ fun UserPicker( LaunchedEffect(Unit) { userPickerState.value = AnimatedViewState.HIDING } - CreateProfile(chat.simplex.common.platform.chatModel, close) + CreateProfile { displayName, shortDescr, image -> + createProfileFromForm(chat.simplex.common.platform.chatModel, displayName, shortDescr, image, close) + } } } } diff --git a/apps/multiplatform/common/src/commonMain/kotlin/chat/simplex/common/views/usersettings/UserProfilesView.kt b/apps/multiplatform/common/src/commonMain/kotlin/chat/simplex/common/views/usersettings/UserProfilesView.kt index ac21fb6b23..38974d2b0e 100644 --- a/apps/multiplatform/common/src/commonMain/kotlin/chat/simplex/common/views/usersettings/UserProfilesView.kt +++ b/apps/multiplatform/common/src/commonMain/kotlin/chat/simplex/common/views/usersettings/UserProfilesView.kt @@ -28,6 +28,7 @@ import chat.simplex.common.views.chatlist.UserProfilePickerItem import chat.simplex.common.views.chatlist.UserProfileRow import chat.simplex.common.views.helpers.* import chat.simplex.common.views.CreateProfile +import chat.simplex.common.views.createProfileFromForm import chat.simplex.common.views.database.* import chat.simplex.common.views.onboarding.OnboardingStage import chat.simplex.res.MR @@ -49,7 +50,9 @@ fun UserProfilesView(m: ChatModel, search: MutableState, profileHidden: addUser = { withAuth { ModalManager.center.showModalCloseable { close -> - CreateProfile(m, close) + CreateProfile { displayName, shortDescr, image -> + createProfileFromForm(m, displayName, shortDescr, image, close) + } } } },