Update owned star count when adding paid reactions.
This commit is contained in:
parent
43b2ffe27f
commit
1a8999c590
@ -14,6 +14,7 @@
|
|||||||
#include "td/telegram/MessageSender.h"
|
#include "td/telegram/MessageSender.h"
|
||||||
#include "td/telegram/MessagesManager.h"
|
#include "td/telegram/MessagesManager.h"
|
||||||
#include "td/telegram/ServerMessageId.h"
|
#include "td/telegram/ServerMessageId.h"
|
||||||
|
#include "td/telegram/StarManager.h"
|
||||||
#include "td/telegram/Td.h"
|
#include "td/telegram/Td.h"
|
||||||
#include "td/telegram/telegram_api.h"
|
#include "td/telegram/telegram_api.h"
|
||||||
#include "td/telegram/UpdatesManager.h"
|
#include "td/telegram/UpdatesManager.h"
|
||||||
@ -797,18 +798,20 @@ bool MessageReactions::do_remove_my_reaction(const ReactionType &reaction_type)
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
void MessageReactions::add_my_paid_reaction(int32 star_count) {
|
void MessageReactions::add_my_paid_reaction(Td *td, int32 star_count) {
|
||||||
if (pending_paid_reactions_ > 1000000000 || star_count > 1000000000) {
|
if (pending_paid_reactions_ > 1000000000 || star_count > 1000000000) {
|
||||||
LOG(ERROR) << "Pending paid reactions overflown";
|
LOG(ERROR) << "Pending paid reactions overflown";
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
td->star_manager_->add_owned_star_count(-star_count);
|
||||||
pending_paid_reactions_ += star_count;
|
pending_paid_reactions_ += star_count;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool MessageReactions::drop_pending_paid_reactions() {
|
bool MessageReactions::drop_pending_paid_reactions(Td *td) {
|
||||||
if (pending_paid_reactions_ == 0) {
|
if (pending_paid_reactions_ == 0) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
td->star_manager_->add_owned_star_count(pending_paid_reactions_);
|
||||||
pending_paid_reactions_ = 0;
|
pending_paid_reactions_ = 0;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -179,9 +179,9 @@ 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 add_my_paid_reaction(Td *td, int32 star_count);
|
||||||
|
|
||||||
bool drop_pending_paid_reactions();
|
bool drop_pending_paid_reactions(Td *td);
|
||||||
|
|
||||||
void sort_reactions(const FlatHashMap<ReactionType, size_t, ReactionTypeHash> &active_reaction_pos);
|
void sort_reactions(const FlatHashMap<ReactionType, size_t, ReactionTypeHash> &active_reaction_pos);
|
||||||
|
|
||||||
|
@ -12143,7 +12143,7 @@ void MessagesManager::on_send_paid_reactions_timeout(int64 task_id) {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (!get_message_available_reactions(d, m, true, nullptr).is_allowed_reaction_type(ReactionType::paid())) {
|
if (!get_message_available_reactions(d, m, true, nullptr).is_allowed_reaction_type(ReactionType::paid())) {
|
||||||
if (m->reactions->drop_pending_paid_reactions()) {
|
if (m->reactions->drop_pending_paid_reactions(td_)) {
|
||||||
send_update_message_interaction_info(d->dialog_id, m);
|
send_update_message_interaction_info(d->dialog_id, m);
|
||||||
on_message_changed(d, m, true, "on_send_paid_reactions_timeout");
|
on_message_changed(d, m, true, "on_send_paid_reactions_timeout");
|
||||||
}
|
}
|
||||||
@ -22806,7 +22806,7 @@ 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(narrow_cast<int32>(star_count));
|
m->reactions->add_my_paid_reaction(td_, 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;
|
||||||
|
|
||||||
@ -22837,7 +22837,7 @@ void MessagesManager::remove_paid_message_reactions(MessageFullId message_full_i
|
|||||||
Dialog *d = get_dialog_force(message_full_id.get_dialog_id(), "remove_paid_message_reaction");
|
Dialog *d = get_dialog_force(message_full_id.get_dialog_id(), "remove_paid_message_reaction");
|
||||||
CHECK(d != nullptr);
|
CHECK(d != nullptr);
|
||||||
auto *m = get_message_force(d, message_full_id.get_message_id(), "on_send_paid_reactions_timeout");
|
auto *m = get_message_force(d, message_full_id.get_message_id(), "on_send_paid_reactions_timeout");
|
||||||
if (m != nullptr && m->reactions != nullptr && m->reactions->drop_pending_paid_reactions()) {
|
if (m != nullptr && m->reactions != nullptr && m->reactions->drop_pending_paid_reactions(td_)) {
|
||||||
send_update_message_interaction_info(d->dialog_id, m);
|
send_update_message_interaction_info(d->dialog_id, m);
|
||||||
on_message_changed(d, m, true, "on_send_paid_reactions_timeout");
|
on_message_changed(d, m, true, "on_send_paid_reactions_timeout");
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user