Fixed requesting contact authorization status in several places

This commit is contained in:
Ilya Laktyushin 2018-12-20 23:10:21 +04:00
parent f65369f308
commit a63a38ca84
5 changed files with 53 additions and 38 deletions

View File

@ -80,7 +80,7 @@ public final class DeviceAccess {
return AVAudioSession.sharedInstance().recordPermission() == .granted return AVAudioSession.sharedInstance().recordPermission() == .granted
} }
public static func authorizationStatus(account: Account, subject: DeviceAccessSubject) -> Signal<AccessType, NoError> { public static func authorizationStatus(account: Account? = nil, subject: DeviceAccessSubject) -> Signal<AccessType, NoError> {
switch subject { switch subject {
case .notifications: case .notifications:
let status = Signal<AccessType, NoError> { subscriber in let status = Signal<AccessType, NoError> { subscriber in
@ -116,9 +116,13 @@ public final class DeviceAccess {
return .complete() return .complete()
} }
}) })
return account.telegramApplicationContext.applicationBindings.applicationInForeground if let account = account {
|> distinctUntilChanged return account.telegramApplicationContext.applicationBindings.applicationInForeground
|> mapToSignal { inForeground -> Signal<AccessType, NoError> in |> distinctUntilChanged
|> mapToSignal { inForeground -> Signal<AccessType, NoError> in
return status
}
} else {
return status return status
} }
case .contacts: case .contacts:
@ -184,20 +188,24 @@ public final class DeviceAccess {
return EmptyDisposable return EmptyDisposable
} }
case .siri: case .siri:
return Signal { subscriber in if let account = account {
let status = account.telegramApplicationContext.applicationBindings.siriAuthorization() return Signal { subscriber in
subscriber.putNext(status) let status = account.telegramApplicationContext.applicationBindings.siriAuthorization()
subscriber.putCompletion() subscriber.putNext(status)
return EmptyDisposable subscriber.putCompletion()
return EmptyDisposable
}
|> then(self.siri
|> mapToSignal { authorized -> Signal<AccessType, NoError> in
if let authorized = authorized {
return .single(authorized ? .allowed : .denied)
} else {
return .complete()
}
})
} else {
return .single(.denied)
} }
|> then(self.siri
|> mapToSignal { authorized -> Signal<AccessType, NoError> in
if let authorized = authorized {
return .single(authorized ? .allowed : .denied)
} else {
return .complete()
}
})
default: default:
return .single(.notDetermined) return .single(.notDetermined)
} }

View File

@ -57,20 +57,23 @@ final class ContactsControllerNode: ASDisplayNode {
}) })
inviteImpl = { [weak self] in inviteImpl = { [weak self] in
let _ = (DeviceAccess.contacts let _ = (DeviceAccess.authorizationStatus(account: account, subject: .contacts)
|> take(1) |> take(1)
|> deliverOnMainQueue).start(next: { value in |> deliverOnMainQueue).start(next: { value in
guard let strongSelf = self else { guard let strongSelf = self else {
return return
} }
if let value = value, value { switch value {
strongSelf.openInvite?() case .allowed:
} else { strongSelf.openInvite?()
let presentationData = strongSelf.presentationData case .notDetermined:
present(standardTextAlertController(theme: AlertControllerTheme(presentationTheme: presentationData.theme), title: presentationData.strings.AccessDenied_Title, text: presentationData.strings.Contacts_AccessDeniedError, actions: [TextAlertAction(type: .defaultAction, title: presentationData.strings.Common_NotNow, action: {}), TextAlertAction(type: .genericAction, title: presentationData.strings.AccessDenied_Settings, action: { DeviceAccess.authorizeAccess(to: .contacts)
self?.account.telegramApplicationContext.applicationBindings.openSettings() default:
})]), nil) let presentationData = strongSelf.presentationData
present(standardTextAlertController(theme: AlertControllerTheme(presentationTheme: presentationData.theme), title: presentationData.strings.AccessDenied_Title, text: presentationData.strings.Contacts_AccessDeniedError, actions: [TextAlertAction(type: .defaultAction, title: presentationData.strings.Common_NotNow, action: {}), TextAlertAction(type: .genericAction, title: presentationData.strings.AccessDenied_Settings, action: {
self?.account.telegramApplicationContext.applicationBindings.openSettings()
})]), nil)
} }
}) })
} }

View File

@ -413,13 +413,13 @@ private final class DeviceContactDataManagerImpl {
init(queue: Queue) { init(queue: Queue) {
self.queue = queue self.queue = queue
self.accessDisposable = (DeviceAccess.contacts self.accessDisposable = (DeviceAccess.authorizationStatus(subject: .contacts)
|> deliverOn(self.queue)).start(next: { [weak self] authorizationStatus in |> deliverOn(self.queue)).start(next: { [weak self] authorizationStatus in
guard let strongSelf = self, let authorizationStatus = authorizationStatus else { guard let strongSelf = self, authorizationStatus != .notDetermined else {
return return
} }
strongSelf.accessInitialized = true strongSelf.accessInitialized = true
if authorizationStatus { if authorizationStatus == .allowed {
if #available(iOSApplicationExtension 9.0, *) { if #available(iOSApplicationExtension 9.0, *) {
let dataContext = DeviceContactDataModernContext(queue: strongSelf.queue, updated: { stableIdToBasicContactData in let dataContext = DeviceContactDataModernContext(queue: strongSelf.queue, updated: { stableIdToBasicContactData in
guard let strongSelf = self else { guard let strongSelf = self else {

View File

@ -107,6 +107,7 @@ final class InstantPageNavigationBar: ASDisplayNode {
self.titleNode = ASTextNode() self.titleNode = ASTextNode()
self.titleNode.maximumNumberOfLines = 1 self.titleNode.maximumNumberOfLines = 1
self.titleNode.truncationMode = .byTruncatingTail
self.progressNode = InstantPageProgressNode() self.progressNode = InstantPageProgressNode()
@ -209,7 +210,7 @@ final class InstantPageNavigationBar: ASDisplayNode {
if let title = title { if let title = title {
self.titleNode.transform = CATransform3DIdentity self.titleNode.transform = CATransform3DIdentity
self.titleNode.attributedText = NSAttributedString(string: title, font: Font.semibold(17.0), textColor: .white, paragraphAlignment: .center) self.titleNode.attributedText = NSAttributedString(string: title, font: Font.semibold(17.0), textColor: .white, paragraphAlignment: .center)
let titleSize = self.titleNode.measure(CGSize(width: size.width - leftInset - rightInset - 30.0 - 88.0, height: size.height)) let titleSize = self.titleNode.measure(CGSize(width: size.width - leftInset - rightInset - 170.0, height: size.height))
self.titleNode.frame = CGRect(origin: CGPoint(x: (size.width - titleSize.width) / 2.0, y: size.height - 30.0), size: titleSize) self.titleNode.frame = CGRect(origin: CGPoint(x: (size.width - titleSize.width) / 2.0, y: size.height - 30.0), size: titleSize)
} }
} }

View File

@ -4,17 +4,20 @@ import TelegramCore
import Display import Display
func openAddContact(account: Account, firstName: String = "", lastName: String = "", phoneNumber: String, label: String = "_$!<Mobile>!$_", present: @escaping (ViewController, Any?) -> Void, completed: @escaping () -> Void = {}) { func openAddContact(account: Account, firstName: String = "", lastName: String = "", phoneNumber: String, label: String = "_$!<Mobile>!$_", present: @escaping (ViewController, Any?) -> Void, completed: @escaping () -> Void = {}) {
let _ = (DeviceAccess.contacts let _ = (DeviceAccess.authorizationStatus(account: account, subject: .contacts)
|> take(1) |> take(1)
|> deliverOnMainQueue).start(next: { value in |> deliverOnMainQueue).start(next: { value in
if let value = value, value { switch value {
let contactData = DeviceContactExtendedData(basicData: DeviceContactBasicData(firstName: firstName, lastName: lastName, phoneNumbers: [DeviceContactPhoneNumberData(label: label, value: phoneNumber)]), middleName: "", prefix: "", suffix: "", organization: "", jobTitle: "", department: "", emailAddresses: [], urls: [], addresses: [], birthdayDate: nil, socialProfiles: [], instantMessagingProfiles: []) case .allowed:
present(deviceContactInfoController(account: account, subject: .create(peer: nil, contactData: contactData, completion: { _, _,_ in }), completed: completed), ViewControllerPresentationArguments(presentationAnimation: .modalSheet)) let contactData = DeviceContactExtendedData(basicData: DeviceContactBasicData(firstName: firstName, lastName: lastName, phoneNumbers: [DeviceContactPhoneNumberData(label: label, value: phoneNumber)]), middleName: "", prefix: "", suffix: "", organization: "", jobTitle: "", department: "", emailAddresses: [], urls: [], addresses: [], birthdayDate: nil, socialProfiles: [], instantMessagingProfiles: [])
} else { present(deviceContactInfoController(account: account, subject: .create(peer: nil, contactData: contactData, completion: { _, _,_ in }), completed: completed), ViewControllerPresentationArguments(presentationAnimation: .modalSheet))
let presentationData = account.telegramApplicationContext.currentPresentationData.with { $0 } case .notDetermined:
present(standardTextAlertController(theme: AlertControllerTheme(presentationTheme: presentationData.theme), title: presentationData.strings.AccessDenied_Title, text: presentationData.strings.Contacts_AccessDeniedError, actions: [TextAlertAction(type: .defaultAction, title: presentationData.strings.Common_NotNow, action: {}), TextAlertAction(type: .genericAction, title: presentationData.strings.AccessDenied_Settings, action: { DeviceAccess.authorizeAccess(to: .contacts)
account.telegramApplicationContext.applicationBindings.openSettings() default:
})]), nil) let presentationData = account.telegramApplicationContext.currentPresentationData.with { $0 }
present(standardTextAlertController(theme: AlertControllerTheme(presentationTheme: presentationData.theme), title: presentationData.strings.AccessDenied_Title, text: presentationData.strings.Contacts_AccessDeniedError, actions: [TextAlertAction(type: .defaultAction, title: presentationData.strings.Common_NotNow, action: {}), TextAlertAction(type: .genericAction, title: presentationData.strings.AccessDenied_Settings, action: {
account.telegramApplicationContext.applicationBindings.openSettings()
})]), nil)
} }
}) })
} }