diff --git a/submodules/TelegramNotices/Sources/Notices.swift b/submodules/TelegramNotices/Sources/Notices.swift index 01b4e7b6b4..a65f6ac38f 100644 --- a/submodules/TelegramNotices/Sources/Notices.swift +++ b/submodules/TelegramNotices/Sources/Notices.swift @@ -167,6 +167,7 @@ private struct ApplicationSpecificNoticeKeys { private static let peerReportNamespace: Int32 = 4 private static let inlineBotLocationRequestNamespace: Int32 = 5 private static let psaAcknowledgementNamespace: Int32 = 6 + private static let botGameNoticeNamespace: Int32 = 7 static func inlineBotLocationRequestNotice(peerId: PeerId) -> NoticeEntryKey { return NoticeEntryKey(namespace: noticeNamespace(namespace: inlineBotLocationRequestNamespace), key: noticeKey(peerId: peerId, key: 0)) @@ -176,6 +177,10 @@ private struct ApplicationSpecificNoticeKeys { return NoticeEntryKey(namespace: noticeNamespace(namespace: botPaymentLiabilityNamespace), key: noticeKey(peerId: peerId, key: 0)) } + static func botGameNotice(peerId: PeerId) -> NoticeEntryKey { + return NoticeEntryKey(namespace: noticeNamespace(namespace: botGameNoticeNamespace), key: noticeKey(peerId: peerId, key: 0)) + } + static func irrelevantPeerGeoNotice(peerId: PeerId) -> NoticeEntryKey { return NoticeEntryKey(namespace: noticeNamespace(namespace: peerReportNamespace), key: noticeKey(peerId: peerId, key: 0)) } @@ -292,6 +297,22 @@ public struct ApplicationSpecificNotice { } } + public static func getBotGameNotice(accountManager: AccountManager, peerId: PeerId) -> Signal { + return accountManager.transaction { transaction -> Bool in + if let _ = transaction.getNotice(ApplicationSpecificNoticeKeys.botGameNotice(peerId: peerId)) as? ApplicationSpecificBoolNotice { + return true + } else { + return false + } + } + } + + public static func setBotGameNotice(accountManager: AccountManager, peerId: PeerId) -> Signal { + return accountManager.transaction { transaction -> Void in + transaction.setNotice(ApplicationSpecificNoticeKeys.botGameNotice(peerId: peerId), ApplicationSpecificBoolNotice()) + } + } + public static func getInlineBotLocationRequest(accountManager: AccountManager, peerId: PeerId) -> Signal { return accountManager.transaction { transaction -> Int32? in if let notice = transaction.getNotice(ApplicationSpecificNoticeKeys.inlineBotLocationRequestNotice(peerId: peerId)) as? ApplicationSpecificTimestampNotice { diff --git a/submodules/TelegramUI/Sources/ChatController.swift b/submodules/TelegramUI/Sources/ChatController.swift index bc19185ab1..0c8a947343 100644 --- a/submodules/TelegramUI/Sources/ChatController.swift +++ b/submodules/TelegramUI/Sources/ChatController.swift @@ -1038,8 +1038,35 @@ public final class ChatControllerImpl: TelegramBaseController, ChatController, G strongSelf.botCallbackAlertMessage.set(message |> then(delayedNoMessage)) case let .url(url): if isGame { - strongSelf.chatDisplayNode.dismissInput() - strongSelf.effectiveNavigationController?.pushViewController(GameController(context: strongSelf.context, url: url, message: message)) + let openBot: () -> Void = { + guard let strongSelf = self else { + return + } + + strongSelf.chatDisplayNode.dismissInput() + strongSelf.effectiveNavigationController?.pushViewController(GameController(context: strongSelf.context, url: url, message: message)) + } + + if let botPeer = message.author as? TelegramUser, botPeer.flags.contains(.isVerified) { + openBot() + } else { + let _ = (ApplicationSpecificNotice.getBotGameNotice(accountManager: strongSelf.context.sharedContext.accountManager, peerId: message.id.peerId) + |> deliverOnMainQueue).start(next: { value in + guard let strongSelf = self else { + return + } + if value { + openBot() + } else if let botPeer = message.author as? TelegramUser { + strongSelf.present(textAlertController(context: strongSelf.context, title: nil, text: strongSelf.presentationData.strings.Conversation_BotInteractiveUrlAlert(botPeer.displayTitle(strings: strongSelf.presentationData.strings, displayOrder: strongSelf.presentationData.nameDisplayOrder)).0, actions: [TextAlertAction(type: .genericAction, title: strongSelf.presentationData.strings.Common_Cancel, action: { }), TextAlertAction(type: .defaultAction, title: strongSelf.presentationData.strings.Common_OK, action: { + if let strongSelf = self { + let _ = ApplicationSpecificNotice.setBotGameNotice(accountManager: strongSelf.context.sharedContext.accountManager, peerId: botPeer.id).start() + openBot() + } + })]), in: .window(.root), with: nil) + } + }) + } } else { strongSelf.openUrl(url, concealed: false) }