mirror of
https://github.com/TelegramMessenger/Telegram-iOS.git
synced 2026-07-05 19:28:46 +02:00
Merge 7a6184aef7 into 6e370e06d1
This commit is contained in:
commit
7ff609b132
2 changed files with 40 additions and 0 deletions
|
|
@ -133,6 +133,33 @@ func matchingCloudContacts(postbox: Postbox, contacts: [MatchingDeviceContact])
|
|||
}
|
||||
}
|
||||
|
||||
func matchingOpenChatWithDeviceContacts(postbox: Postbox, contacts: [MatchingDeviceContact]) -> Signal<[(String, TelegramUser)], NoError> {
|
||||
return postbox.transaction { transaction -> [(String, TelegramUser)] in
|
||||
var result: [(String, TelegramUser)] = []
|
||||
let contactPeerIds = transaction.getContactPeerIds()
|
||||
|
||||
outer: for peerId in transaction.chatListGetAllPeerIds(groupId: .root) {
|
||||
if contactPeerIds.contains(peerId) {
|
||||
continue
|
||||
}
|
||||
if peerId.namespace != Namespaces.Peer.CloudUser {
|
||||
continue
|
||||
}
|
||||
guard let user = transaction.getPeer(peerId) as? TelegramUser, !user.isDeleted else {
|
||||
continue
|
||||
}
|
||||
for contact in contacts {
|
||||
if let contactPeerId = contact.peerId, contactPeerId == peerId {
|
||||
result.append((contact.stableId, user))
|
||||
continue outer
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return result
|
||||
}
|
||||
}
|
||||
|
||||
func matchingCloudContact(postbox: Postbox, peerId: PeerId) -> Signal<TelegramUser?, NoError> {
|
||||
return postbox.transaction { transaction -> TelegramUser? in
|
||||
if let user = transaction.getPeer(peerId) as? TelegramUser {
|
||||
|
|
|
|||
|
|
@ -336,6 +336,19 @@ class DefaultIntentHandler: INExtension, INSendMessageIntentHandling, INSearchFo
|
|||
|> mapToSignal { account -> Signal<[(String, TelegramUser)], IntentContactsError> in
|
||||
if let account = account {
|
||||
return matchingCloudContacts(postbox: account.postbox, contacts: matchedContacts)
|
||||
|> mapToSignal { cloudContacts -> Signal<[(String, TelegramUser)], NoError> in
|
||||
let matchedStableIds = Set(cloudContacts.map { $0.0 })
|
||||
let unmatchedContacts = matchedContacts.filter { !matchedStableIds.contains($0.stableId) }
|
||||
if unmatchedContacts.isEmpty {
|
||||
return .single(cloudContacts)
|
||||
}
|
||||
return matchingOpenChatWithDeviceContacts(postbox: account.postbox, contacts: unmatchedContacts)
|
||||
|> map { openChatContacts -> [(String, TelegramUser)] in
|
||||
var result = cloudContacts
|
||||
result.append(contentsOf: openChatContacts)
|
||||
return result
|
||||
}
|
||||
}
|
||||
|> castError(IntentContactsError.self)
|
||||
} else {
|
||||
return .fail(.generic)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue