Fix friend list refresh triggered by onPresenceReceived

This commit is contained in:
Benoit Martins 2025-09-11 16:31:14 +02:00
parent 1485e7a574
commit 90f2ad7e58
2 changed files with 73 additions and 30 deletions

View file

@ -414,8 +414,11 @@ final class ContactsManager: ObservableObject {
if status == .Successful {
if friendList.displayName != self.nativeAddressBookFriendList && friendList.displayName != self.linphoneAddressBookFriendList {
if let tempRemoteFriendList = self.tempRemoteFriendList {
tempRemoteFriendList.friends.forEach { friend in
_ = tempRemoteFriendList.removeFriend(linphoneFriend: friend)
tempRemoteFriendList.friends.forEach { friend in
if let friendAddress = friend.address,
friendList.friends.contains(where: { $0.address?.weakEqual(address2: friendAddress) == true }) {
_ = tempRemoteFriendList.removeFriend(linphoneFriend: friend)
}
}
}
}
@ -458,6 +461,58 @@ final class ContactsManager: ObservableObject {
},
onPresenceReceived: { (friendList: FriendList, friends: [Friend?]) in
Log.info("\(ContactsManager.TAG) FriendListDelegateStub onPresenceReceived \(friends.count)")
if (friendList.isSubscriptionBodyless) {
Log.info("\(ContactsManager.TAG) Bodyless friendlist \(friendList.displayName ?? "No Display Name") presence received")
if friendList.displayName != self.nativeAddressBookFriendList && friendList.displayName != self.linphoneAddressBookFriendList {
if let tempRemoteFriendList = self.tempRemoteFriendList {
tempRemoteFriendList.friends.forEach { friend in
if let friendAddress = friend.address,
friends.contains(where: { $0?.address?.weakEqual(address2: friendAddress) == true }) {
_ = tempRemoteFriendList.removeFriend(linphoneFriend: friend)
}
}
}
}
let dispatchGroup = DispatchGroup()
friends.forEach { friend in
dispatchGroup.enter()
if let friend = friend {
let addressTmp = friend.address?.clone()?.asStringUriOnly() ?? ""
Log.debug("\(ContactsManager.TAG) Newly discovered SIP Address \(addressTmp) for friend \(friend.name ?? "No Name") in bodyless list \(friendList.displayName ?? "No Display Name")")
let newContact = Contact(
identifier: UUID().uuidString,
firstName: friend.name ?? addressTmp,
lastName: "",
organizationName: "",
jobTitle: "",
displayName: friend.address?.displayName ?? "",
sipAddresses: friend.addresses.map { $0.asStringUriOnly() },
phoneNumbers: [],
imageData: ""
)
let image = self.textToImage(firstName: friend.name ?? addressTmp, lastName: "")
self.saveImage(
image: image,
name: friend.name ?? addressTmp,
prefix: "-default",
contact: newContact, linphoneFriend: friendList.displayName ?? "No Display Name", existingFriend: nil) {
dispatchGroup.leave()
}
}
}
dispatchGroup.notify(queue: .main) {
MagicSearchSingleton.shared.searchForContacts()
if let linphoneFL = self.tempRemoteFriendList {
linphoneFL.updateSubscriptions()
}
}
}
},
onNewSipAddressDiscovered: { (friendList: FriendList, linphoneFriend: Friend, sipUri: String) in
Log.info("\(ContactsManager.TAG) FriendListDelegateStub onNewSipAddressDiscovered \(linphoneFriend.name ?? "")")

View file

@ -168,21 +168,21 @@ struct AddParticipantsFragment: View {
.padding(.horizontal)
ScrollView {
ForEach(0..<contactsManager.lastSearch.count, id: \.self) { index in
ForEach(0..<contactsManager.avatarListModel.count, id: \.self) { index in
HStack {
HStack {
if index == 0
|| contactsManager.lastSearch[index].friend?.name!.lowercased().folding(
|| contactsManager.avatarListModel[index].name.lowercased().folding(
options: .diacriticInsensitive,
locale: .current
).first
!= contactsManager.lastSearch[index-1].friend?.name!.lowercased().folding(
!= contactsManager.avatarListModel[index-1].name.lowercased().folding(
options: .diacriticInsensitive,
locale: .current
).first {
Text(
String(
(contactsManager.lastSearch[index].friend?.name!.uppercased().folding(
(contactsManager.avatarListModel[index].name.uppercased().folding(
options: .diacriticInsensitive,
locale: .current
).first)!))
@ -198,40 +198,28 @@ struct AddParticipantsFragment: View {
.padding(.trailing, 5)
}
if index < contactsManager.avatarListModel.count,
let friend = contactsManager.avatarListModel[index].friend,
let photo = friend.photo,
!photo.isEmpty {
Avatar(contactAvatarModel: contactsManager.avatarListModel[index], avatarSize: 50)
} else {
Image("profil-picture-default")
.resizable()
.frame(width: 50, height: 50)
.clipShape(Circle())
}
Avatar(contactAvatarModel: contactsManager.avatarListModel[index], avatarSize: 50)
Text((contactsManager.lastSearch[index].friend?.name ?? "")!)
Text(contactsManager.avatarListModel[index].name)
.default_text_style(styleSize: 16)
.frame(maxWidth: .infinity, alignment: .leading)
.foregroundStyle(Color.orangeMain500)
if let searchAddress = contactsManager.lastSearch[index].friend?.address?.asStringUriOnly() {
if addParticipantsViewModel.participantsToAdd.contains(where: {
$0.address.asStringUriOnly() == searchAddress
}) {
Image("check")
.renderingMode(.template)
.resizable()
.foregroundStyle(Color.orangeMain500)
.frame(width: 25, height: 25)
.padding(.horizontal)
}
if addParticipantsViewModel.participantsToAdd.contains(where: {
$0.address.asStringUriOnly() == contactsManager.avatarListModel[index].address
}) {
Image("check")
.renderingMode(.template)
.resizable()
.foregroundStyle(Color.orangeMain500)
.frame(width: 25, height: 25)
.padding(.horizontal)
}
}
}
.background(.white)
.onTapGesture {
if let addr = contactsManager.lastSearch[index].address {
if let addr = try? Factory.Instance.createAddress(addr: contactsManager.avatarListModel[index].address) {
addParticipantsViewModel.selectParticipant(addr: addr)
}
}