From 00aff8f557c5396e0c85e45a112f144b4f09a28a Mon Sep 17 00:00:00 2001 From: levlam Date: Thu, 14 Dec 2023 19:55:53 +0300 Subject: [PATCH] Add td_api::updateMessageReaction for bots. --- td/generate/scheme/td_api.tl | 9 ++++++++ td/telegram/UpdatesManager.cpp | 38 ++++++++++++++++++++++++++++++---- td/telegram/UpdatesManager.h | 3 +-- 3 files changed, 44 insertions(+), 6 deletions(-) diff --git a/td/generate/scheme/td_api.tl b/td/generate/scheme/td_api.tl index d1c70c8c5..fe195f4ab 100644 --- a/td/generate/scheme/td_api.tl +++ b/td/generate/scheme/td_api.tl @@ -6604,6 +6604,15 @@ updateNewChatJoinRequest chat_id:int53 request:chatJoinRequest user_chat_id:int5 //@boost New information about the boost updateChatBoost chat_id:int53 boost:chatBoost = Update; +//@description User changed its reactions on a message; for bots only +//@chat_id Chat identifier +//@message_id Message identifier +//@actor_id Identifier of the user or chat that changed reactions +//@date Point in time (Unix timestamp) when the reactions were changed +//@old_reaction_types Old list of chosen reactions +//@new_reaction_types New list of chosen reactions +updateMessageReaction chat_id:int53 message_id:int53 actor_id:MessageSender date:int32 old_reaction_types:vector new_reaction_types:vector = Update; + //@description Contains a list of updates @updates List of updates updates updates:vector = Updates; diff --git a/td/telegram/UpdatesManager.cpp b/td/telegram/UpdatesManager.cpp index 4dd504170..8e3563000 100644 --- a/td/telegram/UpdatesManager.cpp +++ b/td/telegram/UpdatesManager.cpp @@ -34,6 +34,7 @@ #include "td/telegram/LanguagePackManager.h" #include "td/telegram/Location.h" #include "td/telegram/MessageId.h" +#include "td/telegram/MessageSender.h" #include "td/telegram/MessagesManager.h" #include "td/telegram/MessageTtl.h" #include "td/telegram/misc.h" @@ -3007,6 +3008,31 @@ void UpdatesManager::process_qts_update(tl_object_ptr &&up td_->boost_manager_->on_update_dialog_boost(DialogId(update->peer_), std::move(update->boost_)); break; } + case telegram_api::updateBotMessageReaction::ID: { + auto update = move_tl_object_as(update_ptr); + auto dialog_id = DialogId(update->peer_); + auto message_id = MessageId(ServerMessageId(update->msg_id_)); + auto date = update->date_; + auto actor_dialog_id = DialogId(update->actor_); + auto old_reaction_types = ReactionType::get_reaction_types(update->old_reactions_); + auto new_reaction_types = ReactionType::get_reaction_types(update->new_reactions_); + if (!dialog_id.is_valid() || !message_id.is_valid() || !actor_dialog_id.is_valid() || date <= 0 || + old_reaction_types == new_reaction_types) { + LOG(ERROR) << "Receive invalid updateBotMessageReaction for " << MessageFullId{dialog_id, message_id} + << " by " << actor_dialog_id << " at " << date << ": " << old_reaction_types << " -> " + << new_reaction_types; + break; + } + + td_->messages_manager_->force_create_dialog(dialog_id, "on_update_bot_message_reaction", true); + send_closure(G()->td(), &Td::send_update, + td_api::make_object( + td_->messages_manager_->get_chat_id_object(dialog_id, "updateMessageReaction"), + message_id.get(), get_message_sender_object(td_, actor_dialog_id, "updateMessageReaction"), + date, ReactionType::get_reaction_types_object(old_reaction_types), + ReactionType::get_reaction_types_object(new_reaction_types))); + break; + } default: UNREACHABLE(); break; @@ -3783,6 +3809,7 @@ bool UpdatesManager::is_qts_update(const telegram_api::Update *update) { case telegram_api::updateChannelParticipant::ID: case telegram_api::updateBotChatInviteRequester::ID: case telegram_api::updateBotChatBoost::ID: + case telegram_api::updateBotMessageReaction::ID: return true; default: return false; @@ -3805,6 +3832,8 @@ int32 UpdatesManager::get_update_qts(const telegram_api::Update *update) { return static_cast(update)->qts_; case telegram_api::updateBotChatBoost::ID: return static_cast(update)->qts_; + case telegram_api::updateBotMessageReaction::ID: + return static_cast(update)->qts_; default: return 0; } @@ -4283,6 +4312,11 @@ void UpdatesManager::on_update(tl_object_ptr u add_pending_qts_update(std::move(update), qts, std::move(promise)); } +void UpdatesManager::on_update(tl_object_ptr update, Promise &&promise) { + auto qts = update->qts_; + add_pending_qts_update(std::move(update), qts, std::move(promise)); +} + void UpdatesManager::on_update(tl_object_ptr update, Promise &&promise) { td_->theme_manager_->on_update_theme(std::move(update->theme_), std::move(promise)); } @@ -4360,10 +4394,6 @@ void UpdatesManager::on_update(tl_object_ptr update, Promise &&promise) { - promise.set_value(Unit()); -} - void UpdatesManager::on_update(tl_object_ptr update, Promise &&promise) { promise.set_value(Unit()); } diff --git a/td/telegram/UpdatesManager.h b/td/telegram/UpdatesManager.h index eadcadf44..06d922863 100644 --- a/td/telegram/UpdatesManager.h +++ b/td/telegram/UpdatesManager.h @@ -603,6 +603,7 @@ class UpdatesManager final : public Actor { void on_update(tl_object_ptr update, Promise &&promise); void on_update(tl_object_ptr update, Promise &&promise); void on_update(tl_object_ptr update, Promise &&promise); + void on_update(tl_object_ptr update, Promise &&promise); void on_update(tl_object_ptr update, Promise &&promise); @@ -632,8 +633,6 @@ class UpdatesManager final : public Actor { // unsupported updates - void on_update(tl_object_ptr update, Promise &&promise); - void on_update(tl_object_ptr update, Promise &&promise); };