Pass FormattedText to get_first_url.
This commit is contained in:
parent
47c0f387de
commit
b1e43bfbd5
@ -1630,12 +1630,12 @@ InlineMessageContent create_inline_message_content(Td *td, FileId file_id,
|
||||
}
|
||||
|
||||
result.disable_web_page_preview = inline_message->no_webpage_;
|
||||
FormattedText text{std::move(inline_message->message_), std::move(entities)};
|
||||
WebPageId web_page_id;
|
||||
if (!result.disable_web_page_preview) {
|
||||
web_page_id = td->web_pages_manager_->get_web_page_by_url(get_first_url(inline_message->message_, entities));
|
||||
web_page_id = td->web_pages_manager_->get_web_page_by_url(get_first_url(text));
|
||||
}
|
||||
result.message_content = make_unique<MessageText>(
|
||||
FormattedText{std::move(inline_message->message_), std::move(entities)}, web_page_id);
|
||||
result.message_content = make_unique<MessageText>(std::move(text), web_page_id);
|
||||
reply_markup = std::move(inline_message->reply_markup_);
|
||||
break;
|
||||
}
|
||||
@ -1772,8 +1772,7 @@ static Result<InputMessageContent> create_input_message_content(
|
||||
dialog_id.get_type() != DialogType::Channel ||
|
||||
td->contacts_manager_->get_channel_permissions(dialog_id.get_channel_id()).can_add_web_page_previews();
|
||||
if (!is_bot && !disable_web_page_preview && can_add_web_page_previews) {
|
||||
web_page_id = td->web_pages_manager_->get_web_page_by_url(
|
||||
get_first_url(input_message_text.text.text, input_message_text.text.entities));
|
||||
web_page_id = td->web_pages_manager_->get_web_page_by_url(get_first_url(input_message_text.text));
|
||||
}
|
||||
content = make_unique<MessageText>(std::move(input_message_text.text), web_page_id);
|
||||
break;
|
||||
|
@ -1776,8 +1776,8 @@ static bool is_plain_domain(Slice url) {
|
||||
return url.find('/') >= url.size() && url.find('?') >= url.size() && url.find('#') >= url.size();
|
||||
}
|
||||
|
||||
string get_first_url(Slice text, const vector<MessageEntity> &entities) {
|
||||
for (auto &entity : entities) {
|
||||
string get_first_url(const FormattedText &text) {
|
||||
for (auto &entity : text.entities) {
|
||||
switch (entity.type) {
|
||||
case MessageEntity::Type::Mention:
|
||||
break;
|
||||
@ -1786,7 +1786,10 @@ string get_first_url(Slice text, const vector<MessageEntity> &entities) {
|
||||
case MessageEntity::Type::BotCommand:
|
||||
break;
|
||||
case MessageEntity::Type::Url: {
|
||||
Slice url = utf8_utf16_substr(text, entity.offset, entity.length);
|
||||
if (entity.length <= 4) {
|
||||
continue;
|
||||
}
|
||||
Slice url = utf8_utf16_substr(text.text, entity.offset, entity.length);
|
||||
string scheme = to_lower(url.substr(0, 4));
|
||||
if (scheme == "ton:" || begins_with(scheme, "tg:") || scheme == "ftp:" || is_plain_domain(url)) {
|
||||
continue;
|
||||
|
@ -170,7 +170,7 @@ vector<std::pair<Slice, int32>> find_media_timestamps(Slice str); // slice + me
|
||||
|
||||
void remove_empty_entities(vector<MessageEntity> &entities);
|
||||
|
||||
string get_first_url(Slice text, const vector<MessageEntity> &entities);
|
||||
string get_first_url(const FormattedText &text);
|
||||
|
||||
Result<vector<MessageEntity>> parse_markdown(string &text);
|
||||
|
||||
|
@ -814,7 +814,8 @@ int64 WebPagesManager::get_web_page_preview(td_api::object_ptr<td_api::formatted
|
||||
return 0;
|
||||
}
|
||||
|
||||
auto url = get_first_url(text->text_, entities);
|
||||
FormattedText formatted_text{std::move(text->text_), std::move(entities)};
|
||||
auto url = get_first_url(formatted_text);
|
||||
if (url.empty()) {
|
||||
promise.set_value(Unit());
|
||||
return 0;
|
||||
@ -829,8 +830,10 @@ int64 WebPagesManager::get_web_page_preview(td_api::object_ptr<td_api::formatted
|
||||
promise.set_value(Unit());
|
||||
} else {
|
||||
td_->create_handler<GetWebPagePreviewQuery>(std::move(promise))
|
||||
->send(text->text_, get_input_message_entities(td_->contacts_manager_.get(), entities, "get_web_page_preview"),
|
||||
request_id, std::move(url));
|
||||
->send(
|
||||
formatted_text.text,
|
||||
get_input_message_entities(td_->contacts_manager_.get(), formatted_text.entities, "get_web_page_preview"),
|
||||
request_id, std::move(url));
|
||||
}
|
||||
return request_id;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user