Support sending anonymous paid reactions.
This commit is contained in:
parent
6b16461547
commit
8347f4e5b2
@ -9077,7 +9077,8 @@ removeMessageReaction chat_id:int53 message_id:int53 reaction_type:ReactionType
|
||||
//@chat_id Identifier of the chat to which the message belongs
|
||||
//@message_id Identifier of the message
|
||||
//@star_count Number of Telegram Stars to be used for the reaction; 1-getOption("paid_reaction_star_count_max")
|
||||
addPaidMessageReaction chat_id:int53 message_id:int53 star_count:int53 = Ok;
|
||||
//@is_anonymous Pass true to make all paid reactions of the user anonymous; pass false to make the user's profile visible among top reactors
|
||||
addPaidMessageReaction chat_id:int53 message_id:int53 star_count:int53 is_anonymous:Bool = Ok;
|
||||
|
||||
//@description Removes all pending paid reactions on a message. Can be called within 5 seconds after the last addPaidMessageReaction call
|
||||
//@chat_id Identifier of the chat to which the message belongs
|
||||
|
@ -162,7 +162,7 @@ class SendPaidReactionQuery final : public Td::ResultHandler {
|
||||
explicit SendPaidReactionQuery(Promise<Unit> &&promise) : promise_(std::move(promise)) {
|
||||
}
|
||||
|
||||
void send(MessageFullId message_full_id, int32 star_count, int64 random_id) {
|
||||
void send(MessageFullId message_full_id, int32 star_count, bool is_anonymous, int64 random_id) {
|
||||
dialog_id_ = message_full_id.get_dialog_id();
|
||||
|
||||
auto input_peer = td_->dialog_manager_->get_input_peer(dialog_id_, AccessRights::Read);
|
||||
@ -171,6 +171,9 @@ class SendPaidReactionQuery final : public Td::ResultHandler {
|
||||
}
|
||||
|
||||
int32 flags = 0;
|
||||
if (is_anonymous) {
|
||||
flags |= telegram_api::messages_sendPaidReaction::PRIVATE_MASK;
|
||||
}
|
||||
send_query(G()->net_query_creator().create(
|
||||
telegram_api::messages_sendPaidReaction(flags, false /*ignored*/, std::move(input_peer),
|
||||
message_full_id.get_message_id().get_server_message_id().get(),
|
||||
@ -707,6 +710,7 @@ void MessageReactions::update_from(const MessageReactions &old_reactions, Dialog
|
||||
}
|
||||
}
|
||||
pending_paid_reactions_ = old_reactions.pending_paid_reactions_;
|
||||
pending_is_anonymous_ = old_reactions.pending_is_anonymous_;
|
||||
}
|
||||
|
||||
bool MessageReactions::add_my_reaction(const ReactionType &reaction_type, bool is_big, DialogId my_dialog_id,
|
||||
@ -802,13 +806,14 @@ bool MessageReactions::do_remove_my_reaction(const ReactionType &reaction_type)
|
||||
return false;
|
||||
}
|
||||
|
||||
void MessageReactions::add_my_paid_reaction(Td *td, int32 star_count) {
|
||||
void MessageReactions::add_my_paid_reaction(Td *td, int32 star_count, bool is_anonymous) {
|
||||
if (pending_paid_reactions_ > 1000000000 || star_count > 1000000000) {
|
||||
LOG(ERROR) << "Pending paid reactions overflown";
|
||||
return;
|
||||
}
|
||||
td->star_manager_->add_owned_star_count(-star_count);
|
||||
pending_paid_reactions_ += star_count;
|
||||
pending_is_anonymous_ = is_anonymous;
|
||||
}
|
||||
|
||||
bool MessageReactions::drop_pending_paid_reactions(Td *td) {
|
||||
@ -817,6 +822,7 @@ bool MessageReactions::drop_pending_paid_reactions(Td *td) {
|
||||
}
|
||||
td->star_manager_->add_owned_star_count(pending_paid_reactions_);
|
||||
pending_paid_reactions_ = 0;
|
||||
pending_is_anonymous_ = false;
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -929,11 +935,11 @@ vector<MessageReactor> MessageReactions::apply_reactor_pending_paid_reactions(Di
|
||||
top_reactors.push_back(reactor);
|
||||
if (reactor.is_me()) {
|
||||
was_me = true;
|
||||
top_reactors.back().add_count(pending_paid_reactions_);
|
||||
top_reactors.back().add_count(pending_paid_reactions_, pending_is_anonymous_);
|
||||
}
|
||||
}
|
||||
if (!was_me) {
|
||||
top_reactors.emplace_back(my_dialog_id, pending_paid_reactions_);
|
||||
top_reactors.emplace_back(my_dialog_id, pending_paid_reactions_, pending_is_anonymous_);
|
||||
}
|
||||
MessageReactor::fix_message_reactors(top_reactors, false);
|
||||
return top_reactors;
|
||||
@ -1029,6 +1035,7 @@ void MessageReactions::send_paid_message_reaction(Td *td, MessageFullId message_
|
||||
return promise.set_value(Unit());
|
||||
}
|
||||
auto star_count = pending_paid_reactions_;
|
||||
auto is_anonymous = pending_is_anonymous_;
|
||||
top_reactors_ = apply_reactor_pending_paid_reactions(td->dialog_manager_->get_my_dialog_id());
|
||||
if (reactions_.empty() || !reactions_[0].reaction_type_.is_paid_reaction()) {
|
||||
reactions_.insert(reactions_.begin(),
|
||||
@ -1037,8 +1044,10 @@ void MessageReactions::send_paid_message_reaction(Td *td, MessageFullId message_
|
||||
reactions_[0].add_paid_reaction(star_count);
|
||||
}
|
||||
pending_paid_reactions_ = 0;
|
||||
pending_is_anonymous_ = false;
|
||||
|
||||
td->create_handler<SendPaidReactionQuery>(std::move(promise))->send(message_full_id, star_count, random_id);
|
||||
td->create_handler<SendPaidReactionQuery>(std::move(promise))
|
||||
->send(message_full_id, star_count, is_anonymous, random_id);
|
||||
}
|
||||
|
||||
StringBuilder &operator<<(StringBuilder &string_builder, const MessageReactions &reactions) {
|
||||
@ -1050,7 +1059,8 @@ StringBuilder &operator<<(StringBuilder &string_builder, const MessageReactions
|
||||
<< reactions.chosen_reaction_order_
|
||||
<< " and can_get_added_reactions = " << reactions.can_get_added_reactions_
|
||||
<< " with paid reactions by " << reactions.top_reactors_ << " and "
|
||||
<< reactions.pending_paid_reactions_ << " pending paid reactions}";
|
||||
<< reactions.pending_paid_reactions_ << (reactions.pending_is_anonymous_ ? "anonymous " : "")
|
||||
<< " pending paid reactions}";
|
||||
}
|
||||
|
||||
StringBuilder &operator<<(StringBuilder &string_builder, const unique_ptr<MessageReactions> &reactions) {
|
||||
|
@ -158,6 +158,7 @@ struct MessageReactions {
|
||||
vector<ReactionType> chosen_reaction_order_;
|
||||
vector<MessageReactor> top_reactors_;
|
||||
int32 pending_paid_reactions_ = 0;
|
||||
bool pending_is_anonymous_ = false;
|
||||
bool is_min_ = false;
|
||||
bool need_polling_ = true;
|
||||
bool can_get_added_reactions_ = false;
|
||||
@ -181,7 +182,7 @@ struct MessageReactions {
|
||||
|
||||
bool remove_my_reaction(const ReactionType &reaction_type, DialogId my_dialog_id);
|
||||
|
||||
void add_my_paid_reaction(Td *td, int32 star_count);
|
||||
void add_my_paid_reaction(Td *td, int32 star_count, bool is_anonymous);
|
||||
|
||||
bool drop_pending_paid_reactions(Td *td);
|
||||
|
||||
|
@ -82,7 +82,7 @@ void MessageReactor::fix_message_reactors(vector<MessageReactor> &reactors, bool
|
||||
|
||||
bool operator<(const MessageReactor &lhs, const MessageReactor &rhs) {
|
||||
if (lhs.count_ != rhs.count_) {
|
||||
return lhs.count_ < rhs.count_;
|
||||
return lhs.count_ > rhs.count_;
|
||||
}
|
||||
return lhs.dialog_id_.get() < rhs.dialog_id_.get();
|
||||
}
|
||||
|
@ -37,7 +37,8 @@ class MessageReactor {
|
||||
|
||||
explicit MessageReactor(telegram_api::object_ptr<telegram_api::messageReactor> &&reactor);
|
||||
|
||||
MessageReactor(DialogId dialog_id, int32 count) : dialog_id_(dialog_id), count_(count), is_me_(true) {
|
||||
MessageReactor(DialogId dialog_id, int32 count, bool is_anonymous)
|
||||
: dialog_id_(dialog_id), count_(count), is_me_(true), is_anonymous_(is_anonymous) {
|
||||
}
|
||||
|
||||
bool is_valid() const {
|
||||
@ -50,8 +51,9 @@ class MessageReactor {
|
||||
|
||||
bool fix_is_me(DialogId my_dialog_id);
|
||||
|
||||
void add_count(int32 count) {
|
||||
void add_count(int32 count, bool is_anonymous) {
|
||||
count_ += count;
|
||||
is_anonymous_ = is_anonymous;
|
||||
}
|
||||
|
||||
td_api::object_ptr<td_api::paidReactor> get_paid_reactor_object(Td *td) const;
|
||||
|
@ -22783,7 +22783,7 @@ void MessagesManager::remove_message_reaction(MessageFullId message_full_id, Rea
|
||||
}
|
||||
}
|
||||
|
||||
void MessagesManager::add_paid_message_reaction(MessageFullId message_full_id, int64 star_count,
|
||||
void MessagesManager::add_paid_message_reaction(MessageFullId message_full_id, int64 star_count, bool is_anonymous,
|
||||
Promise<Unit> &&promise) {
|
||||
auto dialog_id = message_full_id.get_dialog_id();
|
||||
Dialog *d = get_dialog_force(dialog_id, "add_paid_message_reaction");
|
||||
@ -22808,7 +22808,7 @@ void MessagesManager::add_paid_message_reaction(MessageFullId message_full_id, i
|
||||
}
|
||||
|
||||
LOG(INFO) << "Have message with " << *m->reactions;
|
||||
m->reactions->add_my_paid_reaction(td_, narrow_cast<int32>(star_count));
|
||||
m->reactions->add_my_paid_reaction(td_, narrow_cast<int32>(star_count), is_anonymous);
|
||||
m->reactions->sort_reactions(active_reaction_pos_);
|
||||
LOG(INFO) << "Update message reactions to " << *m->reactions;
|
||||
|
||||
|
@ -796,7 +796,8 @@ class MessagesManager final : public Actor {
|
||||
|
||||
void remove_message_reaction(MessageFullId message_full_id, ReactionType reaction_type, Promise<Unit> &&promise);
|
||||
|
||||
void add_paid_message_reaction(MessageFullId message_full_id, int64 star_count, Promise<Unit> &&promise);
|
||||
void add_paid_message_reaction(MessageFullId message_full_id, int64 star_count, bool is_anonymous,
|
||||
Promise<Unit> &&promise);
|
||||
|
||||
void remove_paid_message_reactions(MessageFullId message_full_id, Promise<Unit> &&promise);
|
||||
|
||||
|
@ -4974,7 +4974,7 @@ void Td::on_request(uint64 id, const td_api::addPaidMessageReaction &request) {
|
||||
CHECK_IS_USER();
|
||||
CREATE_OK_REQUEST_PROMISE();
|
||||
messages_manager_->add_paid_message_reaction({DialogId(request.chat_id_), MessageId(request.message_id_)},
|
||||
request.star_count_, std::move(promise));
|
||||
request.star_count_, request.is_anonymous_, std::move(promise));
|
||||
}
|
||||
|
||||
void Td::on_request(uint64 id, const td_api::removePendingPaidMessageReactions &request) {
|
||||
|
@ -2954,12 +2954,12 @@ class CliClient final : public Actor {
|
||||
get_args(args, chat_id, message_id, reaction, is_big, update_recent_reactions);
|
||||
send_request(td_api::make_object<td_api::addMessageReaction>(chat_id, message_id, as_reaction_type(reaction),
|
||||
is_big, update_recent_reactions));
|
||||
} else if (op == "payreact") {
|
||||
} else if (op == "apmr" || op == "apmra") {
|
||||
ChatId chat_id;
|
||||
MessageId message_id;
|
||||
int64 star_count;
|
||||
get_args(args, chat_id, message_id, star_count);
|
||||
send_request(td_api::make_object<td_api::addPaidMessageReaction>(chat_id, message_id, star_count));
|
||||
send_request(td_api::make_object<td_api::addPaidMessageReaction>(chat_id, message_id, star_count, op == "apmra"));
|
||||
} else if (op == "rppmr") {
|
||||
ChatId chat_id;
|
||||
MessageId message_id;
|
||||
|
Loading…
Reference in New Issue
Block a user