Add td_api::getAnimatedEmoji.

This commit is contained in:
levlam 2021-10-26 17:59:15 +03:00
parent 1dd054d896
commit 6893c49be7
6 changed files with 53 additions and 1 deletions

View File

@ -5219,6 +5219,9 @@ getStickerEmojis sticker:InputFile = Emojis;
//@description Searches for emojis by keywords. Supported only if the file database is enabled @text Text to search for @exact_match True, if only emojis, which exactly match text needs to be returned @input_language_codes List of possible IETF language tags of the user's input language; may be empty if unknown
searchEmojis text:string exact_match:Bool input_language_codes:vector<string> = Emojis;
//@description Returns an animated emoji corresponding to a given emoji. Returns a 404 error if the emoji has no animated emoji @emoji The emoji
getAnimatedEmoji emoji:string = AnimatedEmoji;
//@description Returns an HTTP URL which can be used to automatically log in to the translation platform and suggest new emoji replacements. The URL will be valid for 30 seconds after generation @language_code Language code for which the emoji replacements will be suggested
getEmojiSuggestionsUrl language_code:string = HttpUrl;

View File

@ -1433,6 +1433,11 @@ void StickersManager::on_load_special_sticker_set(const SpecialStickerSetType &t
schedule_update_animated_emoji_clicked(sticker_set, pending_request.emoji_, pending_request.full_message_id_,
std::move(pending_request.clicks_));
}
auto promises = std::move(pending_get_animated_emoji_queries_);
reset_to_empty(pending_get_animated_emoji_queries_);
for (auto &promise : promises) {
promise.set_value(Unit());
}
return;
}
@ -4277,6 +4282,34 @@ void StickersManager::unregister_emoji(const string &emoji, FullMessageId full_m
}
}
void StickersManager::get_animated_emoji(string emoji, bool is_recursive,
Promise<td_api::object_ptr<td_api::animatedEmoji>> &&promise) {
TRY_STATUS_PROMISE(promise, G()->close_status());
auto &special_sticker_set = add_special_sticker_set(SpecialStickerSetType::animated_emoji());
auto sticker_set = get_sticker_set(special_sticker_set.id_);
if (sticker_set == nullptr || !sticker_set->was_loaded) {
if (is_recursive) {
return promise.set_value(nullptr);
}
pending_get_animated_emoji_queries_.push_back(
PromiseCreator::lambda([actor_id = actor_id(this), emoji = std::move(emoji),
promise = std::move(promise)](Result<Unit> &&result) mutable {
if (result.is_error()) {
promise.set_error(result.move_as_error());
} else {
send_closure(actor_id, &StickersManager::get_animated_emoji, std::move(emoji), true, std::move(promise));
}
}));
load_special_sticker_set(special_sticker_set);
return;
}
promise.set_value(get_animated_emoji_object(get_animated_emoji_sticker(sticker_set, emoji),
get_animated_emoji_sound_file_id(emoji)));
}
void StickersManager::get_animated_emoji_click_sticker(const string &message_text, FullMessageId full_message_id,
Promise<td_api::object_ptr<td_api::sticker>> &&promise) {
auto &special_sticker_set = add_special_sticker_set(SpecialStickerSetType::animated_emoji_click());

View File

@ -76,6 +76,9 @@ class StickersManager final : public Actor {
void unregister_emoji(const string &emoji, FullMessageId full_message_id, const char *source);
void get_animated_emoji(string emoji, bool is_recursive,
Promise<td_api::object_ptr<td_api::animatedEmoji>> &&promise);
void get_animated_emoji_click_sticker(const string &message_text, FullMessageId full_message_id,
Promise<td_api::object_ptr<td_api::sticker>> &&promise);
@ -621,7 +624,7 @@ class StickersManager final : public Actor {
FileId get_animated_emoji_sound_file_id(const string &emoji) const;
td_api::object_ptr<td_api::animatedEmoji> get_animated_emoji_object(std::pair<FileId, int> animated_sticker,
FileId sound_file_id) const;
FileId sound_file_id) const;
void try_update_animated_emoji_messages();
@ -798,6 +801,8 @@ class StickersManager final : public Actor {
std::unordered_map<int64, unique_ptr<PendingSetStickerSetThumbnail>> pending_set_sticker_set_thumbnails_;
vector<Promise<Unit>> pending_get_animated_emoji_queries_;
double next_click_animated_emoji_message_time_ = 0;
double next_update_animated_emoji_clicked_time_ = 0;
vector<PendingGetAnimatedEmojiClickSticker> pending_get_animated_emoji_click_stickers_;

View File

@ -7002,6 +7002,13 @@ void Td::on_request(uint64 id, td_api::searchEmojis &request) {
std::move(request.input_language_codes_));
}
void Td::on_request(uint64 id, td_api::getAnimatedEmoji &request) {
CHECK_IS_USER();
CLEAN_INPUT_STRING(request.emoji_);
CREATE_REQUEST_PROMISE();
stickers_manager_->get_animated_emoji(std::move(request.emoji_), false, std::move(promise));
}
void Td::on_request(uint64 id, td_api::getEmojiSuggestionsUrl &request) {
CHECK_IS_USER();
CLEAN_INPUT_STRING(request.language_code_);

View File

@ -1042,6 +1042,8 @@ class Td final : public Actor {
void on_request(uint64 id, td_api::searchEmojis &request);
void on_request(uint64 id, td_api::getAnimatedEmoji &request);
void on_request(uint64 id, td_api::getEmojiSuggestionsUrl &request);
void on_request(uint64 id, const td_api::getFavoriteStickers &request);

View File

@ -2527,6 +2527,8 @@ class CliClient final : public Actor {
send_request(td_api::make_object<td_api::searchEmojis>(args, true, vector<string>()));
} else if (op == "seru") {
send_request(td_api::make_object<td_api::searchEmojis>(args, false, vector<string>{"ru_RU"}));
} else if (op == "gae") {
send_request(td_api::make_object<td_api::getAnimatedEmoji>(args));
} else if (op == "gesu") {
send_request(td_api::make_object<td_api::getEmojiSuggestionsUrl>(args));
} else {