Add reactions on behalf of channels.

This commit is contained in:
levlam 2023-04-27 19:31:31 +03:00
parent 036a7cd539
commit 601a216078
3 changed files with 29 additions and 9 deletions

View File

@ -449,14 +449,14 @@ void MessageReaction::update_recent_chooser_dialog_ids(const MessageReaction &ol
recent_chooser_min_channels_ = old_reaction.recent_chooser_min_channels_; recent_chooser_min_channels_ = old_reaction.recent_chooser_min_channels_;
} }
void MessageReaction::set_as_chosen(DialogId chooser_dialog_id, bool have_recent_choosers) { void MessageReaction::set_as_chosen(DialogId my_dialog_id, bool have_recent_choosers) {
CHECK(!is_chosen_); CHECK(!is_chosen_);
is_chosen_ = true; is_chosen_ = true;
choose_count_++; choose_count_++;
if (have_recent_choosers) { if (have_recent_choosers) {
remove_recent_chooser_dialog_id(); remove_recent_chooser_dialog_id();
add_recent_chooser_dialog_id(chooser_dialog_id); add_recent_chooser_dialog_id(my_dialog_id);
} }
} }
@ -468,6 +468,17 @@ void MessageReaction::unset_as_chosen() {
remove_recent_chooser_dialog_id(); remove_recent_chooser_dialog_id();
} }
void MessageReaction::set_my_recent_chooser_dialog_id(DialogId my_dialog_id) {
if (!my_recent_chooser_dialog_id_.is_valid() || my_recent_chooser_dialog_id_ == my_dialog_id) {
return;
}
if (td::contains(recent_chooser_dialog_ids_, my_dialog_id)) {
my_recent_chooser_dialog_id_ = my_dialog_id;
} else {
my_recent_chooser_dialog_id_ = DialogId();
}
}
td_api::object_ptr<td_api::messageReaction> MessageReaction::get_message_reaction_object(Td *td, UserId my_user_id, td_api::object_ptr<td_api::messageReaction> MessageReaction::get_message_reaction_object(Td *td, UserId my_user_id,
UserId peer_user_id) const { UserId peer_user_id) const {
CHECK(!is_empty()); CHECK(!is_empty());
@ -684,7 +695,7 @@ void MessageReactions::update_from(const MessageReactions &old_reactions) {
} }
} }
bool MessageReactions::add_reaction(const string &reaction, bool is_big, DialogId chooser_dialog_id, bool MessageReactions::add_reaction(const string &reaction, bool is_big, DialogId my_dialog_id,
bool have_recent_choosers) { bool have_recent_choosers) {
vector<string> new_chosen_reaction_order = get_chosen_reactions(); vector<string> new_chosen_reaction_order = get_chosen_reactions();
@ -692,12 +703,12 @@ bool MessageReactions::add_reaction(const string &reaction, bool is_big, DialogI
if (added_reaction == nullptr) { if (added_reaction == nullptr) {
vector<DialogId> recent_chooser_dialog_ids; vector<DialogId> recent_chooser_dialog_ids;
if (have_recent_choosers) { if (have_recent_choosers) {
recent_chooser_dialog_ids.push_back(chooser_dialog_id); recent_chooser_dialog_ids.push_back(my_dialog_id);
} }
reactions_.push_back({reaction, 1, true, chooser_dialog_id, std::move(recent_chooser_dialog_ids), Auto()}); reactions_.push_back({reaction, 1, true, my_dialog_id, std::move(recent_chooser_dialog_ids), Auto()});
new_chosen_reaction_order.emplace_back(reaction); new_chosen_reaction_order.emplace_back(reaction);
} else if (!added_reaction->is_chosen()) { } else if (!added_reaction->is_chosen()) {
added_reaction->set_as_chosen(chooser_dialog_id, have_recent_choosers); added_reaction->set_as_chosen(my_dialog_id, have_recent_choosers);
new_chosen_reaction_order.emplace_back(reaction); new_chosen_reaction_order.emplace_back(reaction);
} else if (!is_big) { } else if (!is_big) {
return false; return false;
@ -716,6 +727,11 @@ bool MessageReactions::add_reaction(const string &reaction, bool is_big, DialogI
new_chosen_reaction_order.clear(); new_chosen_reaction_order.clear();
} }
chosen_reaction_order_ = std::move(new_chosen_reaction_order); chosen_reaction_order_ = std::move(new_chosen_reaction_order);
for (auto &message_reaction : reactions_) {
message_reaction.set_my_recent_chooser_dialog_id(my_dialog_id);
}
return true; return true;
} }

View File

@ -65,7 +65,7 @@ class MessageReaction {
return is_chosen_; return is_chosen_;
} }
void set_as_chosen(DialogId chooser_dialog_id, bool have_recent_choosers); void set_as_chosen(DialogId my_dialog_id, bool have_recent_choosers);
void unset_as_chosen(); void unset_as_chosen();
@ -81,6 +81,8 @@ class MessageReaction {
return choose_count_; return choose_count_;
} }
void set_my_recent_chooser_dialog_id(DialogId my_dialog_id);
DialogId get_my_recent_chooser_dialog_id() const { DialogId get_my_recent_chooser_dialog_id() const {
return my_recent_chooser_dialog_id_; return my_recent_chooser_dialog_id_;
} }
@ -171,7 +173,7 @@ struct MessageReactions {
void update_from(const MessageReactions &old_reactions); void update_from(const MessageReactions &old_reactions);
bool add_reaction(const string &reaction, bool is_big, DialogId chooser_dialog_id, bool have_recent_choosers); bool add_reaction(const string &reaction, bool is_big, DialogId my_dialog_id, bool have_recent_choosers);
bool remove_reaction(const string &reaction); bool remove_reaction(const string &reaction);

View File

@ -23756,7 +23756,9 @@ void MessagesManager::add_message_reaction(FullMessageId full_message_id, string
m->available_reactions_generation = d->available_reactions_generation; m->available_reactions_generation = d->available_reactions_generation;
} }
if (!m->reactions->add_reaction(reaction, is_big, get_my_dialog_id(), have_recent_choosers)) { auto my_dialog_id =
d->default_send_message_as_dialog_id.is_valid() ? d->default_send_message_as_dialog_id : get_my_dialog_id();
if (!m->reactions->add_reaction(reaction, is_big, my_dialog_id, have_recent_choosers)) {
return promise.set_value(Unit()); return promise.set_value(Unit());
} }