diff --git a/submodules/TelegramApi/Sources/Api0.swift b/submodules/TelegramApi/Sources/Api0.swift index 923fbcc0a1..dda69c6afd 100644 --- a/submodules/TelegramApi/Sources/Api0.swift +++ b/submodules/TelegramApi/Sources/Api0.swift @@ -119,7 +119,9 @@ fileprivate let parsers: [Int32 : (BufferReader) -> Any?] = { dict[-567037804] = { return Api.VideoSize.parse_videoSize($0) } dict[-860107216] = { return Api.help.AppUpdate.parse_appUpdate($0) } dict[-1000708810] = { return Api.help.AppUpdate.parse_noAppUpdate($0) } + dict[-2010155333] = { return Api.SimpleWebViewResult.parse_simpleWebViewResultUrl($0) } dict[-209337866] = { return Api.LangPackDifference.parse_langPackDifference($0) } + dict[-1816172929] = { return Api.AttachMenuBotsBot.parse_attachMenuBotsBot($0) } dict[499236004] = { return Api.WallPaperSettings.parse_wallPaperSettings($0) } dict[-1519029347] = { return Api.EmojiURL.parse_emojiURL($0) } dict[-682079097] = { return Api.StatsGroupTopAdmin.parse_statsGroupTopAdmin($0) } @@ -293,6 +295,7 @@ fileprivate let parsers: [Int32 : (BufferReader) -> Any?] = { dict[299870598] = { return Api.Update.parse_updateBotChatInviteRequester($0) } dict[357013699] = { return Api.Update.parse_updateMessageReactions($0) } dict[397910539] = { return Api.Update.parse_updateAttachMenuBots($0) } + dict[-118080598] = { return Api.Update.parse_updateWebViewResultSent($0) } dict[1951948721] = { return Api.Update.parse_updateReadFeed($0) } dict[136574537] = { return Api.messages.VotesList.parse_votesList($0) } dict[1558266229] = { return Api.PopularContact.parse_popularContact($0) } @@ -325,6 +328,7 @@ fileprivate let parsers: [Int32 : (BufferReader) -> Any?] = { dict[-376962181] = { return Api.KeyboardButton.parse_inputKeyboardButtonUserProfile($0) } dict[814112961] = { return Api.KeyboardButton.parse_keyboardButtonUserProfile($0) } dict[326529584] = { return Api.KeyboardButton.parse_keyboardButtonWebView($0) } + dict[-1598009252] = { return Api.KeyboardButton.parse_keyboardButtonSimpleWebView($0) } dict[383348795] = { return Api.ContactStatus.parse_contactStatus($0) } dict[997004590] = { return Api.users.UserFull.parse_userFull($0) } dict[1679398724] = { return Api.SecureFile.parse_secureFileEmpty($0) } @@ -393,7 +397,7 @@ fileprivate let parsers: [Int32 : (BufferReader) -> Any?] = { dict[-1798033689] = { return Api.ChannelMessagesFilter.parse_channelMessagesFilterEmpty($0) } dict[-847783593] = { return Api.ChannelMessagesFilter.parse_channelMessagesFilter($0) } dict[-219353309] = { return Api.ChatAdminWithInvites.parse_chatAdminWithInvites($0) } - dict[-729926056] = { return Api.AttachMenuBot.parse_attachMenuBot($0) } + dict[1340016040] = { return Api.AttachMenuBot.parse_attachMenuBot($0) } dict[2004110666] = { return Api.DialogFilterSuggested.parse_dialogFilterSuggested($0) } dict[326715557] = { return Api.auth.PasswordRecovery.parse_passwordRecovery($0) } dict[-1803769784] = { return Api.messages.BotResults.parse_botResults($0) } @@ -658,6 +662,7 @@ fileprivate let parsers: [Int32 : (BufferReader) -> Any?] = { dict[-1877614335] = { return Api.Updates.parse_updateShortSentMessage($0) } dict[-276825834] = { return Api.stats.MegagroupStats.parse_megagroupStats($0) } dict[-884757282] = { return Api.StatsAbsValueAndPrev.parse_statsAbsValueAndPrev($0) } + dict[211046684] = { return Api.WebViewMessageSent.parse_webViewMessageSent($0) } dict[1038967584] = { return Api.MessageMedia.parse_messageMediaEmpty($0) } dict[1766936791] = { return Api.MessageMedia.parse_messageMediaPhoto($0) } dict[1457575028] = { return Api.MessageMedia.parse_messageMediaGeo($0) } @@ -892,6 +897,8 @@ fileprivate let parsers: [Int32 : (BufferReader) -> Any?] = { dict[-1281329567] = { return Api.MessageAction.parse_messageActionGroupCallScheduled($0) } dict[-1434950843] = { return Api.MessageAction.parse_messageActionSetChatTheme($0) } dict[-339958837] = { return Api.MessageAction.parse_messageActionChatJoinedByRequest($0) } + dict[1205698681] = { return Api.MessageAction.parse_messageActionWebViewDataSentMe($0) } + dict[-1262252875] = { return Api.MessageAction.parse_messageActionWebViewDataSent($0) } dict[1399245077] = { return Api.PhoneCall.parse_phoneCallEmpty($0) } dict[-987599081] = { return Api.PhoneCall.parse_phoneCallWaiting($0) } dict[347139340] = { return Api.PhoneCall.parse_phoneCallRequested($0) } @@ -969,7 +976,6 @@ fileprivate let parsers: [Int32 : (BufferReader) -> Any?] = { dict[512177195] = { return Api.Document.parse_document($0) } dict[-1707344487] = { return Api.messages.HighScores.parse_highScores($0) } dict[-1493633966] = { return Api.WebAuthorization.parse_webAuthorization($0) } - dict[-1428220517] = { return Api.messages.WebViewResult.parse_webViewResult($0) } dict[-1052885936] = { return Api.ImportedContact.parse_importedContact($0) } dict[1042605427] = { return Api.payments.BankCardData.parse_bankCardData($0) } return dict @@ -1099,8 +1105,12 @@ public struct Api { _1.serialize(buffer, boxed) case let _1 as Api.help.AppUpdate: _1.serialize(buffer, boxed) + case let _1 as Api.SimpleWebViewResult: + _1.serialize(buffer, boxed) case let _1 as Api.LangPackDifference: _1.serialize(buffer, boxed) + case let _1 as Api.AttachMenuBotsBot: + _1.serialize(buffer, boxed) case let _1 as Api.WallPaperSettings: _1.serialize(buffer, boxed) case let _1 as Api.EmojiURL: @@ -1479,6 +1489,8 @@ public struct Api { _1.serialize(buffer, boxed) case let _1 as Api.StatsAbsValueAndPrev: _1.serialize(buffer, boxed) + case let _1 as Api.WebViewMessageSent: + _1.serialize(buffer, boxed) case let _1 as Api.MessageMedia: _1.serialize(buffer, boxed) case let _1 as Api.PaymentSavedCredentials: @@ -1713,8 +1725,6 @@ public struct Api { _1.serialize(buffer, boxed) case let _1 as Api.WebAuthorization: _1.serialize(buffer, boxed) - case let _1 as Api.messages.WebViewResult: - _1.serialize(buffer, boxed) case let _1 as Api.ImportedContact: _1.serialize(buffer, boxed) case let _1 as Api.payments.BankCardData: diff --git a/submodules/TelegramApi/Sources/Api1.swift b/submodules/TelegramApi/Sources/Api1.swift index fb914b0348..0773d24fad 100644 --- a/submodules/TelegramApi/Sources/Api1.swift +++ b/submodules/TelegramApi/Sources/Api1.swift @@ -2702,51 +2702,5 @@ public struct messages { } } - public enum WebViewResult: TypeConstructorDescription { - case webViewResult(result: Api.BotInlineResult, users: [Api.User]) - - public func serialize(_ buffer: Buffer, _ boxed: Swift.Bool) { - switch self { - case .webViewResult(let result, let users): - if boxed { - buffer.appendInt32(-1428220517) - } - result.serialize(buffer, true) - buffer.appendInt32(481674261) - buffer.appendInt32(Int32(users.count)) - for item in users { - item.serialize(buffer, true) - } - break - } - } - - public func descriptionFields() -> (String, [(String, Any)]) { - switch self { - case .webViewResult(let result, let users): - return ("webViewResult", [("result", result), ("users", users)]) - } - } - - public static func parse_webViewResult(_ reader: BufferReader) -> WebViewResult? { - var _1: Api.BotInlineResult? - if let signature = reader.readInt32() { - _1 = Api.parse(reader, signature: signature) as? Api.BotInlineResult - } - var _2: [Api.User]? - if let _ = reader.readInt32() { - _2 = Api.parseVector(reader, elementSignature: 0, elementType: Api.User.self) - } - let _c1 = _1 != nil - let _c2 = _2 != nil - if _c1 && _c2 { - return Api.messages.WebViewResult.webViewResult(result: _1!, users: _2!) - } - else { - return nil - } - } - - } } } diff --git a/submodules/TelegramApi/Sources/Api2.swift b/submodules/TelegramApi/Sources/Api2.swift index 41496ba101..d8a1ae9d19 100644 --- a/submodules/TelegramApi/Sources/Api2.swift +++ b/submodules/TelegramApi/Sources/Api2.swift @@ -3336,6 +3336,40 @@ public extension Api { } } + } + public enum SimpleWebViewResult: TypeConstructorDescription { + case simpleWebViewResultUrl(url: String) + + public func serialize(_ buffer: Buffer, _ boxed: Swift.Bool) { + switch self { + case .simpleWebViewResultUrl(let url): + if boxed { + buffer.appendInt32(-2010155333) + } + serializeString(url, buffer: buffer, boxed: false) + break + } + } + + public func descriptionFields() -> (String, [(String, Any)]) { + switch self { + case .simpleWebViewResultUrl(let url): + return ("simpleWebViewResultUrl", [("url", url)]) + } + } + + public static func parse_simpleWebViewResultUrl(_ reader: BufferReader) -> SimpleWebViewResult? { + var _1: String? + _1 = parseString(reader) + let _c1 = _1 != nil + if _c1 { + return Api.SimpleWebViewResult.simpleWebViewResultUrl(url: _1!) + } + else { + return nil + } + } + } public enum LangPackDifference: TypeConstructorDescription { case langPackDifference(langCode: String, fromVersion: Int32, version: Int32, strings: [Api.LangPackString]) @@ -3388,6 +3422,52 @@ public extension Api { } } + } + public enum AttachMenuBotsBot: TypeConstructorDescription { + case attachMenuBotsBot(bot: Api.AttachMenuBot, users: [Api.User]) + + public func serialize(_ buffer: Buffer, _ boxed: Swift.Bool) { + switch self { + case .attachMenuBotsBot(let bot, let users): + if boxed { + buffer.appendInt32(-1816172929) + } + bot.serialize(buffer, true) + buffer.appendInt32(481674261) + buffer.appendInt32(Int32(users.count)) + for item in users { + item.serialize(buffer, true) + } + break + } + } + + public func descriptionFields() -> (String, [(String, Any)]) { + switch self { + case .attachMenuBotsBot(let bot, let users): + return ("attachMenuBotsBot", [("bot", bot), ("users", users)]) + } + } + + public static func parse_attachMenuBotsBot(_ reader: BufferReader) -> AttachMenuBotsBot? { + var _1: Api.AttachMenuBot? + if let signature = reader.readInt32() { + _1 = Api.parse(reader, signature: signature) as? Api.AttachMenuBot + } + var _2: [Api.User]? + if let _ = reader.readInt32() { + _2 = Api.parseVector(reader, elementSignature: 0, elementType: Api.User.self) + } + let _c1 = _1 != nil + let _c2 = _2 != nil + if _c1 && _c2 { + return Api.AttachMenuBotsBot.attachMenuBotsBot(bot: _1!, users: _2!) + } + else { + return nil + } + } + } public enum WallPaperSettings: TypeConstructorDescription { case wallPaperSettings(flags: Int32, backgroundColor: Int32?, secondBackgroundColor: Int32?, thirdBackgroundColor: Int32?, fourthBackgroundColor: Int32?, intensity: Int32?, rotation: Int32?) @@ -4937,6 +5017,7 @@ public extension Api { case updateBotChatInviteRequester(peer: Api.Peer, date: Int32, userId: Int64, about: String, invite: Api.ExportedChatInvite, qts: Int32) case updateMessageReactions(peer: Api.Peer, msgId: Int32, reactions: Api.MessageReactions) case updateAttachMenuBots + case updateWebViewResultSent(peer: Api.Peer, botId: Int64, queryId: Int64) case updateReadFeed(flags: Int32, filterId: Int32, maxPosition: Api.FeedPosition, unreadCount: Int32?, unreadMutedCount: Int32?) public func serialize(_ buffer: Buffer, _ boxed: Swift.Bool) { @@ -5788,6 +5869,14 @@ public extension Api { buffer.appendInt32(397910539) } + break + case .updateWebViewResultSent(let peer, let botId, let queryId): + if boxed { + buffer.appendInt32(-118080598) + } + peer.serialize(buffer, true) + serializeInt64(botId, buffer: buffer, boxed: false) + serializeInt64(queryId, buffer: buffer, boxed: false) break case .updateReadFeed(let flags, let filterId, let maxPosition, let unreadCount, let unreadMutedCount): if boxed { @@ -5998,6 +6087,8 @@ public extension Api { return ("updateMessageReactions", [("peer", peer), ("msgId", msgId), ("reactions", reactions)]) case .updateAttachMenuBots: return ("updateAttachMenuBots", []) + case .updateWebViewResultSent(let peer, let botId, let queryId): + return ("updateWebViewResultSent", [("peer", peer), ("botId", botId), ("queryId", queryId)]) case .updateReadFeed(let flags, let filterId, let maxPosition, let unreadCount, let unreadMutedCount): return ("updateReadFeed", [("flags", flags), ("filterId", filterId), ("maxPosition", maxPosition), ("unreadCount", unreadCount), ("unreadMutedCount", unreadMutedCount)]) } @@ -7734,6 +7825,25 @@ public extension Api { public static func parse_updateAttachMenuBots(_ reader: BufferReader) -> Update? { return Api.Update.updateAttachMenuBots } + public static func parse_updateWebViewResultSent(_ reader: BufferReader) -> Update? { + var _1: Api.Peer? + if let signature = reader.readInt32() { + _1 = Api.parse(reader, signature: signature) as? Api.Peer + } + var _2: Int64? + _2 = reader.readInt64() + var _3: Int64? + _3 = reader.readInt64() + let _c1 = _1 != nil + let _c2 = _2 != nil + let _c3 = _3 != nil + if _c1 && _c2 && _c3 { + return Api.Update.updateWebViewResultSent(peer: _1!, botId: _2!, queryId: _3!) + } + else { + return nil + } + } public static func parse_updateReadFeed(_ reader: BufferReader) -> Update? { var _1: Int32? _1 = reader.readInt32() @@ -8266,6 +8376,7 @@ public extension Api { case inputKeyboardButtonUserProfile(text: String, userId: Api.InputUser) case keyboardButtonUserProfile(text: String, userId: Int64) case keyboardButtonWebView(text: String, url: String) + case keyboardButtonSimpleWebView(text: String, url: String) public func serialize(_ buffer: Buffer, _ boxed: Swift.Bool) { switch self { @@ -8371,6 +8482,13 @@ public extension Api { serializeString(text, buffer: buffer, boxed: false) serializeString(url, buffer: buffer, boxed: false) break + case .keyboardButtonSimpleWebView(let text, let url): + if boxed { + buffer.appendInt32(-1598009252) + } + serializeString(text, buffer: buffer, boxed: false) + serializeString(url, buffer: buffer, boxed: false) + break } } @@ -8404,6 +8522,8 @@ public extension Api { return ("keyboardButtonUserProfile", [("text", text), ("userId", userId)]) case .keyboardButtonWebView(let text, let url): return ("keyboardButtonWebView", [("text", text), ("url", url)]) + case .keyboardButtonSimpleWebView(let text, let url): + return ("keyboardButtonSimpleWebView", [("text", text), ("url", url)]) } } @@ -8621,6 +8741,20 @@ public extension Api { return nil } } + public static func parse_keyboardButtonSimpleWebView(_ reader: BufferReader) -> KeyboardButton? { + var _1: String? + _1 = parseString(reader) + var _2: String? + _2 = parseString(reader) + let _c1 = _1 != nil + let _c2 = _2 != nil + if _c1 && _c2 { + return Api.KeyboardButton.keyboardButtonSimpleWebView(text: _1!, url: _2!) + } + else { + return nil + } + } } public enum ContactStatus: TypeConstructorDescription { @@ -10404,15 +10538,17 @@ public extension Api { } public enum AttachMenuBot: TypeConstructorDescription { - case attachMenuBot(botId: Int64, attachMenuIcon: Api.Document) + case attachMenuBot(flags: Int32, botId: Int64, attachMenuName: String, attachMenuIcon: Api.Document) public func serialize(_ buffer: Buffer, _ boxed: Swift.Bool) { switch self { - case .attachMenuBot(let botId, let attachMenuIcon): + case .attachMenuBot(let flags, let botId, let attachMenuName, let attachMenuIcon): if boxed { - buffer.appendInt32(-729926056) + buffer.appendInt32(1340016040) } + serializeInt32(flags, buffer: buffer, boxed: false) serializeInt64(botId, buffer: buffer, boxed: false) + serializeString(attachMenuName, buffer: buffer, boxed: false) attachMenuIcon.serialize(buffer, true) break } @@ -10420,22 +10556,28 @@ public extension Api { public func descriptionFields() -> (String, [(String, Any)]) { switch self { - case .attachMenuBot(let botId, let attachMenuIcon): - return ("attachMenuBot", [("botId", botId), ("attachMenuIcon", attachMenuIcon)]) + case .attachMenuBot(let flags, let botId, let attachMenuName, let attachMenuIcon): + return ("attachMenuBot", [("flags", flags), ("botId", botId), ("attachMenuName", attachMenuName), ("attachMenuIcon", attachMenuIcon)]) } } public static func parse_attachMenuBot(_ reader: BufferReader) -> AttachMenuBot? { - var _1: Int64? - _1 = reader.readInt64() - var _2: Api.Document? + var _1: Int32? + _1 = reader.readInt32() + var _2: Int64? + _2 = reader.readInt64() + var _3: String? + _3 = parseString(reader) + var _4: Api.Document? if let signature = reader.readInt32() { - _2 = Api.parse(reader, signature: signature) as? Api.Document + _4 = Api.parse(reader, signature: signature) as? Api.Document } let _c1 = _1 != nil let _c2 = _2 != nil - if _c1 && _c2 { - return Api.AttachMenuBot.attachMenuBot(botId: _1!, attachMenuIcon: _2!) + let _c3 = _3 != nil + let _c4 = _4 != nil + if _c1 && _c2 && _c3 && _c4 { + return Api.AttachMenuBot.attachMenuBot(flags: _1!, botId: _2!, attachMenuName: _3!, attachMenuIcon: _4!) } else { return nil @@ -16906,6 +17048,46 @@ public extension Api { } } + } + public enum WebViewMessageSent: TypeConstructorDescription { + case webViewMessageSent(flags: Int32, msgId: Api.InputBotInlineMessageID?) + + public func serialize(_ buffer: Buffer, _ boxed: Swift.Bool) { + switch self { + case .webViewMessageSent(let flags, let msgId): + if boxed { + buffer.appendInt32(211046684) + } + serializeInt32(flags, buffer: buffer, boxed: false) + if Int(flags) & Int(1 << 0) != 0 {msgId!.serialize(buffer, true)} + break + } + } + + public func descriptionFields() -> (String, [(String, Any)]) { + switch self { + case .webViewMessageSent(let flags, let msgId): + return ("webViewMessageSent", [("flags", flags), ("msgId", msgId)]) + } + } + + public static func parse_webViewMessageSent(_ reader: BufferReader) -> WebViewMessageSent? { + var _1: Int32? + _1 = reader.readInt32() + var _2: Api.InputBotInlineMessageID? + if Int(_1!) & Int(1 << 0) != 0 {if let signature = reader.readInt32() { + _2 = Api.parse(reader, signature: signature) as? Api.InputBotInlineMessageID + } } + let _c1 = _1 != nil + let _c2 = (Int(_1!) & Int(1 << 0) == 0) || _2 != nil + if _c1 && _c2 { + return Api.WebViewMessageSent.webViewMessageSent(flags: _1!, msgId: _2) + } + else { + return nil + } + } + } public enum MessageMedia: TypeConstructorDescription { case messageMediaEmpty @@ -22010,6 +22192,8 @@ public extension Api { case messageActionGroupCallScheduled(call: Api.InputGroupCall, scheduleDate: Int32) case messageActionSetChatTheme(emoticon: String) case messageActionChatJoinedByRequest + case messageActionWebViewDataSentMe(text: String, data: String) + case messageActionWebViewDataSent(text: String) public func serialize(_ buffer: Buffer, _ boxed: Swift.Bool) { switch self { @@ -22232,6 +22416,19 @@ public extension Api { buffer.appendInt32(-339958837) } + break + case .messageActionWebViewDataSentMe(let text, let data): + if boxed { + buffer.appendInt32(1205698681) + } + serializeString(text, buffer: buffer, boxed: false) + serializeString(data, buffer: buffer, boxed: false) + break + case .messageActionWebViewDataSent(let text): + if boxed { + buffer.appendInt32(-1262252875) + } + serializeString(text, buffer: buffer, boxed: false) break } } @@ -22298,6 +22495,10 @@ public extension Api { return ("messageActionSetChatTheme", [("emoticon", emoticon)]) case .messageActionChatJoinedByRequest: return ("messageActionChatJoinedByRequest", []) + case .messageActionWebViewDataSentMe(let text, let data): + return ("messageActionWebViewDataSentMe", [("text", text), ("data", data)]) + case .messageActionWebViewDataSent(let text): + return ("messageActionWebViewDataSent", [("text", text)]) } } @@ -22665,6 +22866,31 @@ public extension Api { public static func parse_messageActionChatJoinedByRequest(_ reader: BufferReader) -> MessageAction? { return Api.MessageAction.messageActionChatJoinedByRequest } + public static func parse_messageActionWebViewDataSentMe(_ reader: BufferReader) -> MessageAction? { + var _1: String? + _1 = parseString(reader) + var _2: String? + _2 = parseString(reader) + let _c1 = _1 != nil + let _c2 = _2 != nil + if _c1 && _c2 { + return Api.MessageAction.messageActionWebViewDataSentMe(text: _1!, data: _2!) + } + else { + return nil + } + } + public static func parse_messageActionWebViewDataSent(_ reader: BufferReader) -> MessageAction? { + var _1: String? + _1 = parseString(reader) + let _c1 = _1 != nil + if _c1 { + return Api.MessageAction.messageActionWebViewDataSent(text: _1!) + } + else { + return nil + } + } } public enum PhoneCall: TypeConstructorDescription { diff --git a/submodules/TelegramApi/Sources/Api4.swift b/submodules/TelegramApi/Sources/Api4.swift index a545ef2e68..60b3a2fcb0 100644 --- a/submodules/TelegramApi/Sources/Api4.swift +++ b/submodules/TelegramApi/Sources/Api4.swift @@ -4864,6 +4864,20 @@ public extension Api { }) } + public static func getAttachMenuBot(bot: Api.InputUser) -> (FunctionDescription, Buffer, DeserializeFunctionResponse) { + let buffer = Buffer() + buffer.appendInt32(1998676370) + bot.serialize(buffer, true) + return (FunctionDescription(name: "messages.getAttachMenuBot", parameters: [("bot", bot)]), buffer, DeserializeFunctionResponse { (buffer: Buffer) -> Api.AttachMenuBotsBot? in + let reader = BufferReader(buffer) + var result: Api.AttachMenuBotsBot? + if let signature = reader.readInt32() { + result = Api.parse(reader, signature: signature) as? Api.AttachMenuBotsBot + } + return result + }) + } + public static func toggleBotInAttachMenu(bot: Api.InputUser, enabled: Api.Bool) -> (FunctionDescription, Buffer, DeserializeFunctionResponse) { let buffer = Buffer() buffer.appendInt32(451818415) @@ -4879,15 +4893,16 @@ public extension Api { }) } - public static func requestWebView(flags: Int32, peer: Api.InputPeer, bot: Api.InputUser, url: String?, themeParams: Api.DataJSON?) -> (FunctionDescription, Buffer, DeserializeFunctionResponse) { + public static func requestWebView(flags: Int32, peer: Api.InputPeer, bot: Api.InputUser, url: String?, themeParams: Api.DataJSON?, replyToMsgId: Int32?) -> (FunctionDescription, Buffer, DeserializeFunctionResponse) { let buffer = Buffer() - buffer.appendInt32(-1585704741) + buffer.appendInt32(572653208) serializeInt32(flags, buffer: buffer, boxed: false) peer.serialize(buffer, true) bot.serialize(buffer, true) - if Int(flags) & Int(1 << 0) != 0 {serializeString(url!, buffer: buffer, boxed: false)} - if Int(flags) & Int(1 << 1) != 0 {themeParams!.serialize(buffer, true)} - return (FunctionDescription(name: "messages.requestWebView", parameters: [("flags", flags), ("peer", peer), ("bot", bot), ("url", url), ("themeParams", themeParams)]), buffer, DeserializeFunctionResponse { (buffer: Buffer) -> Api.WebViewResult? in + if Int(flags) & Int(1 << 1) != 0 {serializeString(url!, buffer: buffer, boxed: false)} + if Int(flags) & Int(1 << 2) != 0 {themeParams!.serialize(buffer, true)} + if Int(flags) & Int(1 << 0) != 0 {serializeInt32(replyToMsgId!, buffer: buffer, boxed: false)} + return (FunctionDescription(name: "messages.requestWebView", parameters: [("flags", flags), ("peer", peer), ("bot", bot), ("url", url), ("themeParams", themeParams), ("replyToMsgId", replyToMsgId)]), buffer, DeserializeFunctionResponse { (buffer: Buffer) -> Api.WebViewResult? in let reader = BufferReader(buffer) var result: Api.WebViewResult? if let signature = reader.readInt32() { @@ -4897,12 +4912,15 @@ public extension Api { }) } - public static func setWebViewResult(queryId: Int64, result: Api.InputBotInlineResult) -> (FunctionDescription, Buffer, DeserializeFunctionResponse) { + public static func prolongWebView(flags: Int32, peer: Api.InputPeer, bot: Api.InputUser, queryId: Int64, replyToMsgId: Int32?) -> (FunctionDescription, Buffer, DeserializeFunctionResponse) { let buffer = Buffer() - buffer.appendInt32(-467873507) + buffer.appendInt32(-768945848) + serializeInt32(flags, buffer: buffer, boxed: false) + peer.serialize(buffer, true) + bot.serialize(buffer, true) serializeInt64(queryId, buffer: buffer, boxed: false) - result.serialize(buffer, true) - return (FunctionDescription(name: "messages.setWebViewResult", parameters: [("queryId", queryId), ("result", result)]), buffer, DeserializeFunctionResponse { (buffer: Buffer) -> Api.Bool? in + if Int(flags) & Int(1 << 0) != 0 {serializeInt32(replyToMsgId!, buffer: buffer, boxed: false)} + return (FunctionDescription(name: "messages.prolongWebView", parameters: [("flags", flags), ("peer", peer), ("bot", bot), ("queryId", queryId), ("replyToMsgId", replyToMsgId)]), buffer, DeserializeFunctionResponse { (buffer: Buffer) -> Api.Bool? in let reader = BufferReader(buffer) var result: Api.Bool? if let signature = reader.readInt32() { @@ -4912,17 +4930,50 @@ public extension Api { }) } - public static func getWebViewResult(peer: Api.InputPeer, bot: Api.InputUser, queryId: Int64) -> (FunctionDescription, Buffer, DeserializeFunctionResponse) { + public static func requestSimpleWebView(flags: Int32, bot: Api.InputUser, url: String, themeParams: Api.DataJSON?) -> (FunctionDescription, Buffer, DeserializeFunctionResponse) { let buffer = Buffer() - buffer.appendInt32(582402580) - peer.serialize(buffer, true) + buffer.appendInt32(1790652275) + serializeInt32(flags, buffer: buffer, boxed: false) bot.serialize(buffer, true) - serializeInt64(queryId, buffer: buffer, boxed: false) - return (FunctionDescription(name: "messages.getWebViewResult", parameters: [("peer", peer), ("bot", bot), ("queryId", queryId)]), buffer, DeserializeFunctionResponse { (buffer: Buffer) -> Api.messages.WebViewResult? in + serializeString(url, buffer: buffer, boxed: false) + if Int(flags) & Int(1 << 0) != 0 {themeParams!.serialize(buffer, true)} + return (FunctionDescription(name: "messages.requestSimpleWebView", parameters: [("flags", flags), ("bot", bot), ("url", url), ("themeParams", themeParams)]), buffer, DeserializeFunctionResponse { (buffer: Buffer) -> Api.SimpleWebViewResult? in let reader = BufferReader(buffer) - var result: Api.messages.WebViewResult? + var result: Api.SimpleWebViewResult? if let signature = reader.readInt32() { - result = Api.parse(reader, signature: signature) as? Api.messages.WebViewResult + result = Api.parse(reader, signature: signature) as? Api.SimpleWebViewResult + } + return result + }) + } + + public static func sendWebViewResultMessage(queryId: Int64, result: Api.InputBotInlineResult) -> (FunctionDescription, Buffer, DeserializeFunctionResponse) { + let buffer = Buffer() + buffer.appendInt32(-573615893) + serializeInt64(queryId, buffer: buffer, boxed: false) + result.serialize(buffer, true) + return (FunctionDescription(name: "messages.sendWebViewResultMessage", parameters: [("queryId", queryId), ("result", result)]), buffer, DeserializeFunctionResponse { (buffer: Buffer) -> Api.WebViewMessageSent? in + let reader = BufferReader(buffer) + var result: Api.WebViewMessageSent? + if let signature = reader.readInt32() { + result = Api.parse(reader, signature: signature) as? Api.WebViewMessageSent + } + return result + }) + } + + public static func sendWebViewData(bot: Api.InputUser, randomId: Int64, buttonText: String, data: String) -> (FunctionDescription, Buffer, DeserializeFunctionResponse) { + let buffer = Buffer() + buffer.appendInt32(-603831608) + bot.serialize(buffer, true) + serializeInt64(randomId, buffer: buffer, boxed: false) + serializeString(buttonText, buffer: buffer, boxed: false) + serializeString(data, buffer: buffer, boxed: false) + return (FunctionDescription(name: "messages.sendWebViewData", parameters: [("bot", bot), ("randomId", randomId), ("buttonText", buttonText), ("data", data)]), buffer, DeserializeFunctionResponse { (buffer: Buffer) -> Api.Updates? in + let reader = BufferReader(buffer) + var result: Api.Updates? + if let signature = reader.readInt32() { + result = Api.parse(reader, signature: signature) as? Api.Updates } return result }) @@ -5343,16 +5394,17 @@ public extension Api { }) } - public static func deleteHistory(channel: Api.InputChannel, maxId: Int32) -> (FunctionDescription, Buffer, DeserializeFunctionResponse) { + public static func deleteHistory(flags: Int32, channel: Api.InputChannel, maxId: Int32) -> (FunctionDescription, Buffer, DeserializeFunctionResponse) { let buffer = Buffer() - buffer.appendInt32(-1355375294) + buffer.appendInt32(-1683319225) + serializeInt32(flags, buffer: buffer, boxed: false) channel.serialize(buffer, true) serializeInt32(maxId, buffer: buffer, boxed: false) - return (FunctionDescription(name: "channels.deleteHistory", parameters: [("channel", channel), ("maxId", maxId)]), buffer, DeserializeFunctionResponse { (buffer: Buffer) -> Api.Bool? in + return (FunctionDescription(name: "channels.deleteHistory", parameters: [("flags", flags), ("channel", channel), ("maxId", maxId)]), buffer, DeserializeFunctionResponse { (buffer: Buffer) -> Api.Updates? in let reader = BufferReader(buffer) - var result: Api.Bool? + var result: Api.Updates? if let signature = reader.readInt32() { - result = Api.parse(reader, signature: signature) as? Api.Bool + result = Api.parse(reader, signature: signature) as? Api.Updates } return result }) diff --git a/submodules/TelegramCore/Sources/ApiUtils/ReplyMarkupMessageAttribute.swift b/submodules/TelegramCore/Sources/ApiUtils/ReplyMarkupMessageAttribute.swift index 00158c8d14..3a97dfaaf4 100644 --- a/submodules/TelegramCore/Sources/ApiUtils/ReplyMarkupMessageAttribute.swift +++ b/submodules/TelegramCore/Sources/ApiUtils/ReplyMarkupMessageAttribute.swift @@ -43,7 +43,9 @@ extension ReplyMarkupButton { case let .inputKeyboardButtonUserProfile(text, _): self.init(title: text, titleWhenForwarded: nil, action: .openUserProfile(peerId: PeerId(namespace: Namespaces.Peer.CloudUser, id: PeerId.Id._internalFromInt64Value(0)))) case let .keyboardButtonWebView(text, url): - self.init(title: text, titleWhenForwarded: nil, action: .openWebView(url: url)) + self.init(title: text, titleWhenForwarded: nil, action: .openWebView(url: url, simple: false)) + case let .keyboardButtonSimpleWebView(text, url): + self.init(title: text, titleWhenForwarded: nil, action: .openWebView(url: url, simple: true)) } } } diff --git a/submodules/TelegramCore/Sources/ApiUtils/StoreMessage_Telegram.swift b/submodules/TelegramCore/Sources/ApiUtils/StoreMessage_Telegram.swift index a99c979800..6b2e662b9e 100644 --- a/submodules/TelegramCore/Sources/ApiUtils/StoreMessage_Telegram.swift +++ b/submodules/TelegramCore/Sources/ApiUtils/StoreMessage_Telegram.swift @@ -201,7 +201,7 @@ func apiMessagePeerIds(_ message: Api.Message) -> [PeerId] { } switch action { - case .messageActionChannelCreate, .messageActionChatDeletePhoto, .messageActionChatEditPhoto, .messageActionChatEditTitle, .messageActionEmpty, .messageActionPinMessage, .messageActionHistoryClear, .messageActionGameScore, .messageActionPaymentSent, .messageActionPaymentSentMe, .messageActionPhoneCall, .messageActionScreenshotTaken, .messageActionCustomAction, .messageActionBotAllowed, .messageActionSecureValuesSent, .messageActionSecureValuesSentMe, .messageActionContactSignUp, .messageActionGroupCall, .messageActionSetMessagesTTL, .messageActionGroupCallScheduled, .messageActionSetChatTheme, .messageActionChatJoinedByRequest: + case .messageActionChannelCreate, .messageActionChatDeletePhoto, .messageActionChatEditPhoto, .messageActionChatEditTitle, .messageActionEmpty, .messageActionPinMessage, .messageActionHistoryClear, .messageActionGameScore, .messageActionPaymentSent, .messageActionPaymentSentMe, .messageActionPhoneCall, .messageActionScreenshotTaken, .messageActionCustomAction, .messageActionBotAllowed, .messageActionSecureValuesSent, .messageActionSecureValuesSentMe, .messageActionContactSignUp, .messageActionGroupCall, .messageActionSetMessagesTTL, .messageActionGroupCallScheduled, .messageActionSetChatTheme, .messageActionChatJoinedByRequest, .messageActionWebViewDataSent, .messageActionWebViewDataSentMe: break case let .messageActionChannelMigrateFrom(_, chatId): result.append(PeerId(namespace: Namespaces.Peer.CloudGroup, id: PeerId.Id._internalFromInt64Value(chatId))) diff --git a/submodules/TelegramCore/Sources/ApiUtils/TelegramMediaAction.swift b/submodules/TelegramCore/Sources/ApiUtils/TelegramMediaAction.swift index c2a1b1efdc..dd34b5c563 100644 --- a/submodules/TelegramCore/Sources/ApiUtils/TelegramMediaAction.swift +++ b/submodules/TelegramCore/Sources/ApiUtils/TelegramMediaAction.swift @@ -81,6 +81,8 @@ func telegramMediaActionFromApiAction(_ action: Api.MessageAction) -> TelegramMe return TelegramMediaAction(action: .setChatTheme(emoji: emoji)) case .messageActionChatJoinedByRequest: return TelegramMediaAction(action: .joinedByRequest) + case let .messageActionWebViewDataSentMe(text, _), let .messageActionWebViewDataSent(text): + return TelegramMediaAction(action: .webViewData(text)) } } diff --git a/submodules/TelegramCore/Sources/State/ManagedCloudChatRemoveMessagesOperations.swift b/submodules/TelegramCore/Sources/State/ManagedCloudChatRemoveMessagesOperations.swift index 8f61dfe59d..b4af28309a 100644 --- a/submodules/TelegramCore/Sources/State/ManagedCloudChatRemoveMessagesOperations.swift +++ b/submodules/TelegramCore/Sources/State/ManagedCloudChatRemoveMessagesOperations.swift @@ -395,11 +395,16 @@ private func _internal_clearHistory(transaction: Transaction, postbox: Postbox, if operation.minTimestamp != nil { return .complete() } else { - return network.request(Api.functions.channels.deleteHistory(channel: inputChannel, maxId: operation.topMessageId.id)) - |> `catch` { _ -> Signal in - return .single(.boolFalse) + let flags: Int32 = 0 + return network.request(Api.functions.channels.deleteHistory(flags: flags, channel: inputChannel, maxId: operation.topMessageId.id)) + |> map(Optional.init) + |> `catch` { _ -> Signal in + return .single(nil) } - |> mapToSignal { _ -> Signal in + |> mapToSignal { updates -> Signal in + if let updates = updates { + stateManager.addUpdates(updates) + } return .complete() } } diff --git a/submodules/TelegramCore/Sources/SyncCore/SyncCore_ReplyMarkupMessageAttribute.swift b/submodules/TelegramCore/Sources/SyncCore/SyncCore_ReplyMarkupMessageAttribute.swift index 46ee14e87f..4c45bab232 100644 --- a/submodules/TelegramCore/Sources/SyncCore/SyncCore_ReplyMarkupMessageAttribute.swift +++ b/submodules/TelegramCore/Sources/SyncCore/SyncCore_ReplyMarkupMessageAttribute.swift @@ -12,7 +12,7 @@ public enum ReplyMarkupButtonAction: PostboxCoding, Equatable { case urlAuth(url: String, buttonId: Int32) case setupPoll(isQuiz: Bool?) case openUserProfile(peerId: PeerId) - case openWebView(url: String) + case openWebView(url: String, simple: Bool) public init(decoder: PostboxDecoder) { switch decoder.decodeInt32ForKey("v", orElse: 0) { @@ -39,7 +39,7 @@ public enum ReplyMarkupButtonAction: PostboxCoding, Equatable { case 10: self = .openUserProfile(peerId: PeerId(decoder.decodeInt64ForKey("peerId", orElse: 0))) case 11: - self = .openWebView(url: decoder.decodeStringForKey("u", orElse: "")) + self = .openWebView(url: decoder.decodeStringForKey("u", orElse: ""), simple: decoder.decodeInt32ForKey("s", orElse: 0) != 0) default: self = .text } @@ -82,9 +82,10 @@ public enum ReplyMarkupButtonAction: PostboxCoding, Equatable { case let .openUserProfile(peerId): encoder.encodeInt32(10, forKey: "v") encoder.encodeInt64(peerId.toInt64(), forKey: "peerId") - case let .openWebView(url): + case let .openWebView(url, simple): encoder.encodeInt32(11, forKey: "v") encoder.encodeString(url, forKey: "u") + encoder.encodeInt32(simple ? 1 : 0, forKey: "s") } } } diff --git a/submodules/TelegramCore/Sources/SyncCore/SyncCore_TelegramMediaAction.swift b/submodules/TelegramCore/Sources/SyncCore/SyncCore_TelegramMediaAction.swift index b0261bf8ae..9ca8e87253 100644 --- a/submodules/TelegramCore/Sources/SyncCore/SyncCore_TelegramMediaAction.swift +++ b/submodules/TelegramCore/Sources/SyncCore/SyncCore_TelegramMediaAction.swift @@ -50,6 +50,7 @@ public enum TelegramMediaActionType: PostboxCoding, Equatable { case inviteToGroupPhoneCall(callId: Int64, accessHash: Int64, peerIds: [PeerId]) case setChatTheme(emoji: String) case joinedByRequest + case webViewData(String) public init(decoder: PostboxDecoder) { let rawValue: Int32 = decoder.decodeInt32ForKey("_rawValue", orElse: 0) @@ -116,6 +117,8 @@ public enum TelegramMediaActionType: PostboxCoding, Equatable { self = .setChatTheme(emoji: decoder.decodeStringForKey("emoji", orElse: "")) case 25: self = .joinedByRequest + case 26: + self = .webViewData(decoder.decodeStringForKey("t", orElse: "")) default: self = .unknown } @@ -230,6 +233,9 @@ public enum TelegramMediaActionType: PostboxCoding, Equatable { encoder.encodeString(emoji, forKey: "emoji") case .joinedByRequest: encoder.encodeInt32(25, forKey: "_rawValue") + case let .webViewData(text): + encoder.encodeInt32(26, forKey: "_rawValue") + encoder.encodeString(text, forKey: "t") } } diff --git a/submodules/TelegramCore/Sources/TelegramEngine/Messages/AttachMenuBots.swift b/submodules/TelegramCore/Sources/TelegramEngine/Messages/AttachMenuBots.swift index 83ca3ef76e..44d0ed905a 100644 --- a/submodules/TelegramCore/Sources/TelegramEngine/Messages/AttachMenuBots.swift +++ b/submodules/TelegramCore/Sources/TelegramEngine/Messages/AttachMenuBots.swift @@ -3,21 +3,26 @@ import TelegramApi import Postbox import SwiftSignalKit +//# inactive:flags.0?true bot_id:long attach_menu_name:string attach_menu_icon:Document = AttachMenuBot; public final class AttachMenuBots: Equatable, Codable { public final class Bot: Equatable, Codable { private enum CodingKeys: String, CodingKey { case peerId + case name case icon } public let peerId: PeerId + public let name: String public let icon: TelegramMediaFile public init( peerId: PeerId, + name: String, icon: TelegramMediaFile ) { self.peerId = peerId + self.name = name self.icon = icon } @@ -25,6 +30,9 @@ public final class AttachMenuBots: Equatable, Codable { if lhs.peerId != rhs.peerId { return false } + if lhs.name != rhs.name { + return false + } if lhs.icon != rhs.icon { return false } @@ -37,6 +45,8 @@ public final class AttachMenuBots: Equatable, Codable { let peerIdValue = try container.decode(Int64.self, forKey: .peerId) self.peerId = PeerId(peerIdValue) + self.name = try container.decodeIfPresent(String.self, forKey: .name) ?? "" + let iconData = try container.decode(AdaptedPostboxDecoder.RawObjectData.self, forKey: .icon) self.icon = TelegramMediaFile(decoder: PostboxDecoder(buffer: MemoryBuffer(data: iconData.data))) } @@ -45,6 +55,7 @@ public final class AttachMenuBots: Equatable, Codable { var container = encoder.container(keyedBy: CodingKeys.self) try container.encode(self.peerId.toInt64(), forKey: .peerId) + try container.encode(self.name, forKey: .name) try container.encode(PostboxEncoder().encodeObjectToRawData(self.icon), forKey: .icon) } } @@ -148,9 +159,9 @@ func managedSynchronizeAttachMenuBots(postbox: Postbox, network: Network) -> Sig var resultBots: [AttachMenuBots.Bot] = [] for bot in bots { switch bot { - case let .attachMenuBot(botId, attachMenuIcon): + case let .attachMenuBot(_, botId, name, attachMenuIcon): if let icon = telegramMediaFileFromApiDocument(attachMenuIcon) { - resultBots.append(AttachMenuBots.Bot(peerId: PeerId(namespace: Namespaces.Peer.CloudUser, id: PeerId.Id._internalFromInt64Value(botId)), icon: icon)) + resultBots.append(AttachMenuBots.Bot(peerId: PeerId(namespace: Namespaces.Peer.CloudUser, id: PeerId.Id._internalFromInt64Value(botId)), name: name, icon: icon)) } } } diff --git a/submodules/TelegramCore/Sources/TelegramEngine/Messages/BotWebView.swift b/submodules/TelegramCore/Sources/TelegramEngine/Messages/BotWebView.swift index 5f7d75c54e..6dca28a137 100644 --- a/submodules/TelegramCore/Sources/TelegramEngine/Messages/BotWebView.swift +++ b/submodules/TelegramCore/Sources/TelegramEngine/Messages/BotWebView.swift @@ -4,6 +4,40 @@ import SwiftSignalKit import TelegramApi import MtProtoKit +public enum RequestSimpleWebViewError { + case generic +} + +func _internal_requestSimpleWebView(postbox: Postbox, network: Network, botId: PeerId, url: String, themeParams: [String: Any]?) -> Signal { + var serializedThemeParams: Api.DataJSON? + if let themeParams = themeParams, let data = try? JSONSerialization.data(withJSONObject: themeParams, options: []), let dataString = String(data: data, encoding: .utf8) { + serializedThemeParams = .dataJSON(data: dataString) + } + + return postbox.transaction { transaction -> Signal in + guard let bot = transaction.getPeer(botId), let inputUser = apiInputUser(bot) else { + return .fail(.generic) + } + + var flags: Int32 = 0 + if let _ = serializedThemeParams { + flags |= (1 << 0) + } + return network.request(Api.functions.messages.requestSimpleWebView(flags: flags, bot: inputUser, url: url, themeParams: serializedThemeParams)) + |> mapError { _ -> RequestSimpleWebViewError in + return .generic + } + |> mapToSignal { result -> Signal in + switch result { + case let .simpleWebViewResultUrl(url): + return .single(url) + } + } + } + |> castError(RequestSimpleWebViewError.self) + |> switchToLatest +} + public enum RequestWebViewResult { case webViewResult(queryId: Int64, url: String) case requestConfirmation(botIcon: TelegramMediaFile) @@ -13,7 +47,7 @@ public enum RequestWebViewError { case generic } -func _internal_requestWebView(postbox: Postbox, network: Network, peerId: PeerId, botId: PeerId, url: String?, themeParams: [String: Any]?) -> Signal { +func _internal_requestWebView(postbox: Postbox, network: Network, peerId: PeerId, botId: PeerId, url: String?, themeParams: [String: Any]?, replyToMessageId: MessageId?) -> Signal { var serializedThemeParams: Api.DataJSON? if let themeParams = themeParams, let data = try? JSONSerialization.data(withJSONObject: themeParams, options: []), let dataString = String(data: data, encoding: .utf8) { serializedThemeParams = .dataJSON(data: dataString) @@ -26,12 +60,17 @@ func _internal_requestWebView(postbox: Postbox, network: Network, peerId: PeerId var flags: Int32 = 0 if let _ = url { - flags |= (1 << 0) - } - if let _ = serializedThemeParams { flags |= (1 << 1) } - return network.request(Api.functions.messages.requestWebView(flags: flags, peer: inputPeer, bot: inputUser, url: url, themeParams: serializedThemeParams)) + if let _ = serializedThemeParams { + flags |= (1 << 2) + } + var replyToMsgId: Int32? + if let replyToMessageId = replyToMessageId { + flags |= (1 << 0) + replyToMsgId = replyToMessageId.id + } + return network.request(Api.functions.messages.requestWebView(flags: flags, peer: inputPeer, bot: inputUser, url: url, themeParams: serializedThemeParams, replyToMsgId: replyToMsgId)) |> mapError { _ -> RequestWebViewError in return .generic } @@ -48,7 +87,7 @@ func _internal_requestWebView(postbox: Postbox, network: Network, peerId: PeerId return updated }) - if case let .attachMenuBot(_, attachMenuIcon) = bot, let icon = telegramMediaFileFromApiDocument(attachMenuIcon) { + if case let .attachMenuBot(_, _, _, attachMenuIcon) = bot, let icon = telegramMediaFileFromApiDocument(attachMenuIcon) { return .single(.requestConfirmation(botIcon: icon)) } else { return .complete() @@ -64,38 +103,3 @@ func _internal_requestWebView(postbox: Postbox, network: Network, peerId: PeerId |> castError(RequestWebViewError.self) |> switchToLatest } - -public enum GetWebViewResultError { - case generic -} - -func _internal_getWebViewResult(postbox: Postbox, network: Network, peerId: PeerId, botId: PeerId, queryId: Int64) -> Signal { - return postbox.transaction { transaction -> Signal in - guard let peer = transaction.getPeer(peerId), let inputPeer = apiInputPeer(peer), let bot = transaction.getPeer(botId), let inputUser = apiInputUser(bot) else { - return .fail(.generic) - } - return network.request(Api.functions.messages.getWebViewResult(peer: inputPeer, bot: inputUser, queryId: queryId)) - |> mapError { _ -> GetWebViewResultError in - return .generic - } - |> mapToSignal { result -> Signal in - return postbox.transaction { transaction -> ChatContextResult in - switch result { - case let .webViewResult(result, users): - var peers: [Peer] = [] - for user in users { - let telegramUser = TelegramUser(user: user) - peers.append(telegramUser) - } - updatePeers(transaction: transaction, peers: peers, update: { _, updated -> Peer in - return updated - }) - return ChatContextResult(apiResult: result, queryId: queryId) - } - } - |> castError(GetWebViewResultError.self) - } - } - |> castError(GetWebViewResultError.self) - |> switchToLatest -} diff --git a/submodules/TelegramCore/Sources/TelegramEngine/Messages/TelegramEngineMessages.swift b/submodules/TelegramCore/Sources/TelegramEngine/Messages/TelegramEngineMessages.swift index 21ff8ac888..e678b26d61 100644 --- a/submodules/TelegramCore/Sources/TelegramEngine/Messages/TelegramEngineMessages.swift +++ b/submodules/TelegramCore/Sources/TelegramEngine/Messages/TelegramEngineMessages.swift @@ -322,14 +322,14 @@ public extension TelegramEngine { return _internal_translate(network: self.account.network, text: text, fromLang: fromLang, toLang: toLang) } - public func requestWebView(peerId: PeerId, botId: PeerId, url: String?, themeParams: [String: Any]?) -> Signal { - return _internal_requestWebView(postbox: self.account.postbox, network: self.account.network, peerId: peerId, botId: botId, url: url, themeParams: themeParams) + public func requestWebView(peerId: PeerId, botId: PeerId, url: String?, themeParams: [String: Any]?, replyToMessageId: MessageId?) -> Signal { + return _internal_requestWebView(postbox: self.account.postbox, network: self.account.network, peerId: peerId, botId: botId, url: url, themeParams: themeParams, replyToMessageId: replyToMessageId) } - public func getWebViewResult(peerId: PeerId, botId: PeerId, queryId: Int64) -> Signal { - return _internal_getWebViewResult(postbox: self.account.postbox, network: self.account.network, peerId: peerId, botId: botId, queryId: queryId) + public func requestSimpleWebView(botId: PeerId, url: String, themeParams: [String: Any]?) -> Signal { + return _internal_requestSimpleWebView(postbox: self.account.postbox, network: self.account.network, botId: botId, url: url, themeParams: themeParams) } - + public func addBotToAttachMenu(peerId: PeerId) -> Signal { return _internal_addBotToAttachMenu(postbox: self.account.postbox, network: self.account.network, peerId: peerId) } diff --git a/submodules/TelegramStringFormatting/Sources/ServiceMessageStrings.swift b/submodules/TelegramStringFormatting/Sources/ServiceMessageStrings.swift index 817b0f3662..9a34e044c0 100644 --- a/submodules/TelegramStringFormatting/Sources/ServiceMessageStrings.swift +++ b/submodules/TelegramStringFormatting/Sources/ServiceMessageStrings.swift @@ -631,6 +631,8 @@ public func universalServiceMessageString(presentationData: (PresentationTheme, attributedString = addAttributesToStringWithRanges(resultTitleString._tuple, body: bodyAttributes, argumentAttributes: [0: boldAttributes]) } } + case let .webViewData(text): + attributedString = NSAttributedString(string: "Data for \(text) sent to bot", font: titleFont, textColor: primaryTextColor) case .unknown: attributedString = nil } diff --git a/submodules/TelegramUI/Sources/ChatButtonKeyboardInputNode.swift b/submodules/TelegramUI/Sources/ChatButtonKeyboardInputNode.swift index 209981733e..9dffbf9b01 100644 --- a/submodules/TelegramUI/Sources/ChatButtonKeyboardInputNode.swift +++ b/submodules/TelegramUI/Sources/ChatButtonKeyboardInputNode.swift @@ -215,8 +215,8 @@ final class ChatButtonKeyboardInputNode: ChatInputNode { self.controllerInteraction.openPollCreation(isQuiz) case let .openUserProfile(peerId): self.controllerInteraction.openPeer(peerId, .info, nil, nil) - case let .openWebView(url): - self.controllerInteraction.openWebView(url) + case let .openWebView(url, simple): + self.controllerInteraction.openWebView(url, simple) } if dismissIfOnce { if let message = self.message { diff --git a/submodules/TelegramUI/Sources/ChatController.swift b/submodules/TelegramUI/Sources/ChatController.swift index e9bade6c32..01c02578ce 100644 --- a/submodules/TelegramUI/Sources/ChatController.swift +++ b/submodules/TelegramUI/Sources/ChatController.swift @@ -3301,7 +3301,7 @@ public final class ChatControllerImpl: TelegramBaseController, ChatController, G return } strongSelf.openResolved(result: .join(joinHash), sourceMessageId: nil) - }, openWebView: { [weak self] url in + }, openWebView: { [weak self] url, simple in guard let strongSelf = self, let peerId = strongSelf.chatLocation.peerId, let peer = strongSelf.presentationInterfaceState.renderedPeer?.peer else { return } @@ -3350,7 +3350,7 @@ public final class ChatControllerImpl: TelegramBaseController, ChatController, G } } - strongSelf.messageActionCallbackDisposable.set(((strongSelf.context.engine.messages.requestWebView(peerId: peerId, botId: peerId, url: url, themeParams: generateWebAppThemeParams(strongSelf.presentationData.theme)) + strongSelf.messageActionCallbackDisposable.set(((strongSelf.context.engine.messages.requestWebView(peerId: peerId, botId: peerId, url: url, themeParams: generateWebAppThemeParams(strongSelf.presentationData.theme), replyToMessageId: nil) |> afterDisposed { updateProgress() }) @@ -10504,10 +10504,15 @@ public final class ChatControllerImpl: TelegramBaseController, ChatController, G let presentationData = self.presentationData + var isScheduledMessages = false + if case .scheduledMessages = self.presentationInterfaceState.subject { + isScheduledMessages = true + } + var switchToBotImpl: ((AttachmentButtonType) -> Void)? var switchToBotId = botId let buttons: Signal<[AttachmentButtonType], NoError> - if let _ = peer as? TelegramUser { + if let _ = peer as? TelegramUser, !isScheduledMessages { buttons = .single(availableButtons) |> then( self.context.engine.messages.attachMenuBots() diff --git a/submodules/TelegramUI/Sources/ChatControllerInteraction.swift b/submodules/TelegramUI/Sources/ChatControllerInteraction.swift index 0b72c4a1af..004618f7cb 100644 --- a/submodules/TelegramUI/Sources/ChatControllerInteraction.swift +++ b/submodules/TelegramUI/Sources/ChatControllerInteraction.swift @@ -131,7 +131,7 @@ public final class ChatControllerInteraction { let commitEmojiInteraction: (MessageId, String, EmojiInteraction, TelegramMediaFile) -> Void let openLargeEmojiInfo: (String, String?, TelegramMediaFile) -> Void let openJoinLink: (String) -> Void - let openWebView: (String) -> Void + let openWebView: (String, Bool) -> Void let requestMessageUpdate: (MessageId) -> Void let cancelInteractiveKeyboardGestures: () -> Void @@ -231,7 +231,7 @@ public final class ChatControllerInteraction { commitEmojiInteraction: @escaping (MessageId, String, EmojiInteraction, TelegramMediaFile) -> Void, openLargeEmojiInfo: @escaping (String, String?, TelegramMediaFile) -> Void, openJoinLink: @escaping (String) -> Void, - openWebView: @escaping (String) -> Void, + openWebView: @escaping (String, Bool) -> Void, requestMessageUpdate: @escaping (MessageId) -> Void, cancelInteractiveKeyboardGestures: @escaping () -> Void, automaticMediaDownloadSettings: MediaAutoDownloadSettings, @@ -377,7 +377,7 @@ public final class ChatControllerInteraction { }, commitEmojiInteraction: { _, _, _, _ in }, openLargeEmojiInfo: { _, _, _ in }, openJoinLink: { _ in - }, openWebView: { _ in + }, openWebView: { _, _ in }, requestMessageUpdate: { _ in }, cancelInteractiveKeyboardGestures: { }, automaticMediaDownloadSettings: MediaAutoDownloadSettings.defaultSettings, diff --git a/submodules/TelegramUI/Sources/ChatMessageItemView.swift b/submodules/TelegramUI/Sources/ChatMessageItemView.swift index 7a2b8a9d07..85e5238220 100644 --- a/submodules/TelegramUI/Sources/ChatMessageItemView.swift +++ b/submodules/TelegramUI/Sources/ChatMessageItemView.swift @@ -854,8 +854,8 @@ public class ChatMessageItemView: ListViewItemNode, ChatMessageItemNodeProtocol break case let .openUserProfile(peerId): item.controllerInteraction.openPeer(peerId, .info, nil, nil) - case let .openWebView(url): - item.controllerInteraction.openWebView(url) + case let .openWebView(url, simple): + item.controllerInteraction.openWebView(url, simple) } } } diff --git a/submodules/TelegramUI/Sources/ChatRecentActionsControllerNode.swift b/submodules/TelegramUI/Sources/ChatRecentActionsControllerNode.swift index 7315816a94..fefd085f4c 100644 --- a/submodules/TelegramUI/Sources/ChatRecentActionsControllerNode.swift +++ b/submodules/TelegramUI/Sources/ChatRecentActionsControllerNode.swift @@ -532,7 +532,7 @@ final class ChatRecentActionsControllerNode: ViewControllerTracingNode { }, commitEmojiInteraction: { _, _, _, _ in }, openLargeEmojiInfo: { _, _, _ in }, openJoinLink: { _ in - }, openWebView: { _ in + }, openWebView: { _, _ in }, requestMessageUpdate: { _ in }, cancelInteractiveKeyboardGestures: { }, automaticMediaDownloadSettings: self.automaticMediaDownloadSettings, diff --git a/submodules/TelegramUI/Sources/DrawingStickersScreen.swift b/submodules/TelegramUI/Sources/DrawingStickersScreen.swift index 67413618cb..a54cf73998 100644 --- a/submodules/TelegramUI/Sources/DrawingStickersScreen.swift +++ b/submodules/TelegramUI/Sources/DrawingStickersScreen.swift @@ -159,7 +159,7 @@ private final class DrawingStickersScreenNode: ViewControllerTracingNode { }, commitEmojiInteraction: { _, _, _, _ in }, openLargeEmojiInfo: { _, _, _ in }, openJoinLink: { _ in - }, openWebView: { _ in + }, openWebView: { _, _ in }, requestMessageUpdate: { _ in }, cancelInteractiveKeyboardGestures: { }, automaticMediaDownloadSettings: MediaAutoDownloadSettings.defaultSettings, diff --git a/submodules/TelegramUI/Sources/OpenResolvedUrl.swift b/submodules/TelegramUI/Sources/OpenResolvedUrl.swift index 2b9f753686..73ef493e7d 100644 --- a/submodules/TelegramUI/Sources/OpenResolvedUrl.swift +++ b/submodules/TelegramUI/Sources/OpenResolvedUrl.swift @@ -563,7 +563,7 @@ func openResolvedUrlImpl(_ resolvedUrl: ResolvedUrl, context: AccountContext, ur guard let peer = peer else { return } - let _ = (context.engine.messages.requestWebView(peerId: peer.id, botId: peer.id, url: nil, themeParams: nil) + let _ = (context.engine.messages.requestWebView(peerId: peer.id, botId: peer.id, url: nil, themeParams: nil, replyToMessageId: nil) |> deliverOnMainQueue).start(next: { result in if case let .requestConfirmation(botIcon) = result { if case let .user(user) = peer, let botInfo = user.botInfo, botInfo.flags.contains(.canBeAddedToAttachMenu) { diff --git a/submodules/TelegramUI/Sources/OverlayAudioPlayerControllerNode.swift b/submodules/TelegramUI/Sources/OverlayAudioPlayerControllerNode.swift index f7a18f821c..c16c7e48f3 100644 --- a/submodules/TelegramUI/Sources/OverlayAudioPlayerControllerNode.swift +++ b/submodules/TelegramUI/Sources/OverlayAudioPlayerControllerNode.swift @@ -151,7 +151,7 @@ final class OverlayAudioPlayerControllerNode: ViewControllerTracingNode, UIGestu }, commitEmojiInteraction: { _, _, _, _ in }, openLargeEmojiInfo: { _, _, _ in }, openJoinLink: { _ in - }, openWebView: { _ in + }, openWebView: { _, _ in }, requestMessageUpdate: { _ in }, cancelInteractiveKeyboardGestures: { }, automaticMediaDownloadSettings: MediaAutoDownloadSettings.defaultSettings, pollActionState: ChatInterfacePollActionState(), stickerSettings: ChatInterfaceStickerSettings(loopAnimatedStickers: false), presentationContext: ChatPresentationContext(backgroundNode: nil)) diff --git a/submodules/TelegramUI/Sources/PeerInfo/PeerInfoScreen.swift b/submodules/TelegramUI/Sources/PeerInfo/PeerInfoScreen.swift index b713d4be7c..83a2c0b67e 100644 --- a/submodules/TelegramUI/Sources/PeerInfo/PeerInfoScreen.swift +++ b/submodules/TelegramUI/Sources/PeerInfo/PeerInfoScreen.swift @@ -2266,7 +2266,7 @@ final class PeerInfoScreenNode: ViewControllerTracingNode, UIScrollViewDelegate }, commitEmojiInteraction: { _, _, _, _ in }, openLargeEmojiInfo: { _, _, _ in }, openJoinLink: { _ in - }, openWebView: { _ in + }, openWebView: { _, _ in }, requestMessageUpdate: { _ in }, cancelInteractiveKeyboardGestures: { }, automaticMediaDownloadSettings: MediaAutoDownloadSettings.defaultSettings, diff --git a/submodules/TelegramUI/Sources/SharedAccountContext.swift b/submodules/TelegramUI/Sources/SharedAccountContext.swift index 15a4da6265..136adcac7e 100644 --- a/submodules/TelegramUI/Sources/SharedAccountContext.swift +++ b/submodules/TelegramUI/Sources/SharedAccountContext.swift @@ -1325,7 +1325,7 @@ public final class SharedAccountContextImpl: SharedAccountContext { }, commitEmojiInteraction: { _, _, _, _ in }, openLargeEmojiInfo: { _, _, _ in }, openJoinLink: { _ in - }, openWebView: { _ in + }, openWebView: { _, _ in }, requestMessageUpdate: { _ in }, cancelInteractiveKeyboardGestures: { }, automaticMediaDownloadSettings: MediaAutoDownloadSettings.defaultSettings, diff --git a/submodules/WebUI/Sources/WebAppController.swift b/submodules/WebUI/Sources/WebAppController.swift index e998320228..89b643c234 100644 --- a/submodules/WebUI/Sources/WebAppController.swift +++ b/submodules/WebUI/Sources/WebAppController.swift @@ -133,7 +133,7 @@ public final class WebAppController: ViewController, AttachmentContainable { self.webView?.load(URLRequest(url: parsedUrl)) } } else { - let _ = (context.engine.messages.requestWebView(peerId: peerId, botId: botId, url: url, themeParams: generateWebAppThemeParams(presentationData.theme)) + let _ = (context.engine.messages.requestWebView(peerId: peerId, botId: botId, url: url, themeParams: generateWebAppThemeParams(presentationData.theme), replyToMessageId: nil) |> deliverOnMainQueue).start(next: { [weak self] result in guard let strongSelf = self else { return @@ -217,7 +217,7 @@ public final class WebAppController: ViewController, AttachmentContainable { } switch eventName { - case "webview_send_result_message": + case "webview_data_send": self.handleSendResultMessage() case "webview_close": self.controller?.dismiss() @@ -243,43 +243,46 @@ public final class WebAppController: ViewController, AttachmentContainable { } let themeParams = generateWebAppThemeParams(presentationData.theme) - var themeParamsString = "{" + var themeParamsString = "{theme_params: {" for (key, value) in themeParams { if let value = value as? Int32 { let color = UIColor(rgb: UInt32(bitPattern: value)) - if themeParamsString.count > 1 { + if themeParamsString.count > 16 { themeParamsString.append(", ") } themeParamsString.append("\"\(key)\": \"#\(color.hexString)\"") } } - themeParamsString.append("}") + themeParamsString.append("}}") self.sendEvent(name: "theme_changed", data: themeParamsString) } - private weak var currentAlertController: AlertController? private func handleSendResultMessage() { - guard let controller = self.controller, let queryId = self.queryId, self.currentAlertController == nil else { + guard let controller = self.controller else { return } - - let _ = (self.context.engine.messages.getWebViewResult(peerId: controller.peerId, botId: controller.botId, queryId: queryId) - |> deliverOnMainQueue).start(next: { [weak self] result in - guard let strongSelf = self, let controller = strongSelf.controller else { - return - } - - let alertController = webAppPreviewResultController(context: strongSelf.context, to: controller.peerId, botId: controller.botId, result: result, completion: { [weak self] in - guard let strongSelf = self, let controller = strongSelf.controller else { - return - } - let _ = strongSelf.context.engine.messages.enqueueOutgoingMessageWithChatContextResult(to: controller.peerId, botId: controller.botId, result: result) - controller.dismiss() - }) - controller.present(alertController, in: .window(.root)) - strongSelf.currentAlertController = alertController - }) + controller.dismiss() +// guard let controller = self.controller, let queryId = self.queryId, self.currentAlertController == nil else { +// return +// } +// +// let _ = (self.context.engine.messages.getWebViewResult(peerId: controller.peerId, botId: controller.botId, queryId: queryId) +// |> deliverOnMainQueue).start(next: { [weak self] result in +// guard let strongSelf = self, let controller = strongSelf.controller else { +// return +// } +// +// let alertController = webAppPreviewResultController(context: strongSelf.context, to: controller.peerId, botId: controller.botId, result: result, completion: { [weak self] in +// guard let strongSelf = self, let controller = strongSelf.controller else { +// return +// } +// let _ = strongSelf.context.engine.messages.enqueueOutgoingMessageWithChatContextResult(to: controller.peerId, botId: controller.botId, result: result) +// controller.dismiss() +// }) +// controller.present(alertController, in: .window(.root)) +// strongSelf.currentAlertController = alertController +// }) } }