Add internalLinkTypeInstantView.

This commit is contained in:
levlam 2022-09-16 01:30:54 +03:00
parent d2ad29725d
commit 0025c4164b
5 changed files with 41 additions and 1 deletions

View File

@ -3725,6 +3725,9 @@ 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 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;

View File

@ -337,6 +337,18 @@ class LinkManager::InternalLinkGame final : public InternalLink {
}
};
class LinkManager::InternalLinkInstantView final : public InternalLink {
string url_;
td_api::object_ptr<td_api::InternalLinkType> get_internal_link_type_object() const final {
return td_api::make_object<td_api::internalLinkTypeInstantView>(url_);
}
public:
explicit InternalLinkInstantView(string url) : url_(std::move(url)) {
}
};
class LinkManager::InternalLinkInvoice final : public InternalLink {
string invoice_name_;
@ -1336,6 +1348,12 @@ unique_ptr<LinkManager::InternalLink> LinkManager::parse_t_me_link_query(Slice q
// /share/url?url=<url>&text=<text>
return get_internal_link_message_draft(get_arg("url"), get_arg("text"));
}
} 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"));
}
} else if (is_valid_username(path[0])) {
if (path.size() >= 2 && to_integer<int64>(path[1]) > 0) {
// /<username>/12345?single&thread=<thread_id>&comment=<message_id>&t=<media_timestamp>

View File

@ -101,6 +101,7 @@ class LinkManager final : public Actor {
class InternalLinkDialogInvite;
class InternalLinkFilterSettings;
class InternalLinkGame;
class InternalLinkInstantView;
class InternalLinkInvoice;
class InternalLinkLanguage;
class InternalLinkLanguageSettings;

View File

@ -197,7 +197,7 @@ HttpUrlQuery parse_url_query(Slice query) {
HttpUrlQuery result;
result.path_ = full_split(url_decode(query.substr(0, path_size), false), '/');
if (!result.path_.empty() && result.path_.back().empty()) {
while (!result.path_.empty() && result.path_.back().empty()) {
result.path_.pop_back();
}

View File

@ -88,6 +88,7 @@ static void parse_internal_link(const td::string &url, td::td_api::object_ptr<td
}
ASSERT_STREQ(url + " " + to_string(expected), url + " " + to_string(object));
} else {
LOG_IF(ERROR, expected != nullptr) << url;
ASSERT_TRUE(expected == nullptr);
}
@ -155,6 +156,9 @@ 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 invoice = [](const td::string &invoice_name) {
return td::td_api::make_object<td::td_api::internalLinkTypeInvoice>(invoice_name);
};
@ -638,6 +642,20 @@ 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("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"));
parse_internal_link("t.me/iv//////?url=https://telegram.org&rhash=",
instant_view("https://t.me/iv?url=https%3A%2F%2Ftelegram.org&rhash"));
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);
parse_internal_link("tg:iv?url=https://telegram.org&rhash=abcdef",
unknown_deep_link("tg://iv?url=https://telegram.org&rhash=abcdef"));
parse_internal_link("t.me/addtheme?slug=abcdef", nullptr);
parse_internal_link("t.me/addtheme", nullptr);
parse_internal_link("t.me/addtheme/", nullptr);