From 3881bdff70559e1099cbe384b20b09cbbd05b51a Mon Sep 17 00:00:00 2001 From: Ilya Laktyushin Date: Thu, 7 Sep 2023 23:54:47 +0400 Subject: [PATCH] Web app improvements --- Telegram/Telegram-iOS/en.lproj/Localizable.strings | 2 +- submodules/TelegramUI/Sources/ChatController.swift | 2 +- submodules/TelegramUI/Sources/OpenResolvedUrl.swift | 2 +- .../TelegramUI/Sources/PeerInfo/PeerInfoScreen.swift | 4 ++-- .../WebUI/Sources/WebAppTermsAlertController.swift | 12 ++++++------ 5 files changed, 11 insertions(+), 11 deletions(-) diff --git a/Telegram/Telegram-iOS/en.lproj/Localizable.strings b/Telegram/Telegram-iOS/en.lproj/Localizable.strings index 7d1bce3d83..8cc33fd4ad 100644 --- a/Telegram/Telegram-iOS/en.lproj/Localizable.strings +++ b/Telegram/Telegram-iOS/en.lproj/Localizable.strings @@ -9915,7 +9915,7 @@ Sorry for the inconvenience."; "Gallery.ViewOnceVideoTooltip" = "This video can only be viewed once."; "WebApp.DisclaimerTitle" = "Warning"; -"WebApp.DisclaimerText" = "You are about to use a mini app operated by an independent party not affiliated with Telegram. You must agree to the Terms of Use of mini apps to continue."; +"WebApp.DisclaimerText" = "You are about to use a mini app operated by an independent party not affiliated with Telegram. You must agree to the Terms of Use of mini apps to continue.\n\n**%@** shortcuts will be added in your attachment menu and Settings."; "WebApp.DisclaimerAgree" = "I agree to the [Terms of Use]()"; "WebApp.DisclaimerContinue" = "Continue"; "WebApp.Disclaimer_URL" = "https://telegram.org/tos/mini-apps"; diff --git a/submodules/TelegramUI/Sources/ChatController.swift b/submodules/TelegramUI/Sources/ChatController.swift index 8ea8acfef3..02f372049d 100644 --- a/submodules/TelegramUI/Sources/ChatController.swift +++ b/submodules/TelegramUI/Sources/ChatController.swift @@ -13418,7 +13418,7 @@ public final class ChatControllerImpl: TelegramBaseController, ChatController, G } else { let _ = (context.engine.messages.getAttachMenuBot(botId: botId) |> deliverOnMainQueue).start(next: { bot in - let controller = webAppTermsAlertController(context: context, updatedPresentationData: strongSelf.updatedPresentationData, peer: bot.peer, requestWriteAccess: bot.flags.contains(.requiresWriteAccess), completion: { allowWrite in + let controller = webAppTermsAlertController(context: context, updatedPresentationData: strongSelf.updatedPresentationData, bot: bot, completion: { allowWrite in let _ = (context.engine.messages.addBotToAttachMenu(botId: botId, allowWrite: allowWrite) |> deliverOnMainQueue).start(error: { _ in diff --git a/submodules/TelegramUI/Sources/OpenResolvedUrl.swift b/submodules/TelegramUI/Sources/OpenResolvedUrl.swift index da7dfd95ee..13da105bb6 100644 --- a/submodules/TelegramUI/Sources/OpenResolvedUrl.swift +++ b/submodules/TelegramUI/Sources/OpenResolvedUrl.swift @@ -669,7 +669,7 @@ func openResolvedUrlImpl(_ resolvedUrl: ResolvedUrl, context: AccountContext, ur |> deliverOnMainQueue).start(next: { bot in let choose = filterChooseTypes(choose, peerTypes: bot.peerTypes) - let controller = webAppTermsAlertController(context: context, updatedPresentationData: updatedPresentationData, peer: bot.peer, requestWriteAccess: bot.flags.contains(.requiresWriteAccess), completion: { allowWrite in + let controller = webAppTermsAlertController(context: context, updatedPresentationData: updatedPresentationData, bot: bot, completion: { allowWrite in let _ = (context.engine.messages.addBotToAttachMenu(botId: peerId, allowWrite: allowWrite) |> deliverOnMainQueue).start(error: { _ in presentError(presentationData.strings.WebApp_AddToAttachmentUnavailableError) diff --git a/submodules/TelegramUI/Sources/PeerInfo/PeerInfoScreen.swift b/submodules/TelegramUI/Sources/PeerInfo/PeerInfoScreen.swift index 3d56272344..298c694c2b 100644 --- a/submodules/TelegramUI/Sources/PeerInfo/PeerInfoScreen.swift +++ b/submodules/TelegramUI/Sources/PeerInfo/PeerInfoScreen.swift @@ -4665,8 +4665,8 @@ final class PeerInfoScreenNode: ViewControllerTracingNode, PeerInfoScreenNodePro })) } - if bot.flags.contains(.showInSettingsDisclaimer) { - let alertController = webAppTermsAlertController(context: self.context, updatedPresentationData: controller.updatedPresentationData, peer: bot.peer, requestWriteAccess: bot.flags.contains(.requiresWriteAccess), completion: { [weak self] allowWrite in + if bot.flags.contains(.notActivated) || bot.flags.contains(.showInSettingsDisclaimer) { + let alertController = webAppTermsAlertController(context: self.context, updatedPresentationData: controller.updatedPresentationData, bot: bot, completion: { [weak self] allowWrite in guard let self else { return } diff --git a/submodules/WebUI/Sources/WebAppTermsAlertController.swift b/submodules/WebUI/Sources/WebAppTermsAlertController.swift index 428e817ce7..8fbd32ed9a 100644 --- a/submodules/WebUI/Sources/WebAppTermsAlertController.swift +++ b/submodules/WebUI/Sources/WebAppTermsAlertController.swift @@ -17,8 +17,8 @@ import TextFormat private let textFont = Font.regular(13.0) private let boldTextFont = Font.semibold(13.0) -private func formattedText(_ text: String, color: UIColor, linkColor: UIColor, textAlignment: NSTextAlignment = .natural) -> NSAttributedString { - return parseMarkdownIntoAttributedString(text, attributes: MarkdownAttributes(body: MarkdownAttributeSet(font: textFont, textColor: color), bold: MarkdownAttributeSet(font: boldTextFont, textColor: color), link: MarkdownAttributeSet(font: textFont, textColor: linkColor), linkAttribute: { _ in return (TelegramTextAttributes.URL, "") }), textAlignment: textAlignment) +private func formattedText(_ text: String, fontSize: CGFloat, color: UIColor, linkColor: UIColor, textAlignment: NSTextAlignment = .natural) -> NSAttributedString { + return parseMarkdownIntoAttributedString(text, attributes: MarkdownAttributes(body: MarkdownAttributeSet(font: Font.regular(fontSize), textColor: color), bold: MarkdownAttributeSet(font: Font.semibold(fontSize), textColor: color), link: MarkdownAttributeSet(font: Font.regular(fontSize), textColor: linkColor), linkAttribute: { _ in return (TelegramTextAttributes.URL, "") }), textAlignment: textAlignment) } private final class WebAppTermsAlertContentNode: AlertContentNode, UIGestureRecognizerDelegate { @@ -67,6 +67,7 @@ private final class WebAppTermsAlertContentNode: AlertContentNode, UIGestureReco self.textNode.maximumNumberOfLines = 0 self.textNode.displaysAsynchronously = false self.textNode.lineSpacing = 0.1 + self.textNode.textAlignment = .center self.acceptTermsCheckNode = InteractiveCheckNode(theme: CheckNodeTheme(backgroundColor: theme.accentColor, strokeColor: theme.contrastColor, borderColor: theme.controlBorderColor, overlayBorder: false, hasInset: false, hasShadow: false)) self.acceptTermsLabelNode = ImmediateTextNode() @@ -177,7 +178,7 @@ private final class WebAppTermsAlertContentNode: AlertContentNode, UIGestureReco override func updateTheme(_ theme: AlertControllerTheme) { self.titleNode.attributedText = NSAttributedString(string: self.title, font: Font.semibold(17.0), textColor: theme.primaryColor, paragraphAlignment: .center) - self.textNode.attributedText = NSAttributedString(string: self.text, font: Font.regular(13.0), textColor: theme.primaryColor, paragraphAlignment: .center) + self.textNode.attributedText = formattedText(self.text, fontSize: 13.0, color: theme.primaryColor, linkColor: theme.accentColor, textAlignment: .center) let attributedAgreeText = parseMarkdownIntoAttributedString( self.strings.WebApp_DisclaimerAgree, @@ -328,8 +329,7 @@ private final class WebAppTermsAlertContentNode: AlertContentNode, UIGestureReco public func webAppTermsAlertController( context: AccountContext, updatedPresentationData: (initial: PresentationData, signal: Signal)?, - peer: EnginePeer, - requestWriteAccess: Bool, + bot: AttachMenuBot, completion: @escaping (Bool) -> Void ) -> AlertController { let theme = defaultDarkColorPresentationTheme @@ -350,7 +350,7 @@ public func webAppTermsAlertController( })] let title = presentationData.strings.WebApp_DisclaimerTitle - let text = presentationData.strings.WebApp_DisclaimerText + let text = presentationData.strings.WebApp_DisclaimerText(bot.peer.compactDisplayTitle).string let contentNode = WebAppTermsAlertContentNode(context: context, theme: AlertControllerTheme(presentationData: presentationData), ptheme: theme, strings: strings, title: title, text: text, actions: actions) contentNode.openTerms = {