From 79330c38812a34539c70efde042c1120ed3f19c0 Mon Sep 17 00:00:00 2001 From: levlam Date: Fri, 27 Sep 2019 01:03:13 +0300 Subject: [PATCH] Partial ton:// URLs support. GitOrigin-RevId: eeaaab10574dc636e9de18cc482f2398f6732fa1 --- td/telegram/MessageEntity.cpp | 4 ++-- td/telegram/misc.cpp | 15 ++++++++++----- td/telegram/misc.h | 2 +- 3 files changed, 13 insertions(+), 8 deletions(-) diff --git a/td/telegram/MessageEntity.cpp b/td/telegram/MessageEntity.cpp index 352ec39e5..91d467038 100644 --- a/td/telegram/MessageEntity.cpp +++ b/td/telegram/MessageEntity.cpp @@ -1181,7 +1181,7 @@ string get_first_url(Slice text, const vector &entities) { break; case MessageEntity::Type::Url: { Slice url = utf8_utf16_substr(text, entity.offset, entity.length); - if (begins_with(url, "tg:") || is_plain_domain(url)) { + if (begins_with(url, "ton:") || begins_with(url, "tg:") || is_plain_domain(url)) { continue; } return url.str(); @@ -1199,7 +1199,7 @@ string get_first_url(Slice text, const vector &entities) { case MessageEntity::Type::PreCode: break; case MessageEntity::Type::TextUrl: - if (begins_with(entity.argument, "tg:")) { + if (begins_with(entity.argument, "ton:") || begins_with(entity.argument, "tg:")) { continue; } return entity.argument; diff --git a/td/telegram/misc.cpp b/td/telegram/misc.cpp index 05b333e48..5f5bbbd72 100644 --- a/td/telegram/misc.cpp +++ b/td/telegram/misc.cpp @@ -277,20 +277,25 @@ string get_emoji_fingerprint(uint64 num) { Result check_url(Slice url) { bool is_tg = false; + bool is_ton = false; if (begins_with(url, "tg://")) { url.remove_prefix(5); is_tg = true; } else if (begins_with(url, "tg:")) { url.remove_prefix(3); is_tg = true; - } else { - is_tg = false; + } else if (begins_with(url, "ton://")) { + url.remove_prefix(6); + is_ton = true; + } else if (begins_with(url, "ton:")) { + url.remove_prefix(4); + is_ton = true; } TRY_RESULT(http_url, parse_url(url)); - if (is_tg) { + if (is_tg || is_ton) { if (begins_with(url, "http://") || http_url.protocol_ == HttpUrl::Protocol::HTTPS || !http_url.userinfo_.empty() || http_url.specified_port_ != 0 || http_url.is_ipv6_) { - return Status::Error("Wrong tg URL"); + return Status::Error(is_tg ? Slice("Wrong tg URL") : Slice("Wrong ton URL")); } Slice query(http_url.query_); @@ -298,7 +303,7 @@ Result check_url(Slice url) { if (query[1] == '?') { query.remove_prefix(1); } - return PSTRING() << "tg://" << http_url.host_ << query; + return PSTRING() << (is_tg ? "tg" : "ton") << "://" << http_url.host_ << query; } if (url.find('.') == string::npos) { diff --git a/td/telegram/misc.h b/td/telegram/misc.h index 6cb4ce382..f25d5ea4b 100644 --- a/td/telegram/misc.h +++ b/td/telegram/misc.h @@ -33,7 +33,7 @@ int32 get_vector_hash(const vector &numbers) TD_WARN_UNUSED_RESULT; // returns emoji corresponding to the specified number string get_emoji_fingerprint(uint64 num); -// checks whether url is a valid tg or HTTP(S) URL and returns its in a canonical form +// checks whether url is a valid tg, ton or HTTP(S) URL and returns its in a canonical form Result check_url(Slice url); } // namespace td