Init disable_web_page_preview for incoming messages.

This commit is contained in:
levlam 2021-11-04 00:21:27 +03:00
parent d63471fcde
commit 46486bd82e
5 changed files with 36 additions and 14 deletions

View File

@ -4100,11 +4100,14 @@ unique_ptr<MessageContent> get_secret_message_content(
unique_ptr<MessageContent> get_message_content(Td *td, FormattedText message,
tl_object_ptr<telegram_api::MessageMedia> &&media,
DialogId owner_dialog_id, bool is_content_read, UserId via_bot_user_id,
int32 *ttl) {
int32 *ttl, bool *disable_web_page_preview) {
if (!td->auth_manager_->was_authorized() && !G()->close_flag() && media != nullptr) {
LOG(ERROR) << "Receive without authorization " << to_string(media);
media = nullptr;
}
if (disable_web_page_preview != nullptr) {
*disable_web_page_preview = false;
}
int32 constructor_id = media == nullptr ? telegram_api::messageMediaEmpty::ID : media->get_id();
switch (constructor_id) {
@ -4112,6 +4115,9 @@ unique_ptr<MessageContent> get_message_content(Td *td, FormattedText message,
if (message.text.empty()) {
LOG(ERROR) << "Receive empty message text and media for message from " << owner_dialog_id;
}
if (disable_web_page_preview != nullptr) {
*disable_web_page_preview = true;
}
return make_unique<MessageText>(std::move(message), WebPageId());
case telegram_api::messageMediaPhoto::ID: {
auto message_photo = move_tl_object_as<telegram_api::messageMediaPhoto>(media);
@ -4233,6 +4239,9 @@ unique_ptr<MessageContent> get_message_content(Td *td, FormattedText message,
get_input_invoice(move_tl_object_as<telegram_api::messageMediaInvoice>(media), td, owner_dialog_id));
case telegram_api::messageMediaWebPage::ID: {
auto media_web_page = move_tl_object_as<telegram_api::messageMediaWebPage>(media);
if (disable_web_page_preview != nullptr) {
*disable_web_page_preview = (media_web_page->webpage_ == nullptr);
}
auto web_page_id = td->web_pages_manager_->on_get_web_page(std::move(media_web_page->webpage_), owner_dialog_id);
return make_unique<MessageText>(std::move(message), web_page_id);
}
@ -4252,6 +4261,9 @@ unique_ptr<MessageContent> get_message_content(Td *td, FormattedText message,
}
// explicit empty media message
if (disable_web_page_preview != nullptr) {
*disable_web_page_preview = true;
}
return make_unique<MessageText>(std::move(message), WebPageId());
}

View File

@ -189,7 +189,7 @@ unique_ptr<MessageContent> get_secret_message_content(
unique_ptr<MessageContent> get_message_content(Td *td, FormattedText message_text,
tl_object_ptr<telegram_api::MessageMedia> &&media,
DialogId owner_dialog_id, bool is_content_read, UserId via_bot_user_id,
int32 *ttl);
int32 *ttl, bool *disable_web_page_preview);
enum class MessageContentDupType : int32 { Send, SendViaBot, Forward, Copy };

View File

@ -6643,7 +6643,6 @@ void MessagesManager::save_auth_notification_ids() {
void MessagesManager::on_update_service_notification(tl_object_ptr<telegram_api::updateServiceNotification> &&update,
bool skip_new_entities, Promise<Unit> &&promise) {
int32 ttl = 0;
bool has_date = (update->flags_ & telegram_api::updateServiceNotification::INBOX_DATE_MASK) != 0;
auto date = has_date ? update->inbox_date_ : G()->unix_time();
if (date <= 0) {
@ -6666,8 +6665,10 @@ void MessagesManager::on_update_service_notification(tl_object_ptr<telegram_api:
auto message_text = get_message_text(contacts_manager, std::move(update->message_), std::move(update->entities_),
skip_new_entities, !is_user, date, false, "on_update_service_notification");
DialogId owner_dialog_id = is_user ? get_service_notifications_dialog()->dialog_id : DialogId();
int32 ttl = 0;
bool disable_web_page_preview = false;
auto content = get_message_content(td_, std::move(message_text), std::move(update->media_), owner_dialog_id, false,
UserId(), &ttl);
UserId(), &ttl, &disable_web_page_preview);
bool is_content_secret = is_secret_message_content(ttl, content->get_type());
if (update->popup_) {
@ -6687,6 +6688,7 @@ void MessagesManager::on_update_service_notification(tl_object_ptr<telegram_api:
new_message->sender_user_id = dialog_id.get_user_id();
new_message->date = date;
new_message->ttl = ttl;
new_message->disable_web_page_preview = disable_web_page_preview;
new_message->is_content_secret = is_content_secret;
new_message->content = std::move(content);
new_message->have_previous = true;
@ -13593,7 +13595,7 @@ MessagesManager::MessageInfo MessagesManager::parse_telegram_api_message(
message_info.forward_header ? message_info.forward_header->date_ : message_info.date,
message_info.media_album_id != 0, new_source.c_str()),
std::move(message->media_), message_info.dialog_id, is_content_read, message_info.via_bot_user_id,
&message_info.ttl);
&message_info.ttl, &message_info.disable_web_page_preview);
message_info.reply_markup =
message->flags_ & MESSAGE_FLAG_HAS_REPLY_MARKUP ? std::move(message->reply_markup_) : nullptr;
message_info.restriction_reasons = get_restriction_reasons(std::move(message->restriction_reason_));
@ -13836,6 +13838,7 @@ std::pair<DialogId, unique_ptr<MessagesManager::Message>> MessagesManager::creat
message->date = date;
message->ttl_period = ttl_period;
message->ttl = ttl;
message->disable_web_page_preview = message_info.disable_web_page_preview;
message->edit_date = edit_date;
message->random_id = message_info.random_id;
message->forward_info = get_message_forward_info(std::move(message_info.forward_header));
@ -14596,8 +14599,9 @@ void MessagesManager::on_update_sent_text_message(int64 random_id,
FormattedText new_message_text = get_message_text(
td_->contacts_manager_.get(), old_message_text->text, std::move(entities), true, td_->auth_manager_->is_bot(),
m->forward_info ? m->forward_info->date : m->date, m->media_album_id != 0, "on_update_sent_text_message");
auto new_content = get_message_content(td_, std::move(new_message_text), std::move(message_media), dialog_id,
true /*likely ignored*/, UserId() /*likely ignored*/, nullptr /*ignored*/);
auto new_content =
get_message_content(td_, std::move(new_message_text), std::move(message_media), dialog_id,
true /*likely ignored*/, UserId() /*likely ignored*/, nullptr /*ignored*/, nullptr);
if (new_content->get_type() != MessageContentType::Text) {
LOG(ERROR) << "Text message content has changed to " << new_content->get_type();
return;
@ -24755,7 +24759,7 @@ void MessagesManager::on_upload_message_media_success(DialogId dialog_id, Messag
auto caption = get_message_content_caption(m->content.get());
auto content = get_message_content(td_, caption == nullptr ? FormattedText() : *caption, std::move(media), dialog_id,
false, UserId(), nullptr);
false, UserId(), nullptr, nullptr);
if (update_message_content(dialog_id, m, std::move(content), true, true, true) &&
m->message_id == d->last_message_id) {
@ -26469,14 +26473,13 @@ void MessagesManager::unregister_message_reply(const Dialog *d, const Message *m
}
bool MessagesManager::get_message_disable_web_page_preview(const Message *m) {
// m->disable_web_page_preview is known only for sent from this client messages
if (m->disable_web_page_preview) {
return true;
}
if (m->content->get_type() != MessageContentType::Text) {
return false;
}
return !has_message_content_web_page(m->content.get());
if (has_message_content_web_page(m->content.get())) {
return false;
}
return m->disable_web_page_preview;
}
int32 MessagesManager::get_message_flags(const Message *m) {
@ -34626,6 +34629,9 @@ bool MessagesManager::update_message(Dialog *d, Message *old_message, unique_ptr
// old_message->disable_notification = new_message->disable_notification;
// need_send_update = true;
}
if (old_message->disable_web_page_preview != new_message->disable_web_page_preview) {
old_message->disable_web_page_preview = new_message->disable_web_page_preview;
}
if (!is_scheduled &&
update_message_contains_unread_mention(d, old_message, new_message->contains_unread_mention, "update_message")) {

View File

@ -969,6 +969,7 @@ class MessagesManager final : public Actor {
int32 date = 0;
int32 ttl_period = 0;
int32 ttl = 0;
bool disable_web_page_preview = false;
int64 random_id = 0;
tl_object_ptr<telegram_api::messageFwdHeader> forward_header;
MessageId reply_to_message_id;

View File

@ -261,11 +261,14 @@ void SponsoredMessageManager::on_get_dialog_sponsored_messages(
std::move(sponsored_message->entities_), true, true, 0, false,
"on_get_dialog_sponsored_messages");
int32 ttl = 0;
auto content = get_message_content(td_, std::move(message_text), nullptr, sponsor_dialog_id, true, UserId(), &ttl);
bool disable_web_page_preview = false;
auto content = get_message_content(td_, std::move(message_text), nullptr, sponsor_dialog_id, true, UserId(), &ttl,
&disable_web_page_preview);
if (ttl != 0) {
LOG(ERROR) << "Receive sponsored message with TTL " << ttl;
continue;
}
CHECK(disable_web_page_preview);
CHECK(current_sponsored_message_id_ < std::numeric_limits<int32>::max());
auto local_id = ++current_sponsored_message_id_;