Add td_api::internalLinkTypeChatBoost.
This commit is contained in:
parent
8230efb97f
commit
714397da80
@ -5077,6 +5077,9 @@ internalLinkTypeBotStartInGroup bot_username:string start_parameter:string admin
|
|||||||
//@description The link is a link to the change phone number section of the app
|
//@description The link is a link to the change phone number section of the app
|
||||||
internalLinkTypeChangePhoneNumber = InternalLinkType;
|
internalLinkTypeChangePhoneNumber = InternalLinkType;
|
||||||
|
|
||||||
|
//@description The link is a link to boost a Telegram chat. Call getChatBoostLinkInfo with the given URL to process the link @url URL to be passed to getChatBoostLinkInfo
|
||||||
|
internalLinkTypeChatBoost url:string = InternalLinkType;
|
||||||
|
|
||||||
//@description The link is an invite link to a chat folder. Call checkChatFolderInviteLink with the given invite link to process the link @invite_link Internal representation of the invite link
|
//@description The link is an invite link to a chat folder. Call checkChatFolderInviteLink with the given invite link to process the link @invite_link Internal representation of the invite link
|
||||||
internalLinkTypeChatFolderInvite invite_link:string = InternalLinkType;
|
internalLinkTypeChatFolderInvite invite_link:string = InternalLinkType;
|
||||||
|
|
||||||
|
@ -392,6 +392,18 @@ class LinkManager::InternalLinkDefaultMessageAutoDeleteTimerSettings final : pub
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
class LinkManager::InternalLinkDialogBoost 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::internalLinkTypeChatBoost>(url_);
|
||||||
|
}
|
||||||
|
|
||||||
|
public:
|
||||||
|
explicit InternalLinkDialogBoost(string url) : url_(std::move(url)) {
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
class LinkManager::InternalLinkDialogFolderInvite final : public InternalLink {
|
class LinkManager::InternalLinkDialogFolderInvite final : public InternalLink {
|
||||||
string url_;
|
string url_;
|
||||||
|
|
||||||
@ -1417,6 +1429,15 @@ unique_ptr<LinkManager::InternalLink> LinkManager::parse_tg_link_query(Slice que
|
|||||||
PSTRING() << "tg://privatepost" << copy_arg("channel") << copy_arg("post") << copy_arg("single")
|
PSTRING() << "tg://privatepost" << copy_arg("channel") << copy_arg("post") << copy_arg("single")
|
||||||
<< copy_arg("thread") << copy_arg("comment") << copy_arg("t"));
|
<< copy_arg("thread") << copy_arg("comment") << copy_arg("t"));
|
||||||
}
|
}
|
||||||
|
} else if (path.size() == 1 && path[0] == "boost") {
|
||||||
|
// boost?domain=channel_username
|
||||||
|
// boost?channel=123456
|
||||||
|
if (has_arg("domain")) {
|
||||||
|
return td::make_unique<InternalLinkDialogBoost>(PSTRING() << "tg://boost" << copy_arg("domain"));
|
||||||
|
}
|
||||||
|
if (has_arg("channel")) {
|
||||||
|
return td::make_unique<InternalLinkDialogBoost>(PSTRING() << "tg://boost" << copy_arg("channel"));
|
||||||
|
}
|
||||||
} else if (path.size() == 1 && path[0] == "bg") {
|
} else if (path.size() == 1 && path[0] == "bg") {
|
||||||
// bg?color=<color>
|
// bg?color=<color>
|
||||||
// bg?gradient=<hex_color>-<hex_color>&rotation=...
|
// bg?gradient=<hex_color>-<hex_color>&rotation=...
|
||||||
@ -1484,6 +1505,9 @@ unique_ptr<LinkManager::InternalLink> LinkManager::parse_t_me_link_query(Slice q
|
|||||||
return td::make_unique<InternalLinkMessage>(PSTRING() << "tg://privatepost?channel=" << to_integer<int64>(path[1])
|
return td::make_unique<InternalLinkMessage>(PSTRING() << "tg://privatepost?channel=" << to_integer<int64>(path[1])
|
||||||
<< "&post=" << post << copy_arg("single") << thread
|
<< "&post=" << post << copy_arg("single") << thread
|
||||||
<< copy_arg("comment") << copy_arg("t"));
|
<< copy_arg("comment") << copy_arg("t"));
|
||||||
|
} else if (path.size() >= 2 && to_integer<int64>(path[1]) > 0 && url_query.has_arg("boost")) {
|
||||||
|
// /c/123456789?boost
|
||||||
|
return td::make_unique<InternalLinkDialogBoost>(PSTRING() << "tg://boost?channel=" << to_integer<int64>(path[1]));
|
||||||
}
|
}
|
||||||
} else if (path[0] == "login") {
|
} else if (path[0] == "login") {
|
||||||
if (path.size() >= 2 && !path[1].empty()) {
|
if (path.size() >= 2 && !path[1].empty()) {
|
||||||
@ -1637,6 +1661,10 @@ unique_ptr<LinkManager::InternalLink> LinkManager::parse_t_me_link_query(Slice q
|
|||||||
}
|
}
|
||||||
return td::make_unique<InternalLinkVoiceChat>(std::move(username), arg.second, arg.first == "livestream");
|
return td::make_unique<InternalLinkVoiceChat>(std::move(username), arg.second, arg.first == "livestream");
|
||||||
}
|
}
|
||||||
|
if (arg.first == "boost") {
|
||||||
|
// /<username>?boost
|
||||||
|
return td::make_unique<InternalLinkDialogBoost>(PSTRING() << "tg://boost?domain=" << url_encode(username));
|
||||||
|
}
|
||||||
if (arg.first == "start" && is_valid_start_parameter(arg.second)) {
|
if (arg.first == "start" && is_valid_start_parameter(arg.second)) {
|
||||||
// /<bot_username>?start=<parameter>
|
// /<bot_username>?start=<parameter>
|
||||||
return td::make_unique<InternalLinkBotStart>(std::move(username), arg.second, is_trusted);
|
return td::make_unique<InternalLinkBotStart>(std::move(username), arg.second, is_trusted);
|
||||||
@ -1945,6 +1973,21 @@ Result<string> LinkManager::get_internal_link_impl(const td_api::InternalLinkTyp
|
|||||||
return Status::Error("HTTP link is unavailable for the link type");
|
return Status::Error("HTTP link is unavailable for the link type");
|
||||||
}
|
}
|
||||||
return "tg://settings/change_number";
|
return "tg://settings/change_number";
|
||||||
|
case td_api::internalLinkTypeChatBoost::ID: {
|
||||||
|
auto link = static_cast<const td_api::internalLinkTypeChatBoost *>(type_ptr);
|
||||||
|
auto parsed_link = parse_internal_link(link->url_);
|
||||||
|
if (parsed_link == nullptr) {
|
||||||
|
return Status::Error(400, "Invalid chat boost URL specified");
|
||||||
|
}
|
||||||
|
auto parsed_object = parsed_link->get_internal_link_type_object();
|
||||||
|
if (parsed_object->get_id() != td_api::internalLinkTypeChatBoost::ID) {
|
||||||
|
return Status::Error(400, "Invalid chat boost URL specified");
|
||||||
|
}
|
||||||
|
if (!is_internal) {
|
||||||
|
return Status::Error(400, "Use getChatBoostLink to get an HTTPS link to boost a chat");
|
||||||
|
}
|
||||||
|
return std::move(static_cast<td_api::internalLinkTypeChatBoost &>(*parsed_object).url_);
|
||||||
|
}
|
||||||
case td_api::internalLinkTypeChatFolderInvite::ID: {
|
case td_api::internalLinkTypeChatFolderInvite::ID: {
|
||||||
auto link = static_cast<const td_api::internalLinkTypeChatFolderInvite *>(type_ptr);
|
auto link = static_cast<const td_api::internalLinkTypeChatFolderInvite *>(type_ptr);
|
||||||
auto slug = get_dialog_filter_invite_link_slug(link->invite_link_);
|
auto slug = get_dialog_filter_invite_link_slug(link->invite_link_);
|
||||||
@ -2069,7 +2112,7 @@ Result<string> LinkManager::get_internal_link_impl(const td_api::InternalLinkTyp
|
|||||||
return Status::Error(400, "Invalid message URL specified");
|
return Status::Error(400, "Invalid message URL specified");
|
||||||
}
|
}
|
||||||
if (!is_internal) {
|
if (!is_internal) {
|
||||||
return Status::Error(400, "Use getMessageLink to get HTTPS link to a message");
|
return Status::Error(400, "Use getMessageLink to get an HTTPS link to a message");
|
||||||
}
|
}
|
||||||
return std::move(static_cast<td_api::internalLinkTypeMessage &>(*parsed_object).url_);
|
return std::move(static_cast<td_api::internalLinkTypeMessage &>(*parsed_object).url_);
|
||||||
}
|
}
|
||||||
|
@ -124,6 +124,7 @@ class LinkManager final : public Actor {
|
|||||||
class InternalLinkChangePhoneNumber;
|
class InternalLinkChangePhoneNumber;
|
||||||
class InternalLinkConfirmPhone;
|
class InternalLinkConfirmPhone;
|
||||||
class InternalLinkDefaultMessageAutoDeleteTimerSettings;
|
class InternalLinkDefaultMessageAutoDeleteTimerSettings;
|
||||||
|
class InternalLinkDialogBoost;
|
||||||
class InternalLinkDialogFolderInvite;
|
class InternalLinkDialogFolderInvite;
|
||||||
class InternalLinkDialogFolderSettings;
|
class InternalLinkDialogFolderSettings;
|
||||||
class InternalLinkDialogInvite;
|
class InternalLinkDialogInvite;
|
||||||
|
@ -97,6 +97,10 @@ 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));
|
ASSERT_STREQ(url + ' ' + to_string(expected), url + ' ' + to_string(object));
|
||||||
|
|
||||||
for (auto is_internal : {true, false}) {
|
for (auto is_internal : {true, false}) {
|
||||||
|
if (!is_internal && expected->get_id() == td::td_api::internalLinkTypeChatBoost::ID) {
|
||||||
|
// external chat boost links must be generated with getChatBoostLink
|
||||||
|
continue;
|
||||||
|
}
|
||||||
if (!is_internal && expected->get_id() == td::td_api::internalLinkTypeMessage::ID) {
|
if (!is_internal && expected->get_id() == td::td_api::internalLinkTypeMessage::ID) {
|
||||||
// external message links must be generated with getMessageLink
|
// external message links must be generated with getMessageLink
|
||||||
continue;
|
continue;
|
||||||
@ -219,6 +223,10 @@ static auto change_phone_number() {
|
|||||||
return td::td_api::make_object<td::td_api::internalLinkTypeChangePhoneNumber>();
|
return td::td_api::make_object<td::td_api::internalLinkTypeChangePhoneNumber>();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static auto chat_boost(const td::string &url) {
|
||||||
|
return td::td_api::make_object<td::td_api::internalLinkTypeChatBoost>(url);
|
||||||
|
}
|
||||||
|
|
||||||
static auto chat_folder_invite(const td::string &slug) {
|
static auto chat_folder_invite(const td::string &slug) {
|
||||||
return td::td_api::make_object<td::td_api::internalLinkTypeChatFolderInvite>("tg:addlist?slug=" + slug);
|
return td::td_api::make_object<td::td_api::internalLinkTypeChatFolderInvite>("tg:addlist?slug=" + slug);
|
||||||
}
|
}
|
||||||
@ -382,6 +390,21 @@ TEST(Link, parse_internal_link_part1) {
|
|||||||
parse_internal_link("t.m/levlam/1", nullptr);
|
parse_internal_link("t.m/levlam/1", nullptr);
|
||||||
parse_internal_link("t.men/levlam/1", nullptr);
|
parse_internal_link("t.men/levlam/1", nullptr);
|
||||||
|
|
||||||
|
parse_internal_link("t.me/levlam?boos", public_chat("levlam"));
|
||||||
|
parse_internal_link("telegram.me/levlam?booster", public_chat("levlam"));
|
||||||
|
parse_internal_link("telegram.dog/levlam?boost", chat_boost("tg://boost?domain=levlam"));
|
||||||
|
parse_internal_link("www.t.me/levlam?boost", chat_boost("tg://boost?domain=levlam"));
|
||||||
|
parse_internal_link("t.me/c/l12345?boost", nullptr);
|
||||||
|
parse_internal_link("t.me/c/12345l5431?boost", chat_boost("tg://boost?channel=12345"));
|
||||||
|
parse_internal_link("t.me/c/12345?boost", chat_boost("tg://boost?channel=12345"));
|
||||||
|
parse_internal_link("t.me/c/123456789012?boost", chat_boost("tg://boost?channel=123456789012"));
|
||||||
|
parse_internal_link("t.me/c/123456789012?boost=12312&domain=123", chat_boost("tg://boost?channel=123456789012"));
|
||||||
|
|
||||||
|
parse_internal_link("tg:boost?domain=username/12345&single", chat_boost("tg://boost?domain=username%2F12345"));
|
||||||
|
parse_internal_link("tg:boost?domain=username&channel=12345", chat_boost("tg://boost?domain=username"));
|
||||||
|
parse_internal_link("tg:boost?channel=12345&domain=username", chat_boost("tg://boost?domain=username"));
|
||||||
|
parse_internal_link("tg:boost?channel=12345", chat_boost("tg://boost?channel=12345"));
|
||||||
|
|
||||||
parse_internal_link("tg:resolve?domain=username&post=12345&single",
|
parse_internal_link("tg:resolve?domain=username&post=12345&single",
|
||||||
message("tg://resolve?domain=username&post=12345&single"));
|
message("tg://resolve?domain=username&post=12345&single"));
|
||||||
parse_internal_link("tg:resolve?domain=username&post=12345&single&startattach=1&attach=test",
|
parse_internal_link("tg:resolve?domain=username&post=12345&single&startattach=1&attach=test",
|
||||||
|
Loading…
Reference in New Issue
Block a user