From 6893c49be70ebafdb561651e5aaf3eb241ffad36 Mon Sep 17 00:00:00 2001 From: levlam Date: Tue, 26 Oct 2021 17:59:15 +0300 Subject: [PATCH] Add td_api::getAnimatedEmoji. --- td/generate/scheme/td_api.tl | 3 +++ td/telegram/StickersManager.cpp | 33 +++++++++++++++++++++++++++++++++ td/telegram/StickersManager.h | 7 ++++++- td/telegram/Td.cpp | 7 +++++++ td/telegram/Td.h | 2 ++ td/telegram/cli.cpp | 2 ++ 6 files changed, 53 insertions(+), 1 deletion(-) diff --git a/td/generate/scheme/td_api.tl b/td/generate/scheme/td_api.tl index a547be450..5aa071d2a 100644 --- a/td/generate/scheme/td_api.tl +++ b/td/generate/scheme/td_api.tl @@ -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 = 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; diff --git a/td/telegram/StickersManager.cpp b/td/telegram/StickersManager.cpp index d88c6a17e..e8f90d733 100644 --- a/td/telegram/StickersManager.cpp +++ b/td/telegram/StickersManager.cpp @@ -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> &&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 &&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> &&promise) { auto &special_sticker_set = add_special_sticker_set(SpecialStickerSetType::animated_emoji_click()); diff --git a/td/telegram/StickersManager.h b/td/telegram/StickersManager.h index ec6090681..dd9e1e13e 100644 --- a/td/telegram/StickersManager.h +++ b/td/telegram/StickersManager.h @@ -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> &&promise); + void get_animated_emoji_click_sticker(const string &message_text, FullMessageId full_message_id, Promise> &&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 get_animated_emoji_object(std::pair 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> pending_set_sticker_set_thumbnails_; + vector> pending_get_animated_emoji_queries_; + double next_click_animated_emoji_message_time_ = 0; double next_update_animated_emoji_clicked_time_ = 0; vector pending_get_animated_emoji_click_stickers_; diff --git a/td/telegram/Td.cpp b/td/telegram/Td.cpp index e3da5f0d1..389332da7 100644 --- a/td/telegram/Td.cpp +++ b/td/telegram/Td.cpp @@ -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_); diff --git a/td/telegram/Td.h b/td/telegram/Td.h index d697d0f1c..cb93c33b7 100644 --- a/td/telegram/Td.h +++ b/td/telegram/Td.h @@ -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); diff --git a/td/telegram/cli.cpp b/td/telegram/cli.cpp index b670b58f4..13aa61408 100644 --- a/td/telegram/cli.cpp +++ b/td/telegram/cli.cpp @@ -2527,6 +2527,8 @@ class CliClient final : public Actor { send_request(td_api::make_object(args, true, vector())); } else if (op == "seru") { send_request(td_api::make_object(args, false, vector{"ru_RU"})); + } else if (op == "gae") { + send_request(td_api::make_object(args)); } else if (op == "gesu") { send_request(td_api::make_object(args)); } else {