Support t.me/s/ links.

This commit is contained in:
levlam 2021-05-28 20:36:05 +03:00
parent ee8e0ec2ad
commit a77707d8d5
2 changed files with 18 additions and 4 deletions

View File

@ -157,7 +157,7 @@ class LinkManager::InternalLinkTheme : public InternalLink {
string theme_name_;
td_api::object_ptr<td_api::InternalLinkType> get_internal_link_type_object() const final {
return td_api::make_object<td_api::internalLinkTypeBackground>(theme_name_);
return td_api::make_object<td_api::internalLinkTypeTheme>(theme_name_);
}
InternalLinkType get_type() const final {
@ -426,7 +426,20 @@ LinkManager::LinkInfo LinkManager::get_link_info(Slice link) {
if (host == t_me_url) {
result.is_internal_ = true;
result.is_tg_ = false;
result.query_ = std::move(http_url.query_);
Slice query = http_url.query_;
while (true) {
if (begins_with(query, "/s/")) {
query.remove_prefix(2);
continue;
}
if (begins_with(query, "/%73/")) {
query.remove_prefix(4);
continue;
}
break;
}
result.query_ = query.str();
return result;
}
}

View File

@ -50,14 +50,13 @@ TEST(Link, check_link) {
}
static void parse_internal_link(td::string url, td::td_api::object_ptr<td::td_api::InternalLinkType> expected) {
// LOG(ERROR) << url;
auto result = td::LinkManager::parse_internal_link(url);
if (result != nullptr) {
auto object = result->get_internal_link_type_object();
if (object->get_id() == td::td_api::internalLinkTypeMessageDraft::ID) {
static_cast<td::td_api::internalLinkTypeMessageDraft *>(object.get())->text_->entities_.clear();
}
ASSERT_STREQ(to_string(expected), to_string(object));
ASSERT_STREQ(url + to_string(expected), url + to_string(object));
} else {
ASSERT_TRUE(expected == nullptr);
}
@ -107,6 +106,8 @@ TEST(Link, parse_internal_link) {
parse_internal_link("www%2etelegram.me/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.t.me/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());
parse_internal_link("http://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());