Add td_api::getEmojiReaction.

This commit is contained in:
levlam 2022-09-12 15:03:35 +03:00
parent d29d3674ba
commit a33eb5233c
6 changed files with 45 additions and 9 deletions

View File

@ -2583,9 +2583,8 @@ addedReactions total_count:int32 reactions:vector<addedReaction> next_offset:str
//@description Represents a list of reactions that can be added to a message @reactions List of available reactions @allow_custom_emoji True, if any other custom emoji reaction can be added
availableReactions reactions:vector<ReactionType> allow_custom_emoji:Bool = AvailableReactions;
//@description Contains stickers which must be used for emoji reaction animation rendering
//@reaction Text representation of the reaction
//@description Contains information about a emoji reaction
//@emoji Text representation of the reaction
//@title Reaction title
//@is_active True, if the reaction can be added to new messages and enabled in chats
//@static_icon Static icon for the reaction
@ -2595,7 +2594,7 @@ availableReactions reactions:vector<ReactionType> allow_custom_emoji:Bool = Avai
//@effect_animation Effect animation for the reaction
//@around_animation Around animation for the reaction; may be null
//@center_animation Center animation for the reaction; may be null
reaction reaction:string title:string is_active:Bool static_icon:sticker appear_animation:sticker select_animation:sticker activate_animation:sticker effect_animation:sticker around_animation:sticker center_animation:sticker = Reaction;
emojiReaction emoji:string title:string is_active:Bool static_icon:sticker appear_animation:sticker select_animation:sticker activate_animation:sticker effect_animation:sticker around_animation:sticker center_animation:sticker = EmojiReaction;
//@description Represents a list of animations @animations List of animations
@ -5164,6 +5163,9 @@ editInlineMessageReplyMarkup inline_message_id:string reply_markup:ReplyMarkup =
editMessageSchedulingState chat_id:int53 message_id:int53 scheduling_state:MessageSchedulingState = Ok;
//@description Returns information about a emoji reaction. Returns a 404 error if the reaction is not found @emoji Text representation of the reaction
getEmojiReaction emoji:string = EmojiReaction;
//@description Returns reactions, which can be added to a message. The list can change after updateActiveEmojiReactions, updateChatAvailableReactions for the chat, or updateMessageInteractionInfo for the message
//@chat_id Identifier of the chat to which the message belongs
//@message_id Identifier of the message
@ -6392,7 +6394,7 @@ reportChat chat_id:int53 message_ids:vector<int53> reason:ChatReportReason text:
reportChatPhoto chat_id:int53 file_id:int32 reason:ChatReportReason text:string = Ok;
//@description Reports reactions set on a message to the Telegram moderators. Reactions on a message can be reported only if message.can_report_reactions
//@chat_id Chat identifier @message_id Message identifier @sender_id Identifier of the sender, added the reaction
//@chat_id Chat identifier @message_id Message identifier @sender_id Identifier of the sender, which added the reaction
reportMessageReactions chat_id:int53 message_id:int53 sender_id:MessageSender = Ok;

View File

@ -1482,12 +1482,27 @@ void StickersManager::init() {
td_->option_manager_->set_option_empty("animated_emoji_sticker_set_name"); // legacy
}
td_api::object_ptr<td_api::emojiReaction> StickersManager::get_emoji_reaction_object(const string &emoji) {
load_reactions();
for (auto &reaction : reactions_.reactions_) {
if (reaction.reaction_ == emoji) {
return td_api::make_object<td_api::emojiReaction>(
reaction.reaction_, reaction.title_, reaction.is_active_, get_sticker_object(reaction.static_icon_),
get_sticker_object(reaction.appear_animation_), get_sticker_object(reaction.select_animation_),
get_sticker_object(reaction.activate_animation_), get_sticker_object(reaction.effect_animation_),
get_sticker_object(reaction.around_animation_), get_sticker_object(reaction.center_animation_));
}
}
return nullptr;
}
void StickersManager::reload_reactions() {
if (G()->close_flag() || reactions_.are_being_reloaded_) {
return;
}
CHECK(!td_->auth_manager_->is_bot());
reactions_.are_being_reloaded_ = true;
load_reactions(); // must be after are_being_reloaded_ is set to true to avoid recursion
td_->create_handler<GetAvailableReactionsQuery>()->send(reactions_.hash_);
}
@ -3687,24 +3702,29 @@ void StickersManager::load_active_reactions() {
}
void StickersManager::load_reactions() {
if (are_reactions_loaded_from_database_) {
return;
}
are_reactions_loaded_from_database_ = true;
string reactions = G()->td_db()->get_binlog_pmc()->get("reactions");
if (reactions.empty()) {
return reload_reactions();
}
auto status = log_event_parse(reactions_, reactions);
auto new_reactions = reactions_;
auto status = log_event_parse(new_reactions, reactions);
if (status.is_error()) {
LOG(ERROR) << "Can't load available reactions: " << status;
reactions_ = {};
return reload_reactions();
}
for (auto &reaction : reactions_.reactions_) {
for (auto &reaction : new_reactions.reactions_) {
if (!reaction.is_valid()) {
LOG(ERROR) << "Loaded invalid reaction";
reactions_ = {};
return reload_reactions();
}
}
reactions_ = std::move(new_reactions);
LOG(INFO) << "Successfully loaded " << reactions_.reactions_.size() << " available reactions";

View File

@ -168,6 +168,8 @@ class StickersManager final : public Actor {
void view_featured_sticker_sets(const vector<StickerSetId> &sticker_set_ids);
td_api::object_ptr<td_api::emojiReaction> get_emoji_reaction_object(const string &emoji);
void reload_reactions();
void reload_special_sticker_set_by_type(SpecialStickerSetType type, bool is_recursive = false);
@ -1009,6 +1011,7 @@ class StickersManager final : public Actor {
Reactions reactions_;
vector<string> active_reactions_;
bool are_reactions_loaded_from_database_ = false;
FlatHashMap<string, vector<string>> emoji_language_codes_;
FlatHashMap<string, int32> emoji_language_code_versions_;

View File

@ -5199,6 +5199,11 @@ void Td::on_request(uint64 id, const td_api::getChatScheduledMessages &request)
CREATE_REQUEST(GetChatScheduledMessagesRequest, request.chat_id_);
}
void Td::on_request(uint64 id, const td_api::getEmojiReaction &request) {
CHECK_IS_USER();
send_closure(actor_id(this), &Td::send_result, id, stickers_manager_->get_emoji_reaction_object(request.emoji_));
}
void Td::on_request(uint64 id, const td_api::getMessageAvailableReactions &request) {
CHECK_IS_USER();
auto r_reactions =

View File

@ -656,6 +656,8 @@ class Td final : public Actor {
void on_request(uint64 id, const td_api::getChatScheduledMessages &request);
void on_request(uint64 id, const td_api::getEmojiReaction &request);
void on_request(uint64 id, const td_api::getMessageAvailableReactions &request);
void on_request(uint64 id, td_api::addMessageReaction &request);

View File

@ -2236,6 +2236,10 @@ class CliClient final : public Actor {
string reaction;
get_args(args, reaction);
send_request(td_api::make_object<td_api::setDefaultReactionType>(as_reaction_type(reaction)));
} else if (op == "ger") {
string emoji;
get_args(args, emoji);
send_request(td_api::make_object<td_api::getEmojiReaction>(emoji));
} else if (op == "gmar") {
ChatId chat_id;
MessageId message_id;