diff --git a/submodules/ChatListUI/Sources/Node/ChatListItem.swift b/submodules/ChatListUI/Sources/Node/ChatListItem.swift index 9261614586..21201a83c3 100644 --- a/submodules/ChatListUI/Sources/Node/ChatListItem.swift +++ b/submodules/ChatListUI/Sources/Node/ChatListItem.swift @@ -2154,7 +2154,11 @@ public class ChatListItemNode: ItemListRevealOptionsItemNode { topForumTopicItems = topForumTopicItemsValue if item.interaction.searchTextHighightState != nil, threadInfo == nil, topForumTopicItems.isEmpty, let message = messagesValue.first, let threadId = message.threadId, let associatedThreadInfo = message.associatedThreadInfo { - topForumTopicItems = [EngineChatList.ForumTopicData(id: threadId, title: associatedThreadInfo.title, iconFileId: associatedThreadInfo.icon, iconColor: associatedThreadInfo.iconColor, maxOutgoingReadMessageId: message.id, isUnread: false, threadPeer: nil)] + var threadPeer: EnginePeer? + if case let .channel(channel) = peerValue.peer, channel.isMonoForum { + threadPeer = message.peers[EnginePeer.Id(threadId)].flatMap(EnginePeer.init) + } + topForumTopicItems = [EngineChatList.ForumTopicData(id: threadId, title: associatedThreadInfo.title, iconFileId: associatedThreadInfo.icon, iconColor: associatedThreadInfo.iconColor, maxOutgoingReadMessageId: message.id, isUnread: false, threadPeer: threadPeer)] } switch peerValue.peer { diff --git a/submodules/ContactsPeerItem/Sources/ContactsPeerItem.swift b/submodules/ContactsPeerItem/Sources/ContactsPeerItem.swift index f46776de21..594cec55dd 100644 --- a/submodules/ContactsPeerItem/Sources/ContactsPeerItem.swift +++ b/submodules/ContactsPeerItem/Sources/ContactsPeerItem.swift @@ -452,6 +452,7 @@ public class ContactsPeerItemNode: ItemListRevealOptionsItemNode { private var avatarIconView: ComponentHostView? private var avatarIconComponent: EmojiStatusComponent? public let titleNode: TextNode + private var titleBadge: (backgroundView: UIImageView, textNode: TextNode)? private var credibilityIconView: ComponentHostView? private var credibilityIconComponent: EmojiStatusComponent? private var verifiedIconView: ComponentHostView? @@ -735,6 +736,7 @@ public class ContactsPeerItemNode: ItemListRevealOptionsItemNode { public func asyncLayout() -> (_ item: ContactsPeerItem, _ params: ListViewItemLayoutParams, _ first: Bool, _ last: Bool, _ firstWithHeader: Bool, _ neighbors: ItemListNeighbors) -> (ListViewItemNodeLayout, () -> (Signal?, (Bool, Bool) -> Void)) { let makeTitleLayout = TextNode.asyncLayout(self.titleNode) + let titleBadgeLayout = TextNode.asyncLayout(self.titleBadge?.textNode) let makeStatusLayout = TextNodeWithEntities.asyncLayout(self.statusNode) let currentSelectionNode = self.selectionNode @@ -933,11 +935,7 @@ public class ContactsPeerItemNode: ItemListRevealOptionsItemNode { } else if case let .legacyGroup(group) = peer { titleAttributedString = NSAttributedString(string: group.title, font: titleBoldFont, textColor: item.presentationData.theme.list.itemPrimaryTextColor) } else if case let .channel(channel) = peer { - if case let .channel(mainChannel) = chatPeer, mainChannel.isMonoForum { - titleAttributedString = NSAttributedString(string: item.presentationData.strings.Monoforum_NameFormat(channel.title).string, font: titleBoldFont, textColor: item.presentationData.theme.list.itemPrimaryTextColor) - } else { - titleAttributedString = NSAttributedString(string: channel.title, font: titleBoldFont, textColor: item.presentationData.theme.list.itemPrimaryTextColor) - } + titleAttributedString = NSAttributedString(string: channel.title, font: titleBoldFont, textColor: item.presentationData.theme.list.itemPrimaryTextColor) } switch item.status { @@ -1120,7 +1118,21 @@ public class ContactsPeerItemNode: ItemListRevealOptionsItemNode { additionalTitleInset += rightLabelTextLayoutAndApply.0.size.width + 36.0 } - let (titleLayout, titleApply) = makeTitleLayout(TextNodeLayoutArguments(attributedString: titleAttributedString, backgroundColor: nil, maximumNumberOfLines: 1, truncationType: .end, constrainedSize: CGSize(width: max(0.0, params.width - leftInset - rightInset - additionalTitleInset), height: CGFloat.infinity), alignment: .natural, cutout: nil, insets: UIEdgeInsets())) + var titleBadgeText: String? + if case let .peer(_, chatPeer) = item.peer, case let .channel(channel) = chatPeer, channel.isMonoForum { + titleBadgeText = item.presentationData.strings.ChatList_MonoforumLabel + } + + var maxTextWidth: CGFloat = params.width - leftInset - rightInset - additionalTitleInset + + var titleBadgeLayoutAndApply: (TextNodeLayout, () -> TextNode)? + if let titleBadgeText { + let titleBadgeLayoutAndApplyValue = titleBadgeLayout(TextNodeLayoutArguments(attributedString: NSAttributedString(string: titleBadgeText, font: Font.semibold(11.0), textColor: item.presentationData.theme.chatList.titleColor.withMultipliedAlpha(0.4)), backgroundColor: nil, maximumNumberOfLines: 1, truncationType: .end, constrainedSize: CGSize(width: maxTextWidth, height: CGFloat.greatestFiniteMagnitude), alignment: .natural, cutout: nil, insets: UIEdgeInsets())) + titleBadgeLayoutAndApply = titleBadgeLayoutAndApplyValue + maxTextWidth = max(0.0, maxTextWidth - titleBadgeLayoutAndApplyValue.0.size.width - 8.0) + } + + let (titleLayout, titleApply) = makeTitleLayout(TextNodeLayoutArguments(attributedString: titleAttributedString, backgroundColor: nil, maximumNumberOfLines: 1, truncationType: .end, constrainedSize: CGSize(width: max(0.0, maxTextWidth), height: CGFloat.infinity), alignment: .natural, cutout: nil, insets: UIEdgeInsets())) var maxStatusWidth: CGFloat = params.width - leftInset - rightInset - badgeSize if let _ = statusIcon { @@ -1565,6 +1577,37 @@ public class ContactsPeerItemNode: ItemListRevealOptionsItemNode { strongSelf.credibilityIconView = nil credibilityIconView.removeFromSuperview() } + + if let (titleBadgeLayout, titleBadgeApply) = titleBadgeLayoutAndApply { + let titleBadgeNode = titleBadgeApply() + let backgroundView: UIImageView + if let current = strongSelf.titleBadge { + backgroundView = current.backgroundView + } else { + backgroundView = UIImageView(image: generateStretchableFilledCircleImage(radius: 4.0, color: .white)?.withRenderingMode(.alwaysTemplate)) + strongSelf.titleBadge = (backgroundView, titleBadgeNode) + + strongSelf.offsetContainerNode.view.addSubview(backgroundView) + strongSelf.offsetContainerNode.addSubnode(titleBadgeNode) + } + nextIconX += 10.0 + let titleBadgeFrame = CGRect(origin: CGPoint(x: nextIconX, y: titleFrame.minY + floor((titleFrame.height - titleBadgeLayout.size.height) * 0.5)), size: titleBadgeLayout.size) + nextIconX += titleBadgeLayout.size.width + 4.0 + titleBadgeNode.frame = titleBadgeFrame + + var titleBadgeBackgroundFrame = titleBadgeFrame.insetBy(dx: -4.0, dy: -2.0) + titleBadgeBackgroundFrame.size.height -= 1.0 + backgroundView.frame = titleBadgeBackgroundFrame + if item.presentationData.theme.overallDarkAppearance { + backgroundView.tintColor = item.presentationData.theme.chatList.titleColor.withMultipliedAlpha(0.1) + } else { + backgroundView.tintColor = item.presentationData.theme.chatList.titleColor.withMultipliedAlpha(0.05) + } + } else if let titleBadge = strongSelf.titleBadge { + strongSelf.titleBadge = nil + titleBadge.backgroundView.removeFromSuperview() + titleBadge.textNode.removeFromSupernode() + } var additionalRightInset: CGFloat = 0.0 if let (titleLayout, titleApply) = actionButtonTitleLayoutAndApply { diff --git a/submodules/TelegramCore/Sources/Utils/MessageUtils.swift b/submodules/TelegramCore/Sources/Utils/MessageUtils.swift index cb3b5a8c40..393234c0a0 100644 --- a/submodules/TelegramCore/Sources/Utils/MessageUtils.swift +++ b/submodules/TelegramCore/Sources/Utils/MessageUtils.swift @@ -234,6 +234,18 @@ func locallyRenderedMessage(message: StoreMessage, peers: [PeerId: Peer], associ messagePeers[channelPeer.id] = channelPeer } } + + if let channel = peer as? TelegramChannel, channel.isMonoForum, let linkedMonoforumId = channel.linkedMonoforumId { + if let channelPeer = peers[linkedMonoforumId] { + messagePeers[channelPeer.id] = channelPeer + } + + if let threadId = message.threadId { + if let threadPeer = peers[PeerId(threadId)] { + messagePeers[threadPeer.id] = threadPeer + } + } + } } for media in message.media { diff --git a/submodules/TelegramCore/Sources/Utils/PeerUtils.swift b/submodules/TelegramCore/Sources/Utils/PeerUtils.swift index eb40aaa6a8..02cfe99123 100644 --- a/submodules/TelegramCore/Sources/Utils/PeerUtils.swift +++ b/submodules/TelegramCore/Sources/Utils/PeerUtils.swift @@ -485,6 +485,10 @@ public extension RenderedPeer { if let regularPeer = message.peers[peer.regularPeerId] { peers[regularPeer.id] = regularPeer } + } else if let peer = peer as? TelegramChannel, peer.isMonoForum, let linkedMonoforumId = peer.linkedMonoforumId { + if let regularPeer = message.peers[linkedMonoforumId] { + peers[regularPeer.id] = regularPeer + } } } self.init(peerId: message.id.peerId, peers: peers, associatedMedia: [:])