Add internalLinkTypeSideMenuBot.is_compact.

This commit is contained in:
levlam 2024-06-29 23:47:33 +03:00
parent aa26c117ee
commit 0f984b24c7
3 changed files with 31 additions and 21 deletions

View File

@ -6365,7 +6365,8 @@ internalLinkTypeSettings = InternalLinkType;
//-If the bot is added to side menu, then use getWebAppUrl with the given URL and open the returned URL as a Web App
//@bot_username Username of the bot
//@url URL to be passed to getWebAppUrl
internalLinkTypeSideMenuBot bot_username:string url:string = InternalLinkType;
//@is_compact True, if the Web App must be opened in a compact mode instead of a full-size mode
internalLinkTypeSideMenuBot bot_username:string url:string is_compact:Bool = InternalLinkType;
//@description The link is a link to a sticker set. Call searchStickerSet with the given sticker set name to process the link and show the sticker set.
//-If the sticker set is found and the user wants to add it, then call changeStickerSet
@ -6414,7 +6415,7 @@ internalLinkTypeVideoChat chat_username:string invite_hash:string is_live_stream
//@bot_username Username of the bot that owns the Web App
//@web_app_short_name Short name of the Web App
//@start_parameter Start parameter to be passed to getWebAppLinkUrl
//@is_compact True, if the Web App must be tried to open in a compact mode with getWebAppLinkUrl
//@is_compact True, if the Web App must be opened in a compact mode instead of a full-size mode
internalLinkTypeWebApp bot_username:string web_app_short_name:string start_parameter:string is_compact:Bool = InternalLinkType;

View File

@ -687,13 +687,15 @@ class LinkManager::InternalLinkSettings final : public InternalLink {
class LinkManager::InternalLinkSideMenuBot final : public InternalLink {
string bot_username_;
string url_;
string mode_;
td_api::object_ptr<td_api::InternalLinkType> get_internal_link_type_object() const final {
return td_api::make_object<td_api::internalLinkTypeSideMenuBot>(bot_username_, url_);
return td_api::make_object<td_api::internalLinkTypeSideMenuBot>(bot_username_, url_, mode_ == "compact");
}
public:
InternalLinkSideMenuBot(string bot_username, string start_parameter) : bot_username_(std::move(bot_username)) {
InternalLinkSideMenuBot(string bot_username, string start_parameter, string mode)
: bot_username_(std::move(bot_username)), mode_(std::move(mode)) {
if (!start_parameter.empty()) {
url_ = PSTRING() << "start://" << start_parameter;
}
@ -1326,8 +1328,9 @@ unique_ptr<LinkManager::InternalLink> LinkManager::parse_tg_link_query(Slice que
}
if (url_query.has_arg("startapp") && !url_query.has_arg("appname")) {
// resolve?domain=<bot_username>&startapp=
// resolve?domain=<bot_username>&startapp=<start_parameter>
return td::make_unique<InternalLinkSideMenuBot>(std::move(username), url_query.get_arg("startapp").str());
// resolve?domain=<bot_username>&startapp=<start_parameter>&mode=compact
return td::make_unique<InternalLinkSideMenuBot>(std::move(username), url_query.get_arg("startapp").str(),
url_query.get_arg("mode").str());
}
if (!url_query.get_arg("attach").empty()) {
// resolve?domain=<username>&attach=<bot_username>
@ -1779,8 +1782,9 @@ unique_ptr<LinkManager::InternalLink> LinkManager::parse_t_me_link_query(Slice q
}
if (arg.first == "startapp" && is_valid_start_parameter(arg.second)) {
// /<bot_username>?startapp
// /<bot_username>?startapp=<parameter>
return td::make_unique<InternalLinkSideMenuBot>(std::move(username), arg.second);
// /<bot_username>?startapp=<parameter>&mode=compact
return td::make_unique<InternalLinkSideMenuBot>(std::move(username), arg.second,
url_query.get_arg("mode").str());
}
if (arg.first == "game" && is_valid_game_name(arg.second)) {
// /<bot_username>?game=<short_name>
@ -2315,10 +2319,11 @@ Result<string> LinkManager::get_internal_link_impl(const td_api::InternalLinkTyp
}
start_parameter = PSTRING() << '=' << start_parameter_slice;
}
string mode = link->is_compact_ ? "&mode=compact" : "";
if (is_internal) {
return PSTRING() << "tg://resolve?domain=" << link->bot_username_ << "&startapp" << start_parameter;
return PSTRING() << "tg://resolve?domain=" << link->bot_username_ << "&startapp" << start_parameter << mode;
} else {
return PSTRING() << get_t_me_url() << link->bot_username_ << "?startapp" << start_parameter;
return PSTRING() << get_t_me_url() << link->bot_username_ << "?startapp" << start_parameter << mode;
}
}
case td_api::internalLinkTypeStickerSet::ID: {

View File

@ -334,9 +334,9 @@ static auto settings() {
return td::td_api::make_object<td::td_api::internalLinkTypeSettings>();
}
static auto side_menu_bot(const td::string &bot_username, const td::string &start_parameter) {
static auto side_menu_bot(const td::string &bot_username, const td::string &start_parameter, bool is_compact) {
return td::td_api::make_object<td::td_api::internalLinkTypeSideMenuBot>(
bot_username, start_parameter.empty() ? td::string() : "start://" + start_parameter);
bot_username, start_parameter.empty() ? td::string() : "start://" + start_parameter, is_compact);
}
static auto sticker_set(const td::string &sticker_set_name, bool expect_custom_emoji) {
@ -1216,21 +1216,25 @@ TEST(Link, parse_internal_link_part4) {
parse_internal_link("https://telegram.dog/tele%63ram/t%63st", web_app("telecram", "tcst", "", false));
parse_internal_link("https://telegram.dog/tele%63ram/t%63st?mode=compact", web_app("telecram", "tcst", "", true));
parse_internal_link("tg:resolve?domain=username&startapp=aasdasd", side_menu_bot("username", "aasdasd"));
parse_internal_link("TG://resolve?domain=username&startapp=&startapp=123asd", side_menu_bot("username", ""));
parse_internal_link("tg:resolve?domain=username&startapp=aasdasd", side_menu_bot("username", "aasdasd", false));
parse_internal_link("TG://resolve?domain=username&startapp=&startapp=123asd", side_menu_bot("username", "", false));
parse_internal_link("TG://test@resolve?domain=username&startapp=asd", nullptr);
parse_internal_link("tg:resolve:80?domain=username&startapp=asd", nullptr);
parse_internal_link("tg:http://resolve?domain=username&startapp=asd", nullptr);
parse_internal_link("tg:https://resolve?domain=username&startapp=asd", nullptr);
parse_internal_link("tg:resolve?domain=&startapp=asd", unknown_deep_link("tg://resolve?domain=&startapp=asd"));
parse_internal_link("tg:resolve?domain=telegram&&&&&&&startapp=%41", side_menu_bot("telegram", "A"));
parse_internal_link("tg:resolve?domain=telegram&&&&&&&startapp=%41b", side_menu_bot("telegram", "Ab"));
parse_internal_link("tg:resolve?domain=telegram&&&&&&&startapp=%41bc", side_menu_bot("telegram", "Abc"));
parse_internal_link("tg:resolve?domain=telegram&&&&&&&startapp=%41", side_menu_bot("telegram", "A", false));
parse_internal_link("tg:resolve?domain=telegram&&&&&&&startapp=%41b", side_menu_bot("telegram", "Ab", false));
parse_internal_link("tg:resolve?domain=telegram&&&&&&&startapp=%41bc", side_menu_bot("telegram", "Abc", false));
parse_internal_link("tg:resolve?domain=telegram&&mode=compact&&&&&&startapp=%41bc",
side_menu_bot("telegram", "Abc", true));
parse_internal_link("t.me/username?startapp=qwe", side_menu_bot("username", "qwe"));
parse_internal_link("t.me/username?12312&startapp=qwe", side_menu_bot("username", "qwe"));
parse_internal_link("t.me/username?startapp=0", side_menu_bot("username", "0"));
parse_internal_link("https://telegram.dog/tele%63ram?startapp=t%63st", side_menu_bot("telecram", "tcst"));
parse_internal_link("t.me/username?startapp=qwe", side_menu_bot("username", "qwe", false));
parse_internal_link("t.me/username?12312&startapp=qwe", side_menu_bot("username", "qwe", false));
parse_internal_link("t.me/username?startapp=0", side_menu_bot("username", "0", false));
parse_internal_link("https://telegram.dog/tele%63ram?startapp=t%63st", side_menu_bot("telecram", "tcst", false));
parse_internal_link("https://telegram.dog/tele%63ram?startapp=t%63st&mode=%63ompact",
side_menu_bot("telecram", "tcst", true));
parse_internal_link("https://telegram.dog?startapp=t%63st", nullptr);
parse_internal_link("tg:resolve?domain=username&Game=asd", public_chat("username"));