Add parameter searchEmojis.input_language_code.

GitOrigin-RevId: c0cc78cb2957c9b9be4c3310a0505d08f6189006
This commit is contained in:
levlam 2020-01-08 19:07:40 +03:00
parent efc483551f
commit 3659757dc3
7 changed files with 30 additions and 14 deletions

View File

@ -142,6 +142,7 @@ Changes in 1.6.0:
- Added the method `confirmQrCodeAuthentication` for authentication confirmation from another device.
* Added the update `updateMessageLiveLocationViewed`, which is supposed to trigger an edit of the corresponding
live location.
* Added the parameter `input_language_code` to the method `searchEmojis`.
* Added the method `getInactiveSupergroupChats`, to be used when the user receives a CHANNELS_TOO_MUCH error after
reaching the limit on the number of joined supergroup and channel chats.
* Added the field `unique_id` to the class `remoteFile`, which can be used to identify the same file for

View File

@ -3817,8 +3817,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
searchEmojis text:string exact_match:Bool = 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; can be empty if unknown
searchEmojis text:string exact_match:Bool input_language_code:string = 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;

Binary file not shown.

View File

@ -4973,12 +4973,15 @@ void StickersManager::on_get_language_codes(const string &key, Result<vector<str
}
}
vector<string> StickersManager::get_emoji_language_codes(Promise<Unit> &promise) {
vector<string> StickersManager::get_emoji_language_codes(const string &input_language_code, Promise<Unit> &promise) {
vector<string> 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);
}
if (language_codes.empty()) {
LOG(ERROR) << "List of language codes is empty";
@ -4987,6 +4990,7 @@ vector<string> StickersManager::get_emoji_language_codes(Promise<Unit> &promise)
std::sort(language_codes.begin(), language_codes.end());
language_codes.erase(std::unique(language_codes.begin(), language_codes.end()), language_codes.end());
LOG(DEBUG) << "Have language codes " << language_codes;
auto key = get_emoji_language_codes_database_key(language_codes);
auto it = emoji_language_codes_.find(key);
if (it == emoji_language_codes_.end()) {
@ -5196,14 +5200,14 @@ void StickersManager::on_get_emoji_keywords_difference(
emoji_language_code_last_difference_times_[language_code] = static_cast<int32>(Time::now_cached());
}
vector<string> StickersManager::search_emojis(const string &text, bool exact_match, bool force,
Promise<Unit> &&promise) {
vector<string> StickersManager::search_emojis(const string &text, bool exact_match, const string &input_language_code,
bool force, Promise<Unit> &&promise) {
if (text.empty() || !G()->parameters().use_file_db /* have SQLite PMC */) {
promise.set_value(Unit());
return {};
}
auto language_codes = get_emoji_language_codes(promise);
auto language_codes = get_emoji_language_codes(input_language_code, promise);
if (language_codes.empty()) {
// promise was consumed
return {};

View File

@ -205,7 +205,8 @@ class StickersManager : public Actor {
vector<string> get_sticker_emojis(const tl_object_ptr<td_api::InputFile> &input_file, Promise<Unit> &&promise);
vector<string> search_emojis(const string &text, bool exact_match, bool force, Promise<Unit> &&promise);
vector<string> search_emojis(const string &text, bool exact_match, const string &input_language_code, bool force,
Promise<Unit> &&promise);
int64 get_emoji_suggestions_url(const string &language_code, Promise<Unit> &&promise);
@ -504,7 +505,7 @@ class StickersManager : public Actor {
double get_emoji_language_code_last_difference_time(const string &language_code);
vector<string> get_emoji_language_codes(Promise<Unit> &promise);
vector<string> get_emoji_language_codes(const string &input_language_code, Promise<Unit> &promise);
void load_language_codes(vector<string> language_codes, string key, Promise<Unit> &&promise);

View File

@ -2778,11 +2778,13 @@ class GetStickerEmojisRequest : public RequestActor<> {
class SearchEmojisRequest : public RequestActor<> {
string text_;
bool exact_match_;
string input_language_code_;
vector<string> emojis_;
void do_run(Promise<Unit> &&promise) override {
emojis_ = td->stickers_manager_->search_emojis(text_, exact_match_, get_tries() < 2, std::move(promise));
emojis_ = td->stickers_manager_->search_emojis(text_, exact_match_, input_language_code_, get_tries() < 2,
std::move(promise));
}
void do_send_result() override {
@ -2790,8 +2792,12 @@ class SearchEmojisRequest : public RequestActor<> {
}
public:
SearchEmojisRequest(ActorShared<Td> td, uint64 request_id, string &&text, bool exact_match)
: RequestActor(std::move(td), request_id), text_(std::move(text)), exact_match_(exact_match) {
SearchEmojisRequest(ActorShared<Td> td, uint64 request_id, string &&text, bool exact_match,
string &&input_language_code)
: RequestActor(std::move(td), request_id)
, text_(std::move(text))
, exact_match_(exact_match)
, input_language_code_(std::move(input_language_code)) {
set_tries(3);
}
};
@ -6726,7 +6732,9 @@ 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_);
CREATE_REQUEST(SearchEmojisRequest, std::move(request.text_), request.exact_match_);
CLEAN_INPUT_STRING(request.input_language_code_);
CREATE_REQUEST(SearchEmojisRequest, std::move(request.text_), request.exact_match_,
std::move(request.input_language_code_));
}
void Td::on_request(uint64 id, td_api::getEmojiSuggestionsUrl &request) {

View File

@ -2365,9 +2365,11 @@ class CliClient final : public Actor {
} else if (op == "gse") {
send_request(td_api::make_object<td_api::getStickerEmojis>(as_input_file_id(args)));
} else if (op == "se") {
send_request(td_api::make_object<td_api::searchEmojis>(args, false));
send_request(td_api::make_object<td_api::searchEmojis>(args, false, ""));
} else if (op == "see") {
send_request(td_api::make_object<td_api::searchEmojis>(args, true));
send_request(td_api::make_object<td_api::searchEmojis>(args, true, ""));
} else if (op == "seru") {
send_request(td_api::make_object<td_api::searchEmojis>(args, false, "ru_RU"));
} else if (op == "gesu") {
send_request(td_api::make_object<td_api::getEmojiSuggestionsUrl>(args));
} else {