From ee65882c96336d871a9227e75a7cb8911a5258fc Mon Sep 17 00:00:00 2001 From: Ali <> Date: Mon, 24 Oct 2022 00:01:57 +0400 Subject: [PATCH] [WIP] Topics --- .../Sources/Node/ChatListItem.swift | 40 +++++++++++++------ .../Sources/State/AccountStateManager.swift | 4 +- .../Sources/ChatAvatarNavigationNode.swift | 3 +- .../TelegramUI/Sources/ChatController.swift | 2 +- .../Sources/ChatMessageNotificationItem.swift | 4 ++ 5 files changed, 37 insertions(+), 16 deletions(-) diff --git a/submodules/ChatListUI/Sources/Node/ChatListItem.swift b/submodules/ChatListUI/Sources/Node/ChatListItem.swift index 6a74b4bf32..e45a1d9459 100644 --- a/submodules/ChatListUI/Sources/Node/ChatListItem.swift +++ b/submodules/ChatListUI/Sources/Node/ChatListItem.swift @@ -553,9 +553,11 @@ class ChatListItemNode: ItemListRevealOptionsItemNode { if let topic = topic { remainingWidth -= 22.0 + 2.0 - arrowIconImage = PresentationResourcesChatList.topicArrowIcon(theme) - if let arrowIconImage = arrowIconImage { - remainingWidth -= arrowIconImage.size.width + 6.0 * 2.0 + if authorTitle != nil { + arrowIconImage = PresentationResourcesChatList.topicArrowIcon(theme) + if let arrowIconImage = arrowIconImage { + remainingWidth -= arrowIconImage.size.width + 6.0 * 2.0 + } } topicTitleArguments = TextNodeLayoutArguments(attributedString: topic.title, backgroundColor: nil, maximumNumberOfLines: 1, truncationType: .end, constrainedSize: CGSize(width: remainingWidth, height: CGFloat.greatestFiniteMagnitude), alignment: .natural, cutout: nil, insets: UIEdgeInsets(top: 2.0, left: 1.0, bottom: 2.0, right: 1.0)) @@ -565,6 +567,7 @@ class ChatListItemNode: ItemListRevealOptionsItemNode { var size = authorTitleLayout.0.size if let topicTitleLayout = topicTitleLayout { + size.height = max(size.height, topicTitleLayout.0.size.height) size.width += 10.0 + topicTitleLayout.0.size.width } @@ -578,7 +581,11 @@ class ChatListItemNode: ItemListRevealOptionsItemNode { self.authorNode.frame = authorFrame var nextX = authorFrame.maxX - 1.0 - if let arrowIconImage = arrowIconImage, let topic = topic { + if authorTitle == nil { + nextX = 0.0 + } + + if let arrowIconImage = arrowIconImage { let titleTopicArrowNode: ASImageNode if let current = self.titleTopicArrowNode { titleTopicArrowNode = current @@ -591,7 +598,14 @@ class ChatListItemNode: ItemListRevealOptionsItemNode { nextX += 6.0 titleTopicArrowNode.frame = CGRect(origin: CGPoint(x: nextX, y: 5.0), size: arrowIconImage.size) nextX += arrowIconImage.size.width + 6.0 - + } else { + if let titleTopicArrowNode = self.titleTopicArrowNode { + self.titleTopicArrowNode = nil + titleTopicArrowNode.removeFromSupernode() + } + } + + if let topic { let titleTopicIconView: ComponentHostView if let current = self.titleTopicIconView { titleTopicIconView = current @@ -627,10 +641,6 @@ class ChatListItemNode: ItemListRevealOptionsItemNode { titleTopicIconView.frame = CGRect(origin: CGPoint(x: nextX, y: UIScreenPixel), size: iconSize) nextX += iconSize.width + 2.0 } else { - if let titleTopicArrowNode = self.titleTopicArrowNode { - self.titleTopicArrowNode = nil - titleTopicArrowNode.removeFromSupernode() - } if let titleTopicIconView = self.titleTopicIconView { self.titleTopicIconView = nil titleTopicIconView.removeFromSuperview() @@ -1315,6 +1325,7 @@ class ChatListItemNode: ItemListRevealOptionsItemNode { } var authorAttributedString: NSAttributedString? + var authorIsCurrentChat: Bool = false var textAttributedString: NSAttributedString? var textLeftCutout: CGFloat = 0.0 var dateAttributedString: NSAttributedString? @@ -1452,6 +1463,7 @@ class ChatListItemNode: ItemListRevealOptionsItemNode { peerText = authorSignature } else { peerText = author.id == account.peerId ? item.presentationData.strings.DialogList_You : EnginePeer(author).displayTitle(strings: item.presentationData.strings, displayOrder: item.presentationData.nameDisplayOrder) + authorIsCurrentChat = author.id == peer.id } } } @@ -1919,14 +1931,16 @@ class ChatListItemNode: ItemListRevealOptionsItemNode { } badgeSize = max(badgeSize, reorderInset) - let authorTitle = (hideAuthor && !hasDraft) ? nil : authorAttributedString + var effectiveAuthorTitle = (hideAuthor && !hasDraft) ? nil : authorAttributedString var forumThreadTitle: (title: NSAttributedString, iconId: Int64?, iconColor: Int32)? - if let _ = authorTitle, let forumThread { + if let _ = effectiveAuthorTitle, let forumThread { + if authorIsCurrentChat { + effectiveAuthorTitle = nil + } forumThreadTitle = (NSAttributedString(string: forumThread.title, font: textFont, textColor: theme.authorNameColor), forumThread.iconId, forumThread.iconColor) } - - let (authorLayout, authorApply) = authorLayout(item.context, rawContentWidth - badgeSize, item.presentationData.theme, authorTitle, forumThreadTitle) + let (authorLayout, authorApply) = authorLayout(item.context, rawContentWidth - badgeSize, item.presentationData.theme, effectiveAuthorTitle, forumThreadTitle) var textCutout: TextNodeCutout? if !textLeftCutout.isZero { diff --git a/submodules/TelegramCore/Sources/State/AccountStateManager.swift b/submodules/TelegramCore/Sources/State/AccountStateManager.swift index a735ec0d9c..5880f84a6e 100644 --- a/submodules/TelegramCore/Sources/State/AccountStateManager.swift +++ b/submodules/TelegramCore/Sources/State/AccountStateManager.swift @@ -1394,7 +1394,9 @@ public func messagesForNotification(transaction: Transaction, id: MessageId, alw } } } - + if threadData == nil, let threadId = message.threadId { + threadData = transaction.getMessageHistoryThreadInfo(peerId: message.id.peerId, threadId: threadId)?.data.get(MessageHistoryThreadData.self) + } for media in message.media { if let action = media as? TelegramMediaAction { diff --git a/submodules/TelegramUI/Sources/ChatAvatarNavigationNode.swift b/submodules/TelegramUI/Sources/ChatAvatarNavigationNode.swift index 20dc58de6a..449ef782aa 100644 --- a/submodules/TelegramUI/Sources/ChatAvatarNavigationNode.swift +++ b/submodules/TelegramUI/Sources/ChatAvatarNavigationNode.swift @@ -47,7 +47,7 @@ final class ChatAvatarNavigationNode: ASDisplayNode { } var contextAction: ((ASDisplayNode, ContextGesture?) -> Void)? - var contextActionIsEnabled: Bool = true { + var contextActionIsEnabled: Bool = false { didSet { if self.contextActionIsEnabled != oldValue { self.containerNode.isGestureEnabled = self.contextActionIsEnabled @@ -57,6 +57,7 @@ final class ChatAvatarNavigationNode: ASDisplayNode { override init() { self.containerNode = ContextControllerSourceNode() + self.containerNode.isGestureEnabled = false self.avatarNode = AvatarNode(font: normalFont) self.statusView = ComponentView() diff --git a/submodules/TelegramUI/Sources/ChatController.swift b/submodules/TelegramUI/Sources/ChatController.swift index 958004a011..df4f48b194 100644 --- a/submodules/TelegramUI/Sources/ChatController.swift +++ b/submodules/TelegramUI/Sources/ChatController.swift @@ -4420,7 +4420,7 @@ 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 + (strongSelf.chatInfoNavigationButton?.buttonItem.customDisplayNode as? ChatAvatarNavigationNode)?.contextActionIsEnabled = strongSelf.chatLocation.threadId == nil && peer.restrictionText(platform: "ios", contentSettings: strongSelf.context.currentContentSettings.with { $0 }) == nil strongSelf.chatInfoNavigationButton?.buttonItem.accessibilityLabel = presentationInterfaceState.strings.Conversation_ContextMenuOpenProfile } } diff --git a/submodules/TelegramUI/Sources/ChatMessageNotificationItem.swift b/submodules/TelegramUI/Sources/ChatMessageNotificationItem.swift index 965f09ee83..07e1fda1ae 100644 --- a/submodules/TelegramUI/Sources/ChatMessageNotificationItem.swift +++ b/submodules/TelegramUI/Sources/ChatMessageNotificationItem.swift @@ -155,6 +155,10 @@ final class ChatMessageNotificationItemNode: NotificationItemNode { break } } + + if let titleValue = title, let threadData = item.threadData { + title = "\(threadData.info.title) (\(titleValue))" + } } } else { title = peer.displayTitle(strings: item.strings, displayOrder: item.nameDisplayOrder)