Open Telegraph links in instant view.

This commit is contained in:
levlam 2022-09-16 13:51:52 +03:00
parent 47d4101def
commit b76a920db8
3 changed files with 22 additions and 3 deletions

View File

@ -945,6 +945,16 @@ LinkManager::LinkInfo LinkManager::get_link_info(Slice link) {
return result; return result;
} }
} }
if (http_url.query_.size() > 1) {
for (auto telegraph_url : {Slice("telegra.ph"), Slice("te.legra.ph"), Slice("graph.org")}) {
if (host == telegraph_url) {
result.type_ = LinkType::Telegraph;
result.query_ = std::move(http_url.query_);
return result;
}
}
}
} }
return result; return result;
} }
@ -963,6 +973,8 @@ unique_ptr<LinkManager::InternalLink> LinkManager::parse_internal_link(Slice lin
return parse_tg_link_query(info.query_, is_trusted); return parse_tg_link_query(info.query_, is_trusted);
case LinkType::TMe: case LinkType::TMe:
return parse_t_me_link_query(info.query_, is_trusted); return parse_t_me_link_query(info.query_, is_trusted);
case LinkType::Telegraph:
return td::make_unique<InternalLinkInstantView>(PSTRING() << "https://telegra.ph" << info.query_);
default: default:
UNREACHABLE(); UNREACHABLE();
return nullptr; return nullptr;

View File

@ -123,7 +123,7 @@ class LinkManager final : public Actor {
class InternalLinkUserPhoneNumber; class InternalLinkUserPhoneNumber;
class InternalLinkVoiceChat; class InternalLinkVoiceChat;
enum class LinkType : int32 { External, TMe, Tg }; enum class LinkType : int32 { External, TMe, Tg, Telegraph };
struct LinkInfo { struct LinkInfo {
LinkType type_ = LinkType::External; LinkType type_ = LinkType::External;

View File

@ -27,7 +27,8 @@ static void check_find_urls(const td::string &url, bool is_valid) {
{ {
if (is_valid && (td::begins_with(url_lower, "http") || td::begins_with(url_lower, "t.me")) && if (is_valid && (td::begins_with(url_lower, "http") || td::begins_with(url_lower, "t.me")) &&
url.find('.') != td::string::npos && url.find(' ') == td::string::npos && url != "http://..") { url.find('.') != td::string::npos && url.find(' ') == td::string::npos && url != "http://.." &&
url.find("ra.ph") == td::string::npos && url.find("Aph") == td::string::npos) {
auto urls = td::find_urls(url); auto urls = td::find_urls(url);
ASSERT_EQ(1u, urls.size()); ASSERT_EQ(1u, urls.size());
ASSERT_STREQ(url, urls[0].first); ASSERT_STREQ(url, urls[0].first);
@ -86,7 +87,7 @@ static void parse_internal_link(const td::string &url, td::td_api::object_ptr<td
if (object->get_id() == td::td_api::internalLinkTypeMessageDraft::ID) { if (object->get_id() == td::td_api::internalLinkTypeMessageDraft::ID) {
static_cast<td::td_api::internalLinkTypeMessageDraft *>(object.get())->text_->entities_.clear(); static_cast<td::td_api::internalLinkTypeMessageDraft *>(object.get())->text_->entities_.clear();
} }
ASSERT_STREQ(url + " " + to_string(expected), url + " " + to_string(object)); ASSERT_STREQ(url + ' ' + to_string(expected), url + ' ' + to_string(object));
} else { } else {
LOG_IF(ERROR, expected != nullptr) << url; LOG_IF(ERROR, expected != nullptr) << url;
ASSERT_TRUE(expected == nullptr); ASSERT_TRUE(expected == nullptr);
@ -964,4 +965,10 @@ TEST(Link, parse_internal_link) {
parse_internal_link("setlanguage.t.me", nullptr); parse_internal_link("setlanguage.t.me", nullptr);
parse_internal_link("share.t.me", nullptr); parse_internal_link("share.t.me", nullptr);
parse_internal_link("socks.t.me", nullptr); parse_internal_link("socks.t.me", nullptr);
parse_internal_link("www.telegra.ph/", nullptr);
parse_internal_link("www.telegrA.ph/#", nullptr);
parse_internal_link("www.telegrA.ph/?", instant_view("https://telegra.ph/?"));
parse_internal_link("http://te.leGra.ph/?", instant_view("https://telegra.ph/?"));
parse_internal_link("https://grAph.org/12345", instant_view("https://telegra.ph/12345"));
} }