Add internalLinkTypeLanguagePack.

This commit is contained in:
levlam 2021-05-28 19:26:09 +03:00
parent 2cb2ecc921
commit 8d8a5d0b30
4 changed files with 52 additions and 0 deletions

View File

@ -3009,6 +3009,9 @@ internalLinkTypeBackground background_name:string = InternalLinkType;
//@description The link is a chat invite link. Call checkChatInviteLink to process the link
internalLinkTypeChatInvite = InternalLinkType;
//@description The link is a link to a language pack. Call getLanguagePackInfo with the given language pack identifier to process the link @language_pack_id Language pack identifier
internalLinkTypeLanguagePack language_pack_id:string = InternalLinkType;
//@description The link is a link to a Telegram message. Call getMessageLinkInfo to process the link
internalLinkTypeMessage = InternalLinkType;

View File

@ -83,6 +83,22 @@ class LinkManager::InternalLinkDialogInvite : public InternalLink {
}
};
class LinkManager::InternalLinkLanguage : public InternalLink {
string language_pack_id_;
td_api::object_ptr<td_api::InternalLinkType> get_internal_link_type_object() const final {
return td_api::make_object<td_api::internalLinkTypeLanguagePack>(language_pack_id_);
}
InternalLinkType get_type() const final {
return InternalLinkType::Language;
}
public:
explicit InternalLinkLanguage(string language_pack_id) : language_pack_id_(std::move(language_pack_id)) {
}
};
class LinkManager::InternalLinkMessage : public InternalLink {
td_api::object_ptr<td_api::InternalLinkType> get_internal_link_type_object() const final {
return td_api::make_object<td_api::internalLinkTypeMessage>();
@ -478,6 +494,11 @@ unique_ptr<LinkManager::InternalLink> LinkManager::parse_tg_link_query(Slice que
if (has_arg("set")) {
return td::make_unique<InternalLinkStickerSet>(get_arg("set"));
}
} else if (path.size() == 1 && path[0] == "setlanguage") {
// setlanguage?lang=name
if (has_arg("lang")) {
return td::make_unique<InternalLinkLanguage>(get_arg("lang"));
}
} else if (path.size() == 1 && path[0] == "confirmphone") {
if (has_arg("hash") && has_arg("phone")) {
// confirmphone?phone=<phone>&hash=<hash>
@ -556,6 +577,11 @@ unique_ptr<LinkManager::InternalLink> LinkManager::parse_t_me_link_query(Slice q
// /addstickers/<name>
return td::make_unique<InternalLinkStickerSet>(path[1]);
}
} else if (path[0] == "setlanguage") {
if (path.size() >= 2 && !path[1].empty()) {
// /setlanguage/<name>
return td::make_unique<InternalLinkLanguage>(path[1]);
}
} else if (path[0] == "confirmphone") {
if (has_arg("hash") && has_arg("phone")) {
// /confirmphone?phone=<phone>&hash=<hash>

View File

@ -39,6 +39,7 @@ class LinkManager : public Actor {
Background,
ConfirmPhone,
DialogInvite,
Language,
Message,
MessageDraft,
QrCodeAuthentication,
@ -88,6 +89,7 @@ class LinkManager : public Actor {
class InternalLinkBackground;
class InternalLinkConfirmPhone;
class InternalLinkDialogInvite;
class InternalLinkLanguage;
class InternalLinkMessage;
class InternalLinkMessageDraft;
class InternalLinkQrCodeAuthentication;

View File

@ -73,6 +73,9 @@ TEST(Link, parse_internal_link) {
auto chat_invite = [] {
return td::td_api::make_object<td::td_api::internalLinkTypeChatInvite>();
};
auto language_pack = [](td::string language_pack_name) {
return td::td_api::make_object<td::td_api::internalLinkTypeLanguagePack>(language_pack_name);
};
auto message = [] {
return td::td_api::make_object<td::td_api::internalLinkTypeMessage>();
};
@ -320,4 +323,22 @@ TEST(Link, parse_internal_link) {
phone_number_confirmation("123", "123456789123456789"));
parse_internal_link("tg://confirmphone?hash=&phone=123456789123456789", unknown_deep_link());
parse_internal_link("tg://confirmphone?hash=123456789123456789&phone=", unknown_deep_link());
parse_internal_link("t.me/setlanguage?lang=abcdef", nullptr);
parse_internal_link("t.me/setlanguage", nullptr);
parse_internal_link("t.me/setlanguage/", nullptr);
parse_internal_link("t.me/setlanguage//abcdef", nullptr);
parse_internal_link("t.me/setlanguage?/abcdef", nullptr);
parse_internal_link("t.me/setlanguage/?abcdef", nullptr);
parse_internal_link("t.me/setlanguage/#abcdef", nullptr);
parse_internal_link("t.me/setlanguage/abacaba", language_pack("abacaba"));
parse_internal_link("t.me/setlanguage/aba%20aba", language_pack("aba aba"));
parse_internal_link("t.me/setlanguage/123456a", language_pack("123456a"));
parse_internal_link("t.me/setlanguage/12345678901", language_pack("12345678901"));
parse_internal_link("t.me/setlanguage/123456", language_pack("123456"));
parse_internal_link("t.me/setlanguage/123456/123123/12/31/a/s//21w/?asdas#test", language_pack("123456"));
parse_internal_link("tg:setlanguage?lang=abcdef", language_pack("abcdef"));
parse_internal_link("tg:setlanguage?lang=abc%30ef", language_pack("abc0ef"));
parse_internal_link("tg://setlanguage?lang=", unknown_deep_link());
}