Fix contact refresh

This commit is contained in:
Benoit Martins 2025-01-31 17:52:41 +01:00
parent 00bbf41f9a
commit 46f5f21216
2 changed files with 9 additions and 16 deletions

View file

@ -88,6 +88,8 @@ final class ContactsManager: ObservableObject {
} }
} }
MagicSearchSingleton.shared.searchForContacts(sourceFlags: MagicSearch.Source.Friends.rawValue | MagicSearch.Source.LdapServers.rawValue)
let store = CNContactStore() let store = CNContactStore()
store.requestAccess(for: .contacts) { (granted, error) in store.requestAccess(for: .contacts) { (granted, error) in
if let error = error { if let error = error {
@ -129,7 +131,7 @@ final class ContactsManager: ObservableObject {
name: contact.givenName + contact.familyName, name: contact.givenName + contact.familyName,
prefix: ((imageThumbnail == nil) ? "-default" : ""), prefix: ((imageThumbnail == nil) ? "-default" : ""),
contact: newContact, linphoneFriend: false, existingFriend: nil) { contact: newContact, linphoneFriend: false, existingFriend: nil) {
if (self.friendList?.friends.count ?? 0) + (self.linphoneFriendList?.friends.count ?? 0) == contactCounter { if (self.friendList?.friends.count ?? 0) == contactCounter {
// Every contact properly added, proceed // Every contact properly added, proceed
self.linphoneFriendList?.updateSubscriptions() self.linphoneFriendList?.updateSubscriptions()
self.friendList?.updateSubscriptions() self.friendList?.updateSubscriptions()
@ -137,6 +139,7 @@ final class ContactsManager: ObservableObject {
if let friendListDelegate = self.friendListDelegate { if let friendListDelegate = self.friendListDelegate {
self.friendList?.removeDelegate(delegate: friendListDelegate) self.friendList?.removeDelegate(delegate: friendListDelegate)
} }
self.friendListDelegate = FriendListDelegateStub(onNewSipAddressDiscovered: { (_: FriendList, linphoneFriend: Friend, sipUri: String) in self.friendListDelegate = FriendListDelegateStub(onNewSipAddressDiscovered: { (_: FriendList, linphoneFriend: Friend, sipUri: String) in
var addedAvatarListModel: [ContactAvatarModel] = [] var addedAvatarListModel: [ContactAvatarModel] = []
linphoneFriend.phoneNumbers.forEach { phone in linphoneFriend.phoneNumbers.forEach { phone in
@ -160,11 +163,10 @@ final class ContactsManager: ObservableObject {
DispatchQueue.main.async { DispatchQueue.main.async {
self.avatarListModel += addedAvatarListModel self.avatarListModel += addedAvatarListModel
self.avatarListModel = self.avatarListModel.sorted { $0.name < $1.name }
} }
}) })
self.friendList?.addDelegate(delegate: self.friendListDelegate!) self.friendList?.addDelegate(delegate: self.friendListDelegate!)
MagicSearchSingleton.shared.searchForContacts(sourceFlags: MagicSearch.Source.Friends.rawValue | MagicSearch.Source.LdapServers.rawValue)
} }
} }
} }

View file

@ -73,8 +73,8 @@ struct ContactInnerFragment: View {
} }
Spacer() Spacer()
if contactViewModel.indexDisplayedFriend != nil && contactViewModel.indexDisplayedFriend! < contactsManager.lastSearch.count
&& !contactAvatarModel.nativeUri.isEmpty { if !contactAvatarModel.nativeUri.isEmpty {
Button(action: { Button(action: {
editNativeContact() editNativeContact()
}, label: { }, label: {
@ -118,17 +118,9 @@ struct ContactInnerFragment: View {
VStack(spacing: 0) { VStack(spacing: 0) {
VStack(spacing: 0) { VStack(spacing: 0) {
VStack(spacing: 0) { VStack(spacing: 0) {
if contactViewModel.indexDisplayedFriend != nil && contactViewModel.indexDisplayedFriend! < contactsManager.lastSearch.count { if contactViewModel.indexDisplayedFriend != nil {
Avatar(contactAvatarModel: contactAvatarModel, avatarSize: 100) Avatar(contactAvatarModel: contactAvatarModel, avatarSize: 100)
} else if contactViewModel.indexDisplayedFriend != nil
&& contactViewModel.indexDisplayedFriend! < contactsManager.lastSearch.count {
Image("profil-picture-default")
.resizable()
.frame(width: 100, height: 100)
.clipShape(Circle())
}
if contactViewModel.indexDisplayedFriend != nil
&& contactViewModel.indexDisplayedFriend! < contactsManager.lastSearch.count {
Text(contactAvatarModel.name) Text(contactAvatarModel.name)
.foregroundStyle(Color.grayMain2c700) .foregroundStyle(Color.grayMain2c700)
.multilineTextAlignment(.center) .multilineTextAlignment(.center)
@ -144,7 +136,6 @@ struct ContactInnerFragment: View {
.default_text_style_300(styleSize: 12) .default_text_style_300(styleSize: 12)
.frame(maxWidth: .infinity) .frame(maxWidth: .infinity)
} }
} }
.frame(minHeight: 150) .frame(minHeight: 150)
.frame(maxWidth: .infinity) .frame(maxWidth: .infinity)