diff --git a/Linphone/Contacts/ContactsManager.swift b/Linphone/Contacts/ContactsManager.swift index 5ff02becb..d8e870b16 100644 --- a/Linphone/Contacts/ContactsManager.swift +++ b/Linphone/Contacts/ContactsManager.swift @@ -183,25 +183,24 @@ final class ContactsManager: ObservableObject { } awaitDataWrite(data: data, name: name) { _, result in - let resultFriend = self.saveFriend(result: result, contact: contact, existingFriend: existingFriend) - - if resultFriend != nil { - if linphoneFriend && existingFriend == nil { - _ = self.linphoneFriendList!.addLocalFriend(linphoneFriend: resultFriend!) - - self.linphoneFriendList!.updateSubscriptions() - } else if existingFriend == nil { - _ = self.friendList!.addLocalFriend(linphoneFriend: resultFriend!) - - self.friendList!.updateSubscriptions() - } + self.saveFriend(result: result, contact: contact, existingFriend: existingFriend) { resultFriend in + if resultFriend != nil { + if linphoneFriend && existingFriend == nil { + _ = self.linphoneFriendList!.addLocalFriend(linphoneFriend: resultFriend!) + + self.linphoneFriendList!.updateSubscriptions() + } else if existingFriend == nil { + _ = self.friendList!.addLocalFriend(linphoneFriend: resultFriend!) + + self.friendList!.updateSubscriptions() + } + } } } } - func saveFriend(result: String, contact: Contact, existingFriend: Friend?) -> Friend? { - - self.coreContext.doOnCoreQueue() { core in + func saveFriend(result: String, contact: Contact, existingFriend: Friend?, completion: @escaping (Friend?) -> Void) { + self.coreContext.doOnCoreQueue { core in do { let friend = (existingFriend != nil) ? existingFriend : try core.createFriend() @@ -257,14 +256,14 @@ final class ContactsManager: ObservableObject { friend!.jobTitle = contact.jobTitle friend!.done() - return friend + completion(friend) } } catch let error { print("Failed to enumerate contact", error) - return nil + completion(nil) } } - return nil + completion(nil) } func getImagePath(friendPhotoPath: String) -> URL { diff --git a/Linphone/Core/CoreContext.swift b/Linphone/Core/CoreContext.swift index a68b25127..350fb6a0d 100644 --- a/Linphone/Core/CoreContext.swift +++ b/Linphone/Core/CoreContext.swift @@ -36,7 +36,7 @@ final class CoreContext: ObservableObject { private init() {} - func doOnCoreQueue(synchronous : Bool = false, lambda: @escaping (Core) -> Void) { + func doOnCoreQueue(synchronous: Bool = false, lambda: @escaping (Core) -> Void) { if synchronous { coreQueue.sync { lambda(self.mCore) @@ -77,7 +77,9 @@ final class CoreContext: ObservableObject { } } - self.mCore.publisher?.onAccountRegistrationStateChanged?.postOnMainQueue { (cbVal: (core: Core, account: Account, state: RegistrationState, message: String)) in + self.mCore.publisher?.onAccountRegistrationStateChanged?.postOnMainQueue {(cbVal: + (core: Core, account: Account, state: RegistrationState, message: String) + ) in // If account has been configured correctly, we will go through Progress and Ok states // Otherwise, we will be Failed. NSLog("New registration state is \(cbVal.state) for user id " + diff --git a/Linphone/UI/Assistant/Viewmodel/AccountLoginViewModel.swift b/Linphone/UI/Assistant/Viewmodel/AccountLoginViewModel.swift index d85b4233e..7462e16dd 100644 --- a/Linphone/UI/Assistant/Viewmodel/AccountLoginViewModel.swift +++ b/Linphone/UI/Assistant/Viewmodel/AccountLoginViewModel.swift @@ -52,7 +52,14 @@ class AccountLoginViewModel: ObservableObject { // userID is set to null as it's the same as the username in our case // ha1 is set to null as we are using the clear text password. Upon first register, the hash will be computed automatically. // The realm will be determined automatically from the first register, as well as the algorithm - let authInfo = try Factory.Instance.createAuthInfo(username: self.username, userid: "", passwd: self.passwd, ha1: "", realm: "", domain: self.domain) + let authInfo = try Factory.Instance.createAuthInfo( + username: self.username, + userid: "", + passwd: self.passwd, + ha1: "", + realm: "", + domain: self.domain + ) // Account object replaces deprecated ProxyConfig object // Account object is configured through an AccountParams object that we can obtain from the Core diff --git a/Linphone/UI/Main/Contacts/Fragments/ContactInnerActionsFragment.swift b/Linphone/UI/Main/Contacts/Fragments/ContactInnerActionsFragment.swift index 23eb79e93..0fbe4845b 100644 --- a/Linphone/UI/Main/Contacts/Fragments/ContactInnerActionsFragment.swift +++ b/Linphone/UI/Main/Contacts/Fragments/ContactInnerActionsFragment.swift @@ -192,7 +192,12 @@ struct ContactInnerActionsFragment: View { && !magicSearch.lastSearch[contactViewModel.indexDisplayedFriend!].friend!.jobTitle!.isEmpty { Text("**Job :** \(magicSearch.lastSearch[contactViewModel.indexDisplayedFriend!].friend!.jobTitle!)") .default_text_style(styleSize: 14) - .padding(.vertical, 15) + .padding(.top, + magicSearch.lastSearch[contactViewModel.indexDisplayedFriend!].friend!.organization != nil + && !magicSearch.lastSearch[contactViewModel.indexDisplayedFriend!].friend!.organization!.isEmpty + ? 0 : 15 + ) + .padding(.bottom, 15) .padding(.horizontal, 20) .frame(maxWidth: .infinity, alignment: .leading) } diff --git a/Linphone/UI/Main/Contacts/Fragments/EditContactFragment.swift b/Linphone/UI/Main/Contacts/Fragments/EditContactFragment.swift index 60f744217..5d24c8f72 100644 --- a/Linphone/UI/Main/Contacts/Fragments/EditContactFragment.swift +++ b/Linphone/UI/Main/Contacts/Fragments/EditContactFragment.swift @@ -493,10 +493,10 @@ struct EditContactFragment: View { if editContactViewModel.selectedEditFriend != nil && selectedImage == nil && !removedImage { - _ = ContactsManager.shared.saveFriend( + ContactsManager.shared.saveFriend( result: String(editContactViewModel.selectedEditFriend!.photo!.dropFirst(6)), contact: newContact, - existingFriend: editContactViewModel.selectedEditFriend + existingFriend: editContactViewModel.selectedEditFriend, completion: {_ in } ) } else { ContactsManager.shared.saveImage( diff --git a/Linphone/Utils/MagicSearchSingleton.swift b/Linphone/Utils/MagicSearchSingleton.swift index 50c9f02e9..7ce369b0a 100644 --- a/Linphone/Utils/MagicSearchSingleton.swift +++ b/Linphone/Utils/MagicSearchSingleton.swift @@ -39,7 +39,7 @@ final class MagicSearchSingleton: ObservableObject { private var domainDefaultAccount = "" private init() { - coreContext.doOnCoreQueue{ core in + coreContext.doOnCoreQueue { core in self.domainDefaultAccount = core.defaultAccount?.params?.domain ?? "" self.magicSearch = try? core.createMagicSearch() @@ -53,7 +53,7 @@ final class MagicSearchSingleton: ObservableObject { } func searchForContacts(sourceFlags: Int) { - coreContext.doOnCoreQueue{ core in + coreContext.doOnCoreQueue { _ in var needResetCache = false DispatchQueue.main.sync {