Partial ton:// URLs support.

GitOrigin-RevId: eeaaab10574dc636e9de18cc482f2398f6732fa1
This commit is contained in:
levlam 2019-09-27 01:03:13 +03:00
parent 9b0530e704
commit 79330c3881
3 changed files with 13 additions and 8 deletions

View File

@ -1181,7 +1181,7 @@ string get_first_url(Slice text, const vector<MessageEntity> &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<MessageEntity> &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;

View File

@ -277,20 +277,25 @@ string get_emoji_fingerprint(uint64 num) {
Result<string> 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<string> 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) {

View File

@ -33,7 +33,7 @@ int32 get_vector_hash(const vector<uint32> &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<string> check_url(Slice url);
} // namespace td