mirror of
https://github.com/Swiftgram/Telegram-iOS.git
synced 2025-12-22 22:25:57 +00:00
Merge branch 'master' of gitlab.com:peter-iakovlev/telegram-ios
This commit is contained in:
@@ -36,6 +36,7 @@ import ContextUI
|
||||
import WalletUI
|
||||
import PhoneNumberFormat
|
||||
import AccountUtils
|
||||
import AuthTransferUI
|
||||
|
||||
private let avatarFont = avatarPlaceholderFont(size: 13.0)
|
||||
|
||||
@@ -111,6 +112,7 @@ private final class SettingsItemArguments {
|
||||
let keepPhone: () -> Void
|
||||
let openPhoneNumberChange: () -> Void
|
||||
let accountContextAction: (AccountRecordId, ASDisplayNode, ContextGesture?) -> Void
|
||||
let openDevices: () -> Void
|
||||
|
||||
init(
|
||||
accountManager: AccountManager,
|
||||
@@ -143,7 +145,8 @@ private final class SettingsItemArguments {
|
||||
removeAccount: @escaping (AccountRecordId) -> Void,
|
||||
keepPhone: @escaping () -> Void,
|
||||
openPhoneNumberChange: @escaping () -> Void,
|
||||
accountContextAction: @escaping (AccountRecordId, ASDisplayNode, ContextGesture?) -> Void
|
||||
accountContextAction: @escaping (AccountRecordId, ASDisplayNode, ContextGesture?) -> Void,
|
||||
openDevices: @escaping () -> Void
|
||||
) {
|
||||
self.accountManager = accountManager
|
||||
self.avatarAndNameInfoContext = avatarAndNameInfoContext
|
||||
@@ -176,6 +179,7 @@ private final class SettingsItemArguments {
|
||||
self.keepPhone = keepPhone
|
||||
self.openPhoneNumberChange = openPhoneNumberChange
|
||||
self.accountContextAction = accountContextAction
|
||||
self.openDevices = openDevices
|
||||
}
|
||||
}
|
||||
|
||||
@@ -204,6 +208,8 @@ private indirect enum SettingsEntry: ItemListNodeEntry {
|
||||
|
||||
case proxy(PresentationTheme, UIImage?, String, String)
|
||||
|
||||
case devices(PresentationTheme, UIImage?, String, String)
|
||||
|
||||
case savedMessages(PresentationTheme, UIImage?, String)
|
||||
case recentCalls(PresentationTheme, UIImage?, String)
|
||||
case stickers(PresentationTheme, UIImage?, String, String, [ArchivedStickerPackItem]?)
|
||||
@@ -222,22 +228,24 @@ private indirect enum SettingsEntry: ItemListNodeEntry {
|
||||
|
||||
var section: ItemListSectionId {
|
||||
switch self {
|
||||
case .userInfo, .setProfilePhoto, .setUsername:
|
||||
return SettingsSection.info.rawValue
|
||||
case .phoneInfo, .keepPhone, .changePhone:
|
||||
return SettingsSection.phone.rawValue
|
||||
case .account, .addAccount:
|
||||
return SettingsSection.accounts.rawValue
|
||||
case .proxy:
|
||||
return SettingsSection.proxy.rawValue
|
||||
case .savedMessages, .recentCalls, .stickers:
|
||||
return SettingsSection.media.rawValue
|
||||
case .notificationsAndSounds, .privacyAndSecurity, .dataAndStorage, .themes, .language:
|
||||
return SettingsSection.generalSettings.rawValue
|
||||
case .passport, .wallet, .watch :
|
||||
return SettingsSection.advanced.rawValue
|
||||
case .askAQuestion, .faq:
|
||||
return SettingsSection.help.rawValue
|
||||
case .userInfo, .setProfilePhoto, .setUsername:
|
||||
return SettingsSection.info.rawValue
|
||||
case .phoneInfo, .keepPhone, .changePhone:
|
||||
return SettingsSection.phone.rawValue
|
||||
case .account, .addAccount:
|
||||
return SettingsSection.accounts.rawValue
|
||||
case .proxy:
|
||||
return SettingsSection.proxy.rawValue
|
||||
case .devices:
|
||||
return SettingsSection.media.rawValue
|
||||
case .savedMessages, .recentCalls, .stickers:
|
||||
return SettingsSection.media.rawValue
|
||||
case .notificationsAndSounds, .privacyAndSecurity, .dataAndStorage, .themes, .language:
|
||||
return SettingsSection.generalSettings.rawValue
|
||||
case .passport, .wallet, .watch :
|
||||
return SettingsSection.advanced.rawValue
|
||||
case .askAQuestion, .faq:
|
||||
return SettingsSection.help.rawValue
|
||||
}
|
||||
}
|
||||
|
||||
@@ -267,26 +275,28 @@ private indirect enum SettingsEntry: ItemListNodeEntry {
|
||||
return 1005
|
||||
case .stickers:
|
||||
return 1006
|
||||
case .notificationsAndSounds:
|
||||
case .devices:
|
||||
return 1007
|
||||
case .privacyAndSecurity:
|
||||
case .notificationsAndSounds:
|
||||
return 1008
|
||||
case .dataAndStorage:
|
||||
case .privacyAndSecurity:
|
||||
return 1009
|
||||
case .themes:
|
||||
case .dataAndStorage:
|
||||
return 1010
|
||||
case .language:
|
||||
case .themes:
|
||||
return 1011
|
||||
case .wallet:
|
||||
case .language:
|
||||
return 1012
|
||||
case .passport:
|
||||
case .wallet:
|
||||
return 1013
|
||||
case .watch:
|
||||
case .passport:
|
||||
return 1014
|
||||
case .askAQuestion:
|
||||
case .watch:
|
||||
return 1015
|
||||
case .faq:
|
||||
case .askAQuestion:
|
||||
return 1016
|
||||
case .faq:
|
||||
return 1017
|
||||
}
|
||||
}
|
||||
|
||||
@@ -378,6 +388,12 @@ private indirect enum SettingsEntry: ItemListNodeEntry {
|
||||
} else {
|
||||
return false
|
||||
}
|
||||
case let .devices(lhsTheme, lhsImage, lhsText, lhsValue):
|
||||
if case let .devices(rhsTheme, rhsImage, rhsText, rhsValue) = rhs, lhsTheme === rhsTheme, lhsImage === rhsImage, lhsText == rhsText, lhsValue == rhsValue {
|
||||
return true
|
||||
} else {
|
||||
return false
|
||||
}
|
||||
case let .savedMessages(lhsTheme, lhsImage, lhsText):
|
||||
if case let .savedMessages(rhsTheme, rhsImage, rhsText) = rhs, lhsTheme === rhsTheme, lhsImage === rhsImage, lhsText == rhsText {
|
||||
return true
|
||||
@@ -527,6 +543,10 @@ private indirect enum SettingsEntry: ItemListNodeEntry {
|
||||
return ItemListDisclosureItem(presentationData: presentationData, icon: image, title: text, label: value, sectionId: ItemListSectionId(self.section), style: .blocks, action: {
|
||||
arguments.openProxy()
|
||||
})
|
||||
case let .devices(theme, image, text, value):
|
||||
return ItemListDisclosureItem(presentationData: presentationData, icon: image, title: text, label: value, sectionId: ItemListSectionId(self.section), style: .blocks, action: {
|
||||
arguments.openDevices()
|
||||
})
|
||||
case let .savedMessages(theme, image, text):
|
||||
return ItemListDisclosureItem(presentationData: presentationData, icon: image, title: text, label: "", sectionId: ItemListSectionId(self.section), style: .blocks, action: {
|
||||
arguments.openSavedMessages()
|
||||
@@ -589,7 +609,7 @@ private struct SettingsState: Equatable {
|
||||
var isSearching: Bool
|
||||
}
|
||||
|
||||
private func settingsEntries(account: Account, presentationData: PresentationData, state: SettingsState, view: PeerView, proxySettings: ProxySettings, notifyExceptions: NotificationExceptionsList?, notificationsAuthorizationStatus: AccessType, notificationsWarningSuppressed: Bool, unreadTrendingStickerPacks: Int, archivedPacks: [ArchivedStickerPackItem]?, privacySettings: AccountPrivacySettings?, hasWallet: Bool, hasPassport: Bool, hasWatchApp: Bool, accountsAndPeers: [(Account, Peer, Int32)], inAppNotificationSettings: InAppNotificationSettings, experimentalUISettings: ExperimentalUISettings, displayPhoneNumberConfirmation: Bool) -> [SettingsEntry] {
|
||||
private func settingsEntries(account: Account, presentationData: PresentationData, state: SettingsState, view: PeerView, proxySettings: ProxySettings, notifyExceptions: NotificationExceptionsList?, notificationsAuthorizationStatus: AccessType, notificationsWarningSuppressed: Bool, unreadTrendingStickerPacks: Int, archivedPacks: [ArchivedStickerPackItem]?, privacySettings: AccountPrivacySettings?, hasWallet: Bool, hasPassport: Bool, hasWatchApp: Bool, accountsAndPeers: [(Account, Peer, Int32)], inAppNotificationSettings: InAppNotificationSettings, experimentalUISettings: ExperimentalUISettings, displayPhoneNumberConfirmation: Bool, otherSessionCount: Int) -> [SettingsEntry] {
|
||||
var entries: [SettingsEntry] = []
|
||||
|
||||
if let peer = peerViewMainPeer(view) as? TelegramUser {
|
||||
@@ -638,6 +658,7 @@ private func settingsEntries(account: Account, presentationData: PresentationDat
|
||||
entries.append(.savedMessages(presentationData.theme, PresentationResourcesSettings.savedMessages, presentationData.strings.Settings_SavedMessages))
|
||||
entries.append(.recentCalls(presentationData.theme, PresentationResourcesSettings.recentCalls, presentationData.strings.CallSettings_RecentCalls))
|
||||
entries.append(.stickers(presentationData.theme, PresentationResourcesSettings.stickers, presentationData.strings.ChatSettings_Stickers, unreadTrendingStickerPacks == 0 ? "" : "\(unreadTrendingStickerPacks)", archivedPacks))
|
||||
entries.append(.devices(presentationData.theme, UIImage(bundleImageName: "Settings/MenuIcons/Sessions")?.precomposed(), presentationData.strings.Settings_Devices, otherSessionCount == 0 ? presentationData.strings.Settings_AddDevice : "\(otherSessionCount)"))
|
||||
|
||||
let notificationsWarning = shouldDisplayNotificationsPermissionWarning(status: notificationsAuthorizationStatus, suppressed: notificationsWarningSuppressed)
|
||||
entries.append(.notificationsAndSounds(presentationData.theme, PresentationResourcesSettings.notifications, presentationData.strings.Settings_NotificationsAndSounds, notifyExceptions, notificationsWarning))
|
||||
@@ -817,6 +838,23 @@ public func settingsController(context: AccountContext, accountManager: AccountM
|
||||
|
||||
let displayPhoneNumberConfirmation = ValuePromise<Bool>(false)
|
||||
|
||||
let activeSessionsContextAndCountSignal = contextValue.get()
|
||||
|> deliverOnMainQueue
|
||||
|> mapToSignal { context -> Signal<(ActiveSessionsContext, Int), NoError> in
|
||||
let activeSessionsContext = ActiveSessionsContext(account: context.account)
|
||||
let otherSessionCount = activeSessionsContext.state
|
||||
|> map { state -> Int in
|
||||
return state.sessions.filter({ !$0.isCurrent }).count
|
||||
}
|
||||
|> distinctUntilChanged
|
||||
return otherSessionCount
|
||||
|> map { value in
|
||||
return (activeSessionsContext, value)
|
||||
}
|
||||
}
|
||||
let activeSessionsContextAndCount = Promise<(ActiveSessionsContext, Int)>()
|
||||
activeSessionsContextAndCount.set(activeSessionsContextAndCountSignal)
|
||||
|
||||
let arguments = SettingsItemArguments(accountManager: accountManager, avatarAndNameInfoContext: avatarAndNameInfoContext, avatarTapAction: {
|
||||
var updating = false
|
||||
updateState {
|
||||
@@ -874,9 +912,13 @@ public func settingsController(context: AccountContext, accountManager: AccountM
|
||||
let _ = (contextValue.get()
|
||||
|> deliverOnMainQueue
|
||||
|> take(1)).start(next: { context in
|
||||
pushControllerImpl?(privacyAndSecurityController(context: context, initialSettings: privacySettingsValue, updatedSettings: { settings in
|
||||
privacySettings.set(.single(settings))
|
||||
}))
|
||||
let _ = (activeSessionsContextAndCount.get()
|
||||
|> deliverOnMainQueue
|
||||
|> take(1)).start(next: { activeSessionsContext, _ in
|
||||
pushControllerImpl?(privacyAndSecurityController(context: context, initialSettings: privacySettingsValue, updatedSettings: { settings in
|
||||
privacySettings.set(.single(settings))
|
||||
}, activeSessionsContext: activeSessionsContext))
|
||||
})
|
||||
})
|
||||
}, openDataAndStorage: {
|
||||
let _ = (contextValue.get()
|
||||
@@ -1044,6 +1086,16 @@ public func settingsController(context: AccountContext, accountManager: AccountM
|
||||
} else {
|
||||
gesture?.cancel()
|
||||
}
|
||||
}, openDevices: {
|
||||
let _ = (activeSessionsContextAndCount.get()
|
||||
|> deliverOnMainQueue
|
||||
|> take(1)).start(next: { activeSessionsContext, count in
|
||||
if count == 0 {
|
||||
pushControllerImpl?(AuthTransferScanScreen(context: context, activeSessionsContext: activeSessionsContext))
|
||||
} else {
|
||||
pushControllerImpl?(recentSessionsController(context: context, activeSessionsContext: activeSessionsContext))
|
||||
}
|
||||
})
|
||||
})
|
||||
|
||||
changeProfilePhotoImpl = {
|
||||
@@ -1280,8 +1332,10 @@ public func settingsController(context: AccountContext, accountManager: AccountM
|
||||
return context.account.viewTracker.featuredStickerPacks()
|
||||
}
|
||||
|
||||
let signal = combineLatest(queue: Queue.mainQueue(), contextValue.get(), updatedPresentationData, statePromise.get(), peerView, combineLatest(queue: Queue.mainQueue(), preferences, notifyExceptions.get(), notificationsAuthorizationStatus.get(), notificationsWarningSuppressed.get(), privacySettings.get(), displayPhoneNumberConfirmation.get()), combineLatest(featuredStickerPacks, archivedPacks.get()), combineLatest(hasWallet, hasPassport.get(), hasWatchApp), accountsAndPeers.get())
|
||||
|> map { context, presentationData, state, view, preferencesAndExceptions, featuredAndArchived, hasWalletPassportAndWatch, accountsAndPeers -> (ItemListControllerState, (ItemListNodeState, Any)) in
|
||||
let signal = combineLatest(queue: Queue.mainQueue(), contextValue.get(), updatedPresentationData, statePromise.get(), peerView, combineLatest(queue: Queue.mainQueue(), preferences, notifyExceptions.get(), notificationsAuthorizationStatus.get(), notificationsWarningSuppressed.get(), privacySettings.get(), displayPhoneNumberConfirmation.get()), combineLatest(featuredStickerPacks, archivedPacks.get()), combineLatest(hasWallet, hasPassport.get(), hasWatchApp), accountsAndPeers.get(), activeSessionsContextAndCount.get())
|
||||
|> map { context, presentationData, state, view, preferencesAndExceptions, featuredAndArchived, hasWalletPassportAndWatch, accountsAndPeers, activeSessionsContextAndCount -> (ItemListControllerState, (ItemListNodeState, Any)) in
|
||||
let otherSessionCount = activeSessionsContextAndCount.1
|
||||
|
||||
let proxySettings: ProxySettings = preferencesAndExceptions.0.entries[SharedDataKeys.proxySettings] as? ProxySettings ?? ProxySettings.defaultSettings
|
||||
let inAppNotificationSettings: InAppNotificationSettings = preferencesAndExceptions.0.entries[ApplicationSpecificSharedDataKeys.inAppNotificationSettings] as? InAppNotificationSettings ?? InAppNotificationSettings.defaultSettings
|
||||
let experimentalUISettings: ExperimentalUISettings = preferencesAndExceptions.0.entries[ApplicationSpecificSharedDataKeys.experimentalUISettings] as? ExperimentalUISettings ?? ExperimentalUISettings.defaultSettings
|
||||
@@ -1319,7 +1373,7 @@ public func settingsController(context: AccountContext, accountManager: AccountM
|
||||
}, getNavigationController: getNavigationControllerImpl, exceptionsList: notifyExceptions.get(), archivedStickerPacks: archivedPacks.get(), privacySettings: privacySettings.get(), hasWallet: hasWallet)
|
||||
|
||||
let (hasWallet, hasPassport, hasWatchApp) = hasWalletPassportAndWatch
|
||||
let listState = ItemListNodeState(presentationData: ItemListPresentationData(presentationData), entries: settingsEntries(account: context.account, presentationData: presentationData, state: state, view: view, proxySettings: proxySettings, notifyExceptions: preferencesAndExceptions.1, notificationsAuthorizationStatus: preferencesAndExceptions.2, notificationsWarningSuppressed: preferencesAndExceptions.3, unreadTrendingStickerPacks: unreadTrendingStickerPacks, archivedPacks: featuredAndArchived.1, privacySettings: preferencesAndExceptions.4, hasWallet: hasWallet, hasPassport: hasPassport, hasWatchApp: hasWatchApp, accountsAndPeers: accountsAndPeers.1, inAppNotificationSettings: inAppNotificationSettings, experimentalUISettings: experimentalUISettings, displayPhoneNumberConfirmation: preferencesAndExceptions.5), style: .blocks, searchItem: searchItem, initialScrollToItem: ListViewScrollToItem(index: 0, position: .top(-navigationBarSearchContentHeight), animated: false, curve: .Default(duration: 0.0), directionHint: .Up))
|
||||
let listState = ItemListNodeState(presentationData: ItemListPresentationData(presentationData), entries: settingsEntries(account: context.account, presentationData: presentationData, state: state, view: view, proxySettings: proxySettings, notifyExceptions: preferencesAndExceptions.1, notificationsAuthorizationStatus: preferencesAndExceptions.2, notificationsWarningSuppressed: preferencesAndExceptions.3, unreadTrendingStickerPacks: unreadTrendingStickerPacks, archivedPacks: featuredAndArchived.1, privacySettings: preferencesAndExceptions.4, hasWallet: hasWallet, hasPassport: hasPassport, hasWatchApp: hasWatchApp, accountsAndPeers: accountsAndPeers.1, inAppNotificationSettings: inAppNotificationSettings, experimentalUISettings: experimentalUISettings, displayPhoneNumberConfirmation: preferencesAndExceptions.5, otherSessionCount: otherSessionCount), style: .blocks, searchItem: searchItem, initialScrollToItem: ListViewScrollToItem(index: 0, position: .top(-navigationBarSearchContentHeight), animated: false, curve: .Default(duration: 0.0), directionHint: .Up))
|
||||
|
||||
return (controllerState, (listState, arguments))
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user