Add fallback_url to internalLinkTypeInstantView.
This commit is contained in:
parent
35058bb6a7
commit
bc3ea3e123
@ -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;
|
||||
|
@ -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<td_api::InternalLinkType> get_internal_link_type_object() const final {
|
||||
return td_api::make_object<td_api::internalLinkTypeInstantView>(url_);
|
||||
return td_api::make_object<td_api::internalLinkTypeInstantView>(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::InternalLink> 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<InternalLinkInstantView>(PSTRING() << "https://telegra.ph" << info.query_);
|
||||
return td::make_unique<InternalLinkInstantView>(PSTRING() << "https://telegra.ph" << info.query_, link.str());
|
||||
default:
|
||||
UNREACHABLE();
|
||||
return nullptr;
|
||||
@ -1364,8 +1366,8 @@ unique_ptr<LinkManager::InternalLink> LinkManager::parse_t_me_link_query(Slice q
|
||||
} else if (path[0] == "iv") {
|
||||
if (path.size() == 1 && has_arg("url")) {
|
||||
// /iv?url=<url>&rhash=<rhash>
|
||||
return td::make_unique<InternalLinkInstantView>(PSTRING()
|
||||
<< "https://t.me/iv" << copy_arg("url") << copy_arg("rhash"));
|
||||
return td::make_unique<InternalLinkInstantView>(
|
||||
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<int64>(path[1]) > 0) {
|
||||
|
@ -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<td::td_api::internalLinkTypeGame>(bot_username, game_short_name);
|
||||
};
|
||||
auto instant_view = [](const td::string &url) {
|
||||
return td::td_api::make_object<td::td_api::internalLinkTypeInstantView>(url);
|
||||
auto instant_view = [](const td::string &url, const td::string &fallback_url) {
|
||||
return td::td_api::make_object<td::td_api::internalLinkTypeInstantView>(url, fallback_url);
|
||||
};
|
||||
auto invoice = [](const td::string &invoice_name) {
|
||||
return td::td_api::make_object<td::td_api::internalLinkTypeInvoice>(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"));
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user