From 3a2e04ef6766605f79f47a13a5a6ae50e09d8a5e Mon Sep 17 00:00:00 2001 From: Ilya Laktyushin Date: Tue, 4 Dec 2018 22:30:19 +0400 Subject: [PATCH] Update submodules --- Share/ShareRootController.swift | 2 +- Telegram-iOS/AppDelegate.swift | 2 +- Telegram-iOS/ApplicationContext.swift | 112 +++++++++++++++++++--- Telegram-iOS/SnapshotEnvironment.swift | 2 +- Telegram-iOS/en.lproj/Localizable.strings | 32 ++++--- submodules/Display | 2 +- submodules/TelegramCore | 2 +- submodules/TelegramUI | 2 +- 8 files changed, 123 insertions(+), 33 deletions(-) diff --git a/Share/ShareRootController.swift b/Share/ShareRootController.swift index 5d650c933c..53753998fc 100644 --- a/Share/ShareRootController.swift +++ b/Share/ShareRootController.swift @@ -130,7 +130,7 @@ class ShareRootController: UIViewController { }, applicationInForeground: .single(false), applicationIsActive: .single(false), clearMessageNotifications: { _ in }, pushIdleTimerExtension: { return EmptyDisposable - }, openSettings: {}, openAppStorePage: {}, registerForNotifications: {}, getWindowHost: { + }, openSettings: {}, openAppStorePage: {}, registerForNotifications: { _ in }, getWindowHost: { return nil }, presentNativeController: { _ in }, dismissNativeController: { diff --git a/Telegram-iOS/AppDelegate.swift b/Telegram-iOS/AppDelegate.swift index d59f750add..7b42754787 100644 --- a/Telegram-iOS/AppDelegate.swift +++ b/Telegram-iOS/AppDelegate.swift @@ -594,7 +594,7 @@ private enum QueuedWakeup: Int32 { if let url = URL(string: "itms-apps://itunes.apple.com/app/id\(appStoreId)") { UIApplication.shared.openURL(url) } - }, registerForNotifications: { + }, registerForNotifications: { completion in let _ = (self.currentAuthorizedContext() |> take(1) |> deliverOnMainQueue).start(next: { context in diff --git a/Telegram-iOS/ApplicationContext.swift b/Telegram-iOS/ApplicationContext.swift index 38af5622a9..c1622ae44b 100644 --- a/Telegram-iOS/ApplicationContext.swift +++ b/Telegram-iOS/ApplicationContext.swift @@ -183,8 +183,9 @@ final class AuthorizedApplicationContext { private let inAppNotificationSettingsDisposable = MetaDisposable() private let notificationMessagesDisposable = MetaDisposable() private let termsOfServiceUpdatesDisposable = MetaDisposable() - private let proccedTOSBotDisposable = MetaDisposable() - private var watchNavigateToMessageDisposable = MetaDisposable() + private let termsOfServiceProceedToBotDisposable = MetaDisposable() + private let watchNavigateToMessageDisposable = MetaDisposable() + private let permissionsDisposable = MetaDisposable() private var inAppNotificationSettings: InAppNotificationSettings? @@ -195,7 +196,7 @@ final class AuthorizedApplicationContext { private let callState = Promise(nil) private var currentTermsOfServiceUpdate: TermsOfServiceUpdate? - private var currentTermsOfServiceUpdateController: TermsOfServiceController? + private var currentPermissionsController: PermissionController? private let unlockedStatePromise = Promise() var unlockedState: Signal { @@ -743,17 +744,11 @@ final class AuthorizedApplicationContext { self.termsOfServiceUpdatesDisposable.set((account.stateManager.termsOfServiceUpdate |> deliverOnMainQueue).start(next: { [weak self] termsOfServiceUpdate in - guard let strongSelf = self else { - return - } - - if strongSelf.currentTermsOfServiceUpdate == termsOfServiceUpdate { + guard let strongSelf = self, strongSelf.currentTermsOfServiceUpdate != termsOfServiceUpdate else { return } strongSelf.currentTermsOfServiceUpdate = termsOfServiceUpdate - strongSelf.currentTermsOfServiceUpdateController?.dismiss() - strongSelf.currentTermsOfServiceUpdateController = nil if let termsOfServiceUpdate = termsOfServiceUpdate { let presentationData = strongSelf.applicationContext.currentPresentationData.with { $0 } var acceptImpl: ((String?) -> Void)? @@ -777,7 +772,7 @@ final class AuthorizedApplicationContext { |> deliverOnMainQueue).start(completed: { controller?.dismiss() if let botName = botName { - self?.proccedTOSBotDisposable.set((resolvePeerByName(account: account, name: botName, ageLimit: 10) |> take(1) |> deliverOnMainQueue).start(next: { peerId in + self?.termsOfServiceProceedToBotDisposable.set((resolvePeerByName(account: account, name: botName, ageLimit: 10) |> take(1) |> deliverOnMainQueue).start(next: { peerId in if let peerId = peerId { self?.rootController.pushViewController(ChatController(account: account, chatLocation: .peer(peerId), messageId: nil)) } @@ -802,6 +797,98 @@ final class AuthorizedApplicationContext { } })) + let permissionsPosition = ValuePromise(0, ignoreRepeated: true) + self.permissionsDisposable.set((combineLatest(requiredPermissions(account: account), permissionUISplitTest(postbox: account.postbox), permissionsPosition.get()) + |> deliverOnMainQueue).start(next: { [weak self] contactsAndNotifications, splitTest, position in + guard let strongSelf = self else { + return + } + + let config = splitTest.configuration + var states: [(PermissionState, Bool)] = [] + var i: Int = 0 + for subject in config.order { + if i < position { + i += 1 + continue + } + var modal = false + switch subject { + case .contacts: + if case .modal = config.contacts { + modal = true + } + if case .requestable = contactsAndNotifications.0.status { + states.append((contactsAndNotifications.0, modal)) + } + case .notifications: + if case .modal = config.notifications { + modal = true + } + if case .requestable = contactsAndNotifications.1.status { + states.append((contactsAndNotifications.1, modal)) + } + default: + break + } + i += 1 + } + + if let (state, modal) = states.first { + if modal { + if let controller = strongSelf.currentPermissionsController { + controller.setState(state, animated: true) + controller.proceed = { + permissionsPosition.set(position + 1) + } + } else { + let controller = PermissionController(account: account, splitTest: splitTest) + strongSelf.currentPermissionsController = controller + controller.setState(state, animated: false) + controller.proceed = { + permissionsPosition.set(position + 1) + } + dispatch_after_delay(0.15, DispatchQueue.main, { + (strongSelf.rootController.viewControllers.last as? ViewController)?.present(controller, in: .window(.root), with: ViewControllerPresentationArguments.init(presentationAnimation: .modalSheet)) + }) + } + } else { + switch state { + case .contacts: + splitTest.addEvent(.ContactsRequest) + DeviceAccess.authorizeAccess(to: .contacts) { result in + if result { + splitTest.addEvent(.ContactsAllowed) + } else { + splitTest.addEvent(.ContactsDenied) + } + permissionsPosition.set(position + 1) + } + case .notifications: + splitTest.addEvent(.NotificationsRequest) + DeviceAccess.authorizeAccess(to: .notifications) { result in + if result { + splitTest.addEvent(.NotificationsAllowed) + } else { + splitTest.addEvent(.NotificationsDenied) + } + permissionsPosition.set(position + 1) + } + default: + break + } + } + } else { + if let controller = strongSelf.currentPermissionsController { + controller.dismiss(completion: { [weak self] in + if let strongSelf = self { + strongSelf.currentPermissionsController = nil + } + }) + } + } + })) + self.displayAlertsDisposable = (account.stateManager.displayAlerts |> deliverOnMainQueue).start(next: { [weak self] alerts in if let strongSelf = self{ for text in alerts { @@ -1017,8 +1104,9 @@ final class AuthorizedApplicationContext { self.currentCallStatusTextTimer?.invalidate() self.presentationDataDisposable?.dispose() self.enablePostboxTransactionsDiposable?.dispose() - self.proccedTOSBotDisposable.dispose() + self.termsOfServiceProceedToBotDisposable.dispose() self.watchNavigateToMessageDisposable.dispose() + self.permissionsDisposable.dispose() } func openChatWithPeerId(peerId: PeerId, messageId: MessageId? = nil) { diff --git a/Telegram-iOS/SnapshotEnvironment.swift b/Telegram-iOS/SnapshotEnvironment.swift index ddbaf6dd7a..32943e1b68 100644 --- a/Telegram-iOS/SnapshotEnvironment.swift +++ b/Telegram-iOS/SnapshotEnvironment.swift @@ -79,7 +79,7 @@ func snapshotEnvironment(application: UIApplication, mainWindow: UIWindow, statu return EmptyDisposable }, openSettings: { }, openAppStorePage: { - }, registerForNotifications: { + }, registerForNotifications: { _ in }, getWindowHost: { return nil }, presentNativeController: { _ in diff --git a/Telegram-iOS/en.lproj/Localizable.strings b/Telegram-iOS/en.lproj/Localizable.strings index f44f6c9507..1bc885a681 100644 --- a/Telegram-iOS/en.lproj/Localizable.strings +++ b/Telegram-iOS/en.lproj/Localizable.strings @@ -3546,24 +3546,25 @@ Unused sets are archived when you add more."; "Permissions.Skip" = "Skip"; -"Permissions.ContactsTitle" = "Sync Your Contacts"; -"Permissions.ContactsText" = "See who's on Telegram and switch seamlessly, without having to \"add\" your friends."; -"Permissions.ContactsAllow" = "Allow Access"; -"Permissions.ContactsAllowInSettings" = "Allow in Settings"; +"Permissions.ContactsTitle.v0" = "Sync Your Contacts"; +"Permissions.ContactsText.v0" = "See who's on Telegram and switch seamlessly, without having to \"add\" your friends."; +"Permissions.ContactsAllow.v0" = "Allow Access"; +"Permissions.ContactsAllowInSettings.v0" = "Allow in Settings"; -"Permissions.NotificationsTitle" = "Turn ON Notifications"; -"Permissions.NotificationsText" = "Don't miss important messages from your friends and coworkers."; -"Permissions.NotificationsAllow" = "Turn Notifications ON"; -"Permissions.NotificationsAllowInSettings" = "Turn ON in Settings"; +"Permissions.NotificationsTitle.v0" = "Turn ON Notifications"; +"Permissions.NotificationsText.v0" = "Don't miss important messages from your friends and coworkers."; +"Permissions.NotificationsUnreachableText.v0" = "Check that both Alert and Sound are enabled in Settings."; +"Permissions.NotificationsAllow.v0" = "Turn Notifications ON"; +"Permissions.NotificationsAllowInSettings.v0" = "Turn ON in Settings"; -"Permissions.CellularDataTitle" = "Turn ON Notifications"; -"Permissions.CellularDataText" = "Don't worry, Telegram keeps network usage to a minimum. You can further control this in Settings > Data and Storage."; -"Permissions.CellularDataAllowInSettings" = "Turn ON in Settings"; +"Permissions.CellularDataTitle.v0" = "Turn ON Notifications"; +"Permissions.CellularDataText.v0" = "Don't worry, Telegram keeps network usage to a minimum. You can further control this in Settings > Data and Storage."; +"Permissions.CellularDataAllowInSettings.v0" = "Turn ON in Settings"; -"Permissions.SiriTitle" = "Turn ON Siri"; -"Permissions.SiriText" = "Use Siri to send messages and make calls."; -"Permissions.SiriAllow" = "Turn Siri ON"; -"Permissions.SiriAllowInSettings" = "Turn ON in Settings"; +"Permissions.SiriTitle.v0" = "Turn ON Siri"; +"Permissions.SiriText.v0" = "Use Siri to send messages and make calls."; +"Permissions.SiriAllow.v0" = "Turn Siri ON"; +"Permissions.SiriAllowInSettings.v0" = "Turn ON in Settings"; "Permissions.PrivacyPolicy" = "Privacy Policy"; @@ -3574,5 +3575,6 @@ Unused sets are archived when you add more."; "Notifications.PermissionsTitle" = "Turn ON Notifications"; "Notifications.PermissionsText" = "Don't miss important messages from your friends and coworkers."; +"Notifications.PermissionsUnreachableText" = "Check that both Alert and Sound are enabled in Settings."; "Notifications.PermissionsAllow" = "Turn Notifications ON"; "Notifications.PermissionsAllowInSettings" = "Turn ON in Settings"; diff --git a/submodules/Display b/submodules/Display index 7dbc5b2e78..c8a8570465 160000 --- a/submodules/Display +++ b/submodules/Display @@ -1 +1 @@ -Subproject commit 7dbc5b2e78119a24f26c2888030d861e6ff07d45 +Subproject commit c8a85704654a263d5d389339adb612a16c589309 diff --git a/submodules/TelegramCore b/submodules/TelegramCore index e8b5a8e807..37c7241974 160000 --- a/submodules/TelegramCore +++ b/submodules/TelegramCore @@ -1 +1 @@ -Subproject commit e8b5a8e807c186a3994dc6211e746bed61009090 +Subproject commit 37c72419743b7be8a6f82ddcbbc58516ed07e3b0 diff --git a/submodules/TelegramUI b/submodules/TelegramUI index 2579de5d1d..7c850a413f 160000 --- a/submodules/TelegramUI +++ b/submodules/TelegramUI @@ -1 +1 @@ -Subproject commit 2579de5d1d22d37fd92e6d1a038da36f09bf2be2 +Subproject commit 7c850a413fcfb5e5b6237a6cf4b9d22691d51e1d