Add webPage.skip_confirmation.

This commit is contained in:
levlam 2023-10-19 13:03:27 +03:00
parent f78bc2ae32
commit 4194d9478b
6 changed files with 38 additions and 25 deletions

View File

@ -2102,6 +2102,7 @@ webPageInstantView page_blocks:vector<PageBlock> view_count:int32 version:int32
//@has_large_media True, if the preview has large media and its appearance can be changed //@has_large_media True, if the preview has large media and its appearance can be changed
//@force_small_media True, if shown media preview must be small //@force_small_media True, if shown media preview must be small
//@force_large_media True, if shown media preview must be large //@force_large_media True, if shown media preview must be large
//@skip_confirmation True, if there is no need to show an ordinary open URL confirmation, when opening the URL from the preview, because the URL is shown in the message text in clear
//@animation Preview of the content as an animation, if available; may be null //@animation Preview of the content as an animation, if available; may be null
//@audio Preview of the content as an audio file, if available; may be null //@audio Preview of the content as an audio file, if available; may be null
//@document Preview of the content as a document, if available; may be null //@document Preview of the content as a document, if available; may be null
@ -2112,7 +2113,7 @@ webPageInstantView page_blocks:vector<PageBlock> view_count:int32 version:int32
//@story_sender_chat_id The identifier of the sender of the previewed story; 0 if none //@story_sender_chat_id The identifier of the sender of the previewed story; 0 if none
//@story_id The identifier of the previewed story; 0 if none //@story_id The identifier of the previewed story; 0 if none
//@instant_view_version Version of web page instant view (currently, can be 1 or 2); 0 if none //@instant_view_version Version of web page instant view (currently, can be 1 or 2); 0 if none
webPage url:string display_url:string type:string site_name:string title:string description:formattedText photo:photo embed_url:string embed_type:string embed_width:int32 embed_height:int32 duration:int32 author:string has_large_media:Bool force_small_media:Bool force_large_media:Bool animation:animation audio:audio document:document sticker:sticker video:video video_note:videoNote voice_note:voiceNote story_sender_chat_id:int53 story_id:int32 instant_view_version:int32 = WebPage; webPage url:string display_url:string type:string site_name:string title:string description:formattedText photo:photo embed_url:string embed_type:string embed_width:int32 embed_height:int32 duration:int32 author:string has_large_media:Bool force_small_media:Bool force_large_media:Bool skip_confirmation:Bool animation:animation audio:audio document:document sticker:sticker video:video video_note:videoNote voice_note:voiceNote story_sender_chat_id:int53 story_id:int32 instant_view_version:int32 = WebPage;
//@description Contains information about a country //@description Contains information about a country

View File

@ -119,15 +119,17 @@ class MessageText final : public MessageContent {
WebPageId web_page_id; WebPageId web_page_id;
bool force_small_media = false; bool force_small_media = false;
bool force_large_media = false; bool force_large_media = false;
bool skip_web_page_confirmation = false;
string web_page_url; string web_page_url;
MessageText() = default; MessageText() = default;
MessageText(FormattedText text, WebPageId web_page_id, bool force_small_media, bool force_large_media, MessageText(FormattedText text, WebPageId web_page_id, bool force_small_media, bool force_large_media,
string web_page_url) bool skip_web_page_confirmation, string web_page_url)
: text(std::move(text)) : text(std::move(text))
, web_page_id(web_page_id) , web_page_id(web_page_id)
, force_small_media(force_small_media) , force_small_media(force_small_media)
, force_large_media(force_large_media) , force_large_media(force_large_media)
, skip_web_page_confirmation(skip_web_page_confirmation)
, web_page_url(std::move(web_page_url)) { , web_page_url(std::move(web_page_url)) {
if (web_page_url.empty()) { if (web_page_url.empty()) {
force_small_media = false; force_small_media = false;
@ -1081,6 +1083,7 @@ static void store(const MessageContent *content, StorerT &storer) {
STORE_FLAG(m->force_small_media); STORE_FLAG(m->force_small_media);
STORE_FLAG(m->force_large_media); STORE_FLAG(m->force_large_media);
STORE_FLAG(has_web_page_url); STORE_FLAG(has_web_page_url);
STORE_FLAG(m->skip_web_page_confirmation);
END_STORE_FLAGS(); END_STORE_FLAGS();
store(m->text, storer); store(m->text, storer);
if (has_web_page_id) { if (has_web_page_id) {
@ -1570,6 +1573,7 @@ static void parse(unique_ptr<MessageContent> &content, ParserT &parser) {
PARSE_FLAG(m->force_small_media); PARSE_FLAG(m->force_small_media);
PARSE_FLAG(m->force_large_media); PARSE_FLAG(m->force_large_media);
PARSE_FLAG(has_web_page_url); PARSE_FLAG(has_web_page_url);
PARSE_FLAG(m->skip_web_page_confirmation);
END_PARSE_FLAGS(); END_PARSE_FLAGS();
} }
parse(m->text, parser); parse(m->text, parser);
@ -2078,7 +2082,8 @@ InlineMessageContent create_inline_message_content(Td *td, FileId file_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));
} }
result.message_content = td::make_unique<MessageText>(std::move(text), web_page_id, false, false, string()); result.message_content =
td::make_unique<MessageText>(std::move(text), web_page_id, false, false, false, string());
reply_markup = std::move(inline_message->reply_markup_); reply_markup = std::move(inline_message->reply_markup_);
break; break;
} }
@ -2101,9 +2106,9 @@ 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) : web_page_url);
result.message_content = result.message_content = td::make_unique<MessageText>(
td::make_unique<MessageText>(std::move(text), web_page_id, inline_message->force_small_media_, std::move(text), web_page_id, inline_message->force_small_media_, inline_message->force_large_media_,
inline_message->force_large_media_, std::move(web_page_url)); inline_message->safe_, std::move(web_page_url));
reply_markup = std::move(inline_message->reply_markup_); reply_markup = std::move(inline_message->reply_markup_);
break; break;
} }
@ -2181,9 +2186,10 @@ InlineMessageContent create_inline_message_content(Td *td, FileId file_id,
unique_ptr<MessageContent> create_text_message_content(string text, vector<MessageEntity> entities, unique_ptr<MessageContent> create_text_message_content(string text, vector<MessageEntity> entities,
WebPageId web_page_id, bool force_small_media, WebPageId web_page_id, bool force_small_media,
bool force_large_media, string &&web_page_url) { bool force_large_media, bool skip_confirmation,
string &&web_page_url) {
return td::make_unique<MessageText>(FormattedText{std::move(text), std::move(entities)}, web_page_id, return td::make_unique<MessageText>(FormattedText{std::move(text), std::move(entities)}, web_page_id,
force_small_media, force_large_media, std::move(web_page_url)); force_small_media, force_large_media, skip_confirmation, std::move(web_page_url));
} }
unique_ptr<MessageContent> create_contact_registered_message_content() { unique_ptr<MessageContent> create_contact_registered_message_content() {
@ -2246,7 +2252,7 @@ static Result<InputMessageContent> create_input_message_content(
} }
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,
std::move(web_page_url)); false, std::move(web_page_url));
break; break;
} }
case td_api::inputMessageAnimation::ID: { case td_api::inputMessageAnimation::ID: {
@ -3803,6 +3809,7 @@ void remove_message_content_web_page(MessageContent *content) {
message_text->web_page_id = WebPageId(); message_text->web_page_id = WebPageId();
message_text->force_small_media = false; message_text->force_small_media = false;
message_text->force_large_media = false; message_text->force_large_media = false;
message_text->skip_web_page_confirmation = false;
message_text->web_page_url = string(); message_text->web_page_url = string();
} }
@ -3939,7 +3946,8 @@ void merge_message_contents(Td *td, const MessageContent *old_content, MessageCo
need_update = true; need_update = true;
} }
if (old_->web_page_id != new_->web_page_id || old_->force_small_media != new_->force_small_media || if (old_->web_page_id != new_->web_page_id || old_->force_small_media != new_->force_small_media ||
old_->force_large_media != new_->force_large_media) { old_->force_large_media != new_->force_large_media ||
old_->skip_web_page_confirmation != new_->skip_web_page_confirmation) {
LOG(INFO) << "Old: " << old_->web_page_id << ", new: " << new_->web_page_id; LOG(INFO) << "Old: " << old_->web_page_id << ", new: " << new_->web_page_id;
is_content_changed = true; is_content_changed = true;
need_update |= td->web_pages_manager_->have_web_page(old_->web_page_id) || need_update |= td->web_pages_manager_->have_web_page(old_->web_page_id) ||
@ -5133,7 +5141,7 @@ unique_ptr<MessageContent> get_secret_message_content(
auto url = r_http_url.ok().get_url(); auto url = r_http_url.ok().get_url();
auto result = td::make_unique<MessageText>(FormattedText{std::move(message_text), std::move(entities)}, auto result = td::make_unique<MessageText>(FormattedText{std::move(message_text), std::move(entities)},
WebPageId(), false, false, url); WebPageId(), false, false, false, url);
td->web_pages_manager_->get_web_page_by_url( td->web_pages_manager_->get_web_page_by_url(
url, url,
PromiseCreator::lambda([&web_page_id = result->web_page_id, promise = load_data_multipromise.get_promise()]( PromiseCreator::lambda([&web_page_id = result->web_page_id, promise = load_data_multipromise.get_promise()](
@ -5159,7 +5167,7 @@ unique_ptr<MessageContent> get_secret_message_content(
is_media_empty = true; is_media_empty = true;
} }
if (is_media_empty) { if (is_media_empty) {
return create_text_message_content(std::move(message_text), std::move(entities), WebPageId(), false, false, return create_text_message_content(std::move(message_text), std::move(entities), WebPageId(), false, false, false,
string()); string());
} }
switch (constructor_id) { switch (constructor_id) {
@ -5220,7 +5228,7 @@ unique_ptr<MessageContent> get_message_content(Td *td, FormattedText message,
if (disable_web_page_preview != nullptr) { if (disable_web_page_preview != nullptr) {
*disable_web_page_preview = true; *disable_web_page_preview = true;
} }
return td::make_unique<MessageText>(std::move(message), WebPageId(), false, false, string()); return td::make_unique<MessageText>(std::move(message), WebPageId(), false, false, false, string());
case telegram_api::messageMediaPhoto::ID: { case telegram_api::messageMediaPhoto::ID: {
auto media = move_tl_object_as<telegram_api::messageMediaPhoto>(media_ptr); auto media = move_tl_object_as<telegram_api::messageMediaPhoto>(media_ptr);
if (media->photo_ == nullptr) { if (media->photo_ == nullptr) {
@ -5352,7 +5360,7 @@ unique_ptr<MessageContent> get_message_content(Td *td, FormattedText message,
} }
auto web_page_id = td->web_pages_manager_->on_get_web_page(std::move(media->webpage_), owner_dialog_id); auto web_page_id = td->web_pages_manager_->on_get_web_page(std::move(media->webpage_), owner_dialog_id);
return td::make_unique<MessageText>(std::move(message), web_page_id, media->force_small_media_, return td::make_unique<MessageText>(std::move(message), web_page_id, media->force_small_media_,
media->force_large_media_, std::move(web_page_url)); media->force_large_media_, media->safe_, std::move(web_page_url));
} }
case telegram_api::messageMediaPoll::ID: { case telegram_api::messageMediaPoll::ID: {
auto media = move_tl_object_as<telegram_api::messageMediaPoll>(media_ptr); auto media = move_tl_object_as<telegram_api::messageMediaPoll>(media_ptr);
@ -5412,7 +5420,7 @@ unique_ptr<MessageContent> get_message_content(Td *td, FormattedText message,
if (disable_web_page_preview != nullptr) { if (disable_web_page_preview != nullptr) {
*disable_web_page_preview = true; *disable_web_page_preview = true;
} }
return td::make_unique<MessageText>(std::move(message), WebPageId(), false, false, string()); return td::make_unique<MessageText>(std::move(message), WebPageId(), false, false, false, string());
} }
unique_ptr<MessageContent> dup_message_content(Td *td, DialogId dialog_id, const MessageContent *content, unique_ptr<MessageContent> dup_message_content(Td *td, DialogId dialog_id, const MessageContent *content,
@ -6080,7 +6088,7 @@ unique_ptr<MessageContent> get_action_message_content(Td *td, tl_object_ptr<tele
UNREACHABLE(); UNREACHABLE();
} }
// explicit empty or wrong action // explicit empty or wrong action
return td::make_unique<MessageText>(FormattedText(), WebPageId(), false, false, string()); return td::make_unique<MessageText>(FormattedText(), WebPageId(), false, false, false, string());
} }
tl_object_ptr<td_api::MessageContent> get_message_content_object(const MessageContent *content, Td *td, tl_object_ptr<td_api::MessageContent> get_message_content_object(const MessageContent *content, Td *td,
@ -6164,7 +6172,8 @@ tl_object_ptr<td_api::MessageContent> get_message_content_object(const MessageCo
} }
return make_tl_object<td_api::messageText>( return make_tl_object<td_api::messageText>(
get_formatted_text_object(m->text, skip_bot_commands, max_media_timestamp), 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), 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),
m->web_page_url); m->web_page_url);
} }
case MessageContentType::Unsupported: case MessageContentType::Unsupported:

View File

@ -96,7 +96,8 @@ InlineMessageContent create_inline_message_content(Td *td, FileId file_id,
unique_ptr<MessageContent> create_text_message_content(string text, vector<MessageEntity> entities, unique_ptr<MessageContent> create_text_message_content(string text, vector<MessageEntity> entities,
WebPageId web_page_id, bool force_small_media, WebPageId web_page_id, bool force_small_media,
bool force_large_media, string &&web_page_url); bool force_large_media, bool skip_confitmation,
string &&web_page_url);
unique_ptr<MessageContent> create_contact_registered_message_content(); unique_ptr<MessageContent> create_contact_registered_message_content();

View File

@ -14451,7 +14451,8 @@ std::pair<DialogId, unique_ptr<MessagesManager::Message>> MessagesManager::creat
if (content_type == MessageContentType::Sticker && if (content_type == MessageContentType::Sticker &&
get_message_content_sticker_type(td_, message_info.content.get()) == StickerType::CustomEmoji) { get_message_content_sticker_type(td_, message_info.content.get()) == StickerType::CustomEmoji) {
LOG(INFO) << "Replace emoji sticker with an empty message"; LOG(INFO) << "Replace emoji sticker with an empty message";
message_info.content = create_text_message_content("Invalid sticker", {}, WebPageId(), false, false, string()); message_info.content =
create_text_message_content("Invalid sticker", {}, WebPageId(), false, false, false, string());
content_type = message_info.content->get_type(); content_type = message_info.content->get_type();
} }
@ -25915,7 +25916,7 @@ Result<MessageId> MessagesManager::send_bot_start_message(UserId bot_user_id, Di
bool need_update_dialog_pos = false; bool need_update_dialog_pos = false;
Message *m = get_message_to_send( Message *m = get_message_to_send(
d, MessageId(), MessageInputReplyTo(), MessageSendOptions(), d, MessageId(), MessageInputReplyTo(), MessageSendOptions(),
create_text_message_content(text, std::move(text_entities), WebPageId(), false, false, string()), create_text_message_content(text, std::move(text_entities), WebPageId(), false, false, false, string()),
&need_update_dialog_pos); &need_update_dialog_pos);
m->is_bot_start_message = true; m->is_bot_start_message = true;

View File

@ -872,7 +872,7 @@ void WebPagesManager::on_get_web_page_preview_success(const string &first_url, W
on_get_web_page_by_url(first_url, web_page_id, true); on_get_web_page_by_url(first_url, web_page_id, true);
} }
promise.set_value(get_web_page_object(web_page_id, false, false)); promise.set_value(get_web_page_object(web_page_id, false, false, false));
} }
void WebPagesManager::get_web_page_preview(td_api::object_ptr<td_api::formattedText> &&text, void WebPagesManager::get_web_page_preview(td_api::object_ptr<td_api::formattedText> &&text,
@ -890,7 +890,7 @@ void WebPagesManager::get_web_page_preview(td_api::object_ptr<td_api::formattedT
auto web_page_id = get_web_page_by_url(first_url); auto web_page_id = get_web_page_by_url(first_url);
if (web_page_id.is_valid()) { if (web_page_id.is_valid()) {
return promise.set_value(get_web_page_object(web_page_id, false, false)); return promise.set_value(get_web_page_object(web_page_id, false, false, false));
} }
td_->create_handler<GetWebPagePreviewQuery>(std::move(promise)) td_->create_handler<GetWebPagePreviewQuery>(std::move(promise))
->send(formatted_text.text, ->send(formatted_text.text,
@ -1232,7 +1232,8 @@ bool WebPagesManager::have_web_page(WebPageId web_page_id) const {
} }
tl_object_ptr<td_api::webPage> WebPagesManager::get_web_page_object(WebPageId web_page_id, bool force_small_media, tl_object_ptr<td_api::webPage> WebPagesManager::get_web_page_object(WebPageId web_page_id, bool force_small_media,
bool force_large_media) const { bool force_large_media,
bool skip_confirmation) const {
if (!web_page_id.is_valid()) { if (!web_page_id.is_valid()) {
return nullptr; return nullptr;
} }
@ -1336,7 +1337,7 @@ tl_object_ptr<td_api::webPage> WebPagesManager::get_web_page_object(WebPageId we
get_formatted_text_object(description, true, duration == 0 ? std::numeric_limits<int32>::max() : duration), get_formatted_text_object(description, true, duration == 0 ? std::numeric_limits<int32>::max() : duration),
get_photo_object(td_->file_manager_.get(), web_page->photo_), web_page->embed_url_, web_page->embed_type_, get_photo_object(td_->file_manager_.get(), web_page->photo_), web_page->embed_url_, web_page->embed_type_,
web_page->embed_dimensions_.width, web_page->embed_dimensions_.height, web_page->duration_, web_page->author_, web_page->embed_dimensions_.width, web_page->embed_dimensions_.height, web_page->duration_, web_page->author_,
web_page->has_large_media_, force_small_media, web_page->has_large_media_ && force_large_media, web_page->has_large_media_, force_small_media, web_page->has_large_media_ && force_large_media, skip_confirmation,
web_page->document_.type == Document::Type::Animation web_page->document_.type == Document::Type::Animation
? td_->animations_manager_->get_animation_object(web_page->document_.file_id) ? td_->animations_manager_->get_animation_object(web_page->document_.file_id)
: nullptr, : nullptr,

View File

@ -63,7 +63,7 @@ class WebPagesManager final : public Actor {
bool have_web_page_force(WebPageId web_page_id); bool have_web_page_force(WebPageId web_page_id);
tl_object_ptr<td_api::webPage> get_web_page_object(WebPageId web_page_id, bool force_small_media, tl_object_ptr<td_api::webPage> get_web_page_object(WebPageId web_page_id, bool force_small_media,
bool force_large_media) const; bool force_large_media, bool skip_confirmation) const;
tl_object_ptr<td_api::webPageInstantView> get_web_page_instant_view_object(WebPageId web_page_id) const; tl_object_ptr<td_api::webPageInstantView> get_web_page_instant_view_object(WebPageId web_page_id) const;