Add MessageReactions::add_my_paid_reaction.

This commit is contained in:
levlam 2024-08-01 23:31:50 +03:00
parent 049692dcb8
commit 9913849249
3 changed files with 22 additions and 2 deletions

View File

@ -31,6 +31,7 @@
#include "td/utils/Status.h" #include "td/utils/Status.h"
#include <algorithm> #include <algorithm>
#include <limits>
#include <utility> #include <utility>
namespace td { namespace td {
@ -408,6 +409,12 @@ void MessageReaction::unset_as_chosen() {
fix_choose_count(); fix_choose_count();
} }
void MessageReaction::add_paid_reaction(int32 star_count) {
is_chosen_ = true;
CHECK(star_count <= std::numeric_limits<int32>::max() - choose_count_);
choose_count_ += star_count;
}
void MessageReaction::fix_choose_count() { void MessageReaction::fix_choose_count() {
choose_count_ = max(choose_count_, narrow_cast<int32>(recent_chooser_dialog_ids_.size())); choose_count_ = max(choose_count_, narrow_cast<int32>(recent_chooser_dialog_ids_.size()));
} }
@ -778,6 +785,15 @@ bool MessageReactions::do_remove_my_reaction(const ReactionType &reaction_type)
return false; return false;
} }
void MessageReactions::add_my_paid_reaction(int32 star_count) {
auto added_reaction = get_reaction(ReactionType::paid());
if (added_reaction == nullptr) {
reactions_.push_back({ReactionType::paid(), star_count, true, DialogId(), Auto(), Auto()});
} else {
added_reaction->add_paid_reaction(star_count);
}
}
void MessageReactions::sort_reactions(const FlatHashMap<ReactionType, size_t, ReactionTypeHash> &active_reaction_pos) { void MessageReactions::sort_reactions(const FlatHashMap<ReactionType, size_t, ReactionTypeHash> &active_reaction_pos) {
std::sort(reactions_.begin(), reactions_.end(), std::sort(reactions_.begin(), reactions_.end(),
[&active_reaction_pos](const MessageReaction &lhs, const MessageReaction &rhs) { [&active_reaction_pos](const MessageReaction &lhs, const MessageReaction &rhs) {

View File

@ -64,6 +64,8 @@ class MessageReaction {
void unset_as_chosen(); void unset_as_chosen();
void add_paid_reaction(int32 star_count);
void add_my_recent_chooser_dialog_id(DialogId dialog_id); void add_my_recent_chooser_dialog_id(DialogId dialog_id);
bool remove_my_recent_chooser_dialog_id(); bool remove_my_recent_chooser_dialog_id();
@ -176,6 +178,8 @@ struct MessageReactions {
bool remove_my_reaction(const ReactionType &reaction_type, DialogId my_dialog_id); bool remove_my_reaction(const ReactionType &reaction_type, DialogId my_dialog_id);
void add_my_paid_reaction(int32 star_count);
void sort_reactions(const FlatHashMap<ReactionType, size_t, ReactionTypeHash> &active_reaction_pos); void sort_reactions(const FlatHashMap<ReactionType, size_t, ReactionTypeHash> &active_reaction_pos);
void fix_chosen_reaction(); void fix_chosen_reaction();

View File

@ -22682,8 +22682,8 @@ void MessagesManager::add_paid_message_reaction(MessageFullId message_full_id, i
} }
LOG(INFO) << "Have message with " << *m->reactions; LOG(INFO) << "Have message with " << *m->reactions;
// m->reactions->add_my_paid_reaction(star_count); m->reactions->add_my_paid_reaction(narrow_cast<int32>(star_count));
// m->reactions->sort_reactions(active_reaction_pos_); m->reactions->sort_reactions(active_reaction_pos_);
LOG(INFO) << "Update message reactions to " << *m->reactions; LOG(INFO) << "Update message reactions to " << *m->reactions;
pending_reactions_[message_full_id].query_count++; pending_reactions_[message_full_id].query_count++;