From 45cbb2a8046f8061ae42b2f9a1f36f97c2d539d5 Mon Sep 17 00:00:00 2001 From: Ilya Laktyushin Date: Tue, 29 Sep 2020 00:21:11 +0400 Subject: [PATCH] Search filters fixes --- .../Sources/AccountContext.swift | 2 +- .../Sources/ChatController.swift | 2 + .../Sources/ChatListSearchContainerNode.swift | 3 + .../Sources/ChatListSearchListPaneNode.swift | 108 ++++++++++-------- .../Postbox/Sources/MessageHistoryView.swift | 17 +++ .../Sources/TelegramBaseController.swift | 106 +++++++++-------- .../TelegramUI/Sources/ChatController.swift | 2 +- .../Sources/ChatHistoryListNode.swift | 62 ++++++---- .../OverlayAudioPlayerController.swift | 8 +- .../OverlayAudioPlayerControllerNode.swift | 16 ++- .../PeerInfo/Panes/PeerInfoListPaneNode.swift | 2 +- .../Sources/SharedAccountContext.swift | 4 +- 12 files changed, 206 insertions(+), 126 deletions(-) diff --git a/submodules/AccountContext/Sources/AccountContext.swift b/submodules/AccountContext/Sources/AccountContext.swift index f0689eb51a..cc79f7d874 100644 --- a/submodules/AccountContext/Sources/AccountContext.swift +++ b/submodules/AccountContext/Sources/AccountContext.swift @@ -532,7 +532,7 @@ public protocol SharedAccountContext: class { func navigateToChat(accountId: AccountRecordId, peerId: PeerId, messageId: MessageId?) func openChatMessage(_ params: OpenChatMessageParams) -> Bool func messageFromPreloadedChatHistoryViewForLocation(id: MessageId, location: ChatHistoryLocationInput, context: AccountContext, chatLocation: ChatLocation, chatLocationContextHolder: Atomic, tagMask: MessageTags?) -> Signal<(MessageIndex?, Bool), NoError> - func makeOverlayAudioPlayerController(context: AccountContext, peerId: PeerId, type: MediaManagerPlayerType, initialMessageId: MessageId, initialOrder: MusicPlaybackSettingsOrder, isGlobalSearch: Bool, parentNavigationController: NavigationController?) -> ViewController & OverlayAudioPlayerController + func makeOverlayAudioPlayerController(context: AccountContext, peerId: PeerId, type: MediaManagerPlayerType, initialMessageId: MessageId, initialOrder: MusicPlaybackSettingsOrder, playlistLocation: SharedMediaPlaylistLocation?, parentNavigationController: NavigationController?) -> ViewController & OverlayAudioPlayerController func makePeerInfoController(context: AccountContext, peer: Peer, mode: PeerInfoControllerMode, avatarInitiallyExpanded: Bool, fromChat: Bool) -> ViewController? func makeChannelAdminController(context: AccountContext, peerId: PeerId, adminId: PeerId, initialParticipant: ChannelParticipant) -> ViewController? func makeDeviceContactInfoController(context: AccountContext, subject: DeviceContactInfoSubject, completed: (() -> Void)?, cancelled: (() -> Void)?) -> ViewController diff --git a/submodules/AccountContext/Sources/ChatController.swift b/submodules/AccountContext/Sources/ChatController.swift index 2141b1f10c..a99cf4f9ce 100644 --- a/submodules/AccountContext/Sources/ChatController.swift +++ b/submodules/AccountContext/Sources/ChatController.swift @@ -458,6 +458,8 @@ public protocol ChatController: ViewController { var canReadHistory: ValuePromise { get } var parentController: ViewController? { get set } + var purposefulAction: (() -> Void)? { get set } + func updatePresentationMode(_ mode: ChatControllerPresentationMode) func beginMessageSearch(_ query: String) func displayPromoAnnouncement(text: String) diff --git a/submodules/ChatListUI/Sources/ChatListSearchContainerNode.swift b/submodules/ChatListUI/Sources/ChatListSearchContainerNode.swift index 10989ef99f..98ed922830 100644 --- a/submodules/ChatListUI/Sources/ChatListSearchContainerNode.swift +++ b/submodules/ChatListUI/Sources/ChatListSearchContainerNode.swift @@ -892,6 +892,9 @@ public final class ChatListSearchContainerNode: SearchDisplayControllerContentNo // strongSelf.headerNode.navigationButtonContainer.performAction?(.selectionDone) let controller = strongSelf.context.sharedContext.makeChatController(context: strongSelf.context, chatLocation: .peer(peerId), subject: nil, botStart: nil, mode: .standard(previewing: false)) + controller.purposefulAction = { [weak self] in + self?.cancel?() + } strongSelf.navigationController?.pushViewController(controller, animated: false, completion: { if let peerSelectionController = peerSelectionController { peerSelectionController.dismiss() diff --git a/submodules/ChatListUI/Sources/ChatListSearchListPaneNode.swift b/submodules/ChatListUI/Sources/ChatListSearchListPaneNode.swift index 296ec47bae..9c0c62870d 100644 --- a/submodules/ChatListUI/Sources/ChatListSearchListPaneNode.swift +++ b/submodules/ChatListUI/Sources/ChatListSearchListPaneNode.swift @@ -672,6 +672,8 @@ final class ChatListSearchListPaneNode: ASDisplayNode, ChatListSearchPaneNode { private var playlistPreloadDisposable: Disposable? private var playlistStateAndType: (SharedMediaPlaylistItem, SharedMediaPlaylistItem?, SharedMediaPlaylistItem?, MusicPlaybackSettingsOrder, MediaManagerPlayerType, Account)? + private var playlistLocation: SharedMediaPlaylistLocation? + private var mediaAccessoryPanelContainer: PassthroughContainerNode private var mediaAccessoryPanel: (MediaNavigationAccessoryPanel, MediaManagerPlayerType)? private var dismissingPanel: ASDisplayNode? @@ -1563,6 +1565,7 @@ final class ChatListSearchListPaneNode: ASDisplayNode, ChatListSearchPaneNode { strongSelf.update(size: size, sideInset: sideInset, bottomInset: bottomInset, visibleHeight: visibleHeight, presentationData: presentationData, synchronous: true, transition: .animated(duration: 0.4, curve: .spring)) } } + strongSelf.playlistLocation = playlistStateAndType?.1.playlistLocation }) } @@ -1746,57 +1749,68 @@ final class ChatListSearchListPaneNode: ASDisplayNode, ChatListSearchPaneNode { } if let id = state.id as? PeerMessagesMediaPlaylistItemId { if type == .music { - let signal = strongSelf.context.sharedContext.messageFromPreloadedChatHistoryViewForLocation(id: id.messageId, location: ChatHistoryLocationInput(content: .InitialSearch(location: .id(id.messageId), count: 60, highlight: true), id: 0), context: strongSelf.context, chatLocation: .peer(id.messageId.peerId), chatLocationContextHolder: Atomic(value: nil), tagMask: MessageTags.music) - - var cancelImpl: (() -> Void)? - let presentationData = strongSelf.context.sharedContext.currentPresentationData.with { $0 } - let progressSignal = Signal { subscriber in - let controller = OverlayStatusController(theme: presentationData.theme, type: .loading(cancelled: { - cancelImpl?() - })) - self?.interaction.present(controller, nil) - return ActionDisposable { [weak controller] in - Queue.mainQueue().async() { - controller?.dismiss() + if let playlistLocation = strongSelf.playlistLocation as? PeerMessagesPlaylistLocation, case .custom = playlistLocation { + let controllerContext: AccountContext + if account.id == strongSelf.context.account.id { + controllerContext = strongSelf.context + } else { + controllerContext = strongSelf.context.sharedContext.makeTempAccountContext(account: account) + } + let controller = strongSelf.context.sharedContext.makeOverlayAudioPlayerController(context: controllerContext, peerId: id.messageId.peerId, type: type, initialMessageId: id.messageId, initialOrder: order, playlistLocation: playlistLocation, parentNavigationController: navigationController) + strongSelf.interaction.dismissInput() + strongSelf.interaction.present(controller, nil) + } else { + let signal = strongSelf.context.sharedContext.messageFromPreloadedChatHistoryViewForLocation(id: id.messageId, location: ChatHistoryLocationInput(content: .InitialSearch(location: .id(id.messageId), count: 60, highlight: true), id: 0), context: strongSelf.context, chatLocation: .peer(id.messageId.peerId), chatLocationContextHolder: Atomic(value: nil), tagMask: MessageTags.music) + + var cancelImpl: (() -> Void)? + let presentationData = strongSelf.context.sharedContext.currentPresentationData.with { $0 } + let progressSignal = Signal { subscriber in + let controller = OverlayStatusController(theme: presentationData.theme, type: .loading(cancelled: { + cancelImpl?() + })) + self?.interaction.present(controller, nil) + return ActionDisposable { [weak controller] in + Queue.mainQueue().async() { + controller?.dismiss() + } } } - } - |> runOn(Queue.mainQueue()) - |> delay(0.15, queue: Queue.mainQueue()) - let progressDisposable = MetaDisposable() - var progressStarted = false - strongSelf.playlistPreloadDisposable?.dispose() - strongSelf.playlistPreloadDisposable = (signal - |> afterDisposed { - Queue.mainQueue().async { - progressDisposable.dispose() - } - } - |> deliverOnMainQueue).start(next: { index in - guard let strongSelf = self else { - return - } - if let _ = index.0 { - let controllerContext: AccountContext - if account.id == strongSelf.context.account.id { - controllerContext = strongSelf.context - } else { - controllerContext = strongSelf.context.sharedContext.makeTempAccountContext(account: account) - } - let controller = strongSelf.context.sharedContext.makeOverlayAudioPlayerController(context: controllerContext, peerId: id.messageId.peerId, type: type, initialMessageId: id.messageId, initialOrder: order, isGlobalSearch: false, parentNavigationController: navigationController) - strongSelf.view.window?.endEditing(true) - strongSelf.interaction.dismissInput() - strongSelf.interaction.present(controller, nil) - } else if index.1 { - if !progressStarted { - progressStarted = true - progressDisposable.set(progressSignal.start()) + |> runOn(Queue.mainQueue()) + |> delay(0.15, queue: Queue.mainQueue()) + let progressDisposable = MetaDisposable() + var progressStarted = false + strongSelf.playlistPreloadDisposable?.dispose() + strongSelf.playlistPreloadDisposable = (signal + |> afterDisposed { + Queue.mainQueue().async { + progressDisposable.dispose() } } - }, completed: { - }) - cancelImpl = { - self?.playlistPreloadDisposable?.dispose() + |> deliverOnMainQueue).start(next: { index in + guard let strongSelf = self else { + return + } + if let _ = index.0 { + let controllerContext: AccountContext + if account.id == strongSelf.context.account.id { + controllerContext = strongSelf.context + } else { + controllerContext = strongSelf.context.sharedContext.makeTempAccountContext(account: account) + } + let controller = strongSelf.context.sharedContext.makeOverlayAudioPlayerController(context: controllerContext, peerId: id.messageId.peerId, type: type, initialMessageId: id.messageId, initialOrder: order, playlistLocation: nil, parentNavigationController: navigationController) + strongSelf.interaction.dismissInput() + strongSelf.interaction.present(controller, nil) + } else if index.1 { + if !progressStarted { + progressStarted = true + progressDisposable.set(progressSignal.start()) + } + } + }, completed: { + }) + cancelImpl = { + self?.playlistPreloadDisposable?.dispose() + } } } else { strongSelf.context.sharedContext.navigateToChat(accountId: strongSelf.context.account.id, peerId: id.messageId.peerId, messageId: id.messageId) diff --git a/submodules/Postbox/Sources/MessageHistoryView.swift b/submodules/Postbox/Sources/MessageHistoryView.swift index cf50299ed8..47886542cd 100644 --- a/submodules/Postbox/Sources/MessageHistoryView.swift +++ b/submodules/Postbox/Sources/MessageHistoryView.swift @@ -881,6 +881,23 @@ public final class MessageHistoryView { public let isLoading: Bool public let isAddedToChatList: Bool + public init(tagMask: MessageTags?, namespaces: MessageIdNamespaces, entries: [MessageHistoryEntry], holeEarlier: Bool) { + self.tagMask = tagMask + self.namespaces = namespaces + self.anchorIndex = .lowerBound + self.earlierId = nil + self.laterId = nil + self.holeEarlier = holeEarlier + self.holeLater = false + self.entries = entries + self.maxReadIndex = nil + self.fixedReadStates = nil + self.topTaggedMessages = [] + self.additionalData = [] + self.isLoading = false + self.isAddedToChatList = false + } + init(_ mutableView: MutableMessageHistoryView) { self.tagMask = mutableView.tag self.namespaces = mutableView.namespaces diff --git a/submodules/TelegramBaseController/Sources/TelegramBaseController.swift b/submodules/TelegramBaseController/Sources/TelegramBaseController.swift index e97b542b3a..7542b7de0d 100644 --- a/submodules/TelegramBaseController/Sources/TelegramBaseController.swift +++ b/submodules/TelegramBaseController/Sources/TelegramBaseController.swift @@ -68,6 +68,7 @@ open class TelegramBaseController: ViewController, KeyShortcutResponder { private var locationBroadcastDisposable: Disposable? public private(set) var playlistStateAndType: (SharedMediaPlaylistItem, SharedMediaPlaylistItem?, SharedMediaPlaylistItem?, MusicPlaybackSettingsOrder, MediaManagerPlayerType, Account)? + private var playlistLocation: SharedMediaPlaylistLocation? public var tempVoicePlaylistEnded: (() -> Void)? public var tempVoicePlaylistItemChanged: ((SharedMediaPlaylistItem?, SharedMediaPlaylistItem?) -> Void)? @@ -168,6 +169,7 @@ open class TelegramBaseController: ViewController, KeyShortcutResponder { } strongSelf.requestLayout(transition: .animated(duration: 0.4, curve: .spring)) } + strongSelf.playlistLocation = playlistStateAndType?.1.playlistLocation }) } @@ -557,56 +559,68 @@ open class TelegramBaseController: ViewController, KeyShortcutResponder { } if let id = state.id as? PeerMessagesMediaPlaylistItemId { if type == .music { - let signal = strongSelf.context.sharedContext.messageFromPreloadedChatHistoryViewForLocation(id: id.messageId, location: ChatHistoryLocationInput(content: .InitialSearch(location: .id(id.messageId), count: 60, highlight: true), id: 0), context: strongSelf.context, chatLocation: .peer(id.messageId.peerId), chatLocationContextHolder: Atomic(value: nil), tagMask: MessageTags.music) - - var cancelImpl: (() -> Void)? - let presentationData = strongSelf.context.sharedContext.currentPresentationData.with { $0 } - let progressSignal = Signal { subscriber in - let controller = OverlayStatusController(theme: presentationData.theme, type: .loading(cancelled: { - cancelImpl?() - })) - self?.present(controller, in: .window(.root)) - return ActionDisposable { [weak controller] in - Queue.mainQueue().async() { - controller?.dismiss() + if let playlistLocation = strongSelf.playlistLocation as? PeerMessagesPlaylistLocation, case .custom = playlistLocation { + let controllerContext: AccountContext + if account.id == strongSelf.context.account.id { + controllerContext = strongSelf.context + } else { + controllerContext = strongSelf.context.sharedContext.makeTempAccountContext(account: account) + } + let controller = strongSelf.context.sharedContext.makeOverlayAudioPlayerController(context: controllerContext, peerId: id.messageId.peerId, type: type, initialMessageId: id.messageId, initialOrder: order, playlistLocation: playlistLocation, parentNavigationController: strongSelf.navigationController as? NavigationController) + strongSelf.displayNode.view.window?.endEditing(true) + strongSelf.present(controller, in: .window(.root)) + } else { + let signal = strongSelf.context.sharedContext.messageFromPreloadedChatHistoryViewForLocation(id: id.messageId, location: ChatHistoryLocationInput(content: .InitialSearch(location: .id(id.messageId), count: 60, highlight: true), id: 0), context: strongSelf.context, chatLocation: .peer(id.messageId.peerId), chatLocationContextHolder: Atomic(value: nil), tagMask: MessageTags.music) + + var cancelImpl: (() -> Void)? + let presentationData = strongSelf.context.sharedContext.currentPresentationData.with { $0 } + let progressSignal = Signal { subscriber in + let controller = OverlayStatusController(theme: presentationData.theme, type: .loading(cancelled: { + cancelImpl?() + })) + self?.present(controller, in: .window(.root)) + return ActionDisposable { [weak controller] in + Queue.mainQueue().async() { + controller?.dismiss() + } } } - } - |> runOn(Queue.mainQueue()) - |> delay(0.15, queue: Queue.mainQueue()) - let progressDisposable = MetaDisposable() - var progressStarted = false - strongSelf.playlistPreloadDisposable?.dispose() - strongSelf.playlistPreloadDisposable = (signal - |> afterDisposed { - Queue.mainQueue().async { - progressDisposable.dispose() - } - } - |> deliverOnMainQueue).start(next: { index in - guard let strongSelf = self else { - return - } - if let _ = index.0 { - let controllerContext: AccountContext - if account.id == strongSelf.context.account.id { - controllerContext = strongSelf.context - } else { - controllerContext = strongSelf.context.sharedContext.makeTempAccountContext(account: account) - } - let controller = strongSelf.context.sharedContext.makeOverlayAudioPlayerController(context: controllerContext, peerId: id.messageId.peerId, type: type, initialMessageId: id.messageId, initialOrder: order, isGlobalSearch: false, parentNavigationController: strongSelf.navigationController as? NavigationController) - strongSelf.displayNode.view.window?.endEditing(true) - strongSelf.present(controller, in: .window(.root)) - } else if index.1 { - if !progressStarted { - progressStarted = true - progressDisposable.set(progressSignal.start()) + |> runOn(Queue.mainQueue()) + |> delay(0.15, queue: Queue.mainQueue()) + let progressDisposable = MetaDisposable() + var progressStarted = false + strongSelf.playlistPreloadDisposable?.dispose() + strongSelf.playlistPreloadDisposable = (signal + |> afterDisposed { + Queue.mainQueue().async { + progressDisposable.dispose() } } - }, completed: { - }) - cancelImpl = { - self?.playlistPreloadDisposable?.dispose() + |> deliverOnMainQueue).start(next: { index in + guard let strongSelf = self else { + return + } + if let _ = index.0 { + let controllerContext: AccountContext + if account.id == strongSelf.context.account.id { + controllerContext = strongSelf.context + } else { + controllerContext = strongSelf.context.sharedContext.makeTempAccountContext(account: account) + } + let controller = strongSelf.context.sharedContext.makeOverlayAudioPlayerController(context: controllerContext, peerId: id.messageId.peerId, type: type, initialMessageId: id.messageId, initialOrder: order, playlistLocation: nil, parentNavigationController: strongSelf.navigationController as? NavigationController) + strongSelf.displayNode.view.window?.endEditing(true) + strongSelf.present(controller, in: .window(.root)) + } else if index.1 { + if !progressStarted { + progressStarted = true + progressDisposable.set(progressSignal.start()) + } + } + }, completed: { + }) + cancelImpl = { + self?.playlistPreloadDisposable?.dispose() + } } } else { strongSelf.context.sharedContext.navigateToChat(accountId: strongSelf.context.account.id, peerId: id.messageId.peerId, messageId: id.messageId) diff --git a/submodules/TelegramUI/Sources/ChatController.swift b/submodules/TelegramUI/Sources/ChatController.swift index fe520ba9b6..a2a872e1d7 100644 --- a/submodules/TelegramUI/Sources/ChatController.swift +++ b/submodules/TelegramUI/Sources/ChatController.swift @@ -355,7 +355,7 @@ public final class ChatControllerImpl: TelegramBaseController, ChatController, G return self.chatLocation } - var purposefulAction: (() -> Void)? + public var purposefulAction: (() -> Void)? public init(context: AccountContext, chatLocation: ChatLocation, chatLocationContextHolder: Atomic = Atomic(value: nil), subject: ChatControllerSubject? = nil, botStart: ChatControllerInitialBotStart? = nil, mode: ChatControllerPresentationMode = .standard(previewing: false), peekData: ChatPeekTimeout? = nil, peerNearbyData: ChatPeerNearbyData? = nil) { let _ = ChatControllerCount.modify { value in diff --git a/submodules/TelegramUI/Sources/ChatHistoryListNode.swift b/submodules/TelegramUI/Sources/ChatHistoryListNode.swift index a14a9185af..022c8ef381 100644 --- a/submodules/TelegramUI/Sources/ChatHistoryListNode.swift +++ b/submodules/TelegramUI/Sources/ChatHistoryListNode.swift @@ -431,6 +431,11 @@ private struct ChatHistoryAnimatedEmojiConfiguration { private var nextClientId: Int32 = 1 +public enum ChatHistoryListSource { + case `default` + case custom(messages: Signal<([Message], Int32, Bool), NoError>, messageId: MessageId, loadMore: (() -> Void)?) +} + public final class ChatHistoryListNode: ListView, ChatHistoryNode { private let context: AccountContext private let chatLocation: ChatLocation @@ -549,7 +554,7 @@ public final class ChatHistoryListNode: ListView, ChatHistoryNode { private let clientId: Atomic - public init(context: AccountContext, chatLocation: ChatLocation, chatLocationContextHolder: Atomic, tagMask: MessageTags?, subject: ChatControllerSubject?, controllerInteraction: ChatControllerInteraction, selectedMessages: Signal?, NoError>, mode: ChatHistoryListMode = .bubbles) { + public init(context: AccountContext, chatLocation: ChatLocation, chatLocationContextHolder: Atomic, tagMask: MessageTags?, source: ChatHistoryListSource = .default, subject: ChatControllerSubject?, controllerInteraction: ChatControllerInteraction, selectedMessages: Signal?, NoError>, mode: ChatHistoryListMode = .bubbles) { self.context = context self.chatLocation = chatLocation self.chatLocationContextHolder = chatLocationContextHolder @@ -643,28 +648,43 @@ public final class ChatHistoryListNode: ListView, ChatHistoryNode { let currentViewVersion = Atomic(value: nil) - let historyViewUpdate = self.chatHistoryLocationPromise.get() - |> distinctUntilChanged - |> mapToSignal { location in - return chatHistoryViewForLocation(location, context: context, chatLocation: chatLocation, chatLocationContextHolder: chatLocationContextHolder, scheduled: isScheduledMessages, fixedCombinedReadStates: fixedCombinedReadStates.with { $0 }, tagMask: tagMask, additionalData: additionalData) - |> beforeNext { viewUpdate in - switch viewUpdate { - case let .HistoryView(view, _, _, _, _, _, _): - let _ = fixedCombinedReadStates.swap(view.fixedReadStates) - default: - break + let historyViewUpdate: Signal<(ChatHistoryViewUpdate, Int), NoError> + if case let .custom(messages, _, loadMore) = source { + historyViewUpdate = messages + |> map { messages, _, hasMore in + let version = currentViewVersion.modify({ value in + if let value = value { + return value + 1 + } else { + return 0 + } + })! + return (ChatHistoryViewUpdate.HistoryView(view: MessageHistoryView(tagMask: nil, namespaces: .all, entries: messages.reversed().map { MessageHistoryEntry(message: $0, isRead: false, location: nil, monthLocation: nil, attributes: MutableMessageHistoryEntryAttributes(authorIsContact: false)) }, holeEarlier: hasMore), type: .Generic(type: ViewUpdateType.Initial), scrollPosition: nil, flashIndicators: false, originalScrollPosition: nil, initialData: ChatHistoryCombinedInitialData(initialData: nil, buttonKeyboardMessage: nil, cachedData: nil, cachedDataMessages: nil, readStateData: nil), id: 0), version) + } + } else { + historyViewUpdate = self.chatHistoryLocationPromise.get() + |> distinctUntilChanged + |> mapToSignal { location in + return chatHistoryViewForLocation(location, context: context, chatLocation: chatLocation, chatLocationContextHolder: chatLocationContextHolder, scheduled: isScheduledMessages, fixedCombinedReadStates: fixedCombinedReadStates.with { $0 }, tagMask: tagMask, additionalData: additionalData) + |> beforeNext { viewUpdate in + switch viewUpdate { + case let .HistoryView(view, _, _, _, _, _, _): + let _ = fixedCombinedReadStates.swap(view.fixedReadStates) + default: + break + } } } - } - |> map { view -> (ChatHistoryViewUpdate, Int) in - let version = currentViewVersion.modify({ value in - if let value = value { - return value + 1 - } else { - return 0 - } - })! - return (view, version) + |> map { view -> (ChatHistoryViewUpdate, Int) in + let version = currentViewVersion.modify({ value in + if let value = value { + return value + 1 + } else { + return 0 + } + })! + return (view, version) + } } let previousView = Atomic<(ChatHistoryView, Int, Set?)?>(value: nil) diff --git a/submodules/TelegramUI/Sources/OverlayAudioPlayerController.swift b/submodules/TelegramUI/Sources/OverlayAudioPlayerController.swift index 9581fbc8ff..f46647013e 100644 --- a/submodules/TelegramUI/Sources/OverlayAudioPlayerController.swift +++ b/submodules/TelegramUI/Sources/OverlayAudioPlayerController.swift @@ -15,7 +15,7 @@ final class OverlayAudioPlayerControllerImpl: ViewController, OverlayAudioPlayer let type: MediaManagerPlayerType let initialMessageId: MessageId let initialOrder: MusicPlaybackSettingsOrder - let isGlobalSearch: Bool + let playlistLocation: SharedMediaPlaylistLocation? private weak var parentNavigationController: NavigationController? @@ -27,13 +27,13 @@ final class OverlayAudioPlayerControllerImpl: ViewController, OverlayAudioPlayer private var accountInUseDisposable: Disposable? - init(context: AccountContext, peerId: PeerId, type: MediaManagerPlayerType, initialMessageId: MessageId, initialOrder: MusicPlaybackSettingsOrder, isGlobalSearch: Bool = false, parentNavigationController: NavigationController?) { + init(context: AccountContext, peerId: PeerId, type: MediaManagerPlayerType, initialMessageId: MessageId, initialOrder: MusicPlaybackSettingsOrder, playlistLocation: SharedMediaPlaylistLocation? = nil, parentNavigationController: NavigationController?) { self.context = context self.peerId = peerId self.type = type self.initialMessageId = initialMessageId self.initialOrder = initialOrder - self.isGlobalSearch = isGlobalSearch + self.playlistLocation = playlistLocation self.parentNavigationController = parentNavigationController super.init(navigationBarPresentationData: nil) @@ -54,7 +54,7 @@ final class OverlayAudioPlayerControllerImpl: ViewController, OverlayAudioPlayer } override public func loadDisplayNode() { - self.displayNode = OverlayAudioPlayerControllerNode(context: self.context, peerId: self.peerId, type: self.type, initialMessageId: self.initialMessageId, initialOrder: self.initialOrder, isGlobalSearch: self.isGlobalSearch, requestDismiss: { [weak self] in + self.displayNode = OverlayAudioPlayerControllerNode(context: self.context, peerId: self.peerId, type: self.type, initialMessageId: self.initialMessageId, initialOrder: self.initialOrder, playlistLocation: self.playlistLocation, requestDismiss: { [weak self] in self?.dismiss() }, requestShare: { [weak self] messageId in if let strongSelf = self { diff --git a/submodules/TelegramUI/Sources/OverlayAudioPlayerControllerNode.swift b/submodules/TelegramUI/Sources/OverlayAudioPlayerControllerNode.swift index f0d348eaad..01706277c3 100644 --- a/submodules/TelegramUI/Sources/OverlayAudioPlayerControllerNode.swift +++ b/submodules/TelegramUI/Sources/OverlayAudioPlayerControllerNode.swift @@ -20,6 +20,7 @@ final class OverlayAudioPlayerControllerNode: ViewControllerTracingNode, UIGestu private let type: MediaManagerPlayerType private let requestDismiss: () -> Void private let requestShare: (MessageId) -> Void + private let playlistLocation: SharedMediaPlaylistLocation? private let isGlobalSearch: Bool private let controllerInteraction: ChatControllerInteraction @@ -41,14 +42,14 @@ final class OverlayAudioPlayerControllerNode: ViewControllerTracingNode, UIGestu private var presentationDataDisposable: Disposable? private let replacementHistoryNodeReadyDisposable = MetaDisposable() - init(context: AccountContext, peerId: PeerId, type: MediaManagerPlayerType, initialMessageId: MessageId, initialOrder: MusicPlaybackSettingsOrder, isGlobalSearch: Bool, requestDismiss: @escaping () -> Void, requestShare: @escaping (MessageId) -> Void) { + init(context: AccountContext, peerId: PeerId, type: MediaManagerPlayerType, initialMessageId: MessageId, initialOrder: MusicPlaybackSettingsOrder, playlistLocation: SharedMediaPlaylistLocation?, requestDismiss: @escaping () -> Void, requestShare: @escaping (MessageId) -> Void) { self.context = context self.peerId = peerId self.presentationData = context.sharedContext.currentPresentationData.with { $0 } self.type = type self.requestDismiss = requestDismiss self.requestShare = requestShare - self.isGlobalSearch = isGlobalSearch + self.playlistLocation = playlistLocation if case .regular = initialOrder { self.currentIsReversed = false @@ -165,7 +166,16 @@ final class OverlayAudioPlayerControllerNode: ViewControllerTracingNode, UIGestu let chatLocationContextHolder = Atomic(value: nil) - self.historyNode = ChatHistoryListNode(context: context, chatLocation: .peer(peerId), chatLocationContextHolder: chatLocationContextHolder, tagMask: tagMask, subject: .message(id: initialMessageId, highlight: true), controllerInteraction: self.controllerInteraction, selectedMessages: .single(nil), mode: .list(search: false, reversed: self.currentIsReversed, displayHeaders: .none, hintLinks: false, isGlobalSearch: isGlobalSearch)) + let source: ChatHistoryListSource + if let playlistLocation = playlistLocation as? PeerMessagesPlaylistLocation, case let .custom(messages, at, loadMore) = playlistLocation { + source = .custom(messages: messages, messageId: at, loadMore: loadMore) + self.isGlobalSearch = true + } else { + source = .default + self.isGlobalSearch = false + } + + self.historyNode = ChatHistoryListNode(context: context, chatLocation: .peer(peerId), chatLocationContextHolder: chatLocationContextHolder, tagMask: tagMask, source: source, subject: .message(id: initialMessageId, highlight: true), controllerInteraction: self.controllerInteraction, selectedMessages: .single(nil), mode: .list(search: false, reversed: self.currentIsReversed, displayHeaders: .none, hintLinks: false, isGlobalSearch: self.isGlobalSearch)) super.init() diff --git a/submodules/TelegramUI/Sources/PeerInfo/Panes/PeerInfoListPaneNode.swift b/submodules/TelegramUI/Sources/PeerInfo/Panes/PeerInfoListPaneNode.swift index ea63e93b1d..6e63766175 100644 --- a/submodules/TelegramUI/Sources/PeerInfo/Panes/PeerInfoListPaneNode.swift +++ b/submodules/TelegramUI/Sources/PeerInfo/Panes/PeerInfoListPaneNode.swift @@ -293,7 +293,7 @@ final class PeerInfoListPaneNode: ASDisplayNode, PeerInfoPaneNode { } else { controllerContext = strongSelf.context.sharedContext.makeTempAccountContext(account: account) } - let controller = strongSelf.context.sharedContext.makeOverlayAudioPlayerController(context: controllerContext, peerId: id.messageId.peerId, type: type, initialMessageId: id.messageId, initialOrder: order, isGlobalSearch: false, parentNavigationController: strongSelf.chatControllerInteraction.navigationController()) + let controller = strongSelf.context.sharedContext.makeOverlayAudioPlayerController(context: controllerContext, peerId: id.messageId.peerId, type: type, initialMessageId: id.messageId, initialOrder: order, playlistLocation: nil, parentNavigationController: strongSelf.chatControllerInteraction.navigationController()) strongSelf.view.window?.endEditing(true) strongSelf.chatControllerInteraction.presentController(controller, nil) } else if index.1 { diff --git a/submodules/TelegramUI/Sources/SharedAccountContext.swift b/submodules/TelegramUI/Sources/SharedAccountContext.swift index a3ab0c5715..c138ed9e9f 100644 --- a/submodules/TelegramUI/Sources/SharedAccountContext.swift +++ b/submodules/TelegramUI/Sources/SharedAccountContext.swift @@ -936,8 +936,8 @@ public final class SharedAccountContextImpl: SharedAccountContext { }) } - public func makeOverlayAudioPlayerController(context: AccountContext, peerId: PeerId, type: MediaManagerPlayerType, initialMessageId: MessageId, initialOrder: MusicPlaybackSettingsOrder, isGlobalSearch: Bool, parentNavigationController: NavigationController?) -> ViewController & OverlayAudioPlayerController { - return OverlayAudioPlayerControllerImpl(context: context, peerId: peerId, type: type, initialMessageId: initialMessageId, initialOrder: initialOrder, isGlobalSearch: isGlobalSearch, parentNavigationController: parentNavigationController) + public func makeOverlayAudioPlayerController(context: AccountContext, peerId: PeerId, type: MediaManagerPlayerType, initialMessageId: MessageId, initialOrder: MusicPlaybackSettingsOrder, playlistLocation: SharedMediaPlaylistLocation?, parentNavigationController: NavigationController?) -> ViewController & OverlayAudioPlayerController { + return OverlayAudioPlayerControllerImpl(context: context, peerId: peerId, type: type, initialMessageId: initialMessageId, initialOrder: initialOrder, playlistLocation: playlistLocation, parentNavigationController: parentNavigationController) } public func makeTempAccountContext(account: Account) -> AccountContext {