From 51cb747d2af953b8e99e515677c44e3638d396b8 Mon Sep 17 00:00:00 2001 From: Narasimha-sc <166327228+Narasimha-sc@users.noreply.github.com> Date: Thu, 6 Aug 2026 19:15:56 +0000 Subject: [PATCH] ios: derive the switch outcome from the active user instead of a flag The one-time link picker's old-core fallback set selectedProfile to the new user unconditionally, but the resync it does first is wrapped in a catch - so when the switch threw, the picker put its checkmark on a profile that is not active and cannot be selected, because the view then thinks it is already selected. Reading chatModel.currentUser instead is right in both cases and is a line shorter. The compose picker had the same question answered with a local switched flag. The active user answers it there too, which removes the flag, the two assignments that set it, and with them the mutable-local-in-a-@Sendable-closure problem that flag caused when it was first introduced. --- .../Chat/ComposeMessage/ContextProfilePickerView.swift | 10 +++++----- apps/ios/Shared/Views/NewChat/NewChatView.swift | 6 ++++-- 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/apps/ios/Shared/Views/Chat/ComposeMessage/ContextProfilePickerView.swift b/apps/ios/Shared/Views/Chat/ComposeMessage/ContextProfilePickerView.swift index 52fa8a0b07..aa09b563bd 100644 --- a/apps/ios/Shared/Views/Chat/ComposeMessage/ContextProfilePickerView.swift +++ b/apps/ios/Shared/Views/Chat/ComposeMessage/ContextProfilePickerView.swift @@ -269,19 +269,19 @@ struct ContextProfilePickerView: View { if newUser.activeUser { // An older remote host ignored keepActiveUser, so the reassignment would // fail. Resync and report - not rethrown, or the form blames the creation. - let switched: Bool do { try await changeActiveUserAsync_(newUser.userId, viewPwd: nil) - switched = true } catch { logger.error("changeActiveUserAsync_ error: \(responseError(error))") - switched = false } await MainActor.run { // Unconditional: the switch only removes this view when it succeeded showAddProfile = false - // Only if it switched: the chat is then gone from the list and renders blank - if switched && chatModel.chatId == chat.id { chatModel.chatId = nil } + // Only if it switched, which the active user tells us: the prepared chat + // is then gone from the reloaded list and would render blank. + if chatModel.currentUser?.userId == newUser.userId && chatModel.chatId == chat.id { + chatModel.chatId = nil + } } alertAfterDismissal(NSLocalizedString("Error changing chat profile", comment: "alert title")) return diff --git a/apps/ios/Shared/Views/NewChat/NewChatView.swift b/apps/ios/Shared/Views/NewChat/NewChatView.swift index 7fcd042714..067478d4f8 100644 --- a/apps/ios/Shared/Views/NewChat/NewChatView.swift +++ b/apps/ios/Shared/Views/NewChat/NewChatView.swift @@ -610,9 +610,11 @@ private struct ActiveProfilePicker: View { // with the previous one, so a second attempt would fail the same way. await MainActor.run { showAddProfile = false - // Make the picker agree with the profile that is now active profileSwitchStatus = .idle - selectedProfile = newUser + // Whatever the resync above ended up with - newUser if it switched, the + // previous profile if it threw. Not newUser unconditionally, or a failed + // switch leaves the checkmark on a profile that is not active. + selectedProfile = chatModel.currentUser ?? selectedProfile } alertAfterDismissal(NSLocalizedString("Error changing chat profile", comment: "alert title")) return