This commit is contained in:
Isaac 2026-03-27 19:23:09 +08:00
parent 22e58eb5e4
commit 911ebd07ab
50 changed files with 5096 additions and 5079 deletions

View file

@ -96,16 +96,23 @@ private func matchPhoneNumbers(_ lhs: String, _ rhs: String) -> Bool {
func matchingCloudContacts(postbox: Postbox, contacts: [MatchingDeviceContact]) -> Signal<[(String, TelegramUser)], NoError> {
return postbox.transaction { transaction -> [(String, TelegramUser)] in
var result: [(String, TelegramUser)] = []
var matchingIds = Set<EnginePeer.Id>()
outer: for peerId in transaction.getContactPeerIds() {
if let peer = transaction.getPeer(peerId) as? TelegramUser {
for contact in contacts {
if let contactPeerId = contact.peerId, contactPeerId == peerId {
result.append((contact.stableId, peer))
if !matchingIds.contains(peer.id) {
matchingIds.insert(peer.id)
result.append((contact.stableId, peer))
}
continue outer
} else if let peerPhoneNumber = peer.phone {
for contactPhoneNumber in contact.phoneNumbers {
if matchPhoneNumbers(contactPhoneNumber, peerPhoneNumber) {
result.append((contact.stableId, peer))
if !matchingIds.contains(peer.id) {
matchingIds.insert(peer.id)
result.append((contact.stableId, peer))
}
continue outer
}
}
@ -113,6 +120,15 @@ func matchingCloudContacts(postbox: Postbox, contacts: [MatchingDeviceContact])
}
}
}
for contact in contacts {
if let peerId = contact.peerId, let peer = transaction.getPeer(peerId) as? TelegramUser {
if !matchingIds.contains(peer.id) {
matchingIds.insert(peer.id)
result.append((contact.stableId, peer))
}
}
}
return result
}
}