Merge branch 'master' of gitlab.com:peter-iakovlev/TelegramUI

This commit is contained in:
Ilya Laktyushin 2018-12-28 21:26:44 +04:00
commit eaaf1aa787
7 changed files with 2417 additions and 2346 deletions

View File

@ -136,15 +136,57 @@ public final class AuthorizationSequenceController: NavigationController {
text = strongSelf.strings.Login_CodeFloodError text = strongSelf.strings.Login_CodeFloodError
case .invalidPhoneNumber: case .invalidPhoneNumber:
text = strongSelf.strings.Login_InvalidPhoneError text = strongSelf.strings.Login_InvalidPhoneError
actions.append(TextAlertAction(type: .defaultAction, title: strongSelf.strings.Login_PhoneNumberHelp, action: { actions.append(TextAlertAction(type: .defaultAction, title: strongSelf.strings.Login_PhoneNumberHelp, action: { [weak controller] in
guard let strongSelf = self, let controller = controller else {
return
}
let formattedNumber = formatPhoneNumber(number)
let appVersion = (Bundle.main.infoDictionary?["CFBundleShortVersionString"] as? String) ?? "unknown"
let systemVersion = UIDevice.current.systemVersion
let locale = Locale.current.identifier
let carrier = CTCarrier()
let mnc = carrier.mobileNetworkCode ?? "none"
strongSelf.presentEmailComposeController(address: "login@stel.com", subject: strongSelf.strings.Login_InvalidPhoneEmailSubject(formattedNumber).0, body: strongSelf.strings.Login_InvalidPhoneEmailBody(formattedNumber, appVersion, systemVersion, locale, mnc).0, from: controller)
})) }))
case .phoneLimitExceeded: case .phoneLimitExceeded:
text = strongSelf.strings.Login_PhoneFloodError text = strongSelf.strings.Login_PhoneFloodError
case .phoneBanned: case .phoneBanned:
text = strongSelf.strings.Login_PhoneBannedError text = strongSelf.strings.Login_PhoneBannedError
case .generic: actions.append(TextAlertAction(type: .defaultAction, title: strongSelf.strings.Login_PhoneNumberHelp, action: { [weak controller] in
guard let strongSelf = self, let controller = controller else {
return
}
let formattedNumber = formatPhoneNumber(number)
let appVersion = (Bundle.main.infoDictionary?["CFBundleShortVersionString"] as? String) ?? "unknown"
let systemVersion = UIDevice.current.systemVersion
let locale = Locale.current.identifier
let carrier = CTCarrier()
let mnc = carrier.mobileNetworkCode ?? "none"
strongSelf.presentEmailComposeController(address: "login@stel.com", subject: strongSelf.strings.Login_PhoneBannedEmailSubject(formattedNumber).0, body: strongSelf.strings.Login_PhoneBannedEmailBody(formattedNumber, appVersion, systemVersion, locale, mnc).0, from: controller)
}))
case let .generic(info):
text = strongSelf.strings.Login_UnknownError text = strongSelf.strings.Login_UnknownError
actions.append(TextAlertAction(type: .defaultAction, title: strongSelf.strings.Login_PhoneNumberHelp, action: { [weak controller] in
guard let strongSelf = self, let controller = controller else {
return
}
let formattedNumber = formatPhoneNumber(number)
let appVersion = (Bundle.main.infoDictionary?["CFBundleShortVersionString"] as? String) ?? "unknown"
let systemVersion = UIDevice.current.systemVersion
let locale = Locale.current.identifier
let carrier = CTCarrier()
let mnc = carrier.mobileNetworkCode ?? "none"
let errorString: String
if let (code, description) = info {
errorString = "\(code): \(description)"
} else {
errorString = "unknown"
}
strongSelf.presentEmailComposeController(address: "login@stel.com", subject: strongSelf.strings.Login_PhoneGenericEmailSubject(formattedNumber).0, body: strongSelf.strings.Login_PhoneGenericEmailBody(formattedNumber, errorString, appVersion, systemVersion, locale, mnc).0, from: controller)
}))
case .timeout: case .timeout:
text = strongSelf.strings.Login_NetworkError text = strongSelf.strings.Login_NetworkError
actions.append(TextAlertAction(type: .genericAction, title: strongSelf.strings.ChatSettings_ConnectionType_UseProxy, action: { [weak controller] in actions.append(TextAlertAction(type: .genericAction, title: strongSelf.strings.ChatSettings_ConnectionType_UseProxy, action: { [weak controller] in
@ -185,35 +227,6 @@ public final class AuthorizationSequenceController: NavigationController {
if let strongSelf = self { if let strongSelf = self {
controller?.inProgress = true controller?.inProgress = true
/*
if let (termsOfService, exclusuve) = self.termsOfService, exclusuve {
var acceptImpl: (() -> Void)?
var declineImpl: (() -> Void)?
let controller = TermsOfServiceController(theme: TermsOfServiceControllerTheme(authTheme: self.theme), strings: self.strings, text: termsOfService.text, entities: termsOfService.entities, ageConfirmation: termsOfService.ageConfirmation, signingUp: true, accept: { _ in
acceptImpl?()
}, decline: {
declineImpl?()
}, openUrl: { [weak self] url in
self?.openUrl(url)
})
acceptImpl = { [weak self, weak controller] in
controller?.dismiss()
if let strongSelf = self {
strongSelf.termsOfService = nil
strongSelf.loginWithCode?(code)
}
}
declineImpl = { [weak self, weak controller] in
controller?.dismiss()
self?.reset?()
self?.controllerNode.activateInput()
}
self.view.endEditing(true)
self.present(controller, in: .window(.root))
} else {
*/
strongSelf.actionDisposable.set((authorizeWithCode(account: strongSelf.account, code: code, termsOfService: termsOfService?.0) strongSelf.actionDisposable.set((authorizeWithCode(account: strongSelf.account, code: code, termsOfService: termsOfService?.0)
|> deliverOnMainQueue).start(next: { result in |> deliverOnMainQueue).start(next: { result in
guard let strongSelf = self else { guard let strongSelf = self else {
@ -656,6 +669,19 @@ public final class AuthorizationSequenceController: NavigationController {
controller.applyConfirmationCode(code) controller.applyConfirmationCode(code)
} }
} }
private func presentEmailComposeController(address: String, subject: String, body: String, from controller: ViewController) {
if MFMailComposeViewController.canSendMail() {
let composeController = MFMailComposeViewController()
composeController.setToRecipients([address])
composeController.setSubject(subject)
composeController.setMessageBody(body, isHTML: false)
controller.view.window?.rootViewController?.present(composeController, animated: true, completion: nil)
} else {
controller.present(standardTextAlertController(theme: AlertControllerTheme(authTheme: self.theme), title: nil, text: self.strings.Login_EmailNotConfiguredError, actions: [TextAlertAction(type: .defaultAction, title: self.strings.Common_OK, action: {})]), in: .window(.root))
}
}
} }
private func defaultCountryCode() -> Int32 { private func defaultCountryCode() -> Int32 {

View File

@ -4,8 +4,8 @@ import AsyncDisplayKit
import SwiftSignalKit import SwiftSignalKit
import AVFoundation import AVFoundation
private final class MediaPlayerNodeLayerNullAction: NSNull { private final class MediaPlayerNodeLayerNullAction: NSObject, CAAction {
@objc override func run(forKey event: String, object anObject: Any, arguments dict: [AnyHashable : Any]?) { @objc func run(forKey event: String, object anObject: Any, arguments dict: [AnyHashable : Any]?) {
} }
} }

View File

@ -34,13 +34,15 @@ private final class NotificationsAndSoundsArguments {
let updateIncludeTag: (PeerSummaryCounterTags, Bool) -> Void let updateIncludeTag: (PeerSummaryCounterTags, Bool) -> Void
let updateTotalUnreadCountCategory: (Bool) -> Void let updateTotalUnreadCountCategory: (Bool) -> Void
let updateJoinedNotifications: (Bool) -> Void
let resetNotifications: () -> Void let resetNotifications: () -> Void
let updatedExceptionMode: (NotificationExceptionMode) -> Void let updatedExceptionMode: (NotificationExceptionMode) -> Void
let openAppSettings: () -> Void let openAppSettings: () -> Void
init(account: Account, presentController: @escaping (ViewController, ViewControllerPresentationArguments?) -> Void, pushController: @escaping(ViewController)->Void, soundSelectionDisposable: MetaDisposable, authorizeNotifications: @escaping () -> Void, suppressWarning: @escaping () -> Void, updateMessageAlerts: @escaping (Bool) -> Void, updateMessagePreviews: @escaping (Bool) -> Void, updateMessageSound: @escaping (PeerMessageSound) -> Void, updateGroupAlerts: @escaping (Bool) -> Void, updateGroupPreviews: @escaping (Bool) -> Void, updateGroupSound: @escaping (PeerMessageSound) -> Void, updateChannelAlerts: @escaping (Bool) -> Void, updateChannelPreviews: @escaping (Bool) -> Void, updateChannelSound: @escaping (PeerMessageSound) -> Void, updateInAppSounds: @escaping (Bool) -> Void, updateInAppVibration: @escaping (Bool) -> Void, updateInAppPreviews: @escaping (Bool) -> Void, updateDisplayNameOnLockscreen: @escaping (Bool) -> Void, updateTotalUnreadCountStyle: @escaping (Bool) -> Void, updateIncludeTag: @escaping (PeerSummaryCounterTags, Bool) -> Void, updateTotalUnreadCountCategory: @escaping (Bool) -> Void, resetNotifications: @escaping () -> Void, updatedExceptionMode: @escaping(NotificationExceptionMode) -> Void, openAppSettings: @escaping () -> Void) { init(account: Account, presentController: @escaping (ViewController, ViewControllerPresentationArguments?) -> Void, pushController: @escaping(ViewController)->Void, soundSelectionDisposable: MetaDisposable, authorizeNotifications: @escaping () -> Void, suppressWarning: @escaping () -> Void, updateMessageAlerts: @escaping (Bool) -> Void, updateMessagePreviews: @escaping (Bool) -> Void, updateMessageSound: @escaping (PeerMessageSound) -> Void, updateGroupAlerts: @escaping (Bool) -> Void, updateGroupPreviews: @escaping (Bool) -> Void, updateGroupSound: @escaping (PeerMessageSound) -> Void, updateChannelAlerts: @escaping (Bool) -> Void, updateChannelPreviews: @escaping (Bool) -> Void, updateChannelSound: @escaping (PeerMessageSound) -> Void, updateInAppSounds: @escaping (Bool) -> Void, updateInAppVibration: @escaping (Bool) -> Void, updateInAppPreviews: @escaping (Bool) -> Void, updateDisplayNameOnLockscreen: @escaping (Bool) -> Void, updateTotalUnreadCountStyle: @escaping (Bool) -> Void, updateIncludeTag: @escaping (PeerSummaryCounterTags, Bool) -> Void, updateTotalUnreadCountCategory: @escaping (Bool) -> Void, resetNotifications: @escaping () -> Void, updatedExceptionMode: @escaping(NotificationExceptionMode) -> Void, openAppSettings: @escaping () -> Void, updateJoinedNotifications: @escaping (Bool) -> Void) {
self.account = account self.account = account
self.presentController = presentController self.presentController = presentController
self.pushController = pushController self.pushController = pushController
@ -66,6 +68,7 @@ private final class NotificationsAndSoundsArguments {
self.resetNotifications = resetNotifications self.resetNotifications = resetNotifications
self.updatedExceptionMode = updatedExceptionMode self.updatedExceptionMode = updatedExceptionMode
self.openAppSettings = openAppSettings self.openAppSettings = openAppSettings
self.updateJoinedNotifications = updateJoinedNotifications
} }
} }
@ -77,6 +80,7 @@ private enum NotificationsAndSoundsSection: Int32 {
case inApp case inApp
case displayNamesOnLockscreen case displayNamesOnLockscreen
case badge case badge
case joinedNotifications
case reset case reset
} }
@ -121,6 +125,8 @@ private enum NotificationsAndSoundsEntry: ItemListNodeEntry {
case unreadCountCategory(PresentationTheme, String, Bool) case unreadCountCategory(PresentationTheme, String, Bool)
case unreadCountCategoryInfo(PresentationTheme, String) case unreadCountCategoryInfo(PresentationTheme, String)
case joinedNotifications(PresentationTheme, String, Bool)
case reset(PresentationTheme, String) case reset(PresentationTheme, String)
case resetNotice(PresentationTheme, String) case resetNotice(PresentationTheme, String)
@ -140,6 +146,8 @@ private enum NotificationsAndSoundsEntry: ItemListNodeEntry {
return NotificationsAndSoundsSection.displayNamesOnLockscreen.rawValue return NotificationsAndSoundsSection.displayNamesOnLockscreen.rawValue
case .badgeHeader, .unreadCountStyle, .includePublicGroups, .includeChannels, .unreadCountCategory, .unreadCountCategoryInfo: case .badgeHeader, .unreadCountStyle, .includePublicGroups, .includeChannels, .unreadCountCategory, .unreadCountCategoryInfo:
return NotificationsAndSoundsSection.badge.rawValue return NotificationsAndSoundsSection.badge.rawValue
case .joinedNotifications:
return NotificationsAndSoundsSection.joinedNotifications.rawValue
case .reset, .resetNotice: case .reset, .resetNotice:
return NotificationsAndSoundsSection.reset.rawValue return NotificationsAndSoundsSection.reset.rawValue
} }
@ -211,10 +219,12 @@ private enum NotificationsAndSoundsEntry: ItemListNodeEntry {
return 30 return 30
case .unreadCountCategoryInfo: case .unreadCountCategoryInfo:
return 31 return 31
case .reset: case .joinedNotifications:
return 32 return 32
case .resetNotice: case .reset:
return 33 return 33
case .resetNotice:
return 34
} }
} }
@ -412,6 +422,12 @@ private enum NotificationsAndSoundsEntry: ItemListNodeEntry {
} else { } else {
return false return false
} }
case let .joinedNotifications(lhsTheme, lhsText, lhsValue):
if case let .joinedNotifications(rhsTheme, rhsText, rhsValue) = rhs, lhsTheme === rhsTheme, lhsText == rhsText, lhsValue == rhsValue {
return true
} else {
return false
}
case let .reset(lhsTheme, lhsText): case let .reset(lhsTheme, lhsText):
if case let .reset(rhsTheme, rhsText) = rhs, lhsTheme === rhsTheme, lhsText == rhsText { if case let .reset(rhsTheme, rhsText) = rhs, lhsTheme === rhsTheme, lhsText == rhsText {
return true return true
@ -555,6 +571,10 @@ private enum NotificationsAndSoundsEntry: ItemListNodeEntry {
}) })
case let .unreadCountCategoryInfo(theme, text): case let .unreadCountCategoryInfo(theme, text):
return ItemListTextItem(theme: theme, text: .plain(text), sectionId: self.section) return ItemListTextItem(theme: theme, text: .plain(text), sectionId: self.section)
case let .joinedNotifications(theme, text, value):
return ItemListSwitchItem(theme: theme, title: text, value: value, sectionId: self.section, style: .blocks, updated: { updatedValue in
arguments.updateJoinedNotifications(updatedValue)
})
case let .reset(theme, text): case let .reset(theme, text):
return ItemListActionItem(theme: theme, title: text, kind: .destructive, alignment: .natural, sectionId: self.section, style: .blocks, action: { return ItemListActionItem(theme: theme, title: text, kind: .destructive, alignment: .natural, sectionId: self.section, style: .blocks, action: {
arguments.resetNotifications() arguments.resetNotifications()
@ -639,6 +659,7 @@ private func notificationsAndSoundsEntries(authorizationStatus: AccessType, warn
entries.append(.includeChannels(presentationData.theme, presentationData.strings.Notifications_Badge_IncludeChannels, inAppSettings.totalUnreadCountIncludeTags.contains(.channels))) entries.append(.includeChannels(presentationData.theme, presentationData.strings.Notifications_Badge_IncludeChannels, inAppSettings.totalUnreadCountIncludeTags.contains(.channels)))
entries.append(.unreadCountCategory(presentationData.theme, presentationData.strings.Notifications_Badge_CountUnreadMessages, inAppSettings.totalUnreadCountDisplayCategory == .messages)) entries.append(.unreadCountCategory(presentationData.theme, presentationData.strings.Notifications_Badge_CountUnreadMessages, inAppSettings.totalUnreadCountDisplayCategory == .messages))
entries.append(.unreadCountCategoryInfo(presentationData.theme, inAppSettings.totalUnreadCountDisplayCategory == .chats ? presentationData.strings.Notifications_Badge_CountUnreadMessages_InfoOff : presentationData.strings.Notifications_Badge_CountUnreadMessages_InfoOn)) entries.append(.unreadCountCategoryInfo(presentationData.theme, inAppSettings.totalUnreadCountDisplayCategory == .chats ? presentationData.strings.Notifications_Badge_CountUnreadMessages_InfoOff : presentationData.strings.Notifications_Badge_CountUnreadMessages_InfoOn))
entries.append(.joinedNotifications(presentationData.theme, presentationData.strings.NotificationSettings_ContactJoined, globalSettings.contactsJoined))
entries.append(.reset(presentationData.theme, presentationData.strings.Notifications_ResetAllNotifications)) entries.append(.reset(presentationData.theme, presentationData.strings.Notifications_ResetAllNotifications))
entries.append(.resetNotice(presentationData.theme, presentationData.strings.Notifications_ResetAllNotificationsHelp)) entries.append(.resetNotice(presentationData.theme, presentationData.strings.Notifications_ResetAllNotificationsHelp))
@ -685,57 +706,57 @@ public func notificationsAndSoundsController(account: Account, exceptionsList: N
})]), nil) })]), nil)
}, updateMessageAlerts: { value in }, updateMessageAlerts: { value in
let _ = updateGlobalNotificationSettingsInteractively(postbox: account.postbox, { settings in let _ = updateGlobalNotificationSettingsInteractively(postbox: account.postbox, { settings in
return settings.withUpdatedPrivateChats { var settings = settings
return $0.withUpdatedEnabled(value) settings.privateChats.enabled = value
} return settings
}).start() }).start()
}, updateMessagePreviews: { value in }, updateMessagePreviews: { value in
let _ = updateGlobalNotificationSettingsInteractively(postbox: account.postbox, { settings in let _ = updateGlobalNotificationSettingsInteractively(postbox: account.postbox, { settings in
return settings.withUpdatedPrivateChats { var settings = settings
return $0.withUpdatedDisplayPreviews(value) settings.privateChats.displayPreviews = value
} return settings
}).start() }).start()
}, updateMessageSound: { value in }, updateMessageSound: { value in
let _ = updateGlobalNotificationSettingsInteractively(postbox: account.postbox, { settings in let _ = updateGlobalNotificationSettingsInteractively(postbox: account.postbox, { settings in
return settings.withUpdatedPrivateChats { var settings = settings
return $0.withUpdatedSound(value) settings.privateChats.sound = value
} return settings
}).start() }).start()
}, updateGroupAlerts: { value in }, updateGroupAlerts: { value in
let _ = updateGlobalNotificationSettingsInteractively(postbox: account.postbox, { settings in let _ = updateGlobalNotificationSettingsInteractively(postbox: account.postbox, { settings in
return settings.withUpdatedGroupChats { var settings = settings
return $0.withUpdatedEnabled(value) settings.groupChats.enabled = value
} return settings
}).start() }).start()
}, updateGroupPreviews: { value in }, updateGroupPreviews: { value in
let _ = updateGlobalNotificationSettingsInteractively(postbox: account.postbox, { settings in let _ = updateGlobalNotificationSettingsInteractively(postbox: account.postbox, { settings in
return settings.withUpdatedGroupChats { var settings = settings
return $0.withUpdatedDisplayPreviews(value) settings.groupChats.displayPreviews = value
} return settings
}).start() }).start()
}, updateGroupSound: {value in }, updateGroupSound: {value in
let _ = updateGlobalNotificationSettingsInteractively(postbox: account.postbox, { settings in let _ = updateGlobalNotificationSettingsInteractively(postbox: account.postbox, { settings in
return settings.withUpdatedGroupChats { var settings = settings
return $0.withUpdatedSound(value) settings.groupChats.sound = value
} return settings
}).start() }).start()
}, updateChannelAlerts: { value in }, updateChannelAlerts: { value in
let _ = updateGlobalNotificationSettingsInteractively(postbox: account.postbox, { settings in let _ = updateGlobalNotificationSettingsInteractively(postbox: account.postbox, { settings in
return settings.withUpdatedChannels { var settings = settings
return $0.withUpdatedEnabled(value) settings.channels.enabled = value
} return settings
}).start() }).start()
}, updateChannelPreviews: { value in }, updateChannelPreviews: { value in
let _ = updateGlobalNotificationSettingsInteractively(postbox: account.postbox, { settings in let _ = updateGlobalNotificationSettingsInteractively(postbox: account.postbox, { settings in
return settings.withUpdatedChannels { var settings = settings
return $0.withUpdatedDisplayPreviews(value) settings.channels.displayPreviews = value
} return settings
}).start() }).start()
}, updateChannelSound: {value in }, updateChannelSound: {value in
let _ = updateGlobalNotificationSettingsInteractively(postbox: account.postbox, { settings in let _ = updateGlobalNotificationSettingsInteractively(postbox: account.postbox, { settings in
return settings.withUpdatedChannels { var settings = settings
return $0.withUpdatedSound(value) settings.channels.sound = value
} return settings
}).start() }).start()
}, updateInAppSounds: { value in }, updateInAppSounds: { value in
let _ = updateInAppNotificationSettingsInteractively(postbox: account.postbox, { settings in let _ = updateInAppNotificationSettingsInteractively(postbox: account.postbox, { settings in
@ -819,6 +840,12 @@ public func notificationsAndSoundsController(account: Account, exceptionsList: N
}) })
}, openAppSettings: { }, openAppSettings: {
account.telegramApplicationContext.applicationBindings.openSettings() account.telegramApplicationContext.applicationBindings.openSettings()
}, updateJoinedNotifications: { value in
let _ = updateGlobalNotificationSettingsInteractively(postbox: account.postbox, { settings in
var settings = settings
settings.contactsJoined = value
return settings
}).start()
}) })
let preferences = account.postbox.preferencesView(keys: [PreferencesKeys.globalNotifications, ApplicationSpecificPreferencesKeys.inAppNotificationSettings]) let preferences = account.postbox.preferencesView(keys: [PreferencesKeys.globalNotifications, ApplicationSpecificPreferencesKeys.inAppNotificationSettings])

File diff suppressed because it is too large Load Diff

View File

@ -3,8 +3,8 @@ import UIKit
import AVFoundation import AVFoundation
import SwiftSignalKit import SwiftSignalKit
private final class SampleBufferLayerImplNullAction: NSNull { private final class SampleBufferLayerImplNullAction: NSObject, CAAction {
@objc override func run(forKey event: String, object anObject: Any, arguments dict: [AnyHashable : Any]?) { @objc func run(forKey event: String, object anObject: Any, arguments dict: [AnyHashable : Any]?) {
} }
} }

View File

@ -4,8 +4,8 @@ import TelegramCore
import Postbox import Postbox
import SwiftSignalKit import SwiftSignalKit
private final class SoftwareVideoThumbnailLayerNullAction: NSNull { private final class SoftwareVideoThumbnailLayerNullAction: NSObject, CAAction {
@objc override func run(forKey event: String, object anObject: Any, arguments dict: [AnyHashable : Any]?) { @objc func run(forKey event: String, object anObject: Any, arguments dict: [AnyHashable : Any]?) {
} }
} }