mirror of
https://github.com/simplex-chat/simplex-chat.git
synced 2026-09-09 13:56:06 +00:00
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:
@@ -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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user