Handle missing updateMessageReactions in response to getMessagesReactions as a message without reactions.

This commit is contained in:
levlam 2022-01-26 20:06:27 +03:00
parent f9c6fb14f6
commit fd4b9a5a79
2 changed files with 20 additions and 2 deletions

View File

@ -22,16 +22,18 @@ namespace td {
class GetMessagesReactionsQuery final : public Td::ResultHandler { class GetMessagesReactionsQuery final : public Td::ResultHandler {
DialogId dialog_id_; DialogId dialog_id_;
vector<MessageId> message_ids_;
public: public:
void send(DialogId dialog_id, vector<MessageId> &&message_ids) { void send(DialogId dialog_id, vector<MessageId> &&message_ids) {
dialog_id_ = dialog_id; dialog_id_ = dialog_id;
message_ids_ = std::move(message_ids);
auto input_peer = td_->messages_manager_->get_input_peer(dialog_id_, AccessRights::Read); auto input_peer = td_->messages_manager_->get_input_peer(dialog_id_, AccessRights::Read);
CHECK(input_peer != nullptr); CHECK(input_peer != nullptr);
send_query(G()->net_query_creator().create(telegram_api::messages_getMessagesReactions( send_query(G()->net_query_creator().create(telegram_api::messages_getMessagesReactions(
std::move(input_peer), MessagesManager::get_server_message_ids(message_ids)))); std::move(input_peer), MessagesManager::get_server_message_ids(message_ids_))));
} }
void on_result(BufferSlice packet) final { void on_result(BufferSlice packet) final {
@ -42,6 +44,21 @@ class GetMessagesReactionsQuery final : public Td::ResultHandler {
auto ptr = result_ptr.move_as_ok(); auto ptr = result_ptr.move_as_ok();
LOG(INFO) << "Receive result for GetMessagesReactionsQuery: " << to_string(ptr); LOG(INFO) << "Receive result for GetMessagesReactionsQuery: " << to_string(ptr);
if (ptr->get_id() == telegram_api::updates::ID) {
auto &updates = static_cast<telegram_api::updates *>(ptr.get())->updates_;
std::unordered_set<MessageId, MessageIdHash> skipped_message_ids(message_ids_.begin(), message_ids_.end());
for (const auto &update : updates) {
if (update->get_id() == telegram_api::updateMessageReactions::ID) {
auto update_message_reactions = static_cast<const telegram_api::updateMessageReactions *>(update.get());
if (DialogId(update_message_reactions->peer_) == dialog_id_) {
skipped_message_ids.erase(MessageId(ServerMessageId(update_message_reactions->msg_id_)));
}
}
}
for (auto message_id : skipped_message_ids) {
td_->messages_manager_->on_update_message_reactions({dialog_id_, message_id}, nullptr);
}
}
td_->updates_manager_->on_get_updates(std::move(ptr), Promise<Unit>()); td_->updates_manager_->on_get_updates(std::move(ptr), Promise<Unit>());
} }
@ -376,7 +393,7 @@ bool MessageReactions::need_update_message_reactions(const MessageReactions *old
} }
void reload_message_reactions(Td *td, DialogId dialog_id, vector<MessageId> &&message_ids) { void reload_message_reactions(Td *td, DialogId dialog_id, vector<MessageId> &&message_ids) {
if (!td->messages_manager_->have_input_peer(dialog_id, AccessRights::Read)) { if (!td->messages_manager_->have_input_peer(dialog_id, AccessRights::Read) || message_ids.empty()) {
return; return;
} }

View File

@ -9,6 +9,7 @@
#include "td/telegram/ChannelId.h" #include "td/telegram/ChannelId.h"
#include "td/telegram/DialogId.h" #include "td/telegram/DialogId.h"
#include "td/telegram/FullMessageId.h" #include "td/telegram/FullMessageId.h"
#include "td/telegram/MessageId.h"
#include "td/telegram/MinChannel.h" #include "td/telegram/MinChannel.h"
#include "td/telegram/td_api.h" #include "td/telegram/td_api.h"
#include "td/telegram/telegram_api.h" #include "td/telegram/telegram_api.h"