ios: share the create-and-refresh step between both pickers

Both create functions repeated the same create + listUsers + model
update; only the final action differs. Extract it next to
apiCreateActiveUser, as Kotlin already does with
createProfileForInvitation.
This commit is contained in:
Narasimha-sc
2026-09-05 15:12:02 +00:00
parent 0cfbebfbb2
commit 86a8c64aa0
3 changed files with 12 additions and 12 deletions
+8
View File
@@ -259,6 +259,14 @@ func apiCreateActiveUser(_ p: Profile?, pastTimestamp: Bool = false, keepActiveU
throw r.unexpected
}
func createProfileKeepingActiveUser(_ profile: Profile) async throws -> User {
let newUser = try apiCreateActiveUser(profile, keepActiveUser: true)
if let users = try? await listUsersAsync() {
await MainActor.run { ChatModel.shared.users = users }
}
return newUser
}
func listUsers() throws -> [UserInfo] {
return try listUsersResponse(chatSendCmdSync(.listUsers))
}
@@ -229,14 +229,10 @@ struct ContextProfilePickerView: View {
}
private func createProfileForChat(_ profile: Profile) async throws {
let newUser = try apiCreateActiveUser(profile, keepActiveUser: true)
let updatedUsers = try? await listUsersAsync()
let newUser = try await createProfileKeepingActiveUser(profile)
await MainActor.run {
showAddProfile = false
if let updatedUsers {
chatModel.users = updatedUsers
users = updatedUsers.map { $0.user }.filter { u in u.activeUser || !u.hidden }
}
users = chatModel.users.map { $0.user }.filter { u in u.activeUser || !u.hidden }
changeProfile(newUser)
}
}
@@ -576,14 +576,10 @@ private struct ActiveProfilePicker: View {
}
private func createProfileForConnection(_ profile: Profile) async throws {
let newUser = try apiCreateActiveUser(profile, keepActiveUser: true)
let updatedUsers = try? await listUsersAsync()
let newUser = try await createProfileKeepingActiveUser(profile)
await MainActor.run {
showAddProfile = false
if let updatedUsers {
chatModel.users = updatedUsers
profiles = updatedUsers.map { $0.user }
}
profiles = chatModel.users.map { $0.user }
selectedProfile = newUser
profileSwitchStatus = .switchingUser
}