mirror of
https://github.com/simplex-chat/simplex-chat.git
synced 2026-03-30 16:25:57 +00:00
ios: update contacts on profile update (#2970)
* ios: update contacts on profile update * change * remove init --------- Co-authored-by: Evgeny Poberezkin <2769109+epoberezkin@users.noreply.github.com>
This commit is contained in:
committed by
GitHub
parent
9639fd26b8
commit
16792de67a
@@ -691,12 +691,12 @@ func apiListContacts() throws -> [Contact] {
|
||||
throw r
|
||||
}
|
||||
|
||||
func apiUpdateProfile(profile: Profile) async throws -> Profile? {
|
||||
func apiUpdateProfile(profile: Profile) async throws -> (Profile, [Contact])? {
|
||||
let userId = try currentUserId("apiUpdateProfile")
|
||||
let r = await chatSendCmd(.apiUpdateProfile(userId: userId, profile: profile))
|
||||
switch r {
|
||||
case .userProfileNoChange: return nil
|
||||
case let .userProfileUpdated(_, _, toProfile): return toProfile
|
||||
case let .userProfileUpdated(_, _, toProfile, updateSummary): return (toProfile, updateSummary.changedContacts)
|
||||
default: throw r
|
||||
}
|
||||
}
|
||||
@@ -706,7 +706,7 @@ func apiSetProfileAddress(on: Bool) async throws -> User? {
|
||||
let r = await chatSendCmd(.apiSetProfileAddress(userId: userId, on: on))
|
||||
switch r {
|
||||
case .userProfileNoChange: return nil
|
||||
case let .userProfileUpdated(user, _, _): return user
|
||||
case let .userProfileUpdated(user, _, _, _): return user
|
||||
default: throw r
|
||||
}
|
||||
}
|
||||
|
||||
@@ -130,7 +130,7 @@ struct GroupProfileView: View {
|
||||
let err = responseError(error)
|
||||
saveGroupError = err
|
||||
showSaveErrorAlert = true
|
||||
logger.error("UserProfile apiUpdateProfile error: \(err)")
|
||||
logger.error("GroupProfile apiUpdateGroup error: \(err)")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -71,9 +71,10 @@ struct PreferencesView: View {
|
||||
do {
|
||||
var p = fromLocalProfile(profile)
|
||||
p.preferences = fullPreferencesToPreferences(preferences)
|
||||
if let newProfile = try await apiUpdateProfile(profile: p) {
|
||||
if let (newProfile, updatedContacts) = try await apiUpdateProfile(profile: p) {
|
||||
await MainActor.run {
|
||||
chatModel.updateCurrentUser(newProfile, preferences)
|
||||
updatedContacts.forEach(chatModel.updateContact)
|
||||
currentPreferences = preferences
|
||||
}
|
||||
}
|
||||
|
||||
@@ -144,7 +144,7 @@ struct UserProfile: View {
|
||||
func saveProfile() {
|
||||
Task {
|
||||
do {
|
||||
if let newProfile = try await apiUpdateProfile(profile: profile) {
|
||||
if let (newProfile, _) = try await apiUpdateProfile(profile: profile) {
|
||||
DispatchQueue.main.async {
|
||||
chatModel.updateCurrentUser(newProfile)
|
||||
profile = newProfile
|
||||
|
||||
@@ -457,7 +457,7 @@ public enum ChatResponse: Decodable, Error {
|
||||
case contactDeleted(user: UserRef, contact: Contact)
|
||||
case chatCleared(user: UserRef, chatInfo: ChatInfo)
|
||||
case userProfileNoChange(user: User)
|
||||
case userProfileUpdated(user: User, fromProfile: Profile, toProfile: Profile)
|
||||
case userProfileUpdated(user: User, fromProfile: Profile, toProfile: Profile, updateSummary: UserProfileUpdateSummary)
|
||||
case userPrivacy(user: User, updatedUser: User)
|
||||
case contactAliasUpdated(user: UserRef, toContact: Contact)
|
||||
case connectionAliasUpdated(user: UserRef, toConnection: PendingContactConnection)
|
||||
@@ -724,7 +724,7 @@ public enum ChatResponse: Decodable, Error {
|
||||
case let .contactDeleted(u, contact): return withUser(u, String(describing: contact))
|
||||
case let .chatCleared(u, chatInfo): return withUser(u, String(describing: chatInfo))
|
||||
case .userProfileNoChange: return noDetails
|
||||
case let .userProfileUpdated(u, _, toProfile): return withUser(u, String(describing: toProfile))
|
||||
case let .userProfileUpdated(u, _, toProfile, _): return withUser(u, String(describing: toProfile))
|
||||
case let .userPrivacy(u, updatedUser): return withUser(u, String(describing: updatedUser))
|
||||
case let .contactAliasUpdated(u, toContact): return withUser(u, String(describing: toContact))
|
||||
case let .connectionAliasUpdated(u, toConnection): return withUser(u, String(describing: toConnection))
|
||||
|
||||
@@ -171,6 +171,13 @@ public func fromLocalProfile (_ profile: LocalProfile) -> Profile {
|
||||
Profile(displayName: profile.displayName, fullName: profile.fullName, image: profile.image, contactLink: profile.contactLink, preferences: profile.preferences)
|
||||
}
|
||||
|
||||
public struct UserProfileUpdateSummary: Decodable {
|
||||
public var notChanged: Int
|
||||
public var updateSuccesses: Int
|
||||
public var updateFailures: Int
|
||||
public var changedContacts: [Contact]
|
||||
}
|
||||
|
||||
public enum ChatType: String {
|
||||
case direct = "@"
|
||||
case group = "#"
|
||||
|
||||
Reference in New Issue
Block a user