Skip confirmation in link preview opening for visible URLs.
This commit is contained in:
parent
4194d9478b
commit
88199d1865
@ -6170,10 +6170,13 @@ tl_object_ptr<td_api::MessageContent> get_message_content_object(const MessageCo
|
||||
return td_api::make_object<td_api::messageAnimatedEmoji>(std::move(animated_emoji), m->text.text);
|
||||
}
|
||||
}
|
||||
auto web_page = td->web_pages_manager_->get_web_page_object(m->web_page_id, m->force_small_media,
|
||||
m->force_large_media, m->skip_web_page_confirmation);
|
||||
if (web_page != nullptr && !web_page->skip_confirmation_ && is_visible_url(m->text, web_page->url_)) {
|
||||
web_page->skip_confirmation_ = true;
|
||||
}
|
||||
return make_tl_object<td_api::messageText>(
|
||||
get_formatted_text_object(m->text, skip_bot_commands, max_media_timestamp),
|
||||
td->web_pages_manager_->get_web_page_object(m->web_page_id, m->force_small_media, m->force_large_media,
|
||||
m->skip_web_page_confirmation),
|
||||
get_formatted_text_object(m->text, skip_bot_commands, max_media_timestamp), std::move(web_page),
|
||||
m->web_page_url);
|
||||
}
|
||||
case MessageContentType::Unsupported:
|
||||
|
@ -1834,6 +1834,23 @@ string get_first_url(const FormattedText &text) {
|
||||
return string();
|
||||
}
|
||||
|
||||
bool is_visible_url(const FormattedText &text, const string &url) {
|
||||
auto url_size = static_cast<int32>(utf8_utf16_length(url));
|
||||
auto cur_offset = 0;
|
||||
Slice left_text = text.text;
|
||||
for (auto &entity : text.entities) {
|
||||
if (entity.type == MessageEntity::Type::Url && url_size == entity.length) {
|
||||
left_text = utf8_utf16_substr(left_text, entity.offset - cur_offset);
|
||||
cur_offset = entity.offset;
|
||||
if (begins_with(left_text, url)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
Result<vector<MessageEntity>> parse_markdown(string &text) {
|
||||
size_t result_size = 0;
|
||||
vector<MessageEntity> entities;
|
||||
|
@ -185,6 +185,8 @@ void remove_empty_entities(vector<MessageEntity> &entities);
|
||||
|
||||
string get_first_url(const FormattedText &text);
|
||||
|
||||
bool is_visible_url(const FormattedText &text, const string &url);
|
||||
|
||||
Result<vector<MessageEntity>> parse_markdown(string &text);
|
||||
|
||||
Result<vector<MessageEntity>> parse_markdown_v2(string &text);
|
||||
|
Loading…
Reference in New Issue
Block a user