diff --git a/td/generate/scheme/td_api.tl b/td/generate/scheme/td_api.tl index 2b9194862..5d366546c 100644 --- a/td/generate/scheme/td_api.tl +++ b/td/generate/scheme/td_api.tl @@ -1562,6 +1562,7 @@ factCheck text:formattedText country_code:string = FactCheck; //@import_info Information about the initial message for messages created with importMessages; may be null if the message isn't imported //@interaction_info Information about interactions with the message; may be null if none //@unread_reactions Information about unread reactions added to the message +//@fact_check Information about fact check added to the message; may be null if none //@reply_to Information about the message or the story this message is replying to; may be null if none //@message_thread_id If non-zero, the identifier of the message thread the message belongs to; unique within the chat to which the message belongs //@saved_messages_topic_id Identifier of the Saved Messages topic for the message; 0 for messages not from Saved Messages @@ -1577,7 +1578,7 @@ factCheck text:formattedText country_code:string = FactCheck; //@restriction_reason If non-empty, contains a human-readable description of the reason why access to this message must be restricted //@content Content of the message //@reply_markup Reply markup for the message; may be null if none -message id:int53 sender_id:MessageSender chat_id:int53 sending_state:MessageSendingState scheduling_state:MessageSchedulingState is_outgoing:Bool is_pinned:Bool is_from_offline:Bool can_be_edited:Bool can_be_forwarded:Bool can_be_replied_in_another_chat:Bool can_be_saved:Bool can_be_deleted_only_for_self:Bool can_be_deleted_for_all_users:Bool can_get_added_reactions:Bool can_get_statistics:Bool can_get_message_thread:Bool can_get_read_date:Bool can_get_viewers:Bool can_get_media_timestamp_links:Bool can_report_reactions:Bool has_timestamped_media:Bool is_channel_post:Bool is_topic_message:Bool contains_unread_mention:Bool date:int32 edit_date:int32 forward_info:messageForwardInfo import_info:messageImportInfo interaction_info:messageInteractionInfo unread_reactions:vector reply_to:MessageReplyTo message_thread_id:int53 saved_messages_topic_id:int53 self_destruct_type:MessageSelfDestructType self_destruct_in:double auto_delete_in:double via_bot_user_id:int53 sender_business_bot_user_id:int53 sender_boost_count:int32 author_signature:string media_album_id:int64 effect_id:int64 restriction_reason:string content:MessageContent reply_markup:ReplyMarkup = Message; +message id:int53 sender_id:MessageSender chat_id:int53 sending_state:MessageSendingState scheduling_state:MessageSchedulingState is_outgoing:Bool is_pinned:Bool is_from_offline:Bool can_be_edited:Bool can_be_forwarded:Bool can_be_replied_in_another_chat:Bool can_be_saved:Bool can_be_deleted_only_for_self:Bool can_be_deleted_for_all_users:Bool can_get_added_reactions:Bool can_get_statistics:Bool can_get_message_thread:Bool can_get_read_date:Bool can_get_viewers:Bool can_get_media_timestamp_links:Bool can_report_reactions:Bool has_timestamped_media:Bool is_channel_post:Bool is_topic_message:Bool contains_unread_mention:Bool date:int32 edit_date:int32 forward_info:messageForwardInfo import_info:messageImportInfo interaction_info:messageInteractionInfo unread_reactions:vector fact_check:factCheck reply_to:MessageReplyTo message_thread_id:int53 saved_messages_topic_id:int53 self_destruct_type:MessageSelfDestructType self_destruct_in:double auto_delete_in:double via_bot_user_id:int53 sender_business_bot_user_id:int53 sender_boost_count:int32 author_signature:string media_album_id:int64 effect_id:int64 restriction_reason:string content:MessageContent reply_markup:ReplyMarkup = Message; //@description Contains a list of messages @total_count Approximate total number of messages found @messages List of messages; messages may be null messages total_count:int32 messages:vector = Messages; @@ -6964,6 +6965,12 @@ updateMessageMentionRead chat_id:int53 message_id:int53 unread_mention_count:int //@unread_reaction_count The new number of messages with unread reactions left in the chat updateMessageUnreadReactions chat_id:int53 message_id:int53 unread_reactions:vector unread_reaction_count:int32 = Update; +//@description A fact check added to a message was changed +//@chat_id Chat identifier +//@message_id Message identifier +//@fact_check The new fact check +updateMessageFactCheck chat_id:int53 message_id:int53 fact_check:factCheck = Update; + //@description A message with a live location was viewed. When the update is received, the application is supposed to update the live location //@chat_id Identifier of the chat with the live location message //@message_id Identifier of the message with live location diff --git a/td/telegram/MessagesManager.cpp b/td/telegram/MessagesManager.cpp index 9bc7aba78..c5f725c33 100644 --- a/td/telegram/MessagesManager.cpp +++ b/td/telegram/MessagesManager.cpp @@ -28,6 +28,8 @@ #include "td/telegram/DownloadManager.h" #include "td/telegram/DraftMessage.h" #include "td/telegram/DraftMessage.hpp" +#include "td/telegram/FactCheck.h" +#include "td/telegram/FactCheck.hpp" #include "td/telegram/FileReferenceManager.h" #include "td/telegram/files/FileId.hpp" #include "td/telegram/files/FileLocation.h" @@ -4170,6 +4172,7 @@ void MessagesManager::Message::store(StorerT &storer) const { bool has_sender_boost_count = sender_boost_count != 0; bool has_via_business_bot_user_id = via_business_bot_user_id.is_valid(); bool has_effect_id = effect_id != 0; + bool has_fact_check = fact_check != nullptr; BEGIN_STORE_FLAGS(); STORE_FLAG(is_channel_post); STORE_FLAG(is_outgoing); @@ -4257,6 +4260,7 @@ void MessagesManager::Message::store(StorerT &storer) const { STORE_FLAG(has_via_business_bot_user_id); STORE_FLAG(is_from_offline); STORE_FLAG(has_effect_id); + STORE_FLAG(has_fact_check); END_STORE_FLAGS(); } @@ -4386,6 +4390,9 @@ void MessagesManager::Message::store(StorerT &storer) const { if (has_effect_id) { store(effect_id, storer); } + if (has_fact_check) { + store(fact_check, storer); + } } // do not forget to resolve message dependencies @@ -4444,6 +4451,7 @@ void MessagesManager::Message::parse(ParserT &parser) { bool has_sender_boost_count = false; bool has_via_business_bot_user_id = false; bool has_effect_id = false; + bool has_fact_check = false; BEGIN_PARSE_FLAGS(); PARSE_FLAG(is_channel_post); PARSE_FLAG(is_outgoing); @@ -4531,6 +4539,7 @@ void MessagesManager::Message::parse(ParserT &parser) { PARSE_FLAG(has_via_business_bot_user_id); PARSE_FLAG(is_from_offline); PARSE_FLAG(has_effect_id); + PARSE_FLAG(has_fact_check); END_PARSE_FLAGS(); } @@ -4724,6 +4733,9 @@ void MessagesManager::Message::parse(ParserT &parser) { if (has_effect_id) { parse(effect_id, parser); } + if (has_fact_check) { + parse(fact_check, parser); + } CHECK(content != nullptr); is_content_secret |= ttl.is_secret_message_content(content->get_type()); // repair is_content_secret for old messages @@ -6449,6 +6461,13 @@ td_api::object_ptr MessagesManager::get_message_ std::move(reactions)); } +td_api::object_ptr MessagesManager::get_message_fact_check_object(const Message *m) const { + if (m->fact_check == nullptr) { + return nullptr; + } + return m->fact_check->get_fact_check_object(); +} + vector> MessagesManager::get_unread_reactions_object( DialogId dialog_id, const Message *m) const { if (!has_unread_message_reactions(dialog_id, m)) { @@ -12324,7 +12343,7 @@ void MessagesManager::init() { is_inited_ = true; td_->notification_settings_manager_->init(); // load scope notification settings - td_->reaction_manager_->init(); // load available reactions + td_->reaction_manager_->init(); // load active reactions start_time_ = Time::now(); last_channel_pts_jump_warning_time_ = start_time_ - 3600; @@ -13124,6 +13143,7 @@ MessagesManager::MessageInfo MessagesManager::parse_telegram_api_message( message_info.forward_count = message->forwards_; message_info.reply_info = std::move(message->replies_); message_info.reactions = std::move(message->reactions_); + message_info.fact_check = std::move(message->factcheck_); message_info.edit_date = message->edit_date_; message_info.media_album_id = message->grouped_id_; message_info.ttl_period = message->ttl_period_; @@ -13229,6 +13249,7 @@ std::pair> MessagesManager::creat CHECK(message_info.content != nullptr); + auto is_bot = td->auth_manager_->is_bot(); auto dialog_type = dialog_id.get_type(); UserId sender_user_id = message_info.sender_user_id; DialogId sender_dialog_id = message_info.sender_dialog_id; @@ -13237,7 +13258,7 @@ std::pair> MessagesManager::creat LOG(ERROR) << "Receive invalid " << sender_user_id; sender_user_id = UserId(); } - if (!td->dialog_manager_->is_broadcast_channel(dialog_id) && td->auth_manager_->is_bot()) { + if (!td->dialog_manager_->is_broadcast_channel(dialog_id) && is_bot) { if (dialog_id == sender_dialog_id) { td->user_manager_->add_anonymous_bot_user(); } else { @@ -13338,7 +13359,7 @@ std::pair> MessagesManager::creat } bool hide_edit_date = message_info.hide_edit_date; - if (hide_edit_date && td->auth_manager_->is_bot()) { + if (hide_edit_date && is_bot) { hide_edit_date = false; } if (hide_edit_date && content_type == MessageContentType::LiveLocation) { @@ -13371,6 +13392,10 @@ std::pair> MessagesManager::creat LOG(ERROR) << "Receive " << message_id << " in " << dialog_id << " with " << to_string(message_info.reactions); message_info.reactions = nullptr; } + if (message_info.fact_check != nullptr) { + LOG(ERROR) << "Receive " << message_id << " in " << dialog_id << " with " << to_string(message_info.fact_check); + message_info.fact_check = nullptr; + } } int32 view_count = message_info.view_count; if (view_count < 0) { @@ -13382,7 +13407,7 @@ std::pair> MessagesManager::creat LOG(ERROR) << "Wrong forward_count = " << forward_count << " received in " << message_id << " in " << dialog_id; forward_count = 0; } - MessageReplyInfo reply_info(td, std::move(message_info.reply_info), td->auth_manager_->is_bot()); + MessageReplyInfo reply_info(td, std::move(message_info.reply_info), is_bot); if (!top_thread_message_id.is_valid() && td->messages_manager_->is_thread_message(dialog_id, message_id, reply_info, content_type)) { top_thread_message_id = message_id; @@ -13396,13 +13421,13 @@ std::pair> MessagesManager::creat // just in case is_topic_message = false; } - auto reactions = - MessageReactions::get_message_reactions(td, std::move(message_info.reactions), td->auth_manager_->is_bot()); + auto reactions = MessageReactions::get_message_reactions(td, std::move(message_info.reactions), is_bot); if (reactions != nullptr) { reactions->sort_reactions(td->messages_manager_->active_reaction_pos_); reactions->fix_chosen_reaction(); reactions->fix_my_recent_chooser_dialog_id(my_dialog_id); } + auto fact_check = FactCheck::get_fact_check(td, std::move(message_info.fact_check), is_bot); bool has_forward_info = message_info.forward_header != nullptr; bool noforwards = message_info.noforwards; @@ -13451,8 +13476,7 @@ std::pair> MessagesManager::creat message->saved_messages_topic_id = message_info.saved_messages_topic_id; message->is_outgoing = is_outgoing; message->is_channel_post = is_channel_post; - message->contains_mention = - !is_outgoing && dialog_type != DialogType::User && !is_expired && has_mention && !td->auth_manager_->is_bot(); + message->contains_mention = !is_outgoing && dialog_type != DialogType::User && !is_expired && has_mention && !is_bot; message->contains_unread_mention = !message_id.is_scheduled() && message_id.is_server() && message->contains_mention && message_info.has_unread_content && @@ -13470,11 +13494,12 @@ std::pair> MessagesManager::creat message->forward_count = forward_count; message->reply_info = std::move(reply_info); message->reactions = std::move(reactions); + message->fact_check = std::move(fact_check); message->effect_id = message_info.effect_id; message->legacy_layer = (message_info.is_legacy ? MTPROTO_LAYER : 0); message->invert_media = message_info.invert_media; message->content = std::move(message_info.content); - message->reply_markup = get_reply_markup(std::move(message_info.reply_markup), td->auth_manager_->is_bot(), false, + message->reply_markup = get_reply_markup(std::move(message_info.reply_markup), is_bot, false, message->contains_mention || dialog_type == DialogType::User); if (message->reply_markup != nullptr && is_expired) { // just in case @@ -22587,7 +22612,7 @@ td_api::object_ptr MessagesManager::get_dialog_event_log_messag nullptr, nullptr, m->is_outgoing, m->is_pinned, m->is_from_offline, false, false, false, can_be_saved, false, false, false, false, false, false, false, false, false, true, m->is_channel_post, m->is_topic_message, false, m->date, edit_date, std::move(forward_info), std::move(import_info), std::move(interaction_info), Auto(), nullptr, - 0, 0, nullptr, 0.0, 0.0, via_bot_user_id, 0, m->sender_boost_count, m->author_signature, 0, 0, + nullptr, 0, 0, nullptr, 0.0, 0.0, via_bot_user_id, 0, m->sender_boost_count, m->author_signature, 0, 0, get_restriction_reason_description(m->restriction_reasons), std::move(content), std::move(reply_markup)); } @@ -22654,7 +22679,7 @@ td_api::object_ptr MessagesManager::get_business_message_messag m->message_id.get(), std::move(sender), get_chat_id_object(dialog_id, "get_business_message_message_object"), nullptr, nullptr, m->is_outgoing, m->is_from_offline, false, false, false, false, can_be_saved, false, false, false, false, false, false, false, false, false, false, false, false, false, m->date, m->edit_date, - std::move(forward_info), std::move(import_info), nullptr, Auto(), std::move(reply_to), 0, 0, + std::move(forward_info), std::move(import_info), nullptr, Auto(), nullptr, std::move(reply_to), 0, 0, std::move(self_destruct_type), 0.0, 0.0, via_bot_user_id, via_business_bot_user_id, 0, string(), m->media_album_id, m->effect_id, get_restriction_reason_description(m->restriction_reasons), std::move(content), std::move(reply_markup)); @@ -22725,6 +22750,7 @@ td_api::object_ptr MessagesManager::get_message_object(DialogId auto import_info = m->forward_info == nullptr ? nullptr : m->forward_info->get_message_import_info_object(); auto interaction_info = is_bot ? nullptr : get_message_interaction_info_object(dialog_id, m); auto unread_reactions = get_unread_reactions_object(dialog_id, m); + auto fact_check = get_message_fact_check_object(m); auto can_be_saved = can_save_message(dialog_id, m); auto can_be_edited = can_edit_message(dialog_id, m, false, is_bot); auto can_be_forwarded = can_be_saved && can_forward_message(dialog_id, m); @@ -22770,7 +22796,8 @@ td_api::object_ptr MessagesManager::get_message_object(DialogId can_delete_for_all_users, can_get_added_reactions, can_get_statistics, can_get_message_thread, can_get_read_date, can_get_viewers, can_get_media_timestamp_links, can_report_reactions, has_timestamped_media, m->is_channel_post, m->is_topic_message, m->contains_unread_mention, date, edit_date, std::move(forward_info), std::move(import_info), - std::move(interaction_info), std::move(unread_reactions), std::move(reply_to), top_thread_message_id, + std::move(interaction_info), std::move(unread_reactions), std::move(fact_check), std::move(reply_to), + top_thread_message_id, td_->saved_messages_manager_->get_saved_messages_topic_id_object(m->saved_messages_topic_id), std::move(self_destruct_type), ttl_expires_in, auto_delete_in, via_bot_user_id, via_business_bot_user_id, m->sender_boost_count, m->author_signature, m->media_album_id, m->effect_id, @@ -23345,6 +23372,9 @@ void MessagesManager::add_message_dependencies(Dependencies &dependencies, const m->reactions->add_min_channels(td_); m->reactions->add_dependencies(dependencies); } + if (m->fact_check != nullptr) { + m->fact_check->add_dependencies(dependencies); + } add_message_content_dependencies(dependencies, m->content.get(), is_bot); add_reply_markup_dependencies(dependencies, m->reply_markup.get()); add_draft_message_dependencies(dependencies, m->thread_draft_message); @@ -28483,6 +28513,18 @@ void MessagesManager::send_update_message_unread_reactions(DialogId dialog_id, c get_unread_reactions_object(dialog_id, m), unread_reaction_count)); } +void MessagesManager::send_update_message_fact_check(DialogId dialog_id, const Message *m) const { + CHECK(m != nullptr); + if (td_->auth_manager_->is_bot() || !m->is_update_sent) { + return; + } + + send_closure( + G()->td(), &Td::send_update, + td_api::make_object(get_chat_id_object(dialog_id, "updateMessageFactCheck"), + m->message_id.get(), get_message_fact_check_object(m))); +} + void MessagesManager::send_update_message_live_location_viewed(MessageFullId message_full_id) { CHECK(get_message(message_full_id) != nullptr); send_closure(G()->td(), &Td::send_update, @@ -33870,6 +33912,17 @@ bool MessagesManager::update_message(Dialog *d, Message *old_message, unique_ptr "update_message")) { need_send_update = true; } + if (new_message->fact_check != nullptr && old_message->fact_check != nullptr) { + new_message->fact_check->update_from(*old_message->fact_check); + } + if (new_message->fact_check != old_message->fact_check) { + if ((new_message->fact_check != nullptr && !new_message->fact_check->need_check()) || + (old_message->fact_check != nullptr && !old_message->fact_check->need_check())) { + send_update_message_fact_check(dialog_id, new_message.get()); + need_send_update = true; + } + old_message->fact_check = std::move(new_message->fact_check); + } bool is_preview_changed = false; if (old_message->invert_media != new_message->invert_media) { diff --git a/td/telegram/MessagesManager.h b/td/telegram/MessagesManager.h index 93547dc76..cf6a69959 100644 --- a/td/telegram/MessagesManager.h +++ b/td/telegram/MessagesManager.h @@ -111,6 +111,7 @@ class Dependencies; class DialogActionBar; class DialogFilter; class DraftMessage; +class FactCheck; struct InputMessageContent; class MessageContent; class MessageForwardInfo; @@ -1011,6 +1012,7 @@ class MessagesManager final : public Actor { int32 forward_count = 0; tl_object_ptr reply_info; tl_object_ptr reactions; + tl_object_ptr fact_check; int32 sender_boost_count = 0; int32 edit_date = 0; vector restriction_reasons; @@ -1116,6 +1118,7 @@ class MessagesManager final : public Actor { int32 forward_count = 0; MessageReplyInfo reply_info; unique_ptr reactions; + unique_ptr fact_check; unique_ptr thread_draft_message; uint32 available_reactions_generation = 0; int32 interaction_info_update_date = 0; @@ -2033,6 +2036,8 @@ class MessagesManager final : public Actor { td_api::object_ptr get_message_interaction_info_object(DialogId dialog_id, const Message *m) const; + td_api::object_ptr get_message_fact_check_object(const Message *m) const; + vector> get_unread_reactions_object(DialogId dialog_id, const Message *m) const; @@ -2346,6 +2351,8 @@ class MessagesManager final : public Actor { void send_update_message_interaction_info(DialogId dialog_id, const Message *m) const; + void send_update_message_fact_check(DialogId dialog_id, const Message *m) const; + void send_update_message_unread_reactions(DialogId dialog_id, const Message *m, int32 unread_reaction_count) const; void send_update_message_live_location_viewed(MessageFullId message_full_id);