diff --git a/apps/ios/Shared/Views/Chat/ComposeMessage/ContextProfilePickerView.swift b/apps/ios/Shared/Views/Chat/ComposeMessage/ContextProfilePickerView.swift index aa09b563bd..98afa31a47 100644 --- a/apps/ios/Shared/Views/Chat/ComposeMessage/ContextProfilePickerView.swift +++ b/apps/ios/Shared/Views/Chat/ComposeMessage/ContextProfilePickerView.swift @@ -258,14 +258,9 @@ struct ContextProfilePickerView: View { defer { Task { @MainActor in creatingProfile = false } } let profile = Profile(displayName: displayName, fullName: "", shortDescr: shortDescr, image: image) let newUser = try apiCreateActiveUser(profile, keepActiveUser: true) - let updatedUsers = try? await listUsersAsync() - await MainActor.run { - if let updatedUsers = updatedUsers { - chatModel.users = updatedUsers - // Only filled in onAppear otherwise, so the new profile is missing here - users = updatedUsers.map { $0.user }.filter { u in u.activeUser || !u.hidden } - } - } + // Checked before refreshing the lists below: on this path the core has already + // activated the new profile, so they would disagree with chatModel.currentUser + // until the resync lands - and changeActiveUserAsync_ refreshes them anyway. 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. @@ -286,8 +281,14 @@ struct ContextProfilePickerView: View { alertAfterDismissal(NSLocalizedString("Error changing chat profile", comment: "alert title")) return } - // Here too: the defer clears creatingProfile as soon as this returns + let updatedUsers = try? await listUsersAsync() await MainActor.run { + if let updatedUsers = updatedUsers { + chatModel.users = updatedUsers + // Only filled in onAppear otherwise, so the new profile is missing here + users = updatedUsers.map { $0.user }.filter { u in u.activeUser || !u.hidden } + } + // changingProfile here too: the defer clears creatingProfile as soon as this returns showAddProfile = false changingProfile = true } diff --git a/apps/ios/Shared/Views/NewChat/NewChatView.swift b/apps/ios/Shared/Views/NewChat/NewChatView.swift index 067478d4f8..ff04578764 100644 --- a/apps/ios/Shared/Views/NewChat/NewChatView.swift +++ b/apps/ios/Shared/Views/NewChat/NewChatView.swift @@ -594,11 +594,9 @@ private struct ActiveProfilePicker: View { defer { Task { @MainActor in creatingProfile = false } } let profile = Profile(displayName: displayName, fullName: "", shortDescr: shortDescr, image: image) let newUser = try apiCreateActiveUser(profile, keepActiveUser: true) - let updatedUsers = try? await listUsersAsync() - await MainActor.run { - if let updatedUsers = updatedUsers { chatModel.users = updatedUsers } - profiles = chatModel.users.map { $0.user } - } + // Checked before refreshing the lists below: on this path the core has already + // activated the new profile, so they would disagree with chatModel.currentUser + // until the resync lands - and changeActiveUserAsync_ refreshes them anyway. if newUser.activeUser { // An older core ignored keepActiveUser, so the connection change would fail do { @@ -619,7 +617,10 @@ private struct ActiveProfilePicker: View { alertAfterDismissal(NSLocalizedString("Error changing chat profile", comment: "alert title")) return } + let updatedUsers = try? await listUsersAsync() await MainActor.run { + if let updatedUsers = updatedUsers { chatModel.users = updatedUsers } + profiles = chatModel.users.map { $0.user } showAddProfile = false selectedProfile = newUser profileSwitchStatus = .switchingUser