Update top reactors in MessageReactions::update_from.

This commit is contained in:
levlam 2024-08-03 11:46:22 +03:00
parent 8cd69d759d
commit 7d93a305ad
5 changed files with 27 additions and 8 deletions

View File

@ -655,7 +655,7 @@ const MessageReaction *MessageReactions::get_reaction(const ReactionType &reacti
return nullptr;
}
void MessageReactions::update_from(const MessageReactions &old_reactions) {
void MessageReactions::update_from(const MessageReactions &old_reactions, DialogId my_dialog_id) {
if (is_min_ && !old_reactions.is_min_) {
// chosen reactions were known, keep them
is_min_ = false;
@ -675,13 +675,22 @@ void MessageReactions::update_from(const MessageReactions &old_reactions) {
reset_to_empty(chosen_reaction_order_);
}
// self paid reaction was known, keep it
for (auto &reactor : old_reactions.top_reactors_) {
if (reactor.is_me()) {
// top_reactors_.push_back(reactor);
bool was_me = false;
for (auto &reactor : top_reactors_) {
if (reactor.fix_is_me(my_dialog_id)) {
was_me = true;
break;
}
}
if (!was_me) {
for (auto &reactor : old_reactions.top_reactors_) {
if (reactor.is_me()) {
// self paid reaction was known, keep it
top_reactors_.push_back(reactor);
MessageReactor::fix_message_reactors(top_reactors_, false);
}
}
}
MessageReactor::fix_message_reactors(top_reactors_, false);
}
for (const auto &old_reaction : old_reactions.reactions_) {
if (old_reaction.is_chosen() &&

View File

@ -171,7 +171,7 @@ struct MessageReactions {
const MessageReaction *get_reaction(const ReactionType &reaction_type) const;
void update_from(const MessageReactions &old_reactions);
void update_from(const MessageReactions &old_reactions, DialogId my_dialog_id);
bool add_my_reaction(const ReactionType &reaction_type, bool is_big, DialogId my_dialog_id, bool have_recent_choosers,
bool is_tag);

View File

@ -31,6 +31,14 @@ void MessageReactor::add_dependencies(Dependencies &dependencies) const {
dependencies.add_message_sender_dependencies(dialog_id_);
}
bool MessageReactor::fix_is_me(DialogId my_dialog_id) {
if (dialog_id_ == my_dialog_id) {
is_me_ = true;
return true;
}
return false;
}
void MessageReactor::fix_message_reactors(vector<MessageReactor> &reactors, bool need_warning) {
size_t TOP_REACTOR_COUNT = 3u;
if (reactors.size() > TOP_REACTOR_COUNT + 1) {

View File

@ -48,6 +48,8 @@ class MessageReactor {
return is_me_;
}
bool fix_is_me(DialogId my_dialog_id);
td_api::object_ptr<td_api::paidReactor> get_paid_reactor_object(Td *td) const;
void add_dependencies(Dependencies &dependencies) const;

View File

@ -6647,7 +6647,7 @@ bool MessagesManager::update_message_interaction_info(Dialog *d, Message *m, int
}
if (has_reactions && reactions != nullptr) {
if (m->reactions != nullptr) {
reactions->update_from(*m->reactions);
reactions->update_from(*m->reactions, td_->dialog_manager_->get_my_dialog_id());
}
reactions->sort_reactions(active_reaction_pos_);
reactions->fix_chosen_reaction();