diff --git a/submodules/TelegramUI/Sources/ChatControllerNode.swift b/submodules/TelegramUI/Sources/ChatControllerNode.swift index 049bd55562..299ff4fa8b 100644 --- a/submodules/TelegramUI/Sources/ChatControllerNode.swift +++ b/submodules/TelegramUI/Sources/ChatControllerNode.swift @@ -252,8 +252,25 @@ class ChatControllerNode: ASDisplayNode, ASScrollViewDelegate { return adPanelView.message?._asMessage() } + private var shouldDisplayPinnedTitlePanel: Bool { + guard self.chatPresentationInterfaceState.titlePanelContexts.contains(.pinnedMessage) else { + return false + } + guard let pinnedMessage = self.chatPresentationInterfaceState.pinnedMessage else { + return false + } + if pinnedMessage.topMessageId == self.chatPresentationInterfaceState.interfaceState.messageActionsState.closedPinnedMessageId { + return false + } + if self.chatPresentationInterfaceState.pendingUnpinnedAllMessages { + return false + } + return true + } + private let titleAccessoryPanelContainer: ChatControllerTitlePanelNodeContainer private var currentTitleAccessoryPanelNode: ChatTitleAccessoryPanelNode? + private var currentPinnedTitleAccessoryPanelNode: ChatPinnedMessageTitlePanelNode? private var floatingTopicsPanelContainer: ChatControllerTitlePanelNodeContainer private var floatingTopicsPanel: (view: ComponentView, component: ChatFloatingTopicsPanel)? @@ -1564,17 +1581,48 @@ class ChatControllerNode: ASDisplayNode, ASScrollViewDelegate { if let titleAccessoryPanelNode = titlePanelForChatPresentationInterfaceState(self.chatPresentationInterfaceState, context: self.context, currentPanel: self.currentTitleAccessoryPanelNode, controllerInteraction: self.controllerInteraction, interfaceInteraction: self.interfaceInteraction, force: false) { self.currentTitleAccessoryPanelNode = titleAccessoryPanelNode - let panelKey = "\(type(of: titleAccessoryPanelNode))" - headerPanels.append(HeaderPanelContainerComponent.Panel( - key: panelKey, - orderIndex: 3, - component: AnyComponent(LegacyChatHeaderPanelComponent( - panelNode: titleAccessoryPanelNode, - interfaceState: self.chatPresentationInterfaceState - ))) - ) + if titleAccessoryPanelNode is ChatManagingBotTitlePanelNode, self.shouldDisplayPinnedTitlePanel { + let pinnedPanelNode: ChatPinnedMessageTitlePanelNode + if let current = self.currentPinnedTitleAccessoryPanelNode { + pinnedPanelNode = current + } else { + pinnedPanelNode = ChatPinnedMessageTitlePanelNode(context: self.context, animationCache: self.controllerInteraction.presentationContext.animationCache, animationRenderer: self.controllerInteraction.presentationContext.animationRenderer) + pinnedPanelNode.interfaceInteraction = self.interfaceInteraction + self.currentPinnedTitleAccessoryPanelNode = pinnedPanelNode + } + + headerPanels.append(HeaderPanelContainerComponent.Panel( + key: "\(ChatPinnedMessageTitlePanelNode.self)", + orderIndex: 3, + component: AnyComponent(LegacyChatHeaderPanelComponent( + panelNode: pinnedPanelNode, + interfaceState: self.chatPresentationInterfaceState + ))) + ) + headerPanels.append(HeaderPanelContainerComponent.Panel( + key: "\(type(of: titleAccessoryPanelNode))", + orderIndex: 4, + component: AnyComponent(LegacyChatHeaderPanelComponent( + panelNode: titleAccessoryPanelNode, + interfaceState: self.chatPresentationInterfaceState + ))) + ) + } else { + self.currentPinnedTitleAccessoryPanelNode = nil + + let panelKey = "\(type(of: titleAccessoryPanelNode))" + headerPanels.append(HeaderPanelContainerComponent.Panel( + key: panelKey, + orderIndex: 3, + component: AnyComponent(LegacyChatHeaderPanelComponent( + panelNode: titleAccessoryPanelNode, + interfaceState: self.chatPresentationInterfaceState + ))) + ) + } } else { self.currentTitleAccessoryPanelNode = nil + self.currentPinnedTitleAccessoryPanelNode = nil } var displayFeePanel: (value: Int64, peer: EnginePeer)?