Assume Russian language in searchEmojis with Cyrillic text.

GitOrigin-RevId: e9f0212882bafadde17f49a345847f4df8010e73
This commit is contained in:
levlam 2020-04-22 15:02:56 +03:00
parent 226cf0e6dc
commit c96f62b34f
2 changed files with 20 additions and 3 deletions

View File

@ -5770,7 +5770,8 @@ void StickersManager::on_get_language_codes(const string &key, Result<vector<str
}
}
vector<string> StickersManager::get_emoji_language_codes(const string &input_language_code, Promise<Unit> &promise) {
vector<string> StickersManager::get_emoji_language_codes(const string &input_language_code, Slice text,
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) {
@ -5779,6 +5780,21 @@ vector<string> StickersManager::get_emoji_language_codes(const string &input_lan
if (!input_language_code.empty() && input_language_code.find('$') == string::npos) {
language_codes.push_back(input_language_code);
}
if (!text.empty()) {
uint32 code = 0;
next_utf8_unsafe(text.ubegin(), &code, "get_emoji_language_codes");
if ((0x410 <= code && code <= 0x44F) || code == 0x401 || code == 0x451) {
// the first letter is cyrillic
if (!td::contains(language_codes, "ru") && !td::contains(language_codes, "uk") &&
!td::contains(language_codes, "bg") && !td::contains(language_codes, "be") &&
!td::contains(language_codes, "mk") && !td::contains(language_codes, "sr") &&
!td::contains(language_codes, "mn") && !td::contains(language_codes, "ky") &&
!td::contains(language_codes, "kk") && !td::contains(language_codes, "uz") &&
!td::contains(language_codes, "tk")) {
language_codes.push_back("ru");
}
}
}
if (language_codes.empty()) {
LOG(ERROR) << "List of language codes is empty";
@ -6007,7 +6023,7 @@ vector<string> StickersManager::search_emojis(const string &text, bool exact_mat
return {};
}
auto language_codes = get_emoji_language_codes(input_language_code, promise);
auto language_codes = get_emoji_language_codes(input_language_code, text, promise);
if (language_codes.empty()) {
// promise was consumed
return {};

View File

@ -22,6 +22,7 @@
#include "td/utils/buffer.h"
#include "td/utils/common.h"
#include "td/utils/Hints.h"
#include "td/utils/Slice.h"
#include "td/utils/Status.h"
#include "td/telegram/td_api.h"
@ -590,7 +591,7 @@ class StickersManager : public Actor {
double get_emoji_language_code_last_difference_time(const string &language_code);
vector<string> get_emoji_language_codes(const string &input_language_code, Promise<Unit> &promise);
vector<string> get_emoji_language_codes(const string &input_language_code, Slice text, Promise<Unit> &promise);
void load_language_codes(vector<string> language_codes, string key, Promise<Unit> &&promise);