mirror of
https://github.com/TelegramMessenger/Telegram-iOS.git
synced 2026-07-06 03:33:41 +02:00
Allow Siri to send to bots with open chats
This commit is contained in:
parent
e89a069016
commit
751d13a35e
2 changed files with 36 additions and 1 deletions
|
|
@ -117,6 +117,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 {
|
||||
|
|
|
|||
|
|
@ -335,7 +335,15 @@ class DefaultIntentHandler: INExtension, INSendMessageIntentHandling, INSearchFo
|
|||
|> castError(IntentContactsError.self)
|
||||
|> mapToSignal { account -> Signal<[(String, TelegramUser)], IntentContactsError> in
|
||||
if let account = account {
|
||||
return matchingCloudContacts(postbox: account.postbox, contacts: matchedContacts)
|
||||
return combineLatest(
|
||||
matchingCloudContacts(postbox: account.postbox, contacts: matchedContacts),
|
||||
matchingOpenChatWithDeviceContacts(postbox: account.postbox, contacts: matchedContacts)
|
||||
)
|
||||
|> map { cloudContacts, openChatContacts 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