mirror of
https://gitlab.linphone.org/BC/public/linphone-iphone.git
synced 2026-04-17 20:08:31 +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 {
|
guard let address = address, let clonedAddress = address.clone() else {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
clonedAddress.clean()
|
clonedAddress.clean()
|
||||||
let sipUri = clonedAddress.asStringUriOnly()
|
let sipUri = clonedAddress.asStringUriOnly()
|
||||||
|
|
||||||
var friend: Friend?
|
|
||||||
let core = CoreContext.shared.mCore
|
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 {
|
if let friendList = self.friendList {
|
||||||
friend = friendList.friends.first(where: {
|
friend = friendList.friends.first(where: matches)
|
||||||
$0.addresses.contains(where: { $0.asStringUriOnly() == sipUri }) ||
|
|
||||||
(
|
|
||||||
normalizedIncoming != nil &&
|
|
||||||
$0.phoneNumbers.contains(where: {
|
|
||||||
core?.defaultAccount?.normalizePhoneNumber(username: $0) == normalizedIncoming
|
|
||||||
})
|
|
||||||
)
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Linphone friend list
|
||||||
if friend == nil, let linphoneFriendList = self.linphoneFriendList {
|
if friend == nil, let linphoneFriendList = self.linphoneFriendList {
|
||||||
friend = linphoneFriendList.friends.first(where: {
|
friend = linphoneFriendList.friends.first(where: matches)
|
||||||
$0.addresses.contains(where: { $0.asStringUriOnly() == sipUri }) ||
|
|
||||||
(
|
|
||||||
normalizedIncoming != nil &&
|
|
||||||
$0.phoneNumbers.contains(where: {
|
|
||||||
core?.defaultAccount?.normalizePhoneNumber(username: $0) == normalizedIncoming
|
|
||||||
})
|
|
||||||
)
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Temp remote friend list
|
||||||
if friend == nil, let tempRemoteFriendList = self.tempRemoteFriendList {
|
if friend == nil, let tempRemoteFriendList = self.tempRemoteFriendList {
|
||||||
friend = tempRemoteFriendList.friends.first(where: {
|
friend = tempRemoteFriendList.friends.first(where: matches)
|
||||||
$0.addresses.contains(where: { $0.asStringUriOnly() == sipUri }) ||
|
|
||||||
(
|
|
||||||
normalizedIncoming != nil &&
|
|
||||||
$0.phoneNumbers.contains(where: {
|
|
||||||
core?.defaultAccount?.normalizePhoneNumber(username: $0) == normalizedIncoming
|
|
||||||
})
|
|
||||||
)
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if let core {
|
// CardDAV lists
|
||||||
|
if friend == nil, let core {
|
||||||
for list in core.friendsLists where list.type == .CardDAV {
|
for list in core.friendsLists where list.type == .CardDAV {
|
||||||
if friend == nil {
|
friend = list.friends.first(where: matches)
|
||||||
friend = list.friends.first(where: {
|
if friend != nil {
|
||||||
$0.addresses.contains(where: { $0.asStringUriOnly() == sipUri }) ||
|
break
|
||||||
(
|
|
||||||
normalizedIncoming != nil &&
|
|
||||||
$0.phoneNumbers.contains(where: {
|
|
||||||
core.defaultAccount?.normalizePhoneNumber(username: $0) == normalizedIncoming
|
|
||||||
})
|
|
||||||
)
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -2,6 +2,6 @@ import Foundation
|
||||||
|
|
||||||
public enum AppGitInfo {
|
public enum AppGitInfo {
|
||||||
public static let branch = "master"
|
public static let branch = "master"
|
||||||
public static let commit = "1bb372741"
|
public static let commit = "231035f10"
|
||||||
public static let tag = "6.1.0-alpha"
|
public static let tag = "6.1.0-alpha"
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue