mirror of
https://github.com/simplex-chat/simplex-chat.git
synced 2026-08-14 07:10:19 +00:00
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.
This commit is contained in:
@@ -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
|
||||
}
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user