From 80bcaf8405ba4f2dcabec16bfcea8168becfd820 Mon Sep 17 00:00:00 2001 From: Narasimha-sc <166327228+Narasimha-sc@users.noreply.github.com> Date: Thu, 6 Aug 2026 20:31:03 +0000 Subject: [PATCH] ios: check for the ignored flag before refreshing the profile lists Both iOS surfaces refreshed chatModel.users - and their own copy of it - immediately after creating the profile, before checking whether the core had honoured keepActiveUser. On the path where it did not, that list already has the new profile marked active while chatModel.currentUser is still the previous one, so anything derived from users disagrees with the active user until the resync lands. Kotlin checks first and never opens that window. Moving the check up also drops the refresh from that path entirely, since changeActiveUserAsync_ does its own, and lets the remaining refresh share the MainActor.run that was already there. --- .../ContextProfilePickerView.swift | 19 ++++++++++--------- .../Shared/Views/NewChat/NewChatView.swift | 11 ++++++----- 2 files changed, 16 insertions(+), 14 deletions(-) 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