mirror of
https://github.com/Swiftgram/Telegram-iOS.git
synced 2025-11-07 09:20:08 +00:00
Improve settings screen data loading
This commit is contained in:
parent
a38fb8b93f
commit
9500196d5b
@ -94,9 +94,9 @@ final class PeerInfoState {
|
|||||||
final class TelegramGlobalSettings {
|
final class TelegramGlobalSettings {
|
||||||
let suggestPhoneNumberConfirmation: Bool
|
let suggestPhoneNumberConfirmation: Bool
|
||||||
let accountsAndPeers: [(Account, Peer, Int32)]
|
let accountsAndPeers: [(Account, Peer, Int32)]
|
||||||
let activeSessionsContext: ActiveSessionsContext
|
let activeSessionsContext: ActiveSessionsContext?
|
||||||
let webSessionsContext: WebSessionsContext
|
let webSessionsContext: WebSessionsContext?
|
||||||
let otherSessionsCount: Int
|
let otherSessionsCount: Int?
|
||||||
let proxySettings: ProxySettings
|
let proxySettings: ProxySettings
|
||||||
let notificationAuthorizationStatus: AccessType
|
let notificationAuthorizationStatus: AccessType
|
||||||
let notificationWarningSuppressed: Bool
|
let notificationWarningSuppressed: Bool
|
||||||
@ -112,9 +112,9 @@ final class TelegramGlobalSettings {
|
|||||||
init(
|
init(
|
||||||
suggestPhoneNumberConfirmation: Bool,
|
suggestPhoneNumberConfirmation: Bool,
|
||||||
accountsAndPeers: [(Account, Peer, Int32)],
|
accountsAndPeers: [(Account, Peer, Int32)],
|
||||||
activeSessionsContext: ActiveSessionsContext,
|
activeSessionsContext: ActiveSessionsContext?,
|
||||||
webSessionsContext: WebSessionsContext,
|
webSessionsContext: WebSessionsContext?,
|
||||||
otherSessionsCount: Int,
|
otherSessionsCount: Int?,
|
||||||
proxySettings: ProxySettings,
|
proxySettings: ProxySettings,
|
||||||
notificationAuthorizationStatus: AccessType,
|
notificationAuthorizationStatus: AccessType,
|
||||||
notificationWarningSuppressed: Bool,
|
notificationWarningSuppressed: Bool,
|
||||||
@ -366,7 +366,7 @@ func keepPeerInfoScreenDataHot(context: AccountContext, peerId: PeerId) -> Signa
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func peerInfoScreenSettingsData(context: AccountContext, peerId: PeerId, accountsAndPeers: Signal<[(Account, Peer, Int32)], NoError>, activeSessionsContextAndCount: Signal<(ActiveSessionsContext, Int, WebSessionsContext), NoError>, notificationExceptions: Signal<NotificationExceptionsList?, NoError>, privacySettings: Signal<AccountPrivacySettings?, NoError>, archivedStickerPacks: Signal<[ArchivedStickerPackItem]?, NoError>, hasPassport: Signal<Bool, NoError>) -> Signal<PeerInfoScreenData, NoError> {
|
func peerInfoScreenSettingsData(context: AccountContext, peerId: PeerId, accountsAndPeers: Signal<[(Account, Peer, Int32)], NoError>, activeSessionsContextAndCount: Signal<(ActiveSessionsContext, Int, WebSessionsContext)?, NoError>, notificationExceptions: Signal<NotificationExceptionsList?, NoError>, privacySettings: Signal<AccountPrivacySettings?, NoError>, archivedStickerPacks: Signal<[ArchivedStickerPackItem]?, NoError>, hasPassport: Signal<Bool, NoError>) -> Signal<PeerInfoScreenData, NoError> {
|
||||||
let preferences = context.sharedContext.accountManager.sharedData(keys: [
|
let preferences = context.sharedContext.accountManager.sharedData(keys: [
|
||||||
SharedDataKeys.proxySettings,
|
SharedDataKeys.proxySettings,
|
||||||
ApplicationSpecificSharedDataKeys.inAppNotificationSettings,
|
ApplicationSpecificSharedDataKeys.inAppNotificationSettings,
|
||||||
@ -428,7 +428,7 @@ func peerInfoScreenSettingsData(context: AccountContext, peerId: PeerId, account
|
|||||||
enableQRLogin = true
|
enableQRLogin = true
|
||||||
}
|
}
|
||||||
|
|
||||||
let globalSettings = TelegramGlobalSettings(suggestPhoneNumberConfirmation: false, accountsAndPeers: accountsAndPeers, activeSessionsContext: accountSessions.0, webSessionsContext: accountSessions.2, otherSessionsCount: accountSessions.1, proxySettings: proxySettings, notificationAuthorizationStatus: notificationsAuthorizationStatus, notificationWarningSuppressed: notificationsWarningSuppressed, notificationExceptions: notificationExceptions, inAppNotificationSettings: inAppNotificationSettings, privacySettings: privacySettings, unreadTrendingStickerPacks: unreadTrendingStickerPacks, archivedStickerPacks: archivedStickerPacks, hasPassport: hasPassport, hasWatchApp: hasWatchApp, enableQRLogin: enableQRLogin)
|
let globalSettings = TelegramGlobalSettings(suggestPhoneNumberConfirmation: false, accountsAndPeers: accountsAndPeers, activeSessionsContext: accountSessions?.0, webSessionsContext: accountSessions?.2, otherSessionsCount: accountSessions?.1, proxySettings: proxySettings, notificationAuthorizationStatus: notificationsAuthorizationStatus, notificationWarningSuppressed: notificationsWarningSuppressed, notificationExceptions: notificationExceptions, inAppNotificationSettings: inAppNotificationSettings, privacySettings: privacySettings, unreadTrendingStickerPacks: unreadTrendingStickerPacks, archivedStickerPacks: archivedStickerPacks, hasPassport: hasPassport, hasWatchApp: hasWatchApp, enableQRLogin: enableQRLogin)
|
||||||
|
|
||||||
return PeerInfoScreenData(
|
return PeerInfoScreenData(
|
||||||
peer: peerView.peers[peerId],
|
peer: peerView.peers[peerId],
|
||||||
|
|||||||
@ -712,11 +712,11 @@ private func settingsItems(data: PeerInfoScreenData?, context: AccountContext, p
|
|||||||
}))
|
}))
|
||||||
|
|
||||||
let devicesLabel: String
|
let devicesLabel: String
|
||||||
if let settings = data.globalSettings {
|
if let settings = data.globalSettings, let otherSessionsCount = settings.otherSessionsCount {
|
||||||
if settings.enableQRLogin {
|
if settings.enableQRLogin {
|
||||||
devicesLabel = settings.otherSessionsCount == 0 ? presentationData.strings.Settings_AddDevice : "\(settings.otherSessionsCount + 1)"
|
devicesLabel = otherSessionsCount == 0 ? presentationData.strings.Settings_AddDevice : "\(otherSessionsCount + 1)"
|
||||||
} else {
|
} else {
|
||||||
devicesLabel = settings.otherSessionsCount == 0 ? "" : "\(settings.otherSessionsCount + 1)"
|
devicesLabel = otherSessionsCount == 0 ? "" : "\(otherSessionsCount + 1)"
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
devicesLabel = ""
|
devicesLabel = ""
|
||||||
@ -1392,7 +1392,7 @@ private final class PeerInfoScreenNode: ViewControllerTracingNode, UIScrollViewD
|
|||||||
private let preloadStickerDisposable = MetaDisposable()
|
private let preloadStickerDisposable = MetaDisposable()
|
||||||
|
|
||||||
fileprivate let accountsAndPeers = Promise<[(Account, Peer, Int32)]>()
|
fileprivate let accountsAndPeers = Promise<[(Account, Peer, Int32)]>()
|
||||||
private let activeSessionsContextAndCount = Promise<(ActiveSessionsContext, Int, WebSessionsContext)>()
|
fileprivate let activeSessionsContextAndCount = Promise<(ActiveSessionsContext, Int, WebSessionsContext)?>()
|
||||||
private let notificationExceptions = Promise<NotificationExceptionsList?>()
|
private let notificationExceptions = Promise<NotificationExceptionsList?>()
|
||||||
private let privacySettings = Promise<AccountPrivacySettings?>()
|
private let privacySettings = Promise<AccountPrivacySettings?>()
|
||||||
private let archivedPacks = Promise<[ArchivedStickerPackItem]?>()
|
private let archivedPacks = Promise<[ArchivedStickerPackItem]?>()
|
||||||
@ -2489,20 +2489,6 @@ private final class PeerInfoScreenNode: ViewControllerTracingNode, UIScrollViewD
|
|||||||
|
|
||||||
let screenData: Signal<PeerInfoScreenData, NoError>
|
let screenData: Signal<PeerInfoScreenData, NoError>
|
||||||
if self.isSettings {
|
if self.isSettings {
|
||||||
let activeSessionsContextAndCountSignal = deferred { () -> Signal<(ActiveSessionsContext, Int, WebSessionsContext), NoError> in
|
|
||||||
let activeSessionsContext = ActiveSessionsContext(account: context.account)
|
|
||||||
let webSessionsContext = WebSessionsContext(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, webSessionsContext)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
self.activeSessionsContextAndCount.set(activeSessionsContextAndCountSignal)
|
|
||||||
self.notificationExceptions.set(.single(NotificationExceptionsList(peers: [:], settings: [:]))
|
self.notificationExceptions.set(.single(NotificationExceptionsList(peers: [:], settings: [:]))
|
||||||
|> then(
|
|> then(
|
||||||
notificationExceptionsList(postbox: context.account.postbox, network: context.account.network)
|
notificationExceptionsList(postbox: context.account.postbox, network: context.account.network)
|
||||||
@ -4551,7 +4537,7 @@ private final class PeerInfoScreenNode: ViewControllerTracingNode, UIScrollViewD
|
|||||||
let _ = (self.activeSessionsContextAndCount.get()
|
let _ = (self.activeSessionsContextAndCount.get()
|
||||||
|> take(1)
|
|> take(1)
|
||||||
|> deliverOnMainQueue).start(next: { [weak self] activeSessionsContextAndCount in
|
|> deliverOnMainQueue).start(next: { [weak self] activeSessionsContextAndCount in
|
||||||
if let strongSelf = self {
|
if let strongSelf = self, let activeSessionsContextAndCount = activeSessionsContextAndCount {
|
||||||
let (activeSessionsContext, count, webSessionsContext) = activeSessionsContextAndCount
|
let (activeSessionsContext, count, webSessionsContext) = activeSessionsContextAndCount
|
||||||
if count == 0 && settings.enableQRLogin {
|
if count == 0 && settings.enableQRLogin {
|
||||||
strongSelf.controller?.push(AuthDataTransferSplashScreen(context: strongSelf.context, activeSessionsContext: activeSessionsContext))
|
strongSelf.controller?.push(AuthDataTransferSplashScreen(context: strongSelf.context, activeSessionsContext: activeSessionsContext))
|
||||||
@ -4902,7 +4888,7 @@ private final class PeerInfoScreenNode: ViewControllerTracingNode, UIScrollViewD
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}, exceptionsList: .single(settings.notificationExceptions), archivedStickerPacks: .single(settings.archivedStickerPacks), privacySettings: .single(settings.privacySettings), hasWallet: .single(false), activeSessionsContext: self.activeSessionsContextAndCount.get() |> map { $0.0 }, webSessionsContext: self.activeSessionsContextAndCount.get() |> map { $0.2 }), cancel: { [weak self] in
|
}, exceptionsList: .single(settings.notificationExceptions), archivedStickerPacks: .single(settings.archivedStickerPacks), privacySettings: .single(settings.privacySettings), hasWallet: .single(false), activeSessionsContext: self.activeSessionsContextAndCount.get() |> map { $0?.0 }, webSessionsContext: self.activeSessionsContextAndCount.get() |> map { $0?.2 }), cancel: { [weak self] in
|
||||||
self?.deactivateSearch()
|
self?.deactivateSearch()
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
@ -5519,6 +5505,8 @@ public final class PeerInfoScreen: ViewController {
|
|||||||
private var accountsAndPeersValue: ((Account, Peer)?, [(Account, Peer, Int32)])?
|
private var accountsAndPeersValue: ((Account, Peer)?, [(Account, Peer, Int32)])?
|
||||||
private var accountsAndPeersDisposable: Disposable?
|
private var accountsAndPeersDisposable: Disposable?
|
||||||
|
|
||||||
|
private let activeSessionsContextAndCount = Promise<(ActiveSessionsContext, Int, WebSessionsContext)?>(nil)
|
||||||
|
|
||||||
private var tabBarItemDisposable: Disposable?
|
private var tabBarItemDisposable: Disposable?
|
||||||
|
|
||||||
fileprivate var controllerNode: PeerInfoScreenNode {
|
fileprivate var controllerNode: PeerInfoScreenNode {
|
||||||
@ -5558,8 +5546,22 @@ public final class PeerInfoScreen: ViewController {
|
|||||||
), strings: baseNavigationBarPresentationData.strings))
|
), strings: baseNavigationBarPresentationData.strings))
|
||||||
|
|
||||||
if isSettings {
|
if isSettings {
|
||||||
self.accountsAndPeers.set(activeAccountsAndPeers(context: context))
|
let activeSessionsContextAndCountSignal = deferred { () -> Signal<(ActiveSessionsContext, Int, WebSessionsContext)?, NoError> in
|
||||||
|
let activeSessionsContext = ActiveSessionsContext(account: context.account)
|
||||||
|
let webSessionsContext = WebSessionsContext(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, webSessionsContext)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
self.activeSessionsContextAndCount.set(activeSessionsContextAndCountSignal)
|
||||||
|
|
||||||
|
self.accountsAndPeers.set(activeAccountsAndPeers(context: context))
|
||||||
self.accountsAndPeersDisposable = (self.accountsAndPeers.get()
|
self.accountsAndPeersDisposable = (self.accountsAndPeers.get()
|
||||||
|> deliverOnMainQueue).start(next: { [weak self] value in
|
|> deliverOnMainQueue).start(next: { [weak self] value in
|
||||||
self?.accountsAndPeersValue = value
|
self?.accountsAndPeersValue = value
|
||||||
@ -5784,6 +5786,7 @@ public final class PeerInfoScreen: ViewController {
|
|||||||
override public func loadDisplayNode() {
|
override public func loadDisplayNode() {
|
||||||
self.displayNode = PeerInfoScreenNode(controller: self, context: self.context, peerId: self.peerId, avatarInitiallyExpanded: self.avatarInitiallyExpanded, isOpenedFromChat: self.isOpenedFromChat, nearbyPeerDistance: self.nearbyPeerDistance, callMessages: self.callMessages, isSettings: self.isSettings, ignoreGroupInCommon: self.ignoreGroupInCommon)
|
self.displayNode = PeerInfoScreenNode(controller: self, context: self.context, peerId: self.peerId, avatarInitiallyExpanded: self.avatarInitiallyExpanded, isOpenedFromChat: self.isOpenedFromChat, nearbyPeerDistance: self.nearbyPeerDistance, callMessages: self.callMessages, isSettings: self.isSettings, ignoreGroupInCommon: self.ignoreGroupInCommon)
|
||||||
self.controllerNode.accountsAndPeers.set(self.accountsAndPeers.get() |> map { $0.1 })
|
self.controllerNode.accountsAndPeers.set(self.accountsAndPeers.get() |> map { $0.1 })
|
||||||
|
self.controllerNode.activeSessionsContextAndCount.set(self.activeSessionsContextAndCount.get())
|
||||||
self._ready.set(self.controllerNode.ready.get())
|
self._ready.set(self.controllerNode.ready.get())
|
||||||
|
|
||||||
super.displayNodeDidLoad()
|
super.displayNodeDidLoad()
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user