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.
This commit is contained in:
Narasimha-sc
2026-08-06 19:15:56 +00:00
parent f20925e086
commit 51cb747d2a
2 changed files with 9 additions and 7 deletions
@@ -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
@@ -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