mirror of
https://github.com/simplex-chat/simplex-chat.git
synced 2026-08-16 02:30:19 +00:00
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:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user