diff --git a/TelegramUI/CheckDeviceAccess.swift b/TelegramUI/CheckDeviceAccess.swift index 11981ad8ef..ce77c1dfe9 100644 --- a/TelegramUI/CheckDeviceAccess.swift +++ b/TelegramUI/CheckDeviceAccess.swift @@ -80,7 +80,7 @@ public final class DeviceAccess { return AVAudioSession.sharedInstance().recordPermission() == .granted } - public static func authorizationStatus(account: Account, subject: DeviceAccessSubject) -> Signal { + public static func authorizationStatus(account: Account? = nil, subject: DeviceAccessSubject) -> Signal { switch subject { case .notifications: let status = Signal { subscriber in @@ -116,9 +116,13 @@ public final class DeviceAccess { return .complete() } }) - return account.telegramApplicationContext.applicationBindings.applicationInForeground - |> distinctUntilChanged - |> mapToSignal { inForeground -> Signal in + if let account = account { + return account.telegramApplicationContext.applicationBindings.applicationInForeground + |> distinctUntilChanged + |> mapToSignal { inForeground -> Signal in + return status + } + } else { return status } case .contacts: @@ -184,20 +188,24 @@ public final class DeviceAccess { return EmptyDisposable } case .siri: - return Signal { subscriber in - let status = account.telegramApplicationContext.applicationBindings.siriAuthorization() - subscriber.putNext(status) - subscriber.putCompletion() - return EmptyDisposable + if let account = account { + return Signal { subscriber in + let status = account.telegramApplicationContext.applicationBindings.siriAuthorization() + subscriber.putNext(status) + subscriber.putCompletion() + return EmptyDisposable + } + |> then(self.siri + |> mapToSignal { authorized -> Signal in + if let authorized = authorized { + return .single(authorized ? .allowed : .denied) + } else { + return .complete() + } + }) + } else { + return .single(.denied) } - |> then(self.siri - |> mapToSignal { authorized -> Signal in - if let authorized = authorized { - return .single(authorized ? .allowed : .denied) - } else { - return .complete() - } - }) default: return .single(.notDetermined) } diff --git a/TelegramUI/ContactsControllerNode.swift b/TelegramUI/ContactsControllerNode.swift index 455b420100..60644bc0e2 100644 --- a/TelegramUI/ContactsControllerNode.swift +++ b/TelegramUI/ContactsControllerNode.swift @@ -57,20 +57,23 @@ final class ContactsControllerNode: ASDisplayNode { }) inviteImpl = { [weak self] in - let _ = (DeviceAccess.contacts + let _ = (DeviceAccess.authorizationStatus(account: account, subject: .contacts) |> take(1) |> deliverOnMainQueue).start(next: { value in guard let strongSelf = self else { return } - if let value = value, value { - strongSelf.openInvite?() - } else { - 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) + switch value { + case .allowed: + strongSelf.openInvite?() + case .notDetermined: + DeviceAccess.authorizeAccess(to: .contacts) + default: + 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) } }) } diff --git a/TelegramUI/DeviceContactDataManager.swift b/TelegramUI/DeviceContactDataManager.swift index 50dbc1f557..7ef8a15418 100644 --- a/TelegramUI/DeviceContactDataManager.swift +++ b/TelegramUI/DeviceContactDataManager.swift @@ -413,13 +413,13 @@ private final class DeviceContactDataManagerImpl { init(queue: Queue) { self.queue = queue - self.accessDisposable = (DeviceAccess.contacts + self.accessDisposable = (DeviceAccess.authorizationStatus(subject: .contacts) |> 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 } strongSelf.accessInitialized = true - if authorizationStatus { + if authorizationStatus == .allowed { if #available(iOSApplicationExtension 9.0, *) { let dataContext = DeviceContactDataModernContext(queue: strongSelf.queue, updated: { stableIdToBasicContactData in guard let strongSelf = self else { diff --git a/TelegramUI/InstantPageNavigationBar.swift b/TelegramUI/InstantPageNavigationBar.swift index 513d03b79c..138e79c9d1 100644 --- a/TelegramUI/InstantPageNavigationBar.swift +++ b/TelegramUI/InstantPageNavigationBar.swift @@ -107,6 +107,7 @@ final class InstantPageNavigationBar: ASDisplayNode { self.titleNode = ASTextNode() self.titleNode.maximumNumberOfLines = 1 + self.titleNode.truncationMode = .byTruncatingTail self.progressNode = InstantPageProgressNode() @@ -209,7 +210,7 @@ final class InstantPageNavigationBar: ASDisplayNode { if let title = title { self.titleNode.transform = CATransform3DIdentity 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) } } diff --git a/TelegramUI/OpenAddContact.swift b/TelegramUI/OpenAddContact.swift index 225d756352..0771785b8a 100644 --- a/TelegramUI/OpenAddContact.swift +++ b/TelegramUI/OpenAddContact.swift @@ -4,17 +4,20 @@ import TelegramCore import Display func openAddContact(account: Account, firstName: String = "", lastName: String = "", phoneNumber: String, label: String = "_$!!$_", present: @escaping (ViewController, Any?) -> Void, completed: @escaping () -> Void = {}) { - let _ = (DeviceAccess.contacts + let _ = (DeviceAccess.authorizationStatus(account: account, subject: .contacts) |> take(1) |> deliverOnMainQueue).start(next: { value in - if let value = value, 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: []) - present(deviceContactInfoController(account: account, subject: .create(peer: nil, contactData: contactData, completion: { _, _,_ in }), completed: completed), ViewControllerPresentationArguments(presentationAnimation: .modalSheet)) - } else { - 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) + switch value { + case .allowed: + 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: []) + present(deviceContactInfoController(account: account, subject: .create(peer: nil, contactData: contactData, completion: { _, _,_ in }), completed: completed), ViewControllerPresentationArguments(presentationAnimation: .modalSheet)) + case .notDetermined: + DeviceAccess.authorizeAccess(to: .contacts) + default: + 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) } }) }