From e43dcbfaca655652d2215e14d17c22a5baaa137f Mon Sep 17 00:00:00 2001 From: Ali <> Date: Sat, 25 Apr 2020 18:00:03 +0400 Subject: [PATCH] Psa-related fixes --- .../AuthTransferConfirmationScreen.swift | 2 +- .../ChatListUI/Sources/ChatContextMenus.swift | 6 ++- .../Sources/ChatListController.swift | 8 ++-- .../Sources/Node/ChatListItem.swift | 6 ++- .../Display/Source/ImmediateTextNode.swift | 12 ++--- .../Display/Source/TextAlertController.swift | 2 +- .../ChatItemGalleryFooterContentNode.swift | 4 +- .../InstantPageGalleryFooterContentNode.swift | 4 +- .../LanguageLinkPreviewContentNode.swift | 2 +- .../Sources/SecureIdAuthFormContentNode.swift | 2 +- .../Postbox/Sources/MessageHistoryTable.swift | 20 ++++++-- .../TermsOfServiceControllerNode.swift | 4 +- .../StickerPackPreviewControllerNode.swift | 2 +- ...rizationSequenceSignUpControllerNode.swift | 2 +- .../TelegramUI/Sources/ChatController.swift | 10 ++-- submodules/TooltipUI/BUCK | 1 + submodules/TooltipUI/BUILD | 1 + .../TooltipUI/Sources/TooltipScreen.swift | 48 ++++++++++++++----- .../WalletUI/Sources/WalletSplashScreen.swift | 2 +- 19 files changed, 93 insertions(+), 45 deletions(-) diff --git a/submodules/AuthTransferUI/Sources/AuthTransferConfirmationScreen.swift b/submodules/AuthTransferUI/Sources/AuthTransferConfirmationScreen.swift index 0d42f38bf3..4f966b5450 100644 --- a/submodules/AuthTransferUI/Sources/AuthTransferConfirmationScreen.swift +++ b/submodules/AuthTransferUI/Sources/AuthTransferConfirmationScreen.swift @@ -274,7 +274,7 @@ private final class AuthDataTransferSplashScreenNode: ViewControllerTracingNode return nil } } - textNode.tapAttributeAction = { attributes in + textNode.tapAttributeAction = { attributes, _ in if let _ = attributes[NSAttributedString.Key(rawValue: "URL")] { context.sharedContext.openExternalUrl(context: context, urlContext: .generic, url: "https://desktop.telegram.org", forceExternal: true, presentationData: context.sharedContext.currentPresentationData.with { $0 }, navigationController: nil, dismissInput: {}) } diff --git a/submodules/ChatListUI/Sources/ChatContextMenus.swift b/submodules/ChatListUI/Sources/ChatContextMenus.swift index 13e1fc7aec..feb3d752e1 100644 --- a/submodules/ChatListUI/Sources/ChatContextMenus.swift +++ b/submodules/ChatListUI/Sources/ChatContextMenus.swift @@ -44,9 +44,13 @@ enum ChatContextMenuSource { case search(ChatListSearchContextActionSource) } -func chatContextMenuItems(context: AccountContext, peerId: PeerId, source: ChatContextMenuSource, chatListController: ChatListControllerImpl?) -> Signal<[ContextMenuItem], NoError> { +func chatContextMenuItems(context: AccountContext, peerId: PeerId, promoInfo: ChatListNodeEntryPromoInfo?, source: ChatContextMenuSource, chatListController: ChatListControllerImpl?) -> Signal<[ContextMenuItem], NoError> { let strings = context.sharedContext.currentPresentationData.with({ $0 }).strings return context.account.postbox.transaction { [weak chatListController] transaction -> [ContextMenuItem] in + if promoInfo != nil { + return [] + } + var items: [ContextMenuItem] = [] if case let .search(search) = source { diff --git a/submodules/ChatListUI/Sources/ChatListController.swift b/submodules/ChatListUI/Sources/ChatListController.swift index 86b3008cc5..ac1863f340 100644 --- a/submodules/ChatListUI/Sources/ChatListController.swift +++ b/submodules/ChatListUI/Sources/ChatListController.swift @@ -801,10 +801,10 @@ public class ChatListControllerImpl: TelegramBaseController, ChatListController, chatListController.navigationPresentation = .master let contextController = ContextController(account: strongSelf.context.account, presentationData: strongSelf.presentationData, source: .controller(ContextControllerContentSourceImpl(controller: chatListController, sourceNode: node, navigationController: strongSelf.navigationController as? NavigationController)), items: archiveContextMenuItems(context: strongSelf.context, groupId: groupReference.groupId, chatListController: strongSelf), reactionItems: [], gesture: gesture) strongSelf.presentInGlobalOverlay(contextController) - case let .peer(peer): - let chatController = strongSelf.context.sharedContext.makeChatController(context: strongSelf.context, chatLocation: .peer(peer.peer.peerId), subject: nil, botStart: nil, mode: .standard(previewing: true)) + case let .peer(_, peer, _, _, _, _, _, _, promoInfo, _, _, _): + let chatController = strongSelf.context.sharedContext.makeChatController(context: strongSelf.context, chatLocation: .peer(peer.peerId), subject: nil, botStart: nil, mode: .standard(previewing: true)) chatController.canReadHistory.set(false) - let contextController = ContextController(account: strongSelf.context.account, presentationData: strongSelf.presentationData, source: .controller(ContextControllerContentSourceImpl(controller: chatController, sourceNode: node, navigationController: strongSelf.navigationController as? NavigationController)), items: chatContextMenuItems(context: strongSelf.context, peerId: peer.peer.peerId, source: .chatList(filter: strongSelf.chatListDisplayNode.containerNode.currentItemNode.chatListFilter), chatListController: strongSelf), reactionItems: [], gesture: gesture) + let contextController = ContextController(account: strongSelf.context.account, presentationData: strongSelf.presentationData, source: .controller(ContextControllerContentSourceImpl(controller: chatController, sourceNode: node, navigationController: strongSelf.navigationController as? NavigationController)), items: chatContextMenuItems(context: strongSelf.context, peerId: peer.peerId, promoInfo: promoInfo, source: .chatList(filter: strongSelf.chatListDisplayNode.containerNode.currentItemNode.chatListFilter), chatListController: strongSelf), reactionItems: [], gesture: gesture) strongSelf.presentInGlobalOverlay(contextController) } } @@ -817,7 +817,7 @@ public class ChatListControllerImpl: TelegramBaseController, ChatListController, let chatController = strongSelf.context.sharedContext.makeChatController(context: strongSelf.context, chatLocation: .peer(peer.id), subject: nil, botStart: nil, mode: .standard(previewing: true)) chatController.canReadHistory.set(false) - let contextController = ContextController(account: strongSelf.context.account, presentationData: strongSelf.presentationData, source: .controller(ContextControllerContentSourceImpl(controller: chatController, sourceNode: node, navigationController: strongSelf.navigationController as? NavigationController)), items: chatContextMenuItems(context: strongSelf.context, peerId: peer.id, source: .search(source), chatListController: strongSelf), reactionItems: [], gesture: gesture) + let contextController = ContextController(account: strongSelf.context.account, presentationData: strongSelf.presentationData, source: .controller(ContextControllerContentSourceImpl(controller: chatController, sourceNode: node, navigationController: strongSelf.navigationController as? NavigationController)), items: chatContextMenuItems(context: strongSelf.context, peerId: peer.id, promoInfo: nil, source: .search(source), chatListController: strongSelf), reactionItems: [], gesture: gesture) strongSelf.presentInGlobalOverlay(contextController) } diff --git a/submodules/ChatListUI/Sources/Node/ChatListItem.swift b/submodules/ChatListUI/Sources/Node/ChatListItem.swift index f329a09d65..ad8d0eee86 100644 --- a/submodules/ChatListUI/Sources/Node/ChatListItem.swift +++ b/submodules/ChatListUI/Sources/Node/ChatListItem.swift @@ -651,8 +651,10 @@ class ChatListItemNode: ItemListRevealOptionsItemNode { guard let item = self.item, item.editing else { return } - if case .peer = item.content { - item.interaction.togglePeerSelected(item.index.messageIndex.id.peerId) + if case let .peer(_, _, _, _, _, _, _, _, promoInfo, _, _, _) = item.content { + if promoInfo == nil { + item.interaction.togglePeerSelected(item.index.messageIndex.id.peerId) + } } } diff --git a/submodules/Display/Source/ImmediateTextNode.swift b/submodules/Display/Source/ImmediateTextNode.swift index 75116832f0..8111c08e9d 100644 --- a/submodules/Display/Source/ImmediateTextNode.swift +++ b/submodules/Display/Source/ImmediateTextNode.swift @@ -60,8 +60,8 @@ public class ImmediateTextNode: TextNode { } } - public var tapAttributeAction: (([NSAttributedString.Key: Any]) -> Void)? - public var longTapAttributeAction: (([NSAttributedString.Key: Any]) -> Void)? + public var tapAttributeAction: (([NSAttributedString.Key: Any], Int) -> Void)? + public var longTapAttributeAction: (([NSAttributedString.Key: Any], Int) -> Void)? public func makeCopy() -> TextNode { let node = TextNode() @@ -179,12 +179,12 @@ public class ImmediateTextNode: TextNode { if let (gesture, location) = recognizer.lastRecognizedGestureAndLocation { switch gesture { case .tap: - if let (_, attributes) = self.attributesAtPoint(CGPoint(x: location.x, y: location.y)) { - self.tapAttributeAction?(attributes) + if let (index, attributes) = self.attributesAtPoint(CGPoint(x: location.x, y: location.y)) { + self.tapAttributeAction?(attributes, index) } case .longTap: - if let (_, attributes) = self.attributesAtPoint(CGPoint(x: location.x, y: location.y)) { - self.longTapAttributeAction?(attributes) + if let (index, attributes) = self.attributesAtPoint(CGPoint(x: location.x, y: location.y)) { + self.longTapAttributeAction?(attributes, index) } default: break diff --git a/submodules/Display/Source/TextAlertController.swift b/submodules/Display/Source/TextAlertController.swift index 969990714d..cd06ed2fab 100644 --- a/submodules/Display/Source/TextAlertController.swift +++ b/submodules/Display/Source/TextAlertController.swift @@ -147,7 +147,7 @@ public final class TextAlertContentNode: AlertContentNode { return nil } } - self.textNode.tapAttributeAction = { attributes in + self.textNode.tapAttributeAction = { attributes, _ in if let value = attributes[attribute] { textAttributeAction(value) } diff --git a/submodules/GalleryUI/Sources/ChatItemGalleryFooterContentNode.swift b/submodules/GalleryUI/Sources/ChatItemGalleryFooterContentNode.swift index 2a31c310a1..f0fda70373 100644 --- a/submodules/GalleryUI/Sources/ChatItemGalleryFooterContentNode.swift +++ b/submodules/GalleryUI/Sources/ChatItemGalleryFooterContentNode.swift @@ -314,12 +314,12 @@ final class ChatItemGalleryFooterContentNode: GalleryFooterContentNode, UIScroll } return nil } - self.textNode.tapAttributeAction = { [weak self] attributes in + self.textNode.tapAttributeAction = { [weak self] attributes, _ in if let strongSelf = self, let action = strongSelf.actionForAttributes(attributes) { strongSelf.performAction?(action) } } - self.textNode.longTapAttributeAction = { [weak self] attributes in + self.textNode.longTapAttributeAction = { [weak self] attributes, _ in if let strongSelf = self, let action = strongSelf.actionForAttributes(attributes) { strongSelf.openActionOptions?(action) } diff --git a/submodules/InstantPageUI/Sources/InstantPageGalleryFooterContentNode.swift b/submodules/InstantPageUI/Sources/InstantPageGalleryFooterContentNode.swift index 38c92ee1c2..3dba623006 100644 --- a/submodules/InstantPageUI/Sources/InstantPageGalleryFooterContentNode.swift +++ b/submodules/InstantPageUI/Sources/InstantPageGalleryFooterContentNode.swift @@ -55,12 +55,12 @@ final class InstantPageGalleryFooterContentNode: GalleryFooterContentNode { return nil } } - self.textNode.tapAttributeAction = { [weak self] attributes in + self.textNode.tapAttributeAction = { [weak self] attributes, _ in if let strongSelf = self, let url = attributes[NSAttributedString.Key(rawValue: TelegramTextAttributes.URL)] as? InstantPageUrlItem { strongSelf.openUrl?(url) } } - self.textNode.longTapAttributeAction = { [weak self] attributes in + self.textNode.longTapAttributeAction = { [weak self] attributes, _ in if let strongSelf = self, let url = attributes[NSAttributedString.Key(rawValue: TelegramTextAttributes.URL)] as? InstantPageUrlItem { strongSelf.openUrlOptions?(url) } diff --git a/submodules/LanguageLinkPreviewUI/Sources/LanguageLinkPreviewContentNode.swift b/submodules/LanguageLinkPreviewUI/Sources/LanguageLinkPreviewContentNode.swift index a7cd7edb06..84db84a984 100644 --- a/submodules/LanguageLinkPreviewUI/Sources/LanguageLinkPreviewContentNode.swift +++ b/submodules/LanguageLinkPreviewUI/Sources/LanguageLinkPreviewContentNode.swift @@ -58,7 +58,7 @@ final class LanguageLinkPreviewContentNode: ASDisplayNode, ShareContentContainer return nil } } - self.textNode.tapAttributeAction = { attributes in + self.textNode.tapAttributeAction = { attributes, _ in if let _ = attributes[NSAttributedString.Key(rawValue: TelegramTextAttributes.URL)] { let url: String if localizationInfo.platformUrl.isEmpty { diff --git a/submodules/PassportUI/Sources/SecureIdAuthFormContentNode.swift b/submodules/PassportUI/Sources/SecureIdAuthFormContentNode.swift index 12203600c2..065f2749c1 100644 --- a/submodules/PassportUI/Sources/SecureIdAuthFormContentNode.swift +++ b/submodules/PassportUI/Sources/SecureIdAuthFormContentNode.swift @@ -80,7 +80,7 @@ final class SecureIdAuthFormContentNode: ASDisplayNode, SecureIdAuthContentNode, return nil } } - self.textNode.tapAttributeAction = { attributes in + self.textNode.tapAttributeAction = { attributes, _ in if let url = attributes[NSAttributedString.Key(rawValue: TelegramTextAttributes.URL)] as? String { openURL(url) } else if let mention = attributes[NSAttributedString.Key(rawValue: TelegramTextAttributes.PeerMention)] as? TelegramPeerMention { diff --git a/submodules/Postbox/Sources/MessageHistoryTable.swift b/submodules/Postbox/Sources/MessageHistoryTable.swift index 36341ded6a..ea456c2704 100644 --- a/submodules/Postbox/Sources/MessageHistoryTable.swift +++ b/submodules/Postbox/Sources/MessageHistoryTable.swift @@ -1561,13 +1561,16 @@ final class MessageHistoryTable: Table { var forwardInfoFlags: Int8 = 1 if forwardInfo.sourceId != nil { - forwardInfoFlags |= 2 + forwardInfoFlags |= 1 << 1 } if forwardInfo.sourceMessageId != nil { - forwardInfoFlags |= 4 + forwardInfoFlags |= 1 << 2 } if forwardInfo.authorSignature != nil { - forwardInfoFlags |= 8 + forwardInfoFlags |= 1 << 3 + } + if forwardInfo.psaType != nil { + forwardInfoFlags |= 1 << 4 } sharedBuffer.write(&forwardInfoFlags, offset: 0, length: 1) var forwardAuthorId: Int64 = forwardInfo.authorId?.toInt64() ?? 0 @@ -1599,6 +1602,17 @@ final class MessageHistoryTable: Table { sharedBuffer.write(&length, offset: 0, length: 4) } } + + if let psaType = forwardInfo.psaType { + if let data = psaType.data(using: .utf8, allowLossyConversion: true) { + var length: Int32 = Int32(data.count) + sharedBuffer.write(&length, offset: 0, length: 4) + sharedBuffer.write(data) + } else { + var length: Int32 = 0 + sharedBuffer.write(&length, offset: 0, length: 4) + } + } } else { var forwardInfoFlags: Int8 = 0 sharedBuffer.write(&forwardInfoFlags, offset: 0, length: 1) diff --git a/submodules/SettingsUI/Sources/Terms of Service/TermsOfServiceControllerNode.swift b/submodules/SettingsUI/Sources/Terms of Service/TermsOfServiceControllerNode.swift index 248452424c..3091119d69 100644 --- a/submodules/SettingsUI/Sources/Terms of Service/TermsOfServiceControllerNode.swift +++ b/submodules/SettingsUI/Sources/Terms of Service/TermsOfServiceControllerNode.swift @@ -152,7 +152,7 @@ final class TermsOfServiceControllerNode: ViewControllerTracingNode { strongSelf.present(actionSheet, nil) } - self.contentTextNode.tapAttributeAction = { [weak self] attributes in + self.contentTextNode.tapAttributeAction = { [weak self] attributes, _ in guard let strongSelf = self else { return } @@ -164,7 +164,7 @@ final class TermsOfServiceControllerNode: ViewControllerTracingNode { showMentionActionSheet(mention) } } - self.contentTextNode.longTapAttributeAction = { [weak self] attributes in + self.contentTextNode.longTapAttributeAction = { [weak self] attributes, _ in guard let strongSelf = self else { return } diff --git a/submodules/StickerPackPreviewUI/Sources/StickerPackPreviewControllerNode.swift b/submodules/StickerPackPreviewUI/Sources/StickerPackPreviewControllerNode.swift index 823b28822b..a7b3bfebb2 100644 --- a/submodules/StickerPackPreviewUI/Sources/StickerPackPreviewControllerNode.swift +++ b/submodules/StickerPackPreviewUI/Sources/StickerPackPreviewControllerNode.swift @@ -182,7 +182,7 @@ final class StickerPackPreviewControllerNode: ViewControllerTracingNode, UIScrol } } - self.contentTitleNode.tapAttributeAction = { attributes in + self.contentTitleNode.tapAttributeAction = { attributes, _ in if let mention = attributes[NSAttributedString.Key(rawValue: TelegramTextAttributes.PeerTextMention)] as? String, mention.count > 1 { openMention(String(mention[mention.index(after: mention.startIndex)...])) } diff --git a/submodules/TelegramUI/Sources/AuthorizationSequenceSignUpControllerNode.swift b/submodules/TelegramUI/Sources/AuthorizationSequenceSignUpControllerNode.swift index c20b22fda6..da601f2f1f 100644 --- a/submodules/TelegramUI/Sources/AuthorizationSequenceSignUpControllerNode.swift +++ b/submodules/TelegramUI/Sources/AuthorizationSequenceSignUpControllerNode.swift @@ -169,7 +169,7 @@ final class AuthorizationSequenceSignUpControllerNode: ASDisplayNode, UITextFiel return nil } } - self.termsNode.tapAttributeAction = { [weak self] attributes in + self.termsNode.tapAttributeAction = { [weak self] attributes, _ in if let _ = attributes[NSAttributedString.Key(rawValue: TelegramTextAttributes.URL)] { self?.openTermsOfService?() } diff --git a/submodules/TelegramUI/Sources/ChatController.swift b/submodules/TelegramUI/Sources/ChatController.swift index 09085d8d01..aeb5a8a418 100644 --- a/submodules/TelegramUI/Sources/ChatController.swift +++ b/submodules/TelegramUI/Sources/ChatController.swift @@ -6401,10 +6401,10 @@ public final class ChatControllerImpl: TelegramBaseController, ChatController, G return } switch item { - case let .url(url): + case let .url(url, concealed): switch action { case .tap: - strongSelf.openUrl(url, concealed: false) + strongSelf.openUrl(url, concealed: concealed) case .longTap: strongSelf.controllerInteraction?.longTap(.url(url), nil) } @@ -6489,7 +6489,7 @@ public final class ChatControllerImpl: TelegramBaseController, ChatController, G return } switch item { - case let .url(url): + case let .url(url, concealed): switch action { case .tap: strongSelf.openUrl(url, concealed: false) @@ -6575,14 +6575,14 @@ public final class ChatControllerImpl: TelegramBaseController, ChatController, G return } - let tooltipScreen = TooltipScreen(text: psaText, textEntities: psaEntities, icon: .info, location: .top, shouldDismissOnTouch: { point in + let tooltipScreen = TooltipScreen(text: psaText, textEntities: psaEntities, icon: .info, location: .top, displayDuration: .custom(10.0), shouldDismissOnTouch: { point in return .ignore }, openActiveTextItem: { [weak self] item, action in guard let strongSelf = self else { return } switch item { - case let .url(url): + case let .url(url, concealed): switch action { case .tap: strongSelf.openUrl(url, concealed: false) diff --git a/submodules/TooltipUI/BUCK b/submodules/TooltipUI/BUCK index fc70b99e7c..ee83e7145d 100644 --- a/submodules/TooltipUI/BUCK +++ b/submodules/TooltipUI/BUCK @@ -14,6 +14,7 @@ static_library( "//submodules/SyncCore:SyncCore#shared", "//submodules/TelegramCore:TelegramCore#shared", "//submodules/TextFormat:TextFormat", + "//submodules/UrlEscaping:UrlEscaping", ], frameworks = [ "$SDKROOT/System/Library/Frameworks/Foundation.framework", diff --git a/submodules/TooltipUI/BUILD b/submodules/TooltipUI/BUILD index 3af5dc456c..7b1a797388 100644 --- a/submodules/TooltipUI/BUILD +++ b/submodules/TooltipUI/BUILD @@ -15,6 +15,7 @@ swift_library( "//submodules/SyncCore:SyncCore", "//submodules/TelegramCore:TelegramCore", "//submodules/TextFormat:TextFormat", + "//submodules/UrlEscaping:UrlEscaping", ], visibility = [ "//visibility:public", diff --git a/submodules/TooltipUI/Sources/TooltipScreen.swift b/submodules/TooltipUI/Sources/TooltipScreen.swift index 0a8a517d9d..d10bcbc068 100644 --- a/submodules/TooltipUI/Sources/TooltipScreen.swift +++ b/submodules/TooltipUI/Sources/TooltipScreen.swift @@ -9,9 +9,10 @@ import SyncCore import TelegramCore import TextFormat import Postbox +import UrlEscaping public enum TooltipActiveTextItem { - case url(String) + case url(String, Bool) case mention(PeerId, String) case textMention(String) case botCommand(String) @@ -26,6 +27,7 @@ public enum TooltipActiveTextAction { private final class TooltipScreenNode: ViewControllerTracingNode { private let icon: TooltipScreen.Icon? private let location: TooltipScreen.Location + private let displayDuration: TooltipScreen.DisplayDuration private let shouldDismissOnTouch: (CGPoint) -> TooltipScreen.DismissOnTouch private let requestDismiss: () -> Void @@ -42,9 +44,10 @@ private final class TooltipScreenNode: ViewControllerTracingNode { private var validLayout: ContainerViewLayout? - init(text: String, textEntities: [MessageTextEntity], icon: TooltipScreen.Icon?, location: TooltipScreen.Location, shouldDismissOnTouch: @escaping (CGPoint) -> TooltipScreen.DismissOnTouch, requestDismiss: @escaping () -> Void, openActiveTextItem: @escaping (TooltipActiveTextItem, TooltipActiveTextAction) -> Void) { + init(text: String, textEntities: [MessageTextEntity], icon: TooltipScreen.Icon?, location: TooltipScreen.Location, displayDuration: TooltipScreen.DisplayDuration, shouldDismissOnTouch: @escaping (CGPoint) -> TooltipScreen.DismissOnTouch, requestDismiss: @escaping () -> Void, openActiveTextItem: @escaping (TooltipActiveTextItem, TooltipActiveTextAction) -> Void) { self.icon = icon self.location = location + self.displayDuration = displayDuration self.shouldDismissOnTouch = shouldDismissOnTouch self.requestDismiss = requestDismiss @@ -127,12 +130,16 @@ private final class TooltipScreenNode: ViewControllerTracingNode { } return nil } - self.textNode.tapAttributeAction = { [weak self] attributes in - guard let _ = self else { + self.textNode.tapAttributeAction = { [weak self] attributes, index in + guard let strongSelf = self else { return } if let url = attributes[NSAttributedString.Key(rawValue: TelegramTextAttributes.URL)] as? String { - openActiveTextItem(.url(url), .tap) + var concealed = true + if let (attributeText, fullText) = strongSelf.textNode.attributeSubstring(name: TelegramTextAttributes.URL, index: index) { + concealed = !doesUrlMatchText(url: url, text: attributeText, fullText: fullText) + } + openActiveTextItem(.url(url, concealed), .tap) } else if let mention = attributes[NSAttributedString.Key(rawValue: TelegramTextAttributes.PeerMention)] as? TelegramPeerMention { openActiveTextItem(.mention(mention.peerId, mention.mention), .tap) } else if let mention = attributes[NSAttributedString.Key(rawValue: TelegramTextAttributes.PeerTextMention)] as? String { @@ -144,12 +151,16 @@ private final class TooltipScreenNode: ViewControllerTracingNode { } } - self.textNode.longTapAttributeAction = { [weak self] attributes in - guard let _ = self else { + self.textNode.longTapAttributeAction = { [weak self] attributes, index in + guard let strongSelf = self else { return } if let url = attributes[NSAttributedString.Key(rawValue: TelegramTextAttributes.URL)] as? String { - openActiveTextItem(.url(url), .longTap) + var concealed = true + if let (attributeText, fullText) = strongSelf.textNode.attributeSubstring(name: TelegramTextAttributes.URL, index: index) { + concealed = !doesUrlMatchText(url: url, text: attributeText, fullText: fullText) + } + openActiveTextItem(.url(url, concealed), .longTap) } else if let mention = attributes[NSAttributedString.Key(rawValue: TelegramTextAttributes.PeerMention)] as? TelegramPeerMention { openActiveTextItem(.mention(mention.peerId, mention.mention), .longTap) } else if let mention = attributes[NSAttributedString.Key(rawValue: TelegramTextAttributes.PeerTextMention)] as? String { @@ -357,10 +368,16 @@ public final class TooltipScreen: ViewController { case top } + public enum DisplayDuration { + case `default` + case custom(Double) + } + public let text: String public let textEntities: [MessageTextEntity] private let icon: TooltipScreen.Icon? private let location: TooltipScreen.Location + private let displayDuration: DisplayDuration private let shouldDismissOnTouch: (CGPoint) -> TooltipScreen.DismissOnTouch private let openActiveTextItem: (TooltipActiveTextItem, TooltipActiveTextAction) -> Void @@ -374,11 +391,12 @@ public final class TooltipScreen: ViewController { public var willBecomeDismissed: ((TooltipScreen) -> Void)? public var becameDismissed: ((TooltipScreen) -> Void)? - public init(text: String, textEntities: [MessageTextEntity] = [], icon: TooltipScreen.Icon?, location: TooltipScreen.Location, shouldDismissOnTouch: @escaping (CGPoint) -> TooltipScreen.DismissOnTouch, openActiveTextItem: @escaping (TooltipActiveTextItem, TooltipActiveTextAction) -> Void = { _, _ in }) { + public init(text: String, textEntities: [MessageTextEntity] = [], icon: TooltipScreen.Icon?, location: TooltipScreen.Location, displayDuration: DisplayDuration = .default, shouldDismissOnTouch: @escaping (CGPoint) -> TooltipScreen.DismissOnTouch, openActiveTextItem: @escaping (TooltipActiveTextItem, TooltipActiveTextAction) -> Void = { _, _ in }) { self.text = text self.textEntities = textEntities self.icon = icon self.location = location + self.displayDuration = displayDuration self.shouldDismissOnTouch = shouldDismissOnTouch self.openActiveTextItem = openActiveTextItem @@ -396,13 +414,21 @@ public final class TooltipScreen: ViewController { self.controllerNode.animateIn() - DispatchQueue.main.asyncAfter(deadline: DispatchTime.now() + 5.0, execute: { [weak self] in + let timeout: Double + switch self.displayDuration { + case .default: + timeout = 5.0 + case let .custom(value): + timeout = value + } + + DispatchQueue.main.asyncAfter(deadline: DispatchTime.now() + timeout, execute: { [weak self] in self?.dismiss() }) } override public func loadDisplayNode() { - self.displayNode = TooltipScreenNode(text: self.text, textEntities: self.textEntities, icon: self.icon, location: self.location, shouldDismissOnTouch: self.shouldDismissOnTouch, requestDismiss: { [weak self] in + self.displayNode = TooltipScreenNode(text: self.text, textEntities: self.textEntities, icon: self.icon, location: self.location, displayDuration: self.displayDuration, shouldDismissOnTouch: self.shouldDismissOnTouch, requestDismiss: { [weak self] in guard let strongSelf = self else { return } diff --git a/submodules/WalletUI/Sources/WalletSplashScreen.swift b/submodules/WalletUI/Sources/WalletSplashScreen.swift index 96ca943fcd..083be6ae34 100644 --- a/submodules/WalletUI/Sources/WalletSplashScreen.swift +++ b/submodules/WalletUI/Sources/WalletSplashScreen.swift @@ -953,7 +953,7 @@ private final class WalletSplashScreenNode: ViewControllerTracingNode { return nil } } - self.termsNode.tapAttributeAction = { attributes in + self.termsNode.tapAttributeAction = { attributes, _ in if let _ = attributes[NSAttributedString.Key.underlineStyle] { openTerms() }