Add td_api::removePendingPaidMessageReactions.
This commit is contained in:
parent
4dc42bc1bd
commit
ff174f3bce
@ -9052,17 +9052,22 @@ clearRecentReactions = Ok;
|
|||||||
//@update_recent_reactions Pass true if the reaction needs to be added to recent reactions; tags are never added to the list of recent reactions
|
//@update_recent_reactions Pass true if the reaction needs to be added to recent reactions; tags are never added to the list of recent reactions
|
||||||
addMessageReaction chat_id:int53 message_id:int53 reaction_type:ReactionType is_big:Bool update_recent_reactions:Bool = Ok;
|
addMessageReaction chat_id:int53 message_id:int53 reaction_type:ReactionType is_big:Bool update_recent_reactions:Bool = Ok;
|
||||||
|
|
||||||
|
//@description Removes a reaction from a message. A chosen reaction can always be removed
|
||||||
|
//@chat_id Identifier of the chat to which the message belongs
|
||||||
|
//@message_id Identifier of the message
|
||||||
|
//@reaction_type Type of the reaction to remove. The paid reaction can't be removed
|
||||||
|
removeMessageReaction chat_id:int53 message_id:int53 reaction_type:ReactionType = Ok;
|
||||||
|
|
||||||
//@description Adds the paid message reaction to a message. Use getMessageAvailableReactions to receive the list of available reactions for the message
|
//@description Adds the paid message reaction to a message. Use getMessageAvailableReactions to receive the list of available reactions for the message
|
||||||
//@chat_id Identifier of the chat to which the message belongs
|
//@chat_id Identifier of the chat to which the message belongs
|
||||||
//@message_id Identifier of the message
|
//@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")
|
//@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;
|
addPaidMessageReaction chat_id:int53 message_id:int53 star_count:int53 = Ok;
|
||||||
|
|
||||||
//@description Removes a reaction from a message. A chosen reaction can always be removed
|
//@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
|
//@chat_id Identifier of the chat to which the message belongs
|
||||||
//@message_id Identifier of the message
|
//@message_id Identifier of the message
|
||||||
//@reaction_type Type of the reaction to remove. The paid reaction can't be removed
|
removePendingPaidMessageReactions chat_id:int53 message_id:int53 = Ok;
|
||||||
removeMessageReaction chat_id:int53 message_id:int53 reaction_type:ReactionType = Ok;
|
|
||||||
|
|
||||||
//@description Sets reactions on a message; for bots only
|
//@description Sets reactions on a message; for bots only
|
||||||
//@chat_id Identifier of the chat to which the message belongs
|
//@chat_id Identifier of the chat to which the message belongs
|
||||||
|
@ -805,6 +805,14 @@ void MessageReactions::add_my_paid_reaction(int32 star_count) {
|
|||||||
pending_paid_reactions_ += star_count;
|
pending_paid_reactions_ += star_count;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool MessageReactions::drop_pending_paid_reactions() {
|
||||||
|
if (pending_paid_reactions_ == 0) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
pending_paid_reactions_ = 0;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
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) {
|
||||||
|
@ -181,6 +181,8 @@ struct MessageReactions {
|
|||||||
|
|
||||||
void add_my_paid_reaction(int32 star_count);
|
void add_my_paid_reaction(int32 star_count);
|
||||||
|
|
||||||
|
bool drop_pending_paid_reactions();
|
||||||
|
|
||||||
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();
|
||||||
|
@ -12101,7 +12101,10 @@ 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())) {
|
||||||
// TODO drop pending reactions
|
if (m->reactions->drop_pending_paid_reactions()) {
|
||||||
|
send_update_message_interaction_info(d->dialog_id, m);
|
||||||
|
on_message_changed(d, m, true, "on_send_paid_reactions_timeout");
|
||||||
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -22703,6 +22706,41 @@ void MessagesManager::add_message_reaction(MessageFullId message_full_id, Reacti
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void MessagesManager::remove_message_reaction(MessageFullId message_full_id, ReactionType reaction_type,
|
||||||
|
Promise<Unit> &&promise) {
|
||||||
|
auto dialog_id = message_full_id.get_dialog_id();
|
||||||
|
Dialog *d = get_dialog_force(dialog_id, "remove_message_reaction");
|
||||||
|
if (d == nullptr) {
|
||||||
|
return promise.set_error(Status::Error(400, "Chat not found"));
|
||||||
|
}
|
||||||
|
|
||||||
|
Message *m = get_message_force(d, message_full_id.get_message_id(), "remove_message_reaction");
|
||||||
|
if (m == nullptr) {
|
||||||
|
return promise.set_error(Status::Error(400, "Message not found"));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (reaction_type.is_empty() || reaction_type.is_paid_reaction()) {
|
||||||
|
return promise.set_error(Status::Error(400, "Invalid reaction specified"));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (m->reactions == nullptr) {
|
||||||
|
return promise.set_value(Unit());
|
||||||
|
}
|
||||||
|
|
||||||
|
LOG(INFO) << "Have message with " << *m->reactions;
|
||||||
|
auto old_chosen_tags = get_chosen_tags(m->reactions);
|
||||||
|
if (!m->reactions->remove_my_reaction(reaction_type, get_my_reaction_dialog_id(d))) {
|
||||||
|
return promise.set_value(Unit());
|
||||||
|
}
|
||||||
|
|
||||||
|
set_message_reactions(d, m, false, false, std::move(promise));
|
||||||
|
|
||||||
|
if (!old_chosen_tags.empty()) {
|
||||||
|
td_->reaction_manager_->update_saved_messages_tags(m->saved_messages_topic_id, old_chosen_tags,
|
||||||
|
get_chosen_tags(m->reactions));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
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,
|
||||||
Promise<Unit> &&promise) {
|
Promise<Unit> &&promise) {
|
||||||
auto dialog_id = message_full_id.get_dialog_id();
|
auto dialog_id = message_full_id.get_dialog_id();
|
||||||
@ -22744,39 +22782,26 @@ void MessagesManager::add_paid_message_reaction(MessageFullId message_full_id, i
|
|||||||
promise.set_value(Unit());
|
promise.set_value(Unit());
|
||||||
}
|
}
|
||||||
|
|
||||||
void MessagesManager::remove_message_reaction(MessageFullId message_full_id, ReactionType reaction_type,
|
void MessagesManager::remove_paid_message_reactions(MessageFullId message_full_id, Promise<Unit> &&promise) {
|
||||||
Promise<Unit> &&promise) {
|
auto it = paid_reaction_task_ids_.find(message_full_id);
|
||||||
auto dialog_id = message_full_id.get_dialog_id();
|
if (it == paid_reaction_task_ids_.end()) {
|
||||||
Dialog *d = get_dialog_force(dialog_id, "remove_message_reaction");
|
|
||||||
if (d == nullptr) {
|
|
||||||
return promise.set_error(Status::Error(400, "Chat not found"));
|
|
||||||
}
|
|
||||||
|
|
||||||
Message *m = get_message_force(d, message_full_id.get_message_id(), "remove_message_reaction");
|
|
||||||
if (m == nullptr) {
|
|
||||||
return promise.set_error(Status::Error(400, "Message not found"));
|
|
||||||
}
|
|
||||||
|
|
||||||
if (reaction_type.is_empty() || reaction_type.is_paid_reaction()) {
|
|
||||||
return promise.set_error(Status::Error(400, "Invalid reaction specified"));
|
|
||||||
}
|
|
||||||
|
|
||||||
if (m->reactions == nullptr) {
|
|
||||||
return promise.set_value(Unit());
|
return promise.set_value(Unit());
|
||||||
}
|
}
|
||||||
|
auto task_id = it->second;
|
||||||
|
paid_reaction_task_ids_.erase(it);
|
||||||
|
bool is_erased = paid_reaction_tasks_.erase(task_id) > 0;
|
||||||
|
CHECK(is_erased);
|
||||||
|
|
||||||
LOG(INFO) << "Have message with " << *m->reactions;
|
send_paid_reactions_timeout_.cancel_timeout(task_id);
|
||||||
auto old_chosen_tags = get_chosen_tags(m->reactions);
|
|
||||||
if (!m->reactions->remove_my_reaction(reaction_type, get_my_reaction_dialog_id(d))) {
|
Dialog *d = get_dialog_force(message_full_id.get_dialog_id(), "remove_paid_message_reaction");
|
||||||
return promise.set_value(Unit());
|
CHECK(d != nullptr);
|
||||||
}
|
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()) {
|
||||||
set_message_reactions(d, m, false, false, std::move(promise));
|
send_update_message_interaction_info(d->dialog_id, m);
|
||||||
|
on_message_changed(d, m, true, "on_send_paid_reactions_timeout");
|
||||||
if (!old_chosen_tags.empty()) {
|
|
||||||
td_->reaction_manager_->update_saved_messages_tags(m->saved_messages_topic_id, old_chosen_tags,
|
|
||||||
get_chosen_tags(m->reactions));
|
|
||||||
}
|
}
|
||||||
|
promise.set_value(Unit());
|
||||||
}
|
}
|
||||||
|
|
||||||
void MessagesManager::set_message_reactions(Dialog *d, Message *m, bool is_big, bool add_to_recent,
|
void MessagesManager::set_message_reactions(Dialog *d, Message *m, bool is_big, bool add_to_recent,
|
||||||
|
@ -793,9 +793,11 @@ class MessagesManager final : public Actor {
|
|||||||
void add_message_reaction(MessageFullId message_full_id, ReactionType reaction_type, bool is_big, bool add_to_recent,
|
void add_message_reaction(MessageFullId message_full_id, ReactionType reaction_type, bool is_big, bool add_to_recent,
|
||||||
Promise<Unit> &&promise);
|
Promise<Unit> &&promise);
|
||||||
|
|
||||||
|
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, Promise<Unit> &&promise);
|
||||||
|
|
||||||
void remove_message_reaction(MessageFullId message_full_id, ReactionType reaction_type, Promise<Unit> &&promise);
|
void remove_paid_message_reactions(MessageFullId message_full_id, Promise<Unit> &&promise);
|
||||||
|
|
||||||
td_api::object_ptr<td_api::message> get_dialog_event_log_message_object(
|
td_api::object_ptr<td_api::message> get_dialog_event_log_message_object(
|
||||||
DialogId dialog_id, tl_object_ptr<telegram_api::Message> &&message, DialogId &sender_dialog_id);
|
DialogId dialog_id, tl_object_ptr<telegram_api::Message> &&message, DialogId &sender_dialog_id);
|
||||||
|
@ -4998,6 +4998,13 @@ void Td::on_request(uint64 id, const td_api::addPaidMessageReaction &request) {
|
|||||||
request.star_count_, std::move(promise));
|
request.star_count_, std::move(promise));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Td::on_request(uint64 id, const td_api::removePendingPaidMessageReactions &request) {
|
||||||
|
CHECK_IS_USER();
|
||||||
|
CREATE_OK_REQUEST_PROMISE();
|
||||||
|
messages_manager_->remove_paid_message_reactions({DialogId(request.chat_id_), MessageId(request.message_id_)},
|
||||||
|
std::move(promise));
|
||||||
|
}
|
||||||
|
|
||||||
void Td::on_request(uint64 id, const td_api::removeMessageReaction &request) {
|
void Td::on_request(uint64 id, const td_api::removeMessageReaction &request) {
|
||||||
CHECK_IS_USER();
|
CHECK_IS_USER();
|
||||||
CREATE_OK_REQUEST_PROMISE();
|
CREATE_OK_REQUEST_PROMISE();
|
||||||
|
@ -814,6 +814,8 @@ class Td final : public Actor {
|
|||||||
|
|
||||||
void on_request(uint64 id, const td_api::addPaidMessageReaction &request);
|
void on_request(uint64 id, const td_api::addPaidMessageReaction &request);
|
||||||
|
|
||||||
|
void on_request(uint64 id, const td_api::removePendingPaidMessageReactions &request);
|
||||||
|
|
||||||
void on_request(uint64 id, const td_api::removeMessageReaction &request);
|
void on_request(uint64 id, const td_api::removeMessageReaction &request);
|
||||||
|
|
||||||
void on_request(uint64 id, const td_api::setMessageReactions &request);
|
void on_request(uint64 id, const td_api::setMessageReactions &request);
|
||||||
|
@ -2964,6 +2964,11 @@ class CliClient final : public Actor {
|
|||||||
int64 star_count;
|
int64 star_count;
|
||||||
get_args(args, chat_id, message_id, 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));
|
||||||
|
} else if (op == "rppmr") {
|
||||||
|
ChatId chat_id;
|
||||||
|
MessageId message_id;
|
||||||
|
get_args(args, chat_id, message_id);
|
||||||
|
send_request(td_api::make_object<td_api::removePendingPaidMessageReactions>(chat_id, message_id));
|
||||||
} else if (op == "rmr") {
|
} else if (op == "rmr") {
|
||||||
ChatId chat_id;
|
ChatId chat_id;
|
||||||
MessageId message_id;
|
MessageId message_id;
|
||||||
|
Loading…
Reference in New Issue
Block a user