Return Slice from get_first_url().

This commit is contained in:
levlam 2023-11-01 22:13:29 +03:00
parent 46d188e35c
commit d6b3a77899
5 changed files with 10 additions and 10 deletions

View File

@ -61,7 +61,7 @@ Result<InputMessageText> process_input_message_text(const Td *td, DialogId dialo
TRY_RESULT(text, get_formatted_text(td, dialog_id, std::move(input_message_text->text_), is_bot, TRY_RESULT(text, get_formatted_text(td, dialog_id, std::move(input_message_text->text_), is_bot,
for_draft || !web_page_url.empty(), for_draft, for_draft)); for_draft || !web_page_url.empty(), for_draft, for_draft));
if (!disable_web_page_preview && web_page_url.empty() && dialog_id.get_type() == DialogType::SecretChat) { if (!disable_web_page_preview && web_page_url.empty() && dialog_id.get_type() == DialogType::SecretChat) {
web_page_url = get_first_url(text); web_page_url = get_first_url(text).str();
} }
return InputMessageText{ return InputMessageText{
std::move(text), std::move(web_page_url), disable_web_page_preview, force_small_media, std::move(text), std::move(web_page_url), disable_web_page_preview, force_small_media,

View File

@ -2091,7 +2091,7 @@ InlineMessageContent create_inline_message_content(Td *td, FileId file_id,
FormattedText text{std::move(inline_message->message_), std::move(entities)}; FormattedText text{std::move(inline_message->message_), std::move(entities)};
WebPageId web_page_id; WebPageId web_page_id;
if (!result.disable_web_page_preview) { if (!result.disable_web_page_preview) {
web_page_id = td->web_pages_manager_->get_web_page_by_url(get_first_url(text)); web_page_id = td->web_pages_manager_->get_web_page_by_url(get_first_url(text).str());
} }
result.message_content = result.message_content =
td::make_unique<MessageText>(std::move(text), web_page_id, false, false, false, string()); td::make_unique<MessageText>(std::move(text), web_page_id, false, false, false, string());
@ -2116,7 +2116,7 @@ InlineMessageContent create_inline_message_content(Td *td, FileId file_id,
FormattedText text{std::move(inline_message->message_), std::move(entities)}; FormattedText text{std::move(inline_message->message_), std::move(entities)};
WebPageId web_page_id = WebPageId web_page_id =
td->web_pages_manager_->get_web_page_by_url(web_page_url.empty() ? get_first_url(text) : web_page_url); td->web_pages_manager_->get_web_page_by_url(web_page_url.empty() ? get_first_url(text).str() : web_page_url);
result.message_content = td::make_unique<MessageText>( result.message_content = td::make_unique<MessageText>(
std::move(text), web_page_id, inline_message->force_small_media_, inline_message->force_large_media_, std::move(text), web_page_id, inline_message->force_small_media_, inline_message->force_large_media_,
inline_message->safe_, std::move(web_page_url)); inline_message->safe_, std::move(web_page_url));
@ -2263,7 +2263,7 @@ static Result<InputMessageContent> create_input_message_content(
td->contacts_manager_->get_channel_permissions(dialog_id.get_channel_id()).can_add_web_page_previews(); 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) { if (!is_bot && !disable_web_page_preview && can_add_web_page_previews) {
web_page_id = td->web_pages_manager_->get_web_page_by_url( web_page_id = td->web_pages_manager_->get_web_page_by_url(
web_page_url.empty() ? get_first_url(input_message_text.text) : web_page_url); web_page_url.empty() ? get_first_url(input_message_text.text).str() : web_page_url);
} }
content = td::make_unique<MessageText>(std::move(input_message_text.text), web_page_id, content = td::make_unique<MessageText>(std::move(input_message_text.text), web_page_id,
input_message_text.force_small_media, input_message_text.force_large_media, input_message_text.force_small_media, input_message_text.force_large_media,

View File

@ -1785,7 +1785,7 @@ static bool is_plain_domain(Slice url) {
return url.find('/') >= url.size() && url.find('?') >= url.size() && url.find('#') >= url.size(); return url.find('/') >= url.size() && url.find('?') >= url.size() && url.find('#') >= url.size();
} }
string get_first_url(const FormattedText &text) { Slice get_first_url(const FormattedText &text) {
for (auto &entity : text.entities) { for (auto &entity : text.entities) {
switch (entity.type) { switch (entity.type) {
case MessageEntity::Type::Mention: case MessageEntity::Type::Mention:
@ -1803,7 +1803,7 @@ string get_first_url(const FormattedText &text) {
if (scheme == "ton:" || begins_with(scheme, "tg:") || scheme == "ftp:" || is_plain_domain(url)) { if (scheme == "ton:" || begins_with(scheme, "tg:") || scheme == "ftp:" || is_plain_domain(url)) {
continue; continue;
} }
return url.str(); return url;
} }
case MessageEntity::Type::EmailAddress: case MessageEntity::Type::EmailAddress:
break; break;
@ -1828,7 +1828,7 @@ string get_first_url(const FormattedText &text) {
if (begins_with(url, "ton:") || begins_with(url, "tg:") || begins_with(url, "ftp:")) { if (begins_with(url, "ton:") || begins_with(url, "tg:") || begins_with(url, "ftp:")) {
continue; continue;
} }
return url.str(); return url;
} }
case MessageEntity::Type::MentionName: case MessageEntity::Type::MentionName:
break; break;
@ -1849,7 +1849,7 @@ string get_first_url(const FormattedText &text) {
} }
} }
return string(); return Slice();
} }
bool is_visible_url(const FormattedText &text, const string &url) { bool is_visible_url(const FormattedText &text, const string &url) {

View File

@ -185,7 +185,7 @@ void remove_empty_entities(vector<MessageEntity> &entities);
void remove_unallowed_quote_entities(FormattedText &text); void remove_unallowed_quote_entities(FormattedText &text);
string get_first_url(const FormattedText &text); Slice get_first_url(const FormattedText &text);
bool is_visible_url(const FormattedText &text, const string &url); bool is_visible_url(const FormattedText &text, const string &url);

View File

@ -880,7 +880,7 @@ void WebPagesManager::get_web_page_preview(td_api::object_ptr<td_api::formattedT
promise, formatted_text, promise, formatted_text,
get_formatted_text(td_, DialogId(), std::move(text), td_->auth_manager_->is_bot(), true, true, true)); get_formatted_text(td_, DialogId(), std::move(text), td_->auth_manager_->is_bot(), true, true, true));
auto first_url = get_first_url(formatted_text); auto first_url = get_first_url(formatted_text).str();
if (first_url.empty()) { if (first_url.empty()) {
return promise.set_value(nullptr); return promise.set_value(nullptr);
} }