diff --git a/Telegram/Telegram-iOS/en.lproj/Localizable.strings b/Telegram/Telegram-iOS/en.lproj/Localizable.strings index 2a92f3ebe8..bcb8eb3d62 100644 --- a/Telegram/Telegram-iOS/en.lproj/Localizable.strings +++ b/Telegram/Telegram-iOS/en.lproj/Localizable.strings @@ -9863,6 +9863,8 @@ Sorry for the inconvenience."; "Story.ViewList.ViewerCount_any" = "%d Viewers"; "AuthSessions.MessageApp" = "You allowed this bot to message you when you opened %@."; +"Notification.BotWriteAllowedMenu" = "You allowed this bot to message you when you added it to your attachment menu."; +"Notification.BotWriteAllowedRequest" = "You allowed this bot to message you in the app."; "Story.Privacy.PostStoryAs" = "Post Story As"; "Story.Privacy.PostStoryAsHeader" = "POST STORY AS"; @@ -9892,3 +9894,9 @@ Sorry for the inconvenience."; "MediaPicker.Timer.Video.ViewOnceTooltip" = "Video set to view once."; "MediaPicker.Timer.Video.TimerTooltip" = "Video will be deleted in\n%@ seconds after opening."; "MediaPicker.Timer.Video.KeepTooltip" = "Video will be kept in chat."; + +"WebApp.AllowWriteTitle" = "Allow Sending Messages?"; +"WebApp.AllowWriteConfirmation" = "This will allow the bot **%@** to message you on Telegram."; + +"WebApp.SharePhoneTitle" = "Share Phone Number?"; +"WebApp.SharePhoneConfirmation" = "**%@** will know your phone number. This can be useful for integration with other services."; diff --git a/submodules/TelegramCore/Sources/ApiUtils/TelegramMediaAction.swift b/submodules/TelegramCore/Sources/ApiUtils/TelegramMediaAction.swift index eeaff7396f..997719f0cd 100644 --- a/submodules/TelegramCore/Sources/ApiUtils/TelegramMediaAction.swift +++ b/submodules/TelegramCore/Sources/ApiUtils/TelegramMediaAction.swift @@ -53,16 +53,19 @@ func telegramMediaActionFromApiAction(_ action: Api.MessageAction) -> TelegramMe case let .messageActionBotAllowed(flags, domain, app): if let domain = domain { return TelegramMediaAction(action: .botDomainAccessGranted(domain: domain)) - } else if case let .botApp(_, _, _, _, appName, _, _, _, _) = app { + } else { + var appName: String? + if case let .botApp(_, _, _, _, appNameValue, _, _, _, _) = app { + appName = appNameValue + } var type: BotSendMessageAccessGrantedType? - if (flags & (1 << 3)) != 0 { - type = .request - } else if (flags & (1 << 1)) != 0 { + if (flags & (1 << 1)) != 0 { type = .attachMenu } + if (flags & (1 << 3)) != 0 { + type = .request + } return TelegramMediaAction(action: .botAppAccessGranted(appName: appName, type: type)) - } else { - return nil } case .messageActionSecureValuesSentMe: return nil diff --git a/submodules/TelegramCore/Sources/SyncCore/SyncCore_TelegramMediaAction.swift b/submodules/TelegramCore/Sources/SyncCore/SyncCore_TelegramMediaAction.swift index 829908f62b..9e1cf940a1 100644 --- a/submodules/TelegramCore/Sources/SyncCore/SyncCore_TelegramMediaAction.swift +++ b/submodules/TelegramCore/Sources/SyncCore/SyncCore_TelegramMediaAction.swift @@ -91,7 +91,7 @@ public enum TelegramMediaActionType: PostboxCoding, Equatable { case paymentSent(currency: String, totalAmount: Int64, invoiceSlug: String?, isRecurringInit: Bool, isRecurringUsed: Bool) case customText(text: String, entities: [MessageTextEntity]) case botDomainAccessGranted(domain: String) - case botAppAccessGranted(appName: String, type: BotSendMessageAccessGrantedType?) + case botAppAccessGranted(appName: String?, type: BotSendMessageAccessGrantedType?) case botSentSecureValues(types: [SentSecureValueType]) case peerJoined case phoneNumberRequest @@ -202,7 +202,7 @@ public enum TelegramMediaActionType: PostboxCoding, Equatable { self = .unknown } case 35: - self = .botAppAccessGranted(appName: decoder.decodeStringForKey("app", orElse: ""), type: decoder.decodeOptionalInt32ForKey("atp").flatMap { BotSendMessageAccessGrantedType(rawValue: $0) }) + self = .botAppAccessGranted(appName: decoder.decodeOptionalStringForKey("app"), type: decoder.decodeOptionalInt32ForKey("atp").flatMap { BotSendMessageAccessGrantedType(rawValue: $0) }) default: self = .unknown } @@ -372,7 +372,11 @@ public enum TelegramMediaActionType: PostboxCoding, Equatable { encoder.encode(TelegramWallpaperNativeCodable(wallpaper), forKey: "wallpaper") case let .botAppAccessGranted(appName, type): encoder.encodeInt32(35, forKey: "_rawValue") - encoder.encodeString(appName, forKey: "app") + if let appName = appName { + encoder.encodeString(appName, forKey: "app") + } else { + encoder.encodeNil(forKey: "app") + } if let type = type { encoder.encodeInt32(type.rawValue, forKey: "atp") } else { diff --git a/submodules/TelegramStringFormatting/Sources/ServiceMessageStrings.swift b/submodules/TelegramStringFormatting/Sources/ServiceMessageStrings.swift index 1159187c22..0998610d15 100644 --- a/submodules/TelegramStringFormatting/Sources/ServiceMessageStrings.swift +++ b/submodules/TelegramStringFormatting/Sources/ServiceMessageStrings.swift @@ -629,8 +629,16 @@ public func universalServiceMessageString(presentationData: (PresentationTheme, attributedString = stringWithAppliedEntities(text, entities: entities, baseColor: primaryTextColor, linkColor: primaryTextColor, baseFont: titleFont, linkFont: titleBoldFont, boldFont: titleBoldFont, italicFont: titleFont, boldItalicFont: titleBoldFont, fixedFont: titleFont, blockQuoteFont: titleFont, underlineLinks: false, message: message._asMessage()) case let .botDomainAccessGranted(domain): attributedString = NSAttributedString(string: strings.AuthSessions_Message(domain).string, font: titleFont, textColor: primaryTextColor) - case let .botAppAccessGranted(appName, _): - attributedString = NSAttributedString(string: strings.AuthSessions_MessageApp(appName).string, font: titleFont, textColor: primaryTextColor) + case let .botAppAccessGranted(appName, type): + let text: String + if type == .attachMenu { + text = strings.Notification_BotWriteAllowedMenu + } else if type == .request { + text = strings.Notification_BotWriteAllowedRequest + } else { + text = strings.AuthSessions_MessageApp(appName ?? "").string + } + attributedString = NSAttributedString(string: text, font: titleFont, textColor: primaryTextColor) case let .botSentSecureValues(types): var typesString = "" var hasIdentity = false diff --git a/submodules/TelegramUI/Sources/ChatController.swift b/submodules/TelegramUI/Sources/ChatController.swift index e38ad40d13..638d95be18 100644 --- a/submodules/TelegramUI/Sources/ChatController.swift +++ b/submodules/TelegramUI/Sources/ChatController.swift @@ -13213,7 +13213,7 @@ public final class ChatControllerImpl: TelegramBaseController, ChatController, G } let buttons: Signal<([AttachmentButtonType], [AttachmentButtonType], AttachmentButtonType?), NoError> - if !isScheduledMessages { + if !isScheduledMessages && !peer.isDeleted { buttons = self.context.engine.messages.attachMenuBots() |> map { attachMenuBots in var buttons = availableButtons diff --git a/submodules/WebUI/Sources/WebAppController.swift b/submodules/WebUI/Sources/WebAppController.swift index 43b342fd06..6541cc3de7 100644 --- a/submodules/WebUI/Sources/WebAppController.swift +++ b/submodules/WebUI/Sources/WebAppController.swift @@ -1104,7 +1104,7 @@ public final class WebAppController: ViewController, AttachmentContainable { if result { sendEvent(true) } else { - controller.present(textAlertController(context: self.context, updatedPresentationData: controller.updatedPresentationData, title: "Allow Sending Messages?", text: "Allow \(controller.botName) to send messages?", actions: [TextAlertAction(type: .genericAction, title: self.presentationData.strings.Common_Cancel, action: { + controller.present(textAlertController(context: self.context, updatedPresentationData: controller.updatedPresentationData, title: self.presentationData.strings.WebApp_AllowWriteTitle, text: self.presentationData.strings.WebApp_AllowWriteConfirmation(controller.botName).string, actions: [TextAlertAction(type: .genericAction, title: self.presentationData.strings.Common_Cancel, action: { sendEvent(false) }), TextAlertAction(type: .defaultAction, title: self.presentationData.strings.Common_OK, action: { [weak self] in guard let self else { @@ -1115,16 +1115,17 @@ public final class WebAppController: ViewController, AttachmentContainable { |> deliverOnMainQueue).start(completed: { sendEvent(true) }) - })]), in: .window(.root)) + })], parseMarkdown: true), in: .window(.root)) } }) } fileprivate func shareAccountContact() { - guard let controller = self.controller, let botId = self.controller?.botId else { + guard let controller = self.controller, let botId = self.controller?.botId, let botName = self.controller?.botName else { return } + let sendEvent: (Bool) -> Void = { success in var paramsString: String if success { @@ -1149,7 +1150,7 @@ public final class WebAppController: ViewController, AttachmentContainable { requiresUnblock = true } - let alertController = textAlertController(context: self.context, updatedPresentationData: controller.updatedPresentationData, title: self.presentationData.strings.Conversation_ShareBotContactConfirmationTitle, text: self.presentationData.strings.Conversation_ShareBotContactConfirmation, actions: [TextAlertAction(type: .genericAction, title: self.presentationData.strings.Common_Cancel, action: { + let alertController = textAlertController(context: self.context, updatedPresentationData: controller.updatedPresentationData, title: self.presentationData.strings.WebApp_SharePhoneTitle, text: self.presentationData.strings.WebApp_SharePhoneConfirmation(botName).string, actions: [TextAlertAction(type: .genericAction, title: self.presentationData.strings.Common_Cancel, action: { sendEvent(false) }), TextAlertAction(type: .defaultAction, title: self.presentationData.strings.Common_OK, action: { [weak self] in guard let self, case let .user(user) = accountPeer, let phone = user.phone, !phone.isEmpty else { @@ -1190,7 +1191,7 @@ public final class WebAppController: ViewController, AttachmentContainable { } else { sendMessage() } - })]) + })], parseMarkdown: true) alertController.dismissed = { byOutsideTap in if byOutsideTap { sendEvent(false)