From 52ea0998ec6c149693300371f074857e83101d19 Mon Sep 17 00:00:00 2001 From: levlam Date: Wed, 22 Apr 2020 15:17:53 +0300 Subject: [PATCH] Allow to pass multiple input language codes in searchEmojis. GitOrigin-RevId: 0fb99694447f3ac02063eb9c03af2c2b3dfc267e --- td/generate/scheme/td_api.tl | 4 ++-- td/generate/scheme/td_api.tlo | Bin 171416 -> 171440 bytes td/telegram/MessagesManager.cpp | 2 +- td/telegram/StickersManager.cpp | 15 +++++++++------ td/telegram/StickersManager.h | 7 ++++--- td/telegram/Td.cpp | 14 ++++++++------ td/telegram/cli.cpp | 6 +++--- 7 files changed, 27 insertions(+), 21 deletions(-) diff --git a/td/generate/scheme/td_api.tl b/td/generate/scheme/td_api.tl index 00f20c3b..be8b8bcd 100644 --- a/td/generate/scheme/td_api.tl +++ b/td/generate/scheme/td_api.tl @@ -3956,8 +3956,8 @@ removeFavoriteSticker sticker:InputFile = Ok; //@description Returns emoji corresponding to a sticker. The list is only for informational purposes, because a sticker is always sent with a fixed emoji from the corresponding Sticker object @sticker Sticker file identifier 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_code IETF language tag of the user's input language; may be empty if unknown -searchEmojis text:string exact_match:Bool input_language_code:string = 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 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/generate/scheme/td_api.tlo b/td/generate/scheme/td_api.tlo index 0b7414998ec3db85027a61baf380b46d5dc343a7..377f0ce8eb73f5ede1a84f0573b4b5d30b34acdf 100644 GIT binary patch delta 59 zcmbQSn`^^vu7(!IElfvJSeBnSDn9*03R8-RNM>F^X-RxeVqSV_VtQ(Pa(+tc^Zrandom_id != 0 && (m->is_outgoing || d->dialog_id == get_my_dialog_id())) { + if (m != nullptr && m->random_id != 0 && (m->is_outgoing || d->dialog_id == get_my_dialog_id())) { message_random_ids_.erase(m->random_id); } diff --git a/td/telegram/StickersManager.cpp b/td/telegram/StickersManager.cpp index c657288c..33509865 100644 --- a/td/telegram/StickersManager.cpp +++ b/td/telegram/StickersManager.cpp @@ -5770,15 +5770,17 @@ void StickersManager::on_get_language_codes(const string &key, Result StickersManager::get_emoji_language_codes(const string &input_language_code, Slice text, +vector StickersManager::get_emoji_language_codes(const vector &input_language_codes, Slice text, Promise &promise) { vector language_codes = td_->language_pack_manager_->get_actor_unsafe()->get_used_language_codes(); auto system_language_code = G()->mtproto_header().get_system_language_code(); if (!system_language_code.empty() && system_language_code.find('$') == string::npos) { language_codes.push_back(system_language_code); } - if (!input_language_code.empty() && input_language_code.find('$') == string::npos) { - language_codes.push_back(input_language_code); + for (auto &input_language_code : input_language_codes) { + if (!input_language_code.empty() && input_language_code.find('$') == string::npos) { + language_codes.push_back(input_language_code); + } } if (!text.empty()) { uint32 code = 0; @@ -6016,14 +6018,15 @@ void StickersManager::on_get_emoji_keywords_difference( emoji_language_code_last_difference_times_[language_code] = static_cast(Time::now_cached()); } -vector StickersManager::search_emojis(const string &text, bool exact_match, const string &input_language_code, - bool force, Promise &&promise) { +vector StickersManager::search_emojis(const string &text, bool exact_match, + const vector &input_language_codes, bool force, + Promise &&promise) { if (text.empty() || !G()->parameters().use_file_db /* have SQLite PMC */) { promise.set_value(Unit()); return {}; } - auto language_codes = get_emoji_language_codes(input_language_code, text, promise); + auto language_codes = get_emoji_language_codes(input_language_codes, text, promise); if (language_codes.empty()) { // promise was consumed return {}; diff --git a/td/telegram/StickersManager.h b/td/telegram/StickersManager.h index 09ebc521..79e6f69f 100644 --- a/td/telegram/StickersManager.h +++ b/td/telegram/StickersManager.h @@ -228,8 +228,8 @@ class StickersManager : public Actor { vector get_sticker_emojis(const tl_object_ptr &input_file, Promise &&promise); - vector search_emojis(const string &text, bool exact_match, const string &input_language_code, bool force, - Promise &&promise); + vector search_emojis(const string &text, bool exact_match, const vector &input_language_codes, + bool force, Promise &&promise); int64 get_emoji_suggestions_url(const string &language_code, Promise &&promise); @@ -591,7 +591,8 @@ class StickersManager : public Actor { double get_emoji_language_code_last_difference_time(const string &language_code); - vector get_emoji_language_codes(const string &input_language_code, Slice text, Promise &promise); + vector get_emoji_language_codes(const vector &input_language_codes, Slice text, + Promise &promise); void load_language_codes(vector language_codes, string key, Promise &&promise); diff --git a/td/telegram/Td.cpp b/td/telegram/Td.cpp index c140c78f..43cef2e7 100644 --- a/td/telegram/Td.cpp +++ b/td/telegram/Td.cpp @@ -2714,12 +2714,12 @@ class GetStickerEmojisRequest : public RequestActor<> { class SearchEmojisRequest : public RequestActor<> { string text_; bool exact_match_; - string input_language_code_; + vector input_language_codes_; vector emojis_; void do_run(Promise &&promise) override { - emojis_ = td->stickers_manager_->search_emojis(text_, exact_match_, input_language_code_, get_tries() < 2, + emojis_ = td->stickers_manager_->search_emojis(text_, exact_match_, input_language_codes_, get_tries() < 2, std::move(promise)); } @@ -2729,11 +2729,11 @@ class SearchEmojisRequest : public RequestActor<> { public: SearchEmojisRequest(ActorShared td, uint64 request_id, string &&text, bool exact_match, - string &&input_language_code) + vector &&input_language_codes) : RequestActor(std::move(td), request_id) , text_(std::move(text)) , exact_match_(exact_match) - , input_language_code_(std::move(input_language_code)) { + , input_language_codes_(std::move(input_language_codes)) { set_tries(3); } }; @@ -6449,9 +6449,11 @@ void Td::on_request(uint64 id, td_api::getStickerEmojis &request) { void Td::on_request(uint64 id, td_api::searchEmojis &request) { CHECK_IS_USER(); CLEAN_INPUT_STRING(request.text_); - CLEAN_INPUT_STRING(request.input_language_code_); + for (auto &input_language_code : request.input_language_codes_) { + CLEAN_INPUT_STRING(input_language_code); + } CREATE_REQUEST(SearchEmojisRequest, std::move(request.text_), request.exact_match_, - std::move(request.input_language_code_)); + std::move(request.input_language_codes_)); } void Td::on_request(uint64 id, td_api::getEmojiSuggestionsUrl &request) { diff --git a/td/telegram/cli.cpp b/td/telegram/cli.cpp index bcd263a2..3688b899 100644 --- a/td/telegram/cli.cpp +++ b/td/telegram/cli.cpp @@ -2405,11 +2405,11 @@ class CliClient final : public Actor { } else if (op == "gse") { send_request(td_api::make_object(as_input_file_id(args))); } else if (op == "se") { - send_request(td_api::make_object(args, false, "")); + send_request(td_api::make_object(args, false, vector())); } else if (op == "see") { - send_request(td_api::make_object(args, true, "")); + send_request(td_api::make_object(args, true, vector())); } else if (op == "seru") { - send_request(td_api::make_object(args, false, "ru_RU")); + send_request(td_api::make_object(args, false, vector{"ru_RU"})); } else if (op == "gesu") { send_request(td_api::make_object(args)); } else {