diff --git a/td/generate/scheme/td_api.tl b/td/generate/scheme/td_api.tl index 97da59211..af4bbf1bc 100644 --- a/td/generate/scheme/td_api.tl +++ b/td/generate/scheme/td_api.tl @@ -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; diff --git a/td/telegram/LinkManager.cpp b/td/telegram/LinkManager.cpp index bae4020b7..0f947b397 100644 --- a/td/telegram/LinkManager.cpp +++ b/td/telegram/LinkManager.cpp @@ -83,6 +83,22 @@ class LinkManager::InternalLinkDialogInvite : public InternalLink { } }; +class LinkManager::InternalLinkLanguage : public InternalLink { + string language_pack_id_; + + td_api::object_ptr get_internal_link_type_object() const final { + return td_api::make_object(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 get_internal_link_type_object() const final { return td_api::make_object(); @@ -478,6 +494,11 @@ unique_ptr LinkManager::parse_tg_link_query(Slice que if (has_arg("set")) { return td::make_unique(get_arg("set")); } + } else if (path.size() == 1 && path[0] == "setlanguage") { + // setlanguage?lang=name + if (has_arg("lang")) { + return td::make_unique(get_arg("lang")); + } } else if (path.size() == 1 && path[0] == "confirmphone") { if (has_arg("hash") && has_arg("phone")) { // confirmphone?phone=&hash= @@ -556,6 +577,11 @@ unique_ptr LinkManager::parse_t_me_link_query(Slice q // /addstickers/ return td::make_unique(path[1]); } + } else if (path[0] == "setlanguage") { + if (path.size() >= 2 && !path[1].empty()) { + // /setlanguage/ + return td::make_unique(path[1]); + } } else if (path[0] == "confirmphone") { if (has_arg("hash") && has_arg("phone")) { // /confirmphone?phone=&hash= diff --git a/td/telegram/LinkManager.h b/td/telegram/LinkManager.h index b996a1744..0a3f9d54a 100644 --- a/td/telegram/LinkManager.h +++ b/td/telegram/LinkManager.h @@ -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; diff --git a/test/link.cpp b/test/link.cpp index 8eb4d0669..ef0034272 100644 --- a/test/link.cpp +++ b/test/link.cpp @@ -73,6 +73,9 @@ TEST(Link, parse_internal_link) { auto chat_invite = [] { return td::td_api::make_object(); }; + auto language_pack = [](td::string language_pack_name) { + return td::td_api::make_object(language_pack_name); + }; auto message = [] { return td::td_api::make_object(); }; @@ -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()); }