diff --git a/td/generate/scheme/td_api.tl b/td/generate/scheme/td_api.tl index 5180d5e29..da944b5a2 100644 --- a/td/generate/scheme/td_api.tl +++ b/td/generate/scheme/td_api.tl @@ -3751,8 +3751,8 @@ internalLinkTypeFilterSettings = InternalLinkType; //@bot_username Username of the bot that owns the game @game_short_name Short name of the game internalLinkTypeGame bot_username:string game_short_name:string = InternalLinkType; -//@description The link must be opened in an Instant View. Call getWebPageInstantView with the given URL to process the link @url URL to be passed to getWebPageInstantView -internalLinkTypeInstantView url:string = InternalLinkType; +//@description The link must be opened in an Instant View. Call getWebPageInstantView with the given URL to process the link @url URL to be passed to getWebPageInstantView @fallback_url An URL to open if getWebPageInstantView fails +internalLinkTypeInstantView url:string fallback_url:string = InternalLinkType; //@description The link is a link to an invoice. Call getPaymentForm with the given invoice name to process the link @invoice_name Name of the invoice internalLinkTypeInvoice invoice_name:string = InternalLinkType; diff --git a/td/telegram/LinkManager.cpp b/td/telegram/LinkManager.cpp index a62524317..f87366bfd 100644 --- a/td/telegram/LinkManager.cpp +++ b/td/telegram/LinkManager.cpp @@ -339,13 +339,15 @@ class LinkManager::InternalLinkGame final : public InternalLink { class LinkManager::InternalLinkInstantView final : public InternalLink { string url_; + string fallback_url_; td_api::object_ptr get_internal_link_type_object() const final { - return td_api::make_object(url_); + return td_api::make_object(url_, fallback_url_); } public: - explicit InternalLinkInstantView(string url) : url_(std::move(url)) { + InternalLinkInstantView(string url, string fallback_url) + : url_(std::move(url)), fallback_url_(std::move(fallback_url)) { } }; @@ -975,7 +977,7 @@ unique_ptr LinkManager::parse_internal_link(Slice lin case LinkType::TMe: return parse_t_me_link_query(info.query_, is_trusted); case LinkType::Telegraph: - return td::make_unique(PSTRING() << "https://telegra.ph" << info.query_); + return td::make_unique(PSTRING() << "https://telegra.ph" << info.query_, link.str()); default: UNREACHABLE(); return nullptr; @@ -1364,8 +1366,8 @@ unique_ptr LinkManager::parse_t_me_link_query(Slice q } else if (path[0] == "iv") { if (path.size() == 1 && has_arg("url")) { // /iv?url=&rhash= - return td::make_unique(PSTRING() - << "https://t.me/iv" << copy_arg("url") << copy_arg("rhash")); + return td::make_unique( + PSTRING() << "https://t.me/iv" << copy_arg("url") << copy_arg("rhash"), get_arg("url")); } } else if (is_valid_username(path[0])) { if (path.size() >= 2 && to_integer(path[1]) > 0) { diff --git a/test/link.cpp b/test/link.cpp index 256c57bf8..3e2f6dafd 100644 --- a/test/link.cpp +++ b/test/link.cpp @@ -157,8 +157,8 @@ TEST(Link, parse_internal_link) { auto game = [](const td::string &bot_username, const td::string &game_short_name) { return td::td_api::make_object(bot_username, game_short_name); }; - auto instant_view = [](const td::string &url) { - return td::td_api::make_object(url); + auto instant_view = [](const td::string &url, const td::string &fallback_url) { + return td::td_api::make_object(url, fallback_url); }; auto invoice = [](const td::string &invoice_name) { return td::td_api::make_object(invoice_name); @@ -643,14 +643,15 @@ TEST(Link, parse_internal_link) { parse_internal_link("tg:setlanguage?lang=abc%30ef", language_pack("abc0ef")); parse_internal_link("tg://setlanguage?lang=", unknown_deep_link("tg://setlanguage?lang=")); - parse_internal_link("http://telegram.dog/iv?url=https://telegram.org&rhash=abcdef&test=1&tg_rhash=1", - instant_view("https://t.me/iv?url=https%3A%2F%2Ftelegram.org&rhash=abcdef")); + parse_internal_link( + "http://telegram.dog/iv?url=https://telegram.org&rhash=abcdef&test=1&tg_rhash=1", + instant_view("https://t.me/iv?url=https%3A%2F%2Ftelegram.org&rhash=abcdef", "https://telegram.org")); parse_internal_link("t.me/iva?url=https://telegram.org&rhash=abcdef", public_chat("iva")); parse_internal_link("t.me/iv?url=&rhash=abcdef", nullptr); parse_internal_link("t.me/iv?url=https://telegram.org&rhash=", - instant_view("https://t.me/iv?url=https%3A%2F%2Ftelegram.org&rhash")); + instant_view("https://t.me/iv?url=https%3A%2F%2Ftelegram.org&rhash", "https://telegram.org")); parse_internal_link("t.me/iv//////?url=https://telegram.org&rhash=", - instant_view("https://t.me/iv?url=https%3A%2F%2Ftelegram.org&rhash")); + instant_view("https://t.me/iv?url=https%3A%2F%2Ftelegram.org&rhash", "https://telegram.org")); parse_internal_link("t.me/iv/////1/?url=https://telegram.org&rhash=", nullptr); parse_internal_link("t.me/iv", nullptr); parse_internal_link("t.me/iv?#url=https://telegram.org&rhash=abcdef", nullptr); @@ -968,7 +969,7 @@ TEST(Link, parse_internal_link) { parse_internal_link("www.telegra.ph/", nullptr); parse_internal_link("www.telegrA.ph/#", nullptr); - parse_internal_link("www.telegrA.ph/?", instant_view("https://telegra.ph/?")); - parse_internal_link("http://te.leGra.ph/?", instant_view("https://telegra.ph/?")); - parse_internal_link("https://grAph.org/12345", instant_view("https://telegra.ph/12345")); + parse_internal_link("www.telegrA.ph/?", instant_view("https://telegra.ph/?", "www.telegrA.ph/?")); + parse_internal_link("http://te.leGra.ph/?", instant_view("https://telegra.ph/?", "http://te.leGra.ph/?")); + parse_internal_link("https://grAph.org/12345", instant_view("https://telegra.ph/12345", "https://grAph.org/12345")); }