From 3cdfb2031d8315ab0724b5b116c31dc580e958a9 Mon Sep 17 00:00:00 2001 From: Ilya Laktyushin Date: Tue, 3 Sep 2024 18:26:47 +0400 Subject: [PATCH] Various improvements --- .../Sources/ChatController.swift | 3 ++- .../Sources/ChatListController.swift | 9 ++++++++ ...ChatControllerNavigationButtonAction.swift | 3 +++ .../TelegramUI/Sources/ChatController.swift | 23 +++++++++++++++---- .../Sources/ChatControllerNode.swift | 4 +++- 5 files changed, 36 insertions(+), 6 deletions(-) diff --git a/submodules/AccountContext/Sources/ChatController.swift b/submodules/AccountContext/Sources/ChatController.swift index 6f97ed6086..01a4f4a292 100644 --- a/submodules/AccountContext/Sources/ChatController.swift +++ b/submodules/AccountContext/Sources/ChatController.swift @@ -1010,7 +1010,8 @@ public protocol ChatController: ViewController { var canReadHistory: ValuePromise { get } var parentController: ViewController? { get set } var customNavigationController: NavigationController? { get set } - + + var dismissPreviewing: (() -> Void)? { get set } var purposefulAction: (() -> Void)? { get set } var stateUpdated: ((ContainedViewLayoutTransition) -> Void)? { get set } diff --git a/submodules/ChatListUI/Sources/ChatListController.swift b/submodules/ChatListUI/Sources/ChatListController.swift index 60b193b220..6a6d3306d2 100644 --- a/submodules/ChatListUI/Sources/ChatListController.swift +++ b/submodules/ChatListUI/Sources/ChatListController.swift @@ -1402,17 +1402,26 @@ public class ChatListControllerImpl: TelegramBaseController, ChatListController strongSelf.presentInGlobalOverlay(contextController) } } else { + var dismissPreviewingImpl: (() -> Void)? let source: ContextContentSource if let location = location { source = .location(ChatListContextLocationContentSource(controller: strongSelf, location: location)) } else { let chatController = strongSelf.context.sharedContext.makeChatController(context: strongSelf.context, chatLocation: .peer(id: peer.peerId), subject: nil, botStart: nil, mode: .standard(.previewing), params: nil) + chatController.customNavigationController = strongSelf.navigationController as? NavigationController chatController.canReadHistory.set(false) + chatController.dismissPreviewing = { + dismissPreviewingImpl?() + } source = .controller(ContextControllerContentSourceImpl(controller: chatController, sourceNode: node, navigationController: strongSelf.navigationController as? NavigationController)) } let contextController = ContextController(presentationData: strongSelf.presentationData, source: source, items: chatContextMenuItems(context: strongSelf.context, peerId: peer.peerId, promoInfo: promoInfo, source: .chatList(filter: strongSelf.chatListDisplayNode.mainContainerNode.currentItemNode.chatListFilter), chatListController: strongSelf, joined: joined) |> map { ContextController.Items(content: .list($0)) }, gesture: gesture) strongSelf.presentInGlobalOverlay(contextController) + + dismissPreviewingImpl = { [weak contextController] in + contextController?.dismiss() + } } case let .forum(pinnedIndex, _, threadId, _, _): let isPinned: Bool diff --git a/submodules/TelegramUI/Sources/Chat/ChatControllerNavigationButtonAction.swift b/submodules/TelegramUI/Sources/Chat/ChatControllerNavigationButtonAction.swift index ba2854682a..3b3bf94596 100644 --- a/submodules/TelegramUI/Sources/Chat/ChatControllerNavigationButtonAction.swift +++ b/submodules/TelegramUI/Sources/Chat/ChatControllerNavigationButtonAction.swift @@ -387,6 +387,7 @@ extension ChatControllerImpl { |> take(1) |> deliverOnMainQueue).startStrict(next: { [weak self] peerView in if let strongSelf = self, let peer = peerView.peers[peerView.peerId], peer.restrictionText(platform: "ios", contentSettings: strongSelf.context.currentContentSettings.with { $0 }) == nil && !strongSelf.presentationInterfaceState.isNotAccessible { + if peer.id == strongSelf.context.account.peerId { if let peer = strongSelf.presentationInterfaceState.renderedPeer?.chatMainPeer, let infoController = strongSelf.context.sharedContext.makePeerInfoController(context: strongSelf.context, updatedPresentationData: strongSelf.updatedPresentationData, peer: peer, mode: .generic, avatarInitiallyExpanded: false, fromChat: true, requestsContext: nil) { strongSelf.effectiveNavigationController?.pushViewController(infoController) @@ -403,6 +404,8 @@ extension ChatControllerImpl { strongSelf.effectiveNavigationController?.pushViewController(infoController) } } + + strongSelf.dismissPreviewing?() } })) case .replyThread: diff --git a/submodules/TelegramUI/Sources/ChatController.swift b/submodules/TelegramUI/Sources/ChatController.swift index 1eba3b6a34..99161ab2d3 100644 --- a/submodules/TelegramUI/Sources/ChatController.swift +++ b/submodules/TelegramUI/Sources/ChatController.swift @@ -567,6 +567,8 @@ public final class ChatControllerImpl: TelegramBaseController, ChatController, G var scheduledScrollToMessageId: (MessageId, NavigateToMessageParams)? public var purposefulAction: (() -> Void)? + public var dismissPreviewing: (() -> Void)? + var updatedClosedPinnedMessageId: ((MessageId) -> Void)? var requestedUnpinAllMessages: ((Int, MessageId) -> Void)? @@ -4653,7 +4655,10 @@ public final class ChatControllerImpl: TelegramBaseController, ChatController, G self.navigationItem.titleView = self.chatTitleView self.chatTitleView?.longPressed = { [weak self] in if let strongSelf = self, let peerView = strongSelf.peerView, let peer = peerView.peers[peerView.peerId], peer.restrictionText(platform: "ios", contentSettings: strongSelf.context.currentContentSettings.with { $0 }) == nil && !strongSelf.presentationInterfaceState.isNotAccessible { - strongSelf.interfaceInteraction?.beginMessageSearch(.everything, "") + if case .standard(.previewing) = strongSelf.mode { + } else { + strongSelf.interfaceInteraction?.beginMessageSearch(.everything, "") + } } } @@ -5414,7 +5419,11 @@ public final class ChatControllerImpl: TelegramBaseController, ChatController, G imageOverride = nil } (strongSelf.chatInfoNavigationButton?.buttonItem.customDisplayNode as? ChatAvatarNavigationNode)?.setPeer(context: strongSelf.context, theme: strongSelf.presentationData.theme, peer: EnginePeer(peer), overrideImage: imageOverride) - (strongSelf.chatInfoNavigationButton?.buttonItem.customDisplayNode as? ChatAvatarNavigationNode)?.contextActionIsEnabled = peer.restrictionText(platform: "ios", contentSettings: strongSelf.context.currentContentSettings.with { $0 }) == nil + if case .standard(.previewing) = strongSelf.mode { + (strongSelf.chatInfoNavigationButton?.buttonItem.customDisplayNode as? ChatAvatarNavigationNode)?.contextActionIsEnabled = false + } else { + (strongSelf.chatInfoNavigationButton?.buttonItem.customDisplayNode as? ChatAvatarNavigationNode)?.contextActionIsEnabled = peer.restrictionText(platform: "ios", contentSettings: strongSelf.context.currentContentSettings.with { $0 }) == nil + } strongSelf.chatInfoNavigationButton?.buttonItem.accessibilityLabel = presentationInterfaceState.strings.Conversation_ContextMenuOpenProfile strongSelf.storyStats = peerView.storyStats @@ -6304,7 +6313,11 @@ public final class ChatControllerImpl: TelegramBaseController, ChatController, G if strongSelf.isNodeLoaded { strongSelf.chatDisplayNode.overlayTitle = strongSelf.overlayTitle } - (strongSelf.chatInfoNavigationButton?.buttonItem.customDisplayNode as? ChatAvatarNavigationNode)?.contextActionIsEnabled = true + if case .standard(.previewing) = strongSelf.mode { + (strongSelf.chatInfoNavigationButton?.buttonItem.customDisplayNode as? ChatAvatarNavigationNode)?.contextActionIsEnabled = false + } else { + (strongSelf.chatInfoNavigationButton?.buttonItem.customDisplayNode as? ChatAvatarNavigationNode)?.contextActionIsEnabled = true + } var peerDiscussionId: PeerId? var peerGeoLocation: PeerGeoLocation? @@ -8368,7 +8381,9 @@ public final class ChatControllerImpl: TelegramBaseController, ChatController, G @objc func rightNavigationButtonAction() { if let button = self.rightNavigationButton { - if case let .peer(peerId) = self.chatLocation, case .openChatInfo(expandAvatar: true, _) = button.action, let storyStats = self.storyStats, storyStats.unseenCount != 0, let avatarNode = self.avatarNode { + if case .standard(.previewing) = self.mode { + self.navigationButtonAction(button.action) + } else if case let .peer(peerId) = self.chatLocation, case .openChatInfo(expandAvatar: true, _) = button.action, let storyStats = self.storyStats, storyStats.unseenCount != 0, let avatarNode = self.avatarNode { self.openStories(peerId: peerId, avatarHeaderNode: nil, avatarNode: avatarNode.avatarNode) } else { self.navigationButtonAction(button.action) diff --git a/submodules/TelegramUI/Sources/ChatControllerNode.swift b/submodules/TelegramUI/Sources/ChatControllerNode.swift index 649d48a508..33d49ba476 100644 --- a/submodules/TelegramUI/Sources/ChatControllerNode.swift +++ b/submodules/TelegramUI/Sources/ChatControllerNode.swift @@ -3684,7 +3684,9 @@ class ChatControllerNode: ASDisplayNode, ASScrollViewDelegate { } } } - + if let navigationBar = self.navigationBar, let result = navigationBar.view.hitTest(self.view.convert(point, to: navigationBar.view), with: nil) { + return result + } if let result = self.historyNode.view.hitTest(self.view.convert(point, to: self.historyNode.view), with: event), let node = result.asyncdisplaykit_node, node is ChatMessageSelectionNode || node is GridMessageSelectionNode { return result }