diff --git a/td/telegram/InputMessageText.cpp b/td/telegram/InputMessageText.cpp index 81faa3e7b..4601234c1 100644 --- a/td/telegram/InputMessageText.cpp +++ b/td/telegram/InputMessageText.cpp @@ -61,7 +61,7 @@ Result 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, 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) { - web_page_url = get_first_url(text); + web_page_url = get_first_url(text).str(); } return InputMessageText{ std::move(text), std::move(web_page_url), disable_web_page_preview, force_small_media, diff --git a/td/telegram/MessageContent.cpp b/td/telegram/MessageContent.cpp index 8d6515b67..c714b9c6d 100644 --- a/td/telegram/MessageContent.cpp +++ b/td/telegram/MessageContent.cpp @@ -2091,7 +2091,7 @@ InlineMessageContent create_inline_message_content(Td *td, FileId file_id, 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(text)); + web_page_id = td->web_pages_manager_->get_web_page_by_url(get_first_url(text).str()); } result.message_content = td::make_unique(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)}; 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( std::move(text), web_page_id, inline_message->force_small_media_, inline_message->force_large_media_, inline_message->safe_, std::move(web_page_url)); @@ -2263,7 +2263,7 @@ static Result create_input_message_content( 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( - 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(std::move(input_message_text.text), web_page_id, input_message_text.force_small_media, input_message_text.force_large_media, diff --git a/td/telegram/MessageEntity.cpp b/td/telegram/MessageEntity.cpp index f3a4f5e07..626e79757 100644 --- a/td/telegram/MessageEntity.cpp +++ b/td/telegram/MessageEntity.cpp @@ -1785,7 +1785,7 @@ static bool is_plain_domain(Slice url) { 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) { switch (entity.type) { 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)) { continue; } - return url.str(); + return url; } case MessageEntity::Type::EmailAddress: 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:")) { continue; } - return url.str(); + return url; } case MessageEntity::Type::MentionName: 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) { diff --git a/td/telegram/MessageEntity.h b/td/telegram/MessageEntity.h index e20584d21..c25804726 100644 --- a/td/telegram/MessageEntity.h +++ b/td/telegram/MessageEntity.h @@ -185,7 +185,7 @@ void remove_empty_entities(vector &entities); 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); diff --git a/td/telegram/WebPagesManager.cpp b/td/telegram/WebPagesManager.cpp index fe8b5c522..604b772cf 100644 --- a/td/telegram/WebPagesManager.cpp +++ b/td/telegram/WebPagesManager.cpp @@ -880,7 +880,7 @@ void WebPagesManager::get_web_page_preview(td_api::object_ptrauth_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()) { return promise.set_value(nullptr); }