diff --git a/submodules/InviteLinksUI/Sources/InviteLinkEditController.swift b/submodules/InviteLinksUI/Sources/InviteLinkEditController.swift index f1f3721795..f573004bae 100644 --- a/submodules/InviteLinksUI/Sources/InviteLinkEditController.swift +++ b/submodules/InviteLinksUI/Sources/InviteLinkEditController.swift @@ -321,7 +321,7 @@ private struct InviteLinkEditControllerState: Equatable { var updating = false } -public func inviteLinkEditController(context: AccountContext, peerId: PeerId, invite: ExportedInvitation?, completion: ((ExportedInvitation?) -> Void)? = nil) -> ViewController { +public func inviteLinkEditController(context: AccountContext, updatedPresentationData: (initial: PresentationData, signal: Signal)? = nil, peerId: PeerId, invite: ExportedInvitation?, completion: ((ExportedInvitation?) -> Void)? = nil) -> ViewController { var presentControllerImpl: ((ViewController, ViewControllerPresentationArguments?) -> Void)? let actionsDisposable = DisposableSet() @@ -374,7 +374,7 @@ public func inviteLinkEditController(context: AccountContext, peerId: PeerId, in } else { isGroup = true } - let presentationData = context.sharedContext.currentPresentationData.with { $0 } + let presentationData = updatedPresentationData?.initial ?? context.sharedContext.currentPresentationData.with { $0 } let controller = ActionSheetController(presentationData: presentationData) let dismissAction: () -> Void = { [weak controller] in controller?.dismissAnimated() @@ -416,8 +416,10 @@ public func inviteLinkEditController(context: AccountContext, peerId: PeerId, in }) }) + let presentationData = updatedPresentationData?.signal ?? context.sharedContext.presentationData + let previousState = Atomic(value: nil) - let signal = combineLatest(context.sharedContext.presentationData, statePromise.get()) + let signal = combineLatest(presentationData, statePromise.get()) |> deliverOnMainQueue |> map { presentationData, state -> (ItemListControllerState, (ItemListNodeState, Any)) in let leftNavigationButton = ItemListNavigationButton(content: .text(presentationData.strings.Common_Cancel), style: .regular, enabled: true, action: { diff --git a/submodules/PeerInfoUI/Sources/ChannelAdminController.swift b/submodules/PeerInfoUI/Sources/ChannelAdminController.swift index 9f91716540..eb41b2e263 100644 --- a/submodules/PeerInfoUI/Sources/ChannelAdminController.swift +++ b/submodules/PeerInfoUI/Sources/ChannelAdminController.swift @@ -749,7 +749,7 @@ private func channelAdminControllerEntries(presentationData: PresentationData, s return entries } -public func channelAdminController(context: AccountContext, peerId: PeerId, adminId: PeerId, initialParticipant: ChannelParticipant?, updated: @escaping (TelegramChatAdminRights?) -> Void, upgradedToSupergroup: @escaping (PeerId, @escaping () -> Void) -> Void, transferedOwnership: @escaping (PeerId) -> Void) -> ViewController { +public func channelAdminController(context: AccountContext, updatedPresentationData: (initial: PresentationData, signal: Signal)? = nil, peerId: PeerId, adminId: PeerId, initialParticipant: ChannelParticipant?, updated: @escaping (TelegramChatAdminRights?) -> Void, upgradedToSupergroup: @escaping (PeerId, @escaping () -> Void) -> Void, transferedOwnership: @escaping (PeerId) -> Void) -> ViewController { let statePromise = ValuePromise(ChannelAdminControllerState(), ignoreRepeated: true) let stateValue = Atomic(value: ChannelAdminControllerState()) let updateState: ((ChannelAdminControllerState) -> ChannelAdminControllerState) -> Void = { f in @@ -883,7 +883,8 @@ public func channelAdminController(context: AccountContext, peerId: PeerId, admi let combinedView = context.account.postbox.combinedView(keys: [.peer(peerId: peerId, components: .all), .peer(peerId: adminId, components: .all)]) - let signal = combineLatest(context.sharedContext.presentationData, statePromise.get(), combinedView) + let presentationData = updatedPresentationData?.signal ?? context.sharedContext.presentationData + let signal = combineLatest(presentationData, statePromise.get(), combinedView) |> deliverOnMainQueue |> map { presentationData, state, combinedView -> (ItemListControllerState, (ItemListNodeState, Any)) in let channelView = combinedView.views[.peer(peerId: peerId, components: .all)] as! PeerView diff --git a/submodules/PeerInfoUI/Sources/ChannelAdminsController.swift b/submodules/PeerInfoUI/Sources/ChannelAdminsController.swift index 89c10d7ade..e8adf589a0 100644 --- a/submodules/PeerInfoUI/Sources/ChannelAdminsController.swift +++ b/submodules/PeerInfoUI/Sources/ChannelAdminsController.swift @@ -470,7 +470,7 @@ private func channelAdminsControllerEntries(presentationData: PresentationData, return entries } -public func channelAdminsController(context: AccountContext, peerId initialPeerId: PeerId, loadCompleted: @escaping () -> Void = {}) -> ViewController { +public func channelAdminsController(context: AccountContext, updatedPresentationData: (initial: PresentationData, signal: Signal)? = nil, peerId initialPeerId: PeerId, loadCompleted: @escaping () -> Void = {}) -> ViewController { let statePromise = ValuePromise(ChannelAdminsControllerState(), ignoreRepeated: true) let stateValue = Atomic(value: ChannelAdminsControllerState()) let updateState: ((ChannelAdminsControllerState) -> ChannelAdminsControllerState) -> Void = { f in @@ -493,9 +493,7 @@ public func channelAdminsController(context: AccountContext, peerId initialPeerI actionsDisposable.add(upgradeDisposable) let adminsPromise = Promise<[RenderedChannelParticipant]?>(nil) - - let presentationDataSignal = context.sharedContext.presentationData - + var upgradedToSupergroupImpl: ((PeerId, @escaping () -> Void) -> Void)? let currentPeerId = ValuePromise(initialPeerId) @@ -608,7 +606,7 @@ public func channelAdminsController(context: AccountContext, peerId initialPeerI } } } - pushControllerImpl?(channelAdminController(context: context, peerId: peerId, adminId: peer.id, initialParticipant: participant?.participant, updated: { _ in + pushControllerImpl?(channelAdminController(context: context, updatedPresentationData: updatedPresentationData, peerId: peerId, adminId: peer.id, initialParticipant: participant?.participant, updated: { _ in }, upgradedToSupergroup: upgradedToSupergroup, transferedOwnership: transferedOwnership)) }) dismissController = { [weak controller] in @@ -624,7 +622,7 @@ public func channelAdminsController(context: AccountContext, peerId initialPeerI let _ = (currentPeerId.get() |> take(1) |> deliverOnMainQueue).start(next: { peerId in - pushControllerImpl?(channelAdminController(context: context, peerId: peerId, adminId: participant.peerId, initialParticipant: participant, updated: { _ in + pushControllerImpl?(channelAdminController(context: context, updatedPresentationData: updatedPresentationData, peerId: peerId, adminId: participant.peerId, initialParticipant: participant, updated: { _ in }, upgradedToSupergroup: upgradedToSupergroup, transferedOwnership: transferedOwnership)) }) }) @@ -700,7 +698,8 @@ public func channelAdminsController(context: AccountContext, peerId initialPeerI var previousPeers: [RenderedChannelParticipant]? - let signal = combineLatest(queue: .mainQueue(), presentationDataSignal, statePromise.get(), peerView.get(), adminsPromise.get() |> deliverOnMainQueue) + let presentationData = updatedPresentationData?.signal ?? context.sharedContext.presentationData + let signal = combineLatest(queue: .mainQueue(), presentationData, statePromise.get(), peerView.get(), adminsPromise.get() |> deliverOnMainQueue) |> deliverOnMainQueue |> map { presentationData, state, view, admins -> (ItemListControllerState, (ItemListNodeState, Any)) in let peerId = view.peerId @@ -757,7 +756,7 @@ public func channelAdminsController(context: AccountContext, peerId initialPeerI } }, openPeer: { _, participant in if let participant = participant?.participant, case .member = participant { - pushControllerImpl?(channelAdminController(context: context, peerId: peerId, adminId: participant.peerId, initialParticipant: participant, updated: { _ in + pushControllerImpl?(channelAdminController(context: context, updatedPresentationData: updatedPresentationData, peerId: peerId, adminId: participant.peerId, initialParticipant: participant, updated: { _ in updateState { state in return state.withUpdatedSearchingMembers(false) } diff --git a/submodules/PeerInfoUI/Sources/ChannelBannedMemberController.swift b/submodules/PeerInfoUI/Sources/ChannelBannedMemberController.swift index 116be51446..37c3bd6043 100644 --- a/submodules/PeerInfoUI/Sources/ChannelBannedMemberController.swift +++ b/submodules/PeerInfoUI/Sources/ChannelBannedMemberController.swift @@ -354,7 +354,7 @@ private func channelBannedMemberControllerEntries(presentationData: Presentation return entries } -public func channelBannedMemberController(context: AccountContext, peerId: PeerId, memberId: PeerId, initialParticipant: ChannelParticipant?, updated: @escaping (TelegramChatBannedRights?) -> Void, upgradedToSupergroup: @escaping (PeerId, @escaping () -> Void) -> Void) -> ViewController { +public func channelBannedMemberController(context: AccountContext, updatedPresentationData: (initial: PresentationData, signal: Signal)? = nil, peerId: PeerId, memberId: PeerId, initialParticipant: ChannelParticipant?, updated: @escaping (TelegramChatBannedRights?) -> Void, upgradedToSupergroup: @escaping (PeerId, @escaping () -> Void) -> Void) -> ViewController { let initialState = ChannelBannedMemberControllerState(referenceTimestamp: Int32(Date().timeIntervalSince1970), updatedFlags: nil, updatedTimeout: nil, updating: false) let statePromise = ValuePromise(initialState, ignoreRepeated: true) let stateValue = Atomic(value: initialState) @@ -426,7 +426,7 @@ public func channelBannedMemberController(context: AccountContext, peerId: PeerI guard let defaultBannedRights = channel.defaultBannedRights else { return } - let presentationData = context.sharedContext.currentPresentationData.with { $0 } + let presentationData = updatedPresentationData?.initial ?? context.sharedContext.currentPresentationData.with { $0 } let text: String if channel.hasPermission(.banMembers) { if defaultBannedRights.flags.contains(right) { @@ -440,7 +440,7 @@ public func channelBannedMemberController(context: AccountContext, peerId: PeerI presentControllerImpl?(textAlertController(context: context, title: nil, text: text, actions: [TextAlertAction(type: .defaultAction, title: presentationData.strings.Common_OK, action: {})]), nil) }) }, openTimeout: { - let presentationData = context.sharedContext.currentPresentationData.with { $0 } + let presentationData = updatedPresentationData?.initial ?? context.sharedContext.currentPresentationData.with { $0 } let actionSheet = ActionSheetController(presentationData: presentationData) let intervals: [Int32] = [ 1 * 60 * 60 * 24, @@ -478,7 +478,7 @@ public func channelBannedMemberController(context: AccountContext, peerId: PeerI ])]) presentControllerImpl?(actionSheet, nil) }, delete: { - let presentationData = context.sharedContext.currentPresentationData.with { $0 } + let presentationData = updatedPresentationData?.initial ?? context.sharedContext.currentPresentationData.with { $0 } let actionSheet = ActionSheetController(presentationData: presentationData) var items: [ActionSheetItem] = [] items.append(ActionSheetButtonItem(title: presentationData.strings.GroupPermission_Delete, color: .destructive, font: .default, enabled: true, action: { [weak actionSheet] in @@ -512,7 +512,8 @@ public func channelBannedMemberController(context: AccountContext, peerId: PeerI let canEdit = true - let signal = combineLatest(context.sharedContext.presentationData, statePromise.get(), combinedView) + let presentationData = updatedPresentationData?.signal ?? context.sharedContext.presentationData + let signal = combineLatest(presentationData, statePromise.get(), combinedView) |> deliverOnMainQueue |> map { presentationData, state, combinedView -> (ItemListControllerState, (ItemListNodeState, Any)) in let channelView = combinedView.views[.peer(peerId: peerId, components: .all)] as! PeerView @@ -682,7 +683,7 @@ public func channelBannedMemberController(context: AccountContext, peerId: PeerI }, completed: { if previousRights == nil { - let presentationData = context.sharedContext.currentPresentationData.with { $0 } + let presentationData = updatedPresentationData?.initial ?? context.sharedContext.currentPresentationData.with { $0 } presentControllerImpl?(OverlayStatusController(theme: presentationData.theme, type: .genericSuccess(presentationData.strings.GroupPermission_AddSuccess, false)), nil) } updated(cleanResolvedRights.flags.isEmpty ? nil : cleanResolvedRights) @@ -691,7 +692,7 @@ public func channelBannedMemberController(context: AccountContext, peerId: PeerI } } - let presentationData = context.sharedContext.currentPresentationData.with { $0 } + let presentationData = updatedPresentationData?.initial ?? context.sharedContext.currentPresentationData.with { $0 } let actionSheet = ActionSheetController(presentationData: presentationData) var items: [ActionSheetItem] = [] items.append(ActionSheetTextItem(title: presentationData.strings.GroupPermission_ApplyAlertText(peer.displayTitle(strings: presentationData.strings, displayOrder: presentationData.nameDisplayOrder)).string)) diff --git a/submodules/PeerInfoUI/Sources/ChannelBlacklistController.swift b/submodules/PeerInfoUI/Sources/ChannelBlacklistController.swift index 6553aa7e38..abd6cafa6f 100644 --- a/submodules/PeerInfoUI/Sources/ChannelBlacklistController.swift +++ b/submodules/PeerInfoUI/Sources/ChannelBlacklistController.swift @@ -267,7 +267,7 @@ private func channelBlacklistControllerEntries(presentationData: PresentationDat return entries } -public func channelBlacklistController(context: AccountContext, peerId: PeerId) -> ViewController { +public func channelBlacklistController(context: AccountContext, updatedPresentationData: (initial: PresentationData, signal: Signal)? = nil, peerId: PeerId) -> ViewController { let statePromise = ValuePromise(ChannelBlacklistControllerState(referenceTimestamp: Int32(Date().timeIntervalSince1970)), ignoreRepeated: true) let stateValue = Atomic(value: ChannelBlacklistControllerState(referenceTimestamp: Int32(Date().timeIntervalSince1970))) let updateState: ((ChannelBlacklistControllerState) -> ChannelBlacklistControllerState) -> Void = { f in @@ -435,7 +435,8 @@ public func channelBlacklistController(context: AccountContext, peerId: PeerId) let previousParticipantsValue = Atomic<[RenderedChannelParticipant]?>(value: nil) - let signal = combineLatest(queue: .mainQueue(), context.sharedContext.presentationData, statePromise.get(), peerView.get(), blacklistPromise.get()) + let presentationData = updatedPresentationData?.signal ?? context.sharedContext.presentationData + let signal = combineLatest(queue: .mainQueue(), presentationData, statePromise.get(), peerView.get(), blacklistPromise.get()) |> deliverOnMainQueue |> map { presentationData, state, view, participants -> (ItemListControllerState, (ItemListNodeState, Any)) in var rightNavigationButton: ItemListNavigationButton? diff --git a/submodules/PeerInfoUI/Sources/ChannelMembersController.swift b/submodules/PeerInfoUI/Sources/ChannelMembersController.swift index 80e3223a69..f229ff8077 100644 --- a/submodules/PeerInfoUI/Sources/ChannelMembersController.swift +++ b/submodules/PeerInfoUI/Sources/ChannelMembersController.swift @@ -291,7 +291,7 @@ private func channelMembersControllerEntries(context: AccountContext, presentati return entries } -public func channelMembersController(context: AccountContext, peerId: PeerId) -> ViewController { +public func channelMembersController(context: AccountContext, updatedPresentationData: (initial: PresentationData, signal: Signal)? = nil, peerId: PeerId) -> ViewController { let statePromise = ValuePromise(ChannelMembersControllerState(), ignoreRepeated: true) let stateValue = Atomic(value: ChannelMembersControllerState()) let updateState: ((ChannelMembersControllerState) -> ChannelMembersControllerState) -> Void = { f in @@ -442,7 +442,8 @@ public func channelMembersController(context: AccountContext, peerId: PeerId) -> var previousPeers: [RenderedChannelParticipant]? - let signal = combineLatest(queue: .mainQueue(), context.sharedContext.presentationData, statePromise.get(), peerView, peersPromise.get()) + let presentationData = updatedPresentationData?.signal ?? context.sharedContext.presentationData + let signal = combineLatest(queue: .mainQueue(), presentationData, statePromise.get(), peerView, peersPromise.get()) |> deliverOnMainQueue |> map { presentationData, state, view, peers -> (ItemListControllerState, (ItemListNodeState, Any)) in var isGroup = true diff --git a/submodules/PeerInfoUI/Sources/ChannelPermissionsController.swift b/submodules/PeerInfoUI/Sources/ChannelPermissionsController.swift index bd4c0927be..c228cabe52 100644 --- a/submodules/PeerInfoUI/Sources/ChannelPermissionsController.swift +++ b/submodules/PeerInfoUI/Sources/ChannelPermissionsController.swift @@ -494,7 +494,7 @@ private func channelPermissionsControllerEntries(context: AccountContext, presen return entries } -public func channelPermissionsController(context: AccountContext, peerId originalPeerId: PeerId, loadCompleted: @escaping () -> Void = {}) -> ViewController { +public func channelPermissionsController(context: AccountContext, updatedPresentationData: (initial: PresentationData, signal: Signal)? = nil, peerId originalPeerId: PeerId, loadCompleted: @escaping () -> Void = {}) -> ViewController { let statePromise = ValuePromise(ChannelPermissionsControllerState(), ignoreRepeated: true) let stateValue = Atomic(value: ChannelPermissionsControllerState()) let updateState: ((ChannelPermissionsControllerState) -> ChannelPermissionsControllerState) -> Void = { f in @@ -643,7 +643,7 @@ public func channelPermissionsController(context: AccountContext, peerId origina var dismissController: (() -> Void)? let controller = ChannelMembersSearchController(context: context, peerId: peerId, mode: .ban, openPeer: { peer, participant in if let participant = participant { - let presentationData = context.sharedContext.currentPresentationData.with { $0 } + let presentationData = updatedPresentationData?.initial ?? context.sharedContext.currentPresentationData.with { $0 } switch participant.participant { case .creator: return @@ -717,7 +717,7 @@ public func channelPermissionsController(context: AccountContext, peerId origina for (listRight, permission) in allGroupPermissionList { if listRight == right { let text: String - let presentationData = context.sharedContext.currentPresentationData.with { $0 } + let presentationData = updatedPresentationData?.initial ?? context.sharedContext.currentPresentationData.with { $0 } if !channel.hasPermission(permission) { text = presentationData.strings.GroupInfo_Permissions_EditingDisabled } else if right.contains(.banAddMembers) { @@ -731,7 +731,7 @@ public func channelPermissionsController(context: AccountContext, peerId origina } }) }, presentConversionToBroadcastGroup: { - let presentationData = context.sharedContext.currentPresentationData.with { $0 } + let presentationData = updatedPresentationData?.initial ?? context.sharedContext.currentPresentationData.with { $0 } let controller = PermissionController(context: context, splashScreen: true) controller.navigationPresentation = .modal controller.setState(.custom(icon: .animation("BroadcastGroup"), title: presentationData.strings.BroadcastGroups_IntroTitle, subtitle: nil, text: presentationData.strings.BroadcastGroups_IntroText, buttonTitle: presentationData.strings.BroadcastGroups_Convert, secondaryButtonTitle: presentationData.strings.BroadcastGroups_Cancel, footerText: nil), animated: false) @@ -787,7 +787,7 @@ public func channelPermissionsController(context: AccountContext, peerId origina return } - let presentationData = context.sharedContext.currentPresentationData.with { $0 } + let presentationData = updatedPresentationData?.initial ?? context.sharedContext.currentPresentationData.with { $0 } let progress = OverlayStatusController(theme: presentationData.theme, type: .loading(cancelled: nil)) presentControllerImpl?(progress, nil) @@ -855,7 +855,8 @@ public func channelPermissionsController(context: AccountContext, peerId origina return .single((view, peers.1)) } - let signal = combineLatest(queue: .mainQueue(), context.sharedContext.presentationData, statePromise.get(), viewAndParticipants) + let presentationData = updatedPresentationData?.signal ?? context.sharedContext.presentationData + let signal = combineLatest(queue: .mainQueue(), presentationData, statePromise.get(), viewAndParticipants) |> deliverOnMainQueue |> map { presentationData, state, viewAndParticipants -> (ItemListControllerState, (ItemListNodeState, Any)) in let (view, participants) = viewAndParticipants diff --git a/submodules/PeerInfoUI/Sources/GroupPreHistorySetupController.swift b/submodules/PeerInfoUI/Sources/GroupPreHistorySetupController.swift index 2efe6d5472..6b49dc70d3 100644 --- a/submodules/PeerInfoUI/Sources/GroupPreHistorySetupController.swift +++ b/submodules/PeerInfoUI/Sources/GroupPreHistorySetupController.swift @@ -116,7 +116,7 @@ private func groupPreHistorySetupEntries(isSupergroup: Bool, presentationData: P return entries } -public func groupPreHistorySetupController(context: AccountContext, peerId: PeerId, upgradedToSupergroup: @escaping (PeerId, @escaping () -> Void) -> Void) -> ViewController { +public func groupPreHistorySetupController(context: AccountContext, updatedPresentationData: (initial: PresentationData, signal: Signal)? = nil, peerId: PeerId, upgradedToSupergroup: @escaping (PeerId, @escaping () -> Void) -> Void) -> ViewController { let statePromise = ValuePromise(GroupPreHistorySetupState(), ignoreRepeated: true) let stateValue = Atomic(value: GroupPreHistorySetupState()) let updateState: ((GroupPreHistorySetupState) -> GroupPreHistorySetupState) -> Void = { f in @@ -139,7 +139,8 @@ public func groupPreHistorySetupController(context: AccountContext, peerId: Peer } }) - let signal = combineLatest(context.sharedContext.presentationData, statePromise.get(), context.account.viewTracker.peerView(peerId)) + let presentationData = updatedPresentationData?.signal ?? context.sharedContext.presentationData + let signal = combineLatest(presentationData, statePromise.get(), context.account.viewTracker.peerView(peerId)) |> deliverOnMainQueue |> map { presentationData, state, view -> (ItemListControllerState, (ItemListNodeState, Any)) in let defaultValue: Bool = (view.cachedData as? CachedChannelData)?.flags.contains(.preHistoryEnabled) ?? false diff --git a/submodules/PeerInfoUI/Sources/GroupStickerPackSetupController.swift b/submodules/PeerInfoUI/Sources/GroupStickerPackSetupController.swift index 7dc0927e21..b36bc4f35a 100644 --- a/submodules/PeerInfoUI/Sources/GroupStickerPackSetupController.swift +++ b/submodules/PeerInfoUI/Sources/GroupStickerPackSetupController.swift @@ -300,7 +300,7 @@ private func groupStickerPackSetupControllerEntries(presentationData: Presentati return entries } -public func groupStickerPackSetupController(context: AccountContext, peerId: PeerId, currentPackInfo: StickerPackCollectionInfo?) -> ViewController { +public func groupStickerPackSetupController(context: AccountContext, updatedPresentationData: (initial: PresentationData, signal: Signal)? = nil, peerId: PeerId, currentPackInfo: StickerPackCollectionInfo?) -> ViewController { let initialState = GroupStickerPackSetupControllerState(isSaving: false) let statePromise = ValuePromise(initialState, ignoreRepeated: true) @@ -402,7 +402,8 @@ public func groupStickerPackSetupController(context: AccountContext, peerId: Pee let previousHadData = Atomic(value: false) - let signal = combineLatest(context.sharedContext.presentationData, statePromise.get() |> deliverOnMainQueue, initialData.get() |> deliverOnMainQueue, stickerPacks.get() |> deliverOnMainQueue, searchState.get() |> deliverOnMainQueue, context.sharedContext.accountManager.sharedData(keys: [ApplicationSpecificSharedDataKeys.stickerSettings]) |> deliverOnMainQueue) + let presentationData = updatedPresentationData?.signal ?? context.sharedContext.presentationData + let signal = combineLatest(presentationData, statePromise.get() |> deliverOnMainQueue, initialData.get() |> deliverOnMainQueue, stickerPacks.get() |> deliverOnMainQueue, searchState.get() |> deliverOnMainQueue, context.sharedContext.accountManager.sharedData(keys: [ApplicationSpecificSharedDataKeys.stickerSettings]) |> deliverOnMainQueue) |> map { presentationData, state, initialData, view, searchState, sharedData -> (ItemListControllerState, (ItemListNodeState, Any)) in var stickerSettings = StickerSettings.defaultSettings if let value = sharedData.entries[ApplicationSpecificSharedDataKeys.stickerSettings] as? StickerSettings { diff --git a/submodules/PeerInfoUI/Sources/PeerAutoremoveSetupScreen.swift b/submodules/PeerInfoUI/Sources/PeerAutoremoveSetupScreen.swift index 7f08935a61..ae304b1de4 100644 --- a/submodules/PeerInfoUI/Sources/PeerAutoremoveSetupScreen.swift +++ b/submodules/PeerInfoUI/Sources/PeerAutoremoveSetupScreen.swift @@ -143,7 +143,7 @@ public enum PeerAutoremoveSetupScreenResult { case updated(Updated) } -public func peerAutoremoveSetupScreen(context: AccountContext, peerId: PeerId, completion: @escaping (PeerAutoremoveSetupScreenResult) -> Void = { _ in }) -> ViewController { +public func peerAutoremoveSetupScreen(context: AccountContext, updatedPresentationData: (initial: PresentationData, signal: Signal)? = nil, peerId: PeerId, completion: @escaping (PeerAutoremoveSetupScreenResult) -> Void = { _ in }) -> ViewController { let statePromise = ValuePromise(PeerAutoremoveSetupState(), ignoreRepeated: true) let stateValue = Atomic(value: PeerAutoremoveSetupState()) let updateState: ((PeerAutoremoveSetupState) -> PeerAutoremoveSetupState) -> Void = { f in @@ -165,7 +165,8 @@ public func peerAutoremoveSetupScreen(context: AccountContext, peerId: PeerId, c } }) - let signal = combineLatest(context.sharedContext.presentationData, statePromise.get(), context.account.viewTracker.peerView(peerId)) + let presentationData = updatedPresentationData?.signal ?? context.sharedContext.presentationData + let signal = combineLatest(presentationData, statePromise.get(), context.account.viewTracker.peerView(peerId)) |> deliverOnMainQueue |> map { presentationData, state, view -> (ItemListControllerState, (ItemListNodeState, Any)) in var defaultValue: Int32 = Int32.max diff --git a/submodules/StatisticsUI/Sources/ChannelStatsController.swift b/submodules/StatisticsUI/Sources/ChannelStatsController.swift index beea2c2d31..26e31fadeb 100644 --- a/submodules/StatisticsUI/Sources/ChannelStatsController.swift +++ b/submodules/StatisticsUI/Sources/ChannelStatsController.swift @@ -410,7 +410,7 @@ private func channelStatsControllerEntries(data: ChannelStats?, messages: [Messa return entries } -public func channelStatsController(context: AccountContext, peerId: PeerId, cachedPeerData: CachedPeerData) -> ViewController { +public func channelStatsController(context: AccountContext, updatedPresentationData: (initial: PresentationData, signal: Signal)? = nil, peerId: PeerId, cachedPeerData: CachedPeerData) -> ViewController { var openMessageStatsImpl: ((MessageId) -> Void)? var contextActionImpl: ((MessageId, ASDisplayNode, ContextGesture?) -> Void)? @@ -460,7 +460,8 @@ public func channelStatsController(context: AccountContext, peerId: PeerId, cach let previousData = Atomic(value: nil) - let signal = combineLatest(context.sharedContext.presentationData, dataPromise.get(), messagesPromise.get(), longLoadingSignal) + let presentationData = updatedPresentationData?.signal ?? context.sharedContext.presentationData + let signal = combineLatest(presentationData, dataPromise.get(), messagesPromise.get(), longLoadingSignal) |> deliverOnMainQueue |> map { presentationData, data, messageView, longLoading -> (ItemListControllerState, (ItemListNodeState, Any)) in let previous = previousData.swap(data) diff --git a/submodules/StatisticsUI/Sources/GroupStatsController.swift b/submodules/StatisticsUI/Sources/GroupStatsController.swift index a48923e077..22251f924f 100644 --- a/submodules/StatisticsUI/Sources/GroupStatsController.swift +++ b/submodules/StatisticsUI/Sources/GroupStatsController.swift @@ -708,7 +708,7 @@ private func canEditAdminRights(accountPeerId: PeerId, channelPeer: Peer, initia } } -public func groupStatsController(context: AccountContext, peerId: PeerId, cachedPeerData: CachedPeerData) -> ViewController { +public func groupStatsController(context: AccountContext, updatedPresentationData: (initial: PresentationData, signal: Signal)? = nil, peerId: PeerId, cachedPeerData: CachedPeerData) -> ViewController { let statePromise = ValuePromise(GroupStatsState()) let stateValue = Atomic(value: GroupStatsState()) let updateState: ((GroupStatsState) -> GroupStatsState) -> Void = { f in @@ -833,8 +833,8 @@ public func groupStatsController(context: AccountContext, peerId: PeerId, cached let previousData = Atomic(value: nil) - - let signal = combineLatest(statePromise.get(), context.sharedContext.presentationData, dataPromise.get(), context.account.postbox.loadedPeerWithId(peerId), peersPromise.get(), longLoadingSignal) + let presentationData = updatedPresentationData?.signal ?? context.sharedContext.presentationData + let signal = combineLatest(statePromise.get(), presentationData, dataPromise.get(), context.account.postbox.loadedPeerWithId(peerId), peersPromise.get(), longLoadingSignal) |> deliverOnMainQueue |> map { state, presentationData, data, channelPeer, peers, longLoading -> (ItemListControllerState, (ItemListNodeState, Any)) in let previous = previousData.swap(data) diff --git a/submodules/TelegramCallsUI/Sources/VoiceChatController.swift b/submodules/TelegramCallsUI/Sources/VoiceChatController.swift index 022c0d24ef..f179275c4e 100644 --- a/submodules/TelegramCallsUI/Sources/VoiceChatController.swift +++ b/submodules/TelegramCallsUI/Sources/VoiceChatController.swift @@ -2647,40 +2647,40 @@ public final class VoiceChatController: ViewController { return } -// let controller = VoiceChatRecordingSetupController(context: strongSelf.context, completion: { [weak self] videoOrientation in -// if let strongSelf = self { -// strongSelf.call.setShouldBeRecording(true, title: "", videoOrientation: videoOrientation) -// -// strongSelf.presentUndoOverlay(content: .voiceChatRecording(text: text), action: { _ in return false }) -// strongSelf.call.playTone(.recordingStarted) -// } -// }) - - let title: String - let text: String - if let channel = strongSelf.peer as? TelegramChannel, case .broadcast = channel.info { - title = strongSelf.presentationData.strings.LiveStream_StartRecordingTitle - text = strongSelf.presentationData.strings.LiveStream_StartRecordingText - } else { - title = strongSelf.presentationData.strings.VoiceChat_StartRecordingTitle - text = strongSelf.presentationData.strings.VoiceChat_StartRecordingText - } - - let controller = voiceChatTitleEditController(sharedContext: strongSelf.context.sharedContext, account: strongSelf.context.account, forceTheme: strongSelf.darkTheme, title: title, text: text, placeholder: strongSelf.presentationData.strings.VoiceChat_RecordingTitlePlaceholder, value: nil, maxLength: 40, apply: { title in - if let strongSelf = self, let title = title { - strongSelf.call.setShouldBeRecording(true, title: title, videoOrientation: nil) - - let text: String - if let channel = strongSelf.peer as? TelegramChannel, case .broadcast = channel.info { - text = strongSelf.presentationData.strings.LiveStream_RecordingStarted - } else { - text = strongSelf.presentationData.strings.VoiceChat_RecordingStarted - } + let controller = VoiceChatRecordingSetupController(context: strongSelf.context, completion: { [weak self] videoOrientation in + if let strongSelf = self { + strongSelf.call.setShouldBeRecording(true, title: "", videoOrientation: videoOrientation) strongSelf.presentUndoOverlay(content: .voiceChatRecording(text: text), action: { _ in return false }) strongSelf.call.playTone(.recordingStarted) } }) + +// let title: String +// let text: String +// if let channel = strongSelf.peer as? TelegramChannel, case .broadcast = channel.info { +// title = strongSelf.presentationData.strings.LiveStream_StartRecordingTitle +// text = strongSelf.presentationData.strings.LiveStream_StartRecordingText +// } else { +// title = strongSelf.presentationData.strings.VoiceChat_StartRecordingTitle +// text = strongSelf.presentationData.strings.VoiceChat_StartRecordingText +// } +// +// let controller = voiceChatTitleEditController(sharedContext: strongSelf.context.sharedContext, account: strongSelf.context.account, forceTheme: strongSelf.darkTheme, title: title, text: text, placeholder: strongSelf.presentationData.strings.VoiceChat_RecordingTitlePlaceholder, value: nil, maxLength: 40, apply: { title in +// if let strongSelf = self, let title = title { +// strongSelf.call.setShouldBeRecording(true, title: title, videoOrientation: nil) +// +// let text: String +// if let channel = strongSelf.peer as? TelegramChannel, case .broadcast = channel.info { +// text = strongSelf.presentationData.strings.LiveStream_RecordingStarted +// } else { +// text = strongSelf.presentationData.strings.VoiceChat_RecordingStarted +// } +// +// strongSelf.presentUndoOverlay(content: .voiceChatRecording(text: text), action: { _ in return false }) +// strongSelf.call.playTone(.recordingStarted) +// } +// }) self?.controller?.present(controller, in: .window(.root)) }))) } diff --git a/submodules/TelegramPresentationData/Sources/MakePresentationTheme.swift b/submodules/TelegramPresentationData/Sources/MakePresentationTheme.swift index 3f50a3f3ec..68cf8a31a7 100644 --- a/submodules/TelegramPresentationData/Sources/MakePresentationTheme.swift +++ b/submodules/TelegramPresentationData/Sources/MakePresentationTheme.swift @@ -35,8 +35,8 @@ public func customizePresentationTheme(_ theme: PresentationTheme, specialMode: public func makePresentationTheme(settings: TelegramThemeSettings, specialMode: Bool = false, title: String? = nil, serviceBackgroundColor: UIColor? = nil) -> PresentationTheme? { var baseTheme: TelegramBaseTheme = settings.baseTheme - if specialMode && baseTheme == .night { - baseTheme = .tinted + if specialMode && baseTheme == .tinted { + baseTheme = .night } let defaultTheme = makeDefaultPresentationTheme(reference: PresentationBuiltinThemeReference(baseTheme: baseTheme), extendingThemeReference: nil, serviceBackgroundColor: serviceBackgroundColor, preview: false) return customizePresentationTheme(defaultTheme, specialMode: specialMode, editing: true, title: title, accentColor: UIColor(argb: settings.accentColor), backgroundColors: [], bubbleColors: settings.messageColors, animateBubbleColors: settings.animateMessageColors, wallpaper: settings.wallpaper) diff --git a/submodules/TelegramUI/Sources/ChatController.swift b/submodules/TelegramUI/Sources/ChatController.swift index bba2c26553..4dee00c336 100644 --- a/submodules/TelegramUI/Sources/ChatController.swift +++ b/submodules/TelegramUI/Sources/ChatController.swift @@ -357,12 +357,12 @@ public final class ChatControllerImpl: TelegramBaseController, ChatController, G private var themeEmoticonPreviewPromise = ValuePromise(nil) private var themeDarkAppearancePreviewPromise = ValuePromise(nil) private var didSetPresentationData = false - private var presentationDataPromise = Promise() private var presentationData: PresentationData - private var presentationDataDisposable: Disposable? + private var presentationDataPromise = Promise() override public var updatedPresentationData: (PresentationData, Signal) { return (self.presentationData, self.presentationDataPromise.get()) } + private var presentationDataDisposable: Disposable? private var automaticMediaDownloadSettings: MediaAutoDownloadSettings private var automaticMediaDownloadSettingsDisposable: Disposable? @@ -2956,9 +2956,9 @@ public final class ChatControllerImpl: TelegramBaseController, ChatController, G let statsController: ViewController if let channel = peer as? TelegramChannel, case .group = channel.info { - statsController = groupStatsController(context: context, peerId: peer.id, cachedPeerData: cachedData) + statsController = groupStatsController(context: context, updatedPresentationData: strongSelf.updatedPresentationData, peerId: peer.id, cachedPeerData: cachedData) } else { - statsController = channelStatsController(context: context, peerId: peer.id, cachedPeerData: cachedData) + statsController = channelStatsController(context: context, updatedPresentationData: strongSelf.updatedPresentationData, peerId: peer.id, cachedPeerData: cachedData) } strongSelf.push(statsController) }))) @@ -3898,7 +3898,7 @@ public final class ChatControllerImpl: TelegramBaseController, ChatController, G } let accountManager = context.sharedContext.accountManager - self.presentationDataDisposable = combineLatest(queue: Queue.mainQueue(), context.sharedContext.presentationData, themeSettings, context.engine.themes.getChatThemes(accountManager: accountManager, onlyCached: false), themeEmoticon, self.themeEmoticonPreviewPromise.get(), self.themeDarkAppearancePreviewPromise.get()).start(next: { [weak self] presentationData, themeSettings, chatThemes, themeEmoticon, themeEmoticonPreview, darkAppearancePreview in + self.presentationDataDisposable = combineLatest(queue: Queue.mainQueue(), context.sharedContext.presentationData, themeSettings, context.engine.themes.getChatThemes(accountManager: accountManager, onlyCached: true), themeEmoticon, self.themeEmoticonPreviewPromise.get(), self.themeDarkAppearancePreviewPromise.get()).start(next: { [weak self] presentationData, themeSettings, chatThemes, themeEmoticon, themeEmoticonPreview, darkAppearancePreview in if let strongSelf = self { let previousTheme = strongSelf.presentationData.theme let previousStrings = strongSelf.presentationData.strings @@ -3915,11 +3915,11 @@ public final class ChatControllerImpl: TelegramBaseController, ChatController, G var presentationData = presentationData if let themeEmoticon = themeEmoticon, let theme = chatThemes.first(where: { $0.emoji == themeEmoticon }) { - var isDarkAppearance = presentationData.theme.overallDarkAppearance + var useDarkAppearance = presentationData.autoNightModeTriggered if let darkAppearancePreview = darkAppearancePreview { - isDarkAppearance = darkAppearancePreview + useDarkAppearance = darkAppearancePreview } - let customTheme = isDarkAppearance ? theme.darkTheme : theme.theme + let customTheme = useDarkAppearance ? theme.darkTheme : theme.theme if let settings = customTheme.settings, let theme = makePresentationTheme(settings: settings, specialMode: true) { presentationData = presentationData.withUpdated(theme: theme) presentationData = presentationData.withUpdated(chatWallpaper: theme.chat.defaultWallpaper) @@ -13282,7 +13282,7 @@ public final class ChatControllerImpl: TelegramBaseController, ChatController, G return } - let controller = peerAutoremoveSetupScreen(context: self.context, peerId: peer.id, completion: { [weak self] updatedValue in + let controller = peerAutoremoveSetupScreen(context: self.context, updatedPresentationData: self.updatedPresentationData, peerId: peer.id, completion: { [weak self] updatedValue in if case let .updated(value) = updatedValue { guard let strongSelf = self else { return diff --git a/submodules/TelegramUI/Sources/ChatRecentActionsController.swift b/submodules/TelegramUI/Sources/ChatRecentActionsController.swift index b6026136f9..3e6b5fddb5 100644 --- a/submodules/TelegramUI/Sources/ChatRecentActionsController.swift +++ b/submodules/TelegramUI/Sources/ChatRecentActionsController.swift @@ -19,6 +19,10 @@ final class ChatRecentActionsController: TelegramBaseController { private let peer: Peer private let initialAdminPeerId: PeerId? private var presentationData: PresentationData + private var presentationDataPromise = Promise() + override var updatedPresentationData: (PresentationData, Signal) { + return (self.presentationData, self.presentationDataPromise.get()) + } private var presentationDataDisposable: Disposable? private var interaction: ChatRecentActionsInteraction! @@ -151,14 +155,39 @@ final class ChatRecentActionsController: TelegramBaseController { self?.openFilterSetup() } - self.presentationDataDisposable = (context.sharedContext.presentationData - |> deliverOnMainQueue).start(next: { [weak self] presentationData in + let themeEmoticon = self.context.account.postbox.peerView(id: peer.id) + |> map { view -> String? in + let cachedData = view.cachedData + if let cachedData = cachedData as? CachedUserData { + return cachedData.themeEmoticon + } else if let cachedData = cachedData as? CachedGroupData { + return cachedData.themeEmoticon + } else if let cachedData = cachedData as? CachedChannelData { + return cachedData.themeEmoticon + } else { + return nil + } + } + |> distinctUntilChanged + + self.presentationDataDisposable = combineLatest(queue: Queue.mainQueue(), context.sharedContext.presentationData, context.engine.themes.getChatThemes(accountManager: context.sharedContext.accountManager, onlyCached: true), themeEmoticon).start(next: { [weak self] presentationData, chatThemes, themeEmoticon in if let strongSelf = self { let previousTheme = strongSelf.presentationData.theme let previousStrings = strongSelf.presentationData.strings + var presentationData = presentationData + if let themeEmoticon = themeEmoticon, let theme = chatThemes.first(where: { $0.emoji == themeEmoticon }) { + let useDarkAppearance = presentationData.autoNightModeTriggered + let customTheme = useDarkAppearance ? theme.darkTheme : theme.theme + if let settings = customTheme.settings, let theme = makePresentationTheme(settings: settings, specialMode: true) { + presentationData = presentationData.withUpdated(theme: theme) + presentationData = presentationData.withUpdated(chatWallpaper: theme.chat.defaultWallpaper) + } + } + strongSelf.presentationData = presentationData - + strongSelf.presentationDataPromise.set(.single(presentationData)) + if previousTheme !== presentationData.theme || previousStrings !== presentationData.strings { strongSelf.updateThemeAndStrings() } @@ -179,10 +208,12 @@ final class ChatRecentActionsController: TelegramBaseController { self.statusBar.statusBarStyle = self.presentationData.theme.rootController.statusBarStyle.style self.navigationBar?.updatePresentationData(NavigationBarPresentationData(presentationData: self.presentationData)) + + self.controllerNode.updatePresentationData(self.presentationData) } override func loadDisplayNode() { - self.displayNode = ChatRecentActionsControllerNode(context: self.context, peer: self.peer, presentationData: self.presentationData, interaction: self.interaction, pushController: { [weak self] c in + self.displayNode = ChatRecentActionsControllerNode(context: self.context, controller: self, peer: self.peer, presentationData: self.presentationData, interaction: self.interaction, pushController: { [weak self] c in (self?.navigationController as? NavigationController)?.pushViewController(c) }, presentController: { [weak self] c, t, a in self?.present(c, in: t, with: a, blockInteraction: true) @@ -232,7 +263,7 @@ final class ChatRecentActionsController: TelegramBaseController { } private func openFilterSetup() { - self.present(channelRecentActionsFilterController(context: self.context, peer: self.peer, events: self.controllerNode.filter.events, adminPeerIds: self.controllerNode.filter.adminPeerIds, apply: { [weak self] events, adminPeerIds in + self.present(channelRecentActionsFilterController(context: self.context, updatedPresentationData: self.updatedPresentationData, peer: self.peer, events: self.controllerNode.filter.events, adminPeerIds: self.controllerNode.filter.adminPeerIds, apply: { [weak self] events, adminPeerIds in self?.controllerNode.updateFilter(events: events, adminPeerIds: adminPeerIds) self?.updateTitle() }), in: .window(.root), with: ViewControllerPresentationArguments(presentationAnimation: .modalSheet)) diff --git a/submodules/TelegramUI/Sources/ChatRecentActionsControllerNode.swift b/submodules/TelegramUI/Sources/ChatRecentActionsControllerNode.swift index 38e2f92cd0..abad9ee25e 100644 --- a/submodules/TelegramUI/Sources/ChatRecentActionsControllerNode.swift +++ b/submodules/TelegramUI/Sources/ChatRecentActionsControllerNode.swift @@ -50,11 +50,9 @@ final class ChatRecentActionsControllerNode: ViewControllerTracingNode { private let temporaryHiddenGalleryMediaDisposable = MetaDisposable() private var chatPresentationDataPromise: Promise - private var presentationDataDisposable: Disposable? private var automaticMediaDownloadSettings: MediaAutoDownloadSettings - private var state: ChatRecentActionsControllerState private var containerLayout: (ContainerViewLayout, CGFloat)? private let backgroundNode: WallpaperBackgroundNode @@ -87,8 +85,11 @@ final class ChatRecentActionsControllerNode: ViewControllerTracingNode { private var adminsState: ChannelMemberListState? private let banDisposables = DisposableDict() - init(context: AccountContext, peer: Peer, presentationData: PresentationData, interaction: ChatRecentActionsInteraction, pushController: @escaping (ViewController) -> Void, presentController: @escaping (ViewController, PresentationContextType, Any?) -> Void, getNavigationController: @escaping () -> NavigationController?) { + private weak var controller: ChatRecentActionsController? + + init(context: AccountContext, controller: ChatRecentActionsController, peer: Peer, presentationData: PresentationData, interaction: ChatRecentActionsInteraction, pushController: @escaping (ViewController) -> Void, presentController: @escaping (ViewController, PresentationContextType, Any?) -> Void, getNavigationController: @escaping () -> NavigationController?) { self.context = context + self.controller = controller self.peer = peer self.presentationData = presentationData self.interaction = interaction @@ -117,18 +118,13 @@ final class ChatRecentActionsControllerNode: ViewControllerTracingNode { self.loadingNode = ChatLoadingNode(theme: self.presentationData.theme, chatWallpaper: self.presentationData.chatWallpaper, bubbleCorners: self.presentationData.chatBubbleCorners) self.emptyNode = ChatRecentActionsEmptyNode(theme: self.presentationData.theme, chatWallpaper: self.presentationData.chatWallpaper, chatBubbleCorners: self.presentationData.chatBubbleCorners) self.emptyNode.alpha = 0.0 - - self.state = ChatRecentActionsControllerState(chatWallpaper: self.presentationData.chatWallpaper, theme: self.presentationData.theme, strings: self.presentationData.strings, fontSize: self.presentationData.chatFontSize) - - self.chatPresentationDataPromise = Promise(ChatPresentationData(theme: ChatPresentationThemeData(theme: self.presentationData.theme, wallpaper: self.presentationData.chatWallpaper), fontSize: self.presentationData.chatFontSize, strings: self.presentationData.strings, dateTimeFormat: self.presentationData.dateTimeFormat, nameDisplayOrder: self.presentationData.nameDisplayOrder, disableAnimations: true, largeEmoji: self.presentationData.largeEmoji, chatBubbleCorners: self.presentationData.chatBubbleCorners)) + + self.chatPresentationDataPromise = Promise() self.eventLogContext = self.context.engine.peers.channelAdminEventLog(peerId: self.peer.id) super.init() - - self.backgroundNode.update(wallpaper: self.state.chatWallpaper) - self.backgroundNode.updateBubbleTheme(bubbleTheme: self.presentationData.theme, bubbleCorners: self.presentationData.chatBubbleCorners) - + self.addSubnode(self.backgroundNode) self.addSubnode(self.listNode) self.addSubnode(self.loadingNode) @@ -180,7 +176,7 @@ final class ChatRecentActionsControllerNode: ViewControllerTracingNode { ])]) strongSelf.presentController(actionSheet, .window(.root), nil) } else { - let controller = inviteLinkEditController(context: strongSelf.context, peerId: peer.id, invite: invite, completion: { [weak self] _ in + let controller = inviteLinkEditController(context: strongSelf.context, updatedPresentationData: strongSelf.controller?.updatedPresentationData, peerId: peer.id, invite: invite, completion: { [weak self] _ in self?.eventLogContext.reload() }) controller.navigationPresentation = .modal @@ -601,20 +597,9 @@ final class ChatRecentActionsControllerNode: ViewControllerTracingNode { } } })) - - self.presentationDataDisposable = (context.sharedContext.presentationData - |> deliverOnMainQueue).start(next: { [weak self] presentationData in - if let strongSelf = self { - strongSelf.presentationData = presentationData - strongSelf.chatPresentationDataPromise.set(.single(ChatPresentationData(theme: ChatPresentationThemeData(theme: presentationData.theme, wallpaper: presentationData.chatWallpaper), fontSize: presentationData.chatFontSize, strings: presentationData.strings, dateTimeFormat: presentationData.dateTimeFormat, nameDisplayOrder: presentationData.nameDisplayOrder, disableAnimations: true, largeEmoji: presentationData.largeEmoji, chatBubbleCorners: presentationData.chatBubbleCorners))) - - strongSelf.updateThemeAndStrings(theme: presentationData.theme, strings: presentationData.strings) - } - }) } deinit { - self.presentationDataDisposable?.dispose() self.historyDisposable?.dispose() self.navigationActionDisposable.dispose() self.galleryHiddenMesageAndMediaDisposable.dispose() @@ -624,10 +609,17 @@ final class ChatRecentActionsControllerNode: ViewControllerTracingNode { self.banDisposables.dispose() } - func updateThemeAndStrings(theme: PresentationTheme, strings: PresentationStrings) { - self.panelBackgroundNode.updateColor(color: theme.chat.inputPanel.panelBackgroundColor, transition: .immediate) - self.panelSeparatorNode.backgroundColor = theme.chat.inputPanel.panelSeparatorColor - self.panelButtonNode.setTitle(presentationData.strings.Channel_AdminLog_InfoPanelTitle, with: Font.regular(17.0), with: theme.chat.inputPanel.panelControlAccentColor, for: []) + func updatePresentationData(_ presentationData: PresentationData) { + self.presentationData = presentationData + + self.chatPresentationDataPromise.set(.single(ChatPresentationData(theme: ChatPresentationThemeData(theme: presentationData.theme, wallpaper: presentationData.chatWallpaper), fontSize: presentationData.chatFontSize, strings: presentationData.strings, dateTimeFormat: presentationData.dateTimeFormat, nameDisplayOrder: presentationData.nameDisplayOrder, disableAnimations: true, largeEmoji: presentationData.largeEmoji, chatBubbleCorners: presentationData.chatBubbleCorners))) + + self.backgroundNode.update(wallpaper: presentationData.chatWallpaper) + self.backgroundNode.updateBubbleTheme(bubbleTheme: presentationData.theme, bubbleCorners: presentationData.chatBubbleCorners) + + self.panelBackgroundNode.updateColor(color: presentationData.theme.chat.inputPanel.panelBackgroundColor, transition: .immediate) + self.panelSeparatorNode.backgroundColor = presentationData.theme.chat.inputPanel.panelSeparatorColor + self.panelButtonNode.setTitle(presentationData.strings.Channel_AdminLog_InfoPanelTitle, with: Font.regular(17.0), with: presentationData.theme.chat.inputPanel.panelControlAccentColor, for: []) } func containerLayoutUpdated(_ layout: ContainerViewLayout, navigationBarHeight: CGFloat, transition: ContainedViewLayoutTransition) { @@ -948,7 +940,7 @@ final class ChatRecentActionsControllerNode: ViewControllerTracingNode { private func presentAutoremoveSetup() { let peer = self.peer - let controller = peerAutoremoveSetupScreen(context: self.context, peerId: peer.id, completion: { [weak self] updatedValue in + let controller = peerAutoremoveSetupScreen(context: self.context, updatedPresentationData: self.controller?.updatedPresentationData, peerId: peer.id, completion: { [weak self] updatedValue in if case let .updated(value) = updatedValue { guard let strongSelf = self else { return diff --git a/submodules/TelegramUI/Sources/ChatRecentActionsControllerState.swift b/submodules/TelegramUI/Sources/ChatRecentActionsControllerState.swift deleted file mode 100644 index 2aaff1ac9f..0000000000 --- a/submodules/TelegramUI/Sources/ChatRecentActionsControllerState.swift +++ /dev/null @@ -1,35 +0,0 @@ -import Foundation -import UIKit -import TelegramCore -import TelegramPresentationData -import TelegramUIPreferences - -final class ChatRecentActionsControllerState: Equatable { - let chatWallpaper: TelegramWallpaper - let theme: PresentationTheme - let strings: PresentationStrings - let fontSize: PresentationFontSize - - init(chatWallpaper: TelegramWallpaper, theme: PresentationTheme, strings: PresentationStrings, fontSize: PresentationFontSize) { - self.chatWallpaper = chatWallpaper - self.theme = theme - self.strings = strings - self.fontSize = fontSize - } - - static func ==(lhs: ChatRecentActionsControllerState, rhs: ChatRecentActionsControllerState) -> Bool { - if lhs.chatWallpaper != rhs.chatWallpaper { - return false - } - if lhs.theme !== rhs.theme { - return false - } - if lhs.strings !== rhs.strings { - return false - } - if lhs.fontSize != rhs.fontSize { - return false - } - return true - } -} diff --git a/submodules/TelegramUI/Sources/ChatRecentActionsFilterController.swift b/submodules/TelegramUI/Sources/ChatRecentActionsFilterController.swift index 1c5a4da42f..6ceb91fc0f 100644 --- a/submodules/TelegramUI/Sources/ChatRecentActionsFilterController.swift +++ b/submodules/TelegramUI/Sources/ChatRecentActionsFilterController.swift @@ -343,7 +343,7 @@ private func channelRecentActionsFilterControllerEntries(presentationData: Prese return entries } -public func channelRecentActionsFilterController(context: AccountContext, peer: Peer, events: AdminLogEventsFlags, adminPeerIds: [PeerId]?, apply: @escaping (_ events: AdminLogEventsFlags, _ adminPeerIds: [PeerId]?) -> Void) -> ViewController { +public func channelRecentActionsFilterController(context: AccountContext, updatedPresentationData: (initial: PresentationData, signal: Signal)? = nil, peer: Peer, events: AdminLogEventsFlags, adminPeerIds: [PeerId]?, apply: @escaping (_ events: AdminLogEventsFlags, _ adminPeerIds: [PeerId]?) -> Void) -> ViewController { let statePromise = ValuePromise(ChatRecentActionsFilterControllerState(events: events, adminPeerIds: adminPeerIds), ignoreRepeated: true) let stateValue = Atomic(value: ChatRecentActionsFilterControllerState(events: events, adminPeerIds: adminPeerIds)) let updateState: ((ChatRecentActionsFilterControllerState) -> ChatRecentActionsFilterControllerState) -> Void = { f in @@ -353,9 +353,7 @@ public func channelRecentActionsFilterController(context: AccountContext, peer: var dismissImpl: (() -> Void)? let adminsPromise = Promise<[RenderedChannelParticipant]?>(nil) - - let presentationDataSignal = context.sharedContext.presentationData - + let actionsDisposable = DisposableSet() let arguments = ChatRecentActionsFilterControllerArguments(context: context, toggleAllActions: { value in @@ -433,7 +431,8 @@ public func channelRecentActionsFilterController(context: AccountContext, peer: var previousPeers: [RenderedChannelParticipant]? - let signal = combineLatest(presentationDataSignal, statePromise.get(), adminsPromise.get() |> deliverOnMainQueue) + let presentationData = updatedPresentationData?.signal ?? context.sharedContext.presentationData + let signal = combineLatest(presentationData, statePromise.get(), adminsPromise.get() |> deliverOnMainQueue) |> deliverOnMainQueue |> map { presentationData, state, admins -> (ItemListControllerState, (ItemListNodeState, Any)) in let leftNavigationButton = ItemListNavigationButton(content: .text(presentationData.strings.Common_Cancel), style: .regular, enabled: true, action: { diff --git a/submodules/TelegramUI/Sources/PeerInfo/PeerInfoScreen.swift b/submodules/TelegramUI/Sources/PeerInfo/PeerInfoScreen.swift index a155558446..3361de4003 100644 --- a/submodules/TelegramUI/Sources/PeerInfo/PeerInfoScreen.swift +++ b/submodules/TelegramUI/Sources/PeerInfo/PeerInfoScreen.swift @@ -4356,9 +4356,9 @@ private final class PeerInfoScreenNode: ViewControllerTracingNode, UIScrollViewD let statsController: ViewController if let channel = peer as? TelegramChannel, case .group = channel.info { - statsController = groupStatsController(context: self.context, peerId: peer.id, cachedPeerData: cachedData) + statsController = groupStatsController(context: self.context, updatedPresentationData: self.controller?.updatedPresentationData, peerId: peer.id, cachedPeerData: cachedData) } else { - statsController = channelStatsController(context: self.context, peerId: peer.id, cachedPeerData: cachedData) + statsController = channelStatsController(context: self.context, updatedPresentationData: self.controller?.updatedPresentationData, peerId: peer.id, cachedPeerData: cachedData) } controller.push(statsController) } @@ -4706,15 +4706,15 @@ private final class PeerInfoScreenNode: ViewControllerTracingNode, UIScrollViewD } switch section { case .members: - self.controller?.push(channelMembersController(context: self.context, peerId: self.peerId)) + self.controller?.push(channelMembersController(context: self.context, updatedPresentationData: self.controller?.updatedPresentationData, peerId: self.peerId)) case .admins: if peer is TelegramGroup { - self.controller?.push(channelAdminsController(context: self.context, peerId: self.peerId)) + self.controller?.push(channelAdminsController(context: self.context, updatedPresentationData: self.controller?.updatedPresentationData, peerId: self.peerId)) } else if peer is TelegramChannel { - self.controller?.push(channelAdminsController(context: self.context, peerId: self.peerId)) + self.controller?.push(channelAdminsController(context: self.context, updatedPresentationData: self.controller?.updatedPresentationData, peerId: self.peerId)) } case .banned: - self.controller?.push(channelBlacklistController(context: self.context, peerId: self.peerId)) + self.controller?.push(channelBlacklistController(context: self.context, updatedPresentationData: self.controller?.updatedPresentationData, peerId: self.peerId)) } } @@ -4723,7 +4723,7 @@ private final class PeerInfoScreenNode: ViewControllerTracingNode, UIScrollViewD return } var upgradedToSupergroupImpl: (() -> Void)? - let controller = groupPreHistorySetupController(context: self.context, peerId: peer.id, upgradedToSupergroup: { _, f in + let controller = groupPreHistorySetupController(context: self.context, updatedPresentationData: self.controller?.updatedPresentationData, peerId: peer.id, upgradedToSupergroup: { _, f in upgradedToSupergroupImpl?() f() }) @@ -4741,7 +4741,7 @@ private final class PeerInfoScreenNode: ViewControllerTracingNode, UIScrollViewD return } - let controller = peerAutoremoveSetupScreen(context: self.context, peerId: peer.id) + let controller = peerAutoremoveSetupScreen(context: self.context, updatedPresentationData: self.controller?.updatedPresentationData, peerId: peer.id) self.controller?.push(controller) } @@ -4749,14 +4749,14 @@ private final class PeerInfoScreenNode: ViewControllerTracingNode, UIScrollViewD guard let data = self.data, let peer = data.peer else { return } - self.controller?.push(channelPermissionsController(context: self.context, peerId: peer.id)) + self.controller?.push(channelPermissionsController(context: self.context, updatedPresentationData: self.controller?.updatedPresentationData, peerId: peer.id)) } private func editingOpenStickerPackSetup() { guard let data = self.data, let peer = data.peer, let cachedData = data.cachedData as? CachedChannelData else { return } - self.controller?.push(groupStickerPackSetupController(context: self.context, peerId: peer.id, currentPackInfo: cachedData.stickerPack)) + self.controller?.push(groupStickerPackSetupController(context: self.context, updatedPresentationData: self.controller?.updatedPresentationData, peerId: peer.id, currentPackInfo: cachedData.stickerPack)) } private func openLocation() { @@ -4830,12 +4830,12 @@ private final class PeerInfoScreenNode: ViewControllerTracingNode, UIScrollViewD switch action { case .promote: if case let .channelMember(channelMember) = member { - self.controller?.push(channelAdminController(context: self.context, peerId: peer.id, adminId: member.id, initialParticipant: channelMember.participant, updated: { _ in + self.controller?.push(channelAdminController(context: self.context, updatedPresentationData: self.controller?.updatedPresentationData, peerId: peer.id, adminId: member.id, initialParticipant: channelMember.participant, updated: { _ in }, upgradedToSupergroup: { _, f in f() }, transferedOwnership: { _ in })) } case .restrict: if case let .channelMember(channelMember) = member { - self.controller?.push(channelBannedMemberController(context: self.context, peerId: peer.id, memberId: member.id, initialParticipant: channelMember.participant, updated: { _ in + self.controller?.push(channelBannedMemberController(context: self.context, updatedPresentationData: self.controller?.updatedPresentationData, peerId: peer.id, memberId: member.id, initialParticipant: channelMember.participant, updated: { _ in }, upgradedToSupergroup: { _, f in f() })) } case .remove: diff --git a/submodules/WallpaperResources/Sources/WallpaperResources.swift b/submodules/WallpaperResources/Sources/WallpaperResources.swift index 9a1e895d25..94a211b0eb 100644 --- a/submodules/WallpaperResources/Sources/WallpaperResources.swift +++ b/submodules/WallpaperResources/Sources/WallpaperResources.swift @@ -363,14 +363,13 @@ private func patternWallpaperDatas(account: Account, accountManager: AccountMana targetRepresentation = representations[representations.firstIndex(where: { $0.representation == representation })!] } } - + if let targetRepresentation = targetRepresentation { - let maybeFullSize = combineLatest( - accountManager.mediaBox.cachedResourceRepresentation(targetRepresentation.representation.resource, representation: CachedPreparedPatternWallpaperRepresentation(), complete: false, fetch: true), - account.postbox.mediaBox.cachedResourceRepresentation(targetRepresentation.representation.resource, representation: CachedPreparedPatternWallpaperRepresentation(), complete: false, fetch: true) - ) + let sharedResource = mode == .screen ? accountManager.mediaBox.cachedResourceRepresentation(targetRepresentation.representation.resource, representation: CachedPreparedPatternWallpaperRepresentation(), complete: false, fetch: true) : accountManager.mediaBox.resourceData(targetRepresentation.representation.resource) + let accountResource = mode == .screen ? account.postbox.mediaBox.cachedResourceRepresentation(targetRepresentation.representation.resource, representation: CachedPreparedPatternWallpaperRepresentation(), complete: false, fetch: true) : account.postbox.mediaBox.resourceData(targetRepresentation.representation.resource) + let maybeFullSize = combineLatest(sharedResource, accountResource) let signal = maybeFullSize |> take(1) |> mapToSignal { maybeSharedData, maybeData -> Signal<(Data?, Bool), NoError> in @@ -388,7 +387,7 @@ private func patternWallpaperDatas(account: Account, accountManager: AccountMana let accountFullSizeData = Signal<(Data?, Bool), NoError> { subscriber in let fetchedFullSizeDisposable = fetchedFullSize.start() - let fullSizeDisposable = account.postbox.mediaBox.cachedResourceRepresentation(targetRepresentation.representation.resource, representation: CachedPreparedPatternWallpaperRepresentation(), complete: false, fetch: true).start(next: { next in + let fullSizeDisposable = accountResource.start(next: { next in subscriber.putNext((next.size == 0 ? nil : try? Data(contentsOf: URL(fileURLWithPath: next.path), options: []), next.complete)) if next.complete, let data = try? Data(contentsOf: URL(fileURLWithPath: next.path), options: .mappedRead) { @@ -403,7 +402,7 @@ private func patternWallpaperDatas(account: Account, accountManager: AccountMana } let sharedFullSizeData = Signal<(Data?, Bool), NoError> { subscriber in - let fullSizeDisposable = accountManager.mediaBox.cachedResourceRepresentation(targetRepresentation.representation.resource, representation: CachedPreparedPatternWallpaperRepresentation(), complete: false, fetch: true).start(next: { next in + let fullSizeDisposable = sharedResource.start(next: { next in subscriber.putNext((next.size == 0 ? nil : try? Data(contentsOf: URL(fileURLWithPath: next.path), options: []), next.complete)) }, error: subscriber.putError, completed: subscriber.putCompletion) @@ -528,16 +527,12 @@ private func patternWallpaperImageInternal(fullSizeData: Data?, fullSizeComplete c.clear(CGRect(origin: CGPoint(), size: size)) var image: UIImage? if let fullSizeData = fullSizeData { - image = renderPreparedImage(fullSizeData, CGSize(width: size.width * context.scale, height: size.height * context.scale)) + if mode == .screen { + image = renderPreparedImage(fullSizeData, CGSize(width: size.width * context.scale, height: size.height * context.scale)) + } else { + image = UIImage(data: fullSizeData) + } } -// if let fullSizeData = fullSizeData, let unpackedData = TGGUnzipData(fullSizeData, 2 * 1024 * 1024) { -// let preparedData = prepareSvgImage(unpackedData) -// image = renderPreparedImage(preparedData!, CGSize(width: size.width * context.scale, height: size.height * context.scale)) -// -//// image = drawSvgImage(unpackedData, CGSize(width: size.width * context.scale, height: size.height * context.scale), .black, .white) -// } else if let fullSizeData = fullSizeData { -// image = UIImage(data: fullSizeData) -// } if let customPatternColor = customArguments.customPatternColor, customPatternColor.alpha < 1.0 { c.setBlendMode(.copy)