mirror of
https://gitlab.linphone.org/BC/public/linphone-iphone.git
synced 2026-04-17 11:48:27 +00:00
Fix getFriendWithAddress to ignore nil/empty phone numbers
This commit is contained in:
parent
231035f109
commit
9555245ede
2 changed files with 39 additions and 41 deletions
|
|
@ -418,62 +418,60 @@ final class ContactsManager: ObservableObject {
|
|||
guard let address = address, let clonedAddress = address.clone() else {
|
||||
return nil
|
||||
}
|
||||
|
||||
clonedAddress.clean()
|
||||
let sipUri = clonedAddress.asStringUriOnly()
|
||||
|
||||
var friend: Friend?
|
||||
let core = CoreContext.shared.mCore
|
||||
let account = core?.defaultAccount
|
||||
|
||||
let normalizedIncoming = core?.defaultAccount?.normalizePhoneNumber(username: address.username ?? "")
|
||||
let normalizedIncoming = address.username.flatMap {
|
||||
account?.normalizePhoneNumber(username: $0)
|
||||
}
|
||||
|
||||
func matches(_ friend: Friend) -> Bool {
|
||||
|
||||
let sipMatch = friend.addresses.contains {
|
||||
$0.asStringUriOnly() == sipUri
|
||||
}
|
||||
|
||||
let phoneMatch = friend.phoneNumbers.contains { phone in
|
||||
guard
|
||||
let normalizedIncoming,
|
||||
!normalizedIncoming.isEmpty,
|
||||
let normalized = account?.normalizePhoneNumber(username: phone),
|
||||
!normalized.isEmpty
|
||||
else {
|
||||
return false
|
||||
}
|
||||
return normalized == normalizedIncoming
|
||||
}
|
||||
return sipMatch || phoneMatch
|
||||
}
|
||||
|
||||
var friend: Friend?
|
||||
|
||||
// Friend list
|
||||
if let friendList = self.friendList {
|
||||
friend = friendList.friends.first(where: {
|
||||
$0.addresses.contains(where: { $0.asStringUriOnly() == sipUri }) ||
|
||||
(
|
||||
normalizedIncoming != nil &&
|
||||
$0.phoneNumbers.contains(where: {
|
||||
core?.defaultAccount?.normalizePhoneNumber(username: $0) == normalizedIncoming
|
||||
})
|
||||
)
|
||||
})
|
||||
friend = friendList.friends.first(where: matches)
|
||||
}
|
||||
|
||||
// Linphone friend list
|
||||
if friend == nil, let linphoneFriendList = self.linphoneFriendList {
|
||||
friend = linphoneFriendList.friends.first(where: {
|
||||
$0.addresses.contains(where: { $0.asStringUriOnly() == sipUri }) ||
|
||||
(
|
||||
normalizedIncoming != nil &&
|
||||
$0.phoneNumbers.contains(where: {
|
||||
core?.defaultAccount?.normalizePhoneNumber(username: $0) == normalizedIncoming
|
||||
})
|
||||
)
|
||||
})
|
||||
friend = linphoneFriendList.friends.first(where: matches)
|
||||
}
|
||||
|
||||
// Temp remote friend list
|
||||
if friend == nil, let tempRemoteFriendList = self.tempRemoteFriendList {
|
||||
friend = tempRemoteFriendList.friends.first(where: {
|
||||
$0.addresses.contains(where: { $0.asStringUriOnly() == sipUri }) ||
|
||||
(
|
||||
normalizedIncoming != nil &&
|
||||
$0.phoneNumbers.contains(where: {
|
||||
core?.defaultAccount?.normalizePhoneNumber(username: $0) == normalizedIncoming
|
||||
})
|
||||
)
|
||||
})
|
||||
friend = tempRemoteFriendList.friends.first(where: matches)
|
||||
}
|
||||
|
||||
if let core {
|
||||
// CardDAV lists
|
||||
if friend == nil, let core {
|
||||
for list in core.friendsLists where list.type == .CardDAV {
|
||||
if friend == nil {
|
||||
friend = list.friends.first(where: {
|
||||
$0.addresses.contains(where: { $0.asStringUriOnly() == sipUri }) ||
|
||||
(
|
||||
normalizedIncoming != nil &&
|
||||
$0.phoneNumbers.contains(where: {
|
||||
core.defaultAccount?.normalizePhoneNumber(username: $0) == normalizedIncoming
|
||||
})
|
||||
)
|
||||
})
|
||||
friend = list.friends.first(where: matches)
|
||||
if friend != nil {
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,6 +2,6 @@ import Foundation
|
|||
|
||||
public enum AppGitInfo {
|
||||
public static let branch = "master"
|
||||
public static let commit = "1bb372741"
|
||||
public static let commit = "231035f10"
|
||||
public static let tag = "6.1.0-alpha"
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue