diff --git a/Ring/Ring/Bridging/AccountCreation/AccountAdapter.h b/Ring/Ring/Bridging/AccountCreation/AccountAdapter.h index aeacf1a96dd91be9f5c74af1f76711ca884b0d1f..9ff185b340c29c037847f2bca876218301ae976b 100644 --- a/Ring/Ring/Bridging/AccountCreation/AccountAdapter.h +++ b/Ring/Ring/Bridging/AccountCreation/AccountAdapter.h @@ -89,5 +89,8 @@ destinationPath:(NSString *)destinationPath scheme:(NSString *)scheme password:(NSString *)password; +-(void)updateProfile:(NSString *)accountId + displayName:(NSString *)displayName + avatar:(NSString *)avatar; @end diff --git a/Ring/Ring/Bridging/AccountCreation/AccountAdapter.mm b/Ring/Ring/Bridging/AccountCreation/AccountAdapter.mm index 2620fcebd335481a9753fd1975d16efd67de1066..86bf9f7ed126f8b2697a80269b5c88206c817ff7 100644 --- a/Ring/Ring/Bridging/AccountCreation/AccountAdapter.mm +++ b/Ring/Ring/Bridging/AccountCreation/AccountAdapter.mm @@ -225,6 +225,14 @@ static id <AccountAdapterDelegate> _delegate; std::string([newPassword UTF8String])); } +-(void)updateProfile:(NSString *)accountId + displayName:(NSString *)displayName + avatar:(NSString *)avatar { + updateProfile(std::string([accountId UTF8String]), + std::string([displayName UTF8String]), + std::string([avatar UTF8String]), 1); +} + -(void)setAccountsActive:(BOOL) active { auto accounts = getAccountList(); for(auto account: accounts) { diff --git a/Ring/Ring/Features/Settings/Me/EditProfileVM.swift b/Ring/Ring/Features/Settings/Me/EditProfileVM.swift index 0af4282ddb66cd00d1ac88e19560a53c0705686d..a103f2e676dd0b16b4c0e906ddd11da7813094cc 100644 --- a/Ring/Ring/Features/Settings/Me/EditProfileVM.swift +++ b/Ring/Ring/Features/Settings/Me/EditProfileVM.swift @@ -42,18 +42,18 @@ class EditProfileVM: ObservableObject, AvatarViewDataModel { } func updateProfile() { - var photo: String? - if let image = self.profileImage?.fixOrientation(), - let imageData = image.convertToData(ofMaxSize: 40000) { - photo = imageData.base64EncodedString() + // Run on a background thread + Task { + var photo: String? + + if let image = self.profileImage?.fixOrientation(), + let imageData = image.convertToData(ofMaxSize: 40000) { + photo = imageData.base64EncodedString() + } + + let avatar: String = photo ?? "" + + await self.accountService.updateProfile(accountId: self.account.id, displayName: self.profileName, avatar: avatar) } - guard let details = self.account.details else { return } - details.set(withConfigKeyModel: ConfigKeyModel(withKey: ConfigKey.displayName), withValue: self.profileName) - account.details = details - self.accountService.setAccountDetails(forAccountId: account.id, withDetails: details) - let accountUri = AccountModelHelper.init(withAccount: account).uri ?? "" - self.profileService.updateAccountProfile(accountId: account.id, - alias: self.profileName, - photo: photo, accountURI: accountUri) } } diff --git a/Ring/Ring/Features/Walkthrough/Models/WelcomeVM.swift b/Ring/Ring/Features/Walkthrough/Models/WelcomeVM.swift index 825736beb2614c25bc121e584274581c932a33b7..93f7181d46b09c1fec82f477500fcf1d503788a4 100644 --- a/Ring/Ring/Features/Walkthrough/Models/WelcomeVM.swift +++ b/Ring/Ring/Features/Walkthrough/Models/WelcomeVM.swift @@ -229,21 +229,22 @@ extension WelcomeVM { } private func saveProfile(accountId: String) { - guard let account = self.accountService.getAccount(fromAccountId: accountId) else { - return - } - let photo = convertProfileImageToBase64() + // Run on a background thread + Task { + guard let account = self.accountService.getAccount(fromAccountId: accountId) else { + return + } + let photo = convertProfileImageToBase64() - if photo == nil && profileName.isEmpty { - // No changes for profile - return - } + if photo == nil && profileName.isEmpty { + // No changes for profile + return + } - let accountURI = AccountModelHelper(withAccount: account).uri ?? "" - profileService.updateAccountProfile(accountId: accountId, - alias: profileName, - photo: photo, - accountURI: accountURI) + let avatar: String = photo ?? "" + + await self.accountService.updateProfile(accountId: account.id, displayName: self.profileName, avatar: avatar) + } } private func convertProfileImageToBase64() -> String? { diff --git a/Ring/Ring/Services/AccountsService.swift b/Ring/Ring/Services/AccountsService.swift index d8a3a9a6bc3fbcf4c122de1338a07aa19ae5d5ac..94d3f215fd8ebdb882933fedced1c4eaae73f500 100644 --- a/Ring/Ring/Services/AccountsService.swift +++ b/Ring/Ring/Services/AccountsService.swift @@ -382,6 +382,10 @@ class AccountsService: AccountAdapterDelegate { accountAdapter.revokeDevice(account, password: password, deviceId: deviceId) } + func updateProfile(accountId: String, displayName: String, avatar: String) async { + accountAdapter.updateProfile(accountId, displayName: displayName, avatar: avatar) + } + /** Gathers all the initial default details contained by any accounts, Ring or SIP.