mirror of
https://github.com/Swiftgram/Telegram-iOS.git
synced 2025-11-07 01:10:09 +00:00
SiriIntents: fixed contacts matching
This commit is contained in:
parent
d4d1be5300
commit
9462549ea4
@ -31,6 +31,20 @@ private func parseAppSpecificContactReference(_ value: String) -> PeerId? {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private func cleanPhoneNumber(_ text: String) -> String {
|
||||||
|
var result = ""
|
||||||
|
for c in text {
|
||||||
|
if c == "+" {
|
||||||
|
if result.isEmpty {
|
||||||
|
result += String(c)
|
||||||
|
}
|
||||||
|
} else if c >= "0" && c <= "9" {
|
||||||
|
result += String(c)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return result
|
||||||
|
}
|
||||||
|
|
||||||
func matchingDeviceContacts(stableIds: [String]) -> Signal<[MatchingDeviceContact], IntentContactsError> {
|
func matchingDeviceContacts(stableIds: [String]) -> Signal<[MatchingDeviceContact], IntentContactsError> {
|
||||||
guard CNContactStore.authorizationStatus(for: .contacts) == .authorized else {
|
guard CNContactStore.authorizationStatus(for: .contacts) == .authorized else {
|
||||||
return .fail(.generic)
|
return .fail(.generic)
|
||||||
@ -43,7 +57,7 @@ func matchingDeviceContacts(stableIds: [String]) -> Signal<[MatchingDeviceContac
|
|||||||
return .single(contacts.map({ contact in
|
return .single(contacts.map({ contact in
|
||||||
let phoneNumbers = contact.phoneNumbers.compactMap({ number -> String? in
|
let phoneNumbers = contact.phoneNumbers.compactMap({ number -> String? in
|
||||||
if !number.value.stringValue.isEmpty {
|
if !number.value.stringValue.isEmpty {
|
||||||
return number.value.stringValue
|
return cleanPhoneNumber(number.value.stringValue)
|
||||||
} else {
|
} else {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
@ -75,22 +89,18 @@ func matchingCloudContacts(postbox: Postbox, contacts: [MatchingDeviceContact])
|
|||||||
var result: [(String, TelegramUser)] = []
|
var result: [(String, TelegramUser)] = []
|
||||||
outer: for peerId in transaction.getContactPeerIds() {
|
outer: for peerId in transaction.getContactPeerIds() {
|
||||||
if let peer = transaction.getPeer(peerId) as? TelegramUser {
|
if let peer = transaction.getPeer(peerId) as? TelegramUser {
|
||||||
if let peerPhoneNumber = peer.phone {
|
for contact in contacts {
|
||||||
for contact in contacts {
|
if let contactPeerId = contact.peerId, contactPeerId == peerId {
|
||||||
for phoneNumber in contact.phoneNumbers {
|
result.append((contact.stableId, peer))
|
||||||
if matchPhoneNumbers(phoneNumber, peerPhoneNumber) {
|
continue outer
|
||||||
|
} else if let peerPhoneNumber = peer.phone {
|
||||||
|
for contactPhoneNumber in contact.phoneNumbers {
|
||||||
|
if matchPhoneNumbers(contactPhoneNumber, peerPhoneNumber) {
|
||||||
result.append((contact.stableId, peer))
|
result.append((contact.stableId, peer))
|
||||||
continue outer
|
continue outer
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
for contact in contacts {
|
|
||||||
if let contactPeerId = contact.peerId, contactPeerId == peerId {
|
|
||||||
result.append((contact.stableId, peer))
|
|
||||||
continue outer
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -21,11 +21,13 @@ final class ChatScheduleTimeController: ViewController {
|
|||||||
|
|
||||||
private let context: AccountContext
|
private let context: AccountContext
|
||||||
private let mode: ChatScheduleTimeControllerMode
|
private let mode: ChatScheduleTimeControllerMode
|
||||||
|
private let currentTime: Int32?
|
||||||
private let completion: (Int32) -> Void
|
private let completion: (Int32) -> Void
|
||||||
|
|
||||||
init(context: AccountContext, mode: ChatScheduleTimeControllerMode, completion: @escaping (Int32) -> Void) {
|
init(context: AccountContext, mode: ChatScheduleTimeControllerMode, currentTime: Int32? = nil, completion: @escaping (Int32) -> Void) {
|
||||||
self.context = context
|
self.context = context
|
||||||
self.mode = mode
|
self.mode = mode
|
||||||
|
self.currentTime = currentTime
|
||||||
self.completion = completion
|
self.completion = completion
|
||||||
|
|
||||||
super.init(navigationBarPresentationData: nil)
|
super.init(navigationBarPresentationData: nil)
|
||||||
@ -38,7 +40,7 @@ final class ChatScheduleTimeController: ViewController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
override public func loadDisplayNode() {
|
override public func loadDisplayNode() {
|
||||||
self.displayNode = ChatScheduleTimeControllerNode(context: self.context, mode: self.mode)
|
self.displayNode = ChatScheduleTimeControllerNode(context: self.context, mode: self.mode, currentTime: self.currentTime)
|
||||||
self.controllerNode.completion = { [weak self] time in
|
self.controllerNode.completion = { [weak self] time in
|
||||||
self?.completion(time + 5)
|
self?.completion(time + 5)
|
||||||
self?.dismiss()
|
self?.dismiss()
|
||||||
|
|||||||
@ -33,7 +33,7 @@ class ChatScheduleTimeControllerNode: ViewControllerTracingNode, UIScrollViewDel
|
|||||||
var dismiss: (() -> Void)?
|
var dismiss: (() -> Void)?
|
||||||
var cancel: (() -> Void)?
|
var cancel: (() -> Void)?
|
||||||
|
|
||||||
init(context: AccountContext, mode: ChatScheduleTimeControllerMode) {
|
init(context: AccountContext, mode: ChatScheduleTimeControllerMode, currentTime: Int32?) {
|
||||||
self.context = context
|
self.context = context
|
||||||
self.mode = mode
|
self.mode = mode
|
||||||
self.presentationData = context.sharedContext.currentPresentationData.with { $0 }
|
self.presentationData = context.sharedContext.currentPresentationData.with { $0 }
|
||||||
@ -123,11 +123,11 @@ class ChatScheduleTimeControllerNode: ViewControllerTracingNode, UIScrollViewDel
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
self.updateMinimumDate()
|
self.updateMinimumDate(currentTime: currentTime)
|
||||||
self.updateButtonTitle()
|
self.updateButtonTitle()
|
||||||
}
|
}
|
||||||
|
|
||||||
private func updateMinimumDate() {
|
private func updateMinimumDate(currentTime: Int32? = nil) {
|
||||||
let timeZone = TimeZone(secondsFromGMT: 0)!
|
let timeZone = TimeZone(secondsFromGMT: 0)!
|
||||||
var calendar = Calendar(identifier: .gregorian)
|
var calendar = Calendar(identifier: .gregorian)
|
||||||
calendar.timeZone = timeZone
|
calendar.timeZone = timeZone
|
||||||
@ -142,7 +142,11 @@ class ChatScheduleTimeControllerNode: ViewControllerTracingNode, UIScrollViewDel
|
|||||||
|
|
||||||
if let date = calendar.date(byAdding: .minute, value: 5 - minute, to: calendar.date(from: components)!) {
|
if let date = calendar.date(byAdding: .minute, value: 5 - minute, to: calendar.date(from: components)!) {
|
||||||
self.pickerView.minimumDate = date
|
self.pickerView.minimumDate = date
|
||||||
self.pickerView.date = date
|
if let currentTime = currentTime {
|
||||||
|
self.pickerView.date = Date(timeIntervalSince1970: Double(currentTime))
|
||||||
|
} else {
|
||||||
|
self.pickerView.date = date
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user