Make internalLinkTypeChatInvite self-contained.
This commit is contained in:
parent
241718eae8
commit
618742acc2
@ -3057,8 +3057,8 @@ internalLinkTypeBotStartInGroup bot_username:string start_parameter:string = Int
|
|||||||
//@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 chat invite link. Call checkChatInviteLink to process the link
|
//@description The link is a chat invite link. Call checkChatInviteLink with the given URL to process the link @url Internal representation of the link
|
||||||
internalLinkTypeChatInvite = InternalLinkType;
|
internalLinkTypeChatInvite url:string = InternalLinkType;
|
||||||
|
|
||||||
//@description The link is a link to the filter settings section of the app
|
//@description The link is a link to the filter settings section of the app
|
||||||
internalLinkTypeFilterSettings = InternalLinkType;
|
internalLinkTypeFilterSettings = InternalLinkType;
|
||||||
|
@ -65,6 +65,26 @@ static bool is_valid_username(Slice username) {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static string get_url_query_hash(bool is_tg, const HttpUrlQuery &url_query) {
|
||||||
|
const auto &path = url_query.path_;
|
||||||
|
if (is_tg) {
|
||||||
|
if (path.size() == 1 && path[0] == "join" && !url_query.get_arg("invite").empty()) {
|
||||||
|
// join?invite=abcdef
|
||||||
|
return url_query.get_arg("invite").str();
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if (path.size() >= 2 && path[0] == "joinchat" && !path[1].empty()) {
|
||||||
|
// /joinchat/<link>
|
||||||
|
return path[1];
|
||||||
|
}
|
||||||
|
if (path.size() >= 1 && path[0].size() >= 2 && (path[0][0] == ' ' || path[0][0] == '+')) {
|
||||||
|
// /+<link>
|
||||||
|
return path[0].substr(1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return string();
|
||||||
|
}
|
||||||
|
|
||||||
class LinkManager::InternalLinkActiveSessions final : public InternalLink {
|
class LinkManager::InternalLinkActiveSessions final : public InternalLink {
|
||||||
td_api::object_ptr<td_api::InternalLinkType> get_internal_link_type_object() const final {
|
td_api::object_ptr<td_api::InternalLinkType> get_internal_link_type_object() const final {
|
||||||
return td_api::make_object<td_api::internalLinkTypeActiveSessions>();
|
return td_api::make_object<td_api::internalLinkTypeActiveSessions>();
|
||||||
@ -144,8 +164,14 @@ class LinkManager::InternalLinkConfirmPhone final : public InternalLink {
|
|||||||
};
|
};
|
||||||
|
|
||||||
class LinkManager::InternalLinkDialogInvite final : public InternalLink {
|
class LinkManager::InternalLinkDialogInvite final : public InternalLink {
|
||||||
|
string url_;
|
||||||
|
|
||||||
td_api::object_ptr<td_api::InternalLinkType> get_internal_link_type_object() const final {
|
td_api::object_ptr<td_api::InternalLinkType> get_internal_link_type_object() const final {
|
||||||
return td_api::make_object<td_api::internalLinkTypeChatInvite>();
|
return td_api::make_object<td_api::internalLinkTypeChatInvite>(url_);
|
||||||
|
}
|
||||||
|
|
||||||
|
public:
|
||||||
|
explicit InternalLinkDialogInvite(string url) : url_(std::move(url)) {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -783,7 +809,8 @@ unique_ptr<LinkManager::InternalLink> LinkManager::parse_tg_link_query(Slice que
|
|||||||
} else if (path.size() == 1 && path[0] == "join") {
|
} else if (path.size() == 1 && path[0] == "join") {
|
||||||
// join?invite=<hash>
|
// join?invite=<hash>
|
||||||
if (has_arg("invite")) {
|
if (has_arg("invite")) {
|
||||||
return td::make_unique<InternalLinkDialogInvite>();
|
return td::make_unique<InternalLinkDialogInvite>(PSTRING() << "tg:join?invite="
|
||||||
|
<< url_encode(get_url_query_hash(true, url_query)));
|
||||||
}
|
}
|
||||||
} else if (path.size() == 1 && path[0] == "addstickers") {
|
} else if (path.size() == 1 && path[0] == "addstickers") {
|
||||||
// addstickers?set=<name>
|
// addstickers?set=<name>
|
||||||
@ -889,12 +916,14 @@ unique_ptr<LinkManager::InternalLink> LinkManager::parse_t_me_link_query(Slice q
|
|||||||
} else if (path[0] == "joinchat") {
|
} else if (path[0] == "joinchat") {
|
||||||
if (path.size() >= 2 && !path[1].empty()) {
|
if (path.size() >= 2 && !path[1].empty()) {
|
||||||
// /joinchat/<link>
|
// /joinchat/<link>
|
||||||
return td::make_unique<InternalLinkDialogInvite>();
|
return td::make_unique<InternalLinkDialogInvite>(PSTRING() << "tg:join?invite="
|
||||||
|
<< url_encode(get_url_query_hash(false, url_query)));
|
||||||
}
|
}
|
||||||
} else if (path[0][0] == ' ' || path[0][0] == '+') {
|
} else if (path[0][0] == ' ' || path[0][0] == '+') {
|
||||||
if (path[0].size() >= 2) {
|
if (path[0].size() >= 2) {
|
||||||
// /+<link>
|
// /+<link>
|
||||||
return td::make_unique<InternalLinkDialogInvite>();
|
return td::make_unique<InternalLinkDialogInvite>(
|
||||||
|
PSTRING() << "tg:join?invite=" + url_encode(get_url_query_hash(false, url_query)));
|
||||||
}
|
}
|
||||||
} else if (path[0] == "addstickers") {
|
} else if (path[0] == "addstickers") {
|
||||||
if (path.size() >= 2 && !path[1].empty()) {
|
if (path.size() >= 2 && !path[1].empty()) {
|
||||||
@ -1157,24 +1186,7 @@ string LinkManager::get_dialog_invite_link_hash(Slice invite_link) {
|
|||||||
return string();
|
return string();
|
||||||
}
|
}
|
||||||
const auto url_query = parse_url_query(link_info.query_);
|
const auto url_query = parse_url_query(link_info.query_);
|
||||||
const auto &path = url_query.path_;
|
return get_url_query_hash(link_info.is_tg_, url_query);
|
||||||
|
|
||||||
if (link_info.is_tg_) {
|
|
||||||
if (path.size() == 1 && path[0] == "join" && !url_query.get_arg("invite").empty()) {
|
|
||||||
// join?invite=abcdef
|
|
||||||
return url_query.get_arg("invite").str();
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
if (path.size() >= 2 && path[0] == "joinchat" && !path[1].empty()) {
|
|
||||||
// /joinchat/<link>
|
|
||||||
return path[1];
|
|
||||||
}
|
|
||||||
if (path.size() >= 1 && path[0].size() >= 2 && (path[0][0] == ' ' || path[0][0] == '+')) {
|
|
||||||
// /+<link>
|
|
||||||
return path[0].substr(1);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return string();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Result<MessageLinkInfo> LinkManager::get_message_link_info(Slice url) {
|
Result<MessageLinkInfo> LinkManager::get_message_link_info(Slice url) {
|
||||||
|
@ -113,8 +113,8 @@ TEST(Link, parse_internal_link) {
|
|||||||
auto change_phone_number = [] {
|
auto change_phone_number = [] {
|
||||||
return td::td_api::make_object<td::td_api::internalLinkTypeChangePhoneNumber>();
|
return td::td_api::make_object<td::td_api::internalLinkTypeChangePhoneNumber>();
|
||||||
};
|
};
|
||||||
auto chat_invite = [] {
|
auto chat_invite = [](td::string hash) {
|
||||||
return td::td_api::make_object<td::td_api::internalLinkTypeChatInvite>();
|
return td::td_api::make_object<td::td_api::internalLinkTypeChatInvite>("tg:join?invite=" + hash);
|
||||||
};
|
};
|
||||||
auto filter_settings = [] {
|
auto filter_settings = [] {
|
||||||
return td::td_api::make_object<td::td_api::internalLinkTypeFilterSettings>();
|
return td::td_api::make_object<td::td_api::internalLinkTypeFilterSettings>();
|
||||||
@ -181,9 +181,9 @@ TEST(Link, parse_internal_link) {
|
|||||||
parse_internal_link("www%2etelegram.me/levlam/1", message());
|
parse_internal_link("www%2etelegram.me/levlam/1", message());
|
||||||
parse_internal_link("www%2Etelegram.dog/levlam/1", message());
|
parse_internal_link("www%2Etelegram.dog/levlam/1", message());
|
||||||
parse_internal_link("www%252Etelegram.dog/levlam/1", nullptr);
|
parse_internal_link("www%252Etelegram.dog/levlam/1", nullptr);
|
||||||
parse_internal_link("www.t.me/s/s/s/s/s/joinchat/1", chat_invite());
|
parse_internal_link("www.t.me/s/s/s/s/s/joinchat/1", chat_invite("1"));
|
||||||
parse_internal_link("www.t.me/s/%73/%73/s/%73/joinchat/1", chat_invite());
|
parse_internal_link("www.t.me/s/%73/%73/s/%73/joinchat/1", chat_invite("1"));
|
||||||
parse_internal_link("http://t.me/s/s/s/s/s/s/s/s/s/s/s/s/s/s/s/s/s/joinchat/1", chat_invite());
|
parse_internal_link("http://t.me/s/s/s/s/s/s/s/s/s/s/s/s/s/s/s/s/s/joinchat/1", chat_invite("1"));
|
||||||
parse_internal_link("http://t.me/levlam/1", message());
|
parse_internal_link("http://t.me/levlam/1", message());
|
||||||
parse_internal_link("https://t.me/levlam/1", message());
|
parse_internal_link("https://t.me/levlam/1", message());
|
||||||
parse_internal_link("hTtp://www.t.me:443/levlam/1", message());
|
parse_internal_link("hTtp://www.t.me:443/levlam/1", message());
|
||||||
@ -347,29 +347,33 @@ TEST(Link, parse_internal_link) {
|
|||||||
parse_internal_link("t.me/joinchat?/abcdef", nullptr);
|
parse_internal_link("t.me/joinchat?/abcdef", nullptr);
|
||||||
parse_internal_link("t.me/joinchat/?abcdef", nullptr);
|
parse_internal_link("t.me/joinchat/?abcdef", nullptr);
|
||||||
parse_internal_link("t.me/joinchat/#abcdef", nullptr);
|
parse_internal_link("t.me/joinchat/#abcdef", nullptr);
|
||||||
parse_internal_link("t.me/joinchat/abacaba", chat_invite());
|
parse_internal_link("t.me/joinchat/abacaba", chat_invite("abacaba"));
|
||||||
parse_internal_link("t.me/joinchat/aba%20aba", chat_invite());
|
parse_internal_link("t.me/joinchat/aba%20aba", chat_invite("aba%20aba"));
|
||||||
parse_internal_link("t.me/joinchat/123456a", chat_invite());
|
parse_internal_link("t.me/joinchat/aba%30aba", chat_invite("aba0aba"));
|
||||||
parse_internal_link("t.me/joinchat/12345678901", chat_invite());
|
parse_internal_link("t.me/joinchat/123456a", chat_invite("123456a"));
|
||||||
parse_internal_link("t.me/joinchat/123456", chat_invite());
|
parse_internal_link("t.me/joinchat/12345678901", chat_invite("12345678901"));
|
||||||
parse_internal_link("t.me/joinchat/123456/123123/12/31/a/s//21w/?asdas#test", chat_invite());
|
parse_internal_link("t.me/joinchat/123456", chat_invite("123456"));
|
||||||
|
parse_internal_link("t.me/joinchat/123456/123123/12/31/a/s//21w/?asdas#test", chat_invite("123456"));
|
||||||
|
|
||||||
parse_internal_link("t.me/+?invite=abcdef", nullptr);
|
parse_internal_link("t.me/+?invite=abcdef", nullptr);
|
||||||
parse_internal_link("t.me/+a", chat_invite());
|
parse_internal_link("t.me/+a", chat_invite("a"));
|
||||||
parse_internal_link("t.me/+", nullptr);
|
parse_internal_link("t.me/+", nullptr);
|
||||||
parse_internal_link("t.me/+/abcdef", nullptr);
|
parse_internal_link("t.me/+/abcdef", nullptr);
|
||||||
parse_internal_link("t.me/ ?/abcdef", nullptr);
|
parse_internal_link("t.me/ ?/abcdef", nullptr);
|
||||||
parse_internal_link("t.me/+?abcdef", nullptr);
|
parse_internal_link("t.me/+?abcdef", nullptr);
|
||||||
parse_internal_link("t.me/+#abcdef", nullptr);
|
parse_internal_link("t.me/+#abcdef", nullptr);
|
||||||
parse_internal_link("t.me/ abacaba", chat_invite());
|
parse_internal_link("t.me/ abacaba", chat_invite("abacaba"));
|
||||||
parse_internal_link("t.me/+aba%20aba", chat_invite());
|
parse_internal_link("t.me/+aba%20aba", chat_invite("aba%20aba"));
|
||||||
parse_internal_link("t.me/+123456a", chat_invite());
|
parse_internal_link("t.me/+aba%30aba", chat_invite("aba0aba"));
|
||||||
parse_internal_link("t.me/%2012345678901", chat_invite());
|
parse_internal_link("t.me/+123456a", chat_invite("123456a"));
|
||||||
parse_internal_link("t.me/+123456", chat_invite());
|
parse_internal_link("t.me/%2012345678901", chat_invite("12345678901"));
|
||||||
parse_internal_link("t.me/ 123456/123123/12/31/a/s//21w/?asdas#test", chat_invite());
|
parse_internal_link("t.me/+123456", chat_invite("123456"));
|
||||||
|
parse_internal_link("t.me/ 123456/123123/12/31/a/s//21w/?asdas#test", chat_invite("123456"));
|
||||||
parse_internal_link("t.me/ /123456/123123/12/31/a/s//21w/?asdas#test", nullptr);
|
parse_internal_link("t.me/ /123456/123123/12/31/a/s//21w/?asdas#test", nullptr);
|
||||||
|
|
||||||
parse_internal_link("tg:join?invite=abcdef", chat_invite());
|
parse_internal_link("tg:join?invite=abcdef", chat_invite("abcdef"));
|
||||||
|
parse_internal_link("tg:join?invite=abc%20def", chat_invite("abc%20def"));
|
||||||
|
parse_internal_link("tg://join?invite=abc%30def", chat_invite("abc0def"));
|
||||||
parse_internal_link("tg:join?invite=", unknown_deep_link());
|
parse_internal_link("tg:join?invite=", unknown_deep_link());
|
||||||
|
|
||||||
parse_internal_link("t.me/addstickers?set=abcdef", nullptr);
|
parse_internal_link("t.me/addstickers?set=abcdef", nullptr);
|
||||||
|
Loading…
Reference in New Issue
Block a user