From 8bf4cbc1f090d53d1ef8e29e9cd3a6d286c060b8 Mon Sep 17 00:00:00 2001 From: Ilya Laktyushin Date: Thu, 14 Mar 2024 18:02:25 +0400 Subject: [PATCH] Web apps terms of service --- .../Telegram-iOS/en.lproj/Localizable.strings | 3 +++ .../Sources/CachedInternalInstantPages.swift | 8 ++++++++ submodules/WebUI/BUILD | 1 + .../WebUI/Sources/WebAppController.swift | 20 +++++++++++++++++++ 4 files changed, 32 insertions(+) diff --git a/Telegram/Telegram-iOS/en.lproj/Localizable.strings b/Telegram/Telegram-iOS/en.lproj/Localizable.strings index bd9d21d0c2..1ad149bc9c 100644 --- a/Telegram/Telegram-iOS/en.lproj/Localizable.strings +++ b/Telegram/Telegram-iOS/en.lproj/Localizable.strings @@ -11616,3 +11616,6 @@ Sorry for the inconvenience."; "ChannelBoost.NoAds" = "Switch Off Ads"; "ChannelBoost.EnableNoAdsLevelText" = "Your channel needs **Level %1$@** to switch off ads."; + +"WebApp.TermsOfUse" = "Terms of Use"; +"WebApp.TermsOfUse_URL" = "https://telegram.org/tos/mini-apps"; diff --git a/submodules/InstantPageCache/Sources/CachedInternalInstantPages.swift b/submodules/InstantPageCache/Sources/CachedInternalInstantPages.swift index aa5308d68c..3a3d109d25 100644 --- a/submodules/InstantPageCache/Sources/CachedInternalInstantPages.swift +++ b/submodules/InstantPageCache/Sources/CachedInternalInstantPages.swift @@ -48,6 +48,14 @@ public func cachedPrivacyPage(context: AccountContext) -> Signal Signal { + var privacyUrl = context.sharedContext.currentPresentationData.with { $0 }.strings.WebApp_TermsOfUse_URL + if privacyUrl == "WebApp.TermsOfUse_URL" || privacyUrl.isEmpty { + privacyUrl = "https://telegram.org/tos/mini-apps" + } + return cachedInternalInstantPage(context: context, url: privacyUrl) +} + private func cachedInternalInstantPage(context: AccountContext, url: String) -> Signal { let (cachedUrl, anchor) = extractAnchor(string: url) return cachedInstantPage(engine: context.engine, url: cachedUrl) diff --git a/submodules/WebUI/BUILD b/submodules/WebUI/BUILD index 3973bdc9fc..9fdbf7604b 100644 --- a/submodules/WebUI/BUILD +++ b/submodules/WebUI/BUILD @@ -34,6 +34,7 @@ swift_library( "//submodules/Markdown:Markdown", "//submodules/TextFormat:TextFormat", "//submodules/LocalAuth", + "//submodules/InstantPageCache" ], visibility = [ "//visibility:public", diff --git a/submodules/WebUI/Sources/WebAppController.swift b/submodules/WebUI/Sources/WebAppController.swift index 8ee017bd74..4991caf7a8 100644 --- a/submodules/WebUI/Sources/WebAppController.swift +++ b/submodules/WebUI/Sources/WebAppController.swift @@ -23,6 +23,7 @@ import PromptUI import PhoneNumberFormat import QrCodeUI import InstantPageUI +import InstantPageCache import LocalAuth private let durgerKingBotIds: [Int64] = [5104055776, 2200339955] @@ -1849,6 +1850,25 @@ public final class WebAppController: ViewController, AttachmentContainable { self?.controllerNode.webView?.reload() }))) + items.append(.action(ContextMenuActionItem(text: presentationData.strings.WebApp_TermsOfUse, icon: { theme in + return generateTintedImage(image: UIImage(bundleImageName: "Chat/Context Menu/Info"), color: theme.contextMenu.primaryColor) + }, action: { [weak self] c, _ in + c.dismiss(completion: nil) + + guard let self, let navigationController = self.getNavigationController() else { + return + } + + let context = self.context + let _ = (cachedWebAppTermsPage(context: context) + |> deliverOnMainQueue).startStandalone(next: { resolvedUrl in + context.sharedContext.openResolvedUrl(resolvedUrl, context: context, urlContext: .generic, navigationController: navigationController, forceExternal: true, openPeer: { peer, navigation in + }, sendFile: nil, sendSticker: nil, requestMessageActionUrlAuth: nil, joinVoiceChat: nil, present: { [weak self] c, arguments in + self?.push(c) + }, dismissInput: {}, contentContext: nil, progress: nil, completion: nil) + }) + }))) + if let _ = attachMenuBot, [.attachMenu, .settings, .generic].contains(source) { items.append(.action(ContextMenuActionItem(text: presentationData.strings.WebApp_RemoveBot, textColor: .destructive, icon: { theme in return generateTintedImage(image: UIImage(bundleImageName: "Chat/Context Menu/Delete"), color: theme.contextMenu.destructiveColor)