Relaod message reactions if failed to set reaction.
This commit is contained in:
parent
79f1890613
commit
f9c6fb14f6
@ -20,6 +20,36 @@
|
||||
|
||||
namespace td {
|
||||
|
||||
class GetMessagesReactionsQuery final : public Td::ResultHandler {
|
||||
DialogId dialog_id_;
|
||||
|
||||
public:
|
||||
void send(DialogId dialog_id, vector<MessageId> &&message_ids) {
|
||||
dialog_id_ = dialog_id;
|
||||
|
||||
auto input_peer = td_->messages_manager_->get_input_peer(dialog_id_, AccessRights::Read);
|
||||
CHECK(input_peer != nullptr);
|
||||
|
||||
send_query(G()->net_query_creator().create(telegram_api::messages_getMessagesReactions(
|
||||
std::move(input_peer), MessagesManager::get_server_message_ids(message_ids))));
|
||||
}
|
||||
|
||||
void on_result(BufferSlice packet) final {
|
||||
auto result_ptr = fetch_result<telegram_api::messages_getMessagesReactions>(packet);
|
||||
if (result_ptr.is_error()) {
|
||||
return on_error(result_ptr.move_as_error());
|
||||
}
|
||||
|
||||
auto ptr = result_ptr.move_as_ok();
|
||||
LOG(INFO) << "Receive result for GetMessagesReactionsQuery: " << to_string(ptr);
|
||||
td_->updates_manager_->on_get_updates(std::move(ptr), Promise<Unit>());
|
||||
}
|
||||
|
||||
void on_error(Status status) final {
|
||||
td_->messages_manager_->on_get_dialog_error(dialog_id_, status, "GetMessagesReactionsQuery");
|
||||
}
|
||||
};
|
||||
|
||||
class SendReactionQuery final : public Td::ResultHandler {
|
||||
Promise<Unit> promise_;
|
||||
DialogId dialog_id_;
|
||||
@ -345,6 +375,19 @@ bool MessageReactions::need_update_message_reactions(const MessageReactions *old
|
||||
old_reactions->need_polling_ != new_reactions->need_polling_;
|
||||
}
|
||||
|
||||
void reload_message_reactions(Td *td, DialogId dialog_id, vector<MessageId> &&message_ids) {
|
||||
if (!td->messages_manager_->have_input_peer(dialog_id, AccessRights::Read)) {
|
||||
return;
|
||||
}
|
||||
|
||||
for (const auto &message_id : message_ids) {
|
||||
CHECK(message_id.is_valid());
|
||||
CHECK(message_id.is_server());
|
||||
}
|
||||
|
||||
td->create_handler<GetMessagesReactionsQuery>()->send(dialog_id, std::move(message_ids));
|
||||
}
|
||||
|
||||
void set_message_reaction(Td *td, FullMessageId full_message_id, string reaction, bool is_big,
|
||||
Promise<Unit> &&promise) {
|
||||
td->create_handler<SendReactionQuery>(std::move(promise))->send(full_message_id, std::move(reaction), is_big);
|
||||
|
@ -125,6 +125,8 @@ struct MessageReactions {
|
||||
void parse(ParserT &parser);
|
||||
};
|
||||
|
||||
void reload_message_reactions(Td *td, DialogId dialog_id, vector<MessageId> &&message_ids);
|
||||
|
||||
void set_message_reaction(Td *td, FullMessageId full_message_id, string reaction, bool is_big, Promise<Unit> &&promise);
|
||||
|
||||
void get_message_chosen_reactions(Td *td, FullMessageId full_message_id, string reaction, string offset, int32 limit,
|
||||
|
@ -23865,7 +23865,24 @@ void MessagesManager::set_message_reaction(FullMessageId full_message_id, string
|
||||
on_message_changed(d, m, true, "set_message_reaction");
|
||||
|
||||
// TODO invoke_after, cancel previous queries, log event
|
||||
::td::set_message_reaction(td_, full_message_id, std::move(reaction), is_big, std::move(promise));
|
||||
auto query_promise = PromiseCreator::lambda(
|
||||
[actor_id = actor_id(this), full_message_id, promise = std::move(promise)](Result<Unit> &&result) mutable {
|
||||
send_closure(actor_id, &MessagesManager::on_set_message_reaction, full_message_id, std::move(result),
|
||||
std::move(promise));
|
||||
});
|
||||
::td::set_message_reaction(td_, full_message_id, std::move(reaction), is_big, std::move(query_promise));
|
||||
}
|
||||
|
||||
void MessagesManager::on_set_message_reaction(FullMessageId full_message_id, Result<Unit> result,
|
||||
Promise<Unit> promise) {
|
||||
TRY_STATUS_PROMISE(promise, G()->close_status());
|
||||
|
||||
if (result.is_error() && have_message_force(full_message_id, "on_set_message_reaction")) {
|
||||
reload_message_reactions(td_, full_message_id.get_dialog_id(), {full_message_id.get_message_id()});
|
||||
promise.set_error(result.move_as_error());
|
||||
} else {
|
||||
promise.set_value(Unit());
|
||||
}
|
||||
}
|
||||
|
||||
void MessagesManager::get_message_public_forwards(FullMessageId full_message_id, string offset, int32 limit,
|
||||
|
@ -2598,6 +2598,8 @@ class MessagesManager final : public Actor {
|
||||
|
||||
vector<string> get_message_available_reactions(const Dialog *d, const Message *m);
|
||||
|
||||
void on_set_message_reaction(FullMessageId full_message_id, Result<Unit> result, Promise<Unit> promise);
|
||||
|
||||
void set_dialog_available_reactions(Dialog *d, vector<string> &&available_reactions);
|
||||
|
||||
void update_dialog_message_reactions_visibility(const Dialog *d);
|
||||
|
Loading…
Reference in New Issue
Block a user