Add StickersManager::prepare_search_emoji_query.
This commit is contained in:
parent
0b5b4b8dab
commit
4dc89d0b8d
@ -9843,18 +9843,17 @@ void StickersManager::finish_get_emoji_keywords_difference(string language_code,
|
|||||||
emoji_language_code_last_difference_times_[language_code] = static_cast<int32>(Time::now_cached());
|
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 StickersManager::prepare_search_emoji_query(const string &text, const vector<string> &input_language_codes,
|
||||||
const vector<string> &input_language_codes, bool force,
|
bool force, Promise<Unit> &promise, SearchEmojiQuery &query) {
|
||||||
Promise<Unit> &&promise) {
|
|
||||||
if (text.empty() || !G()->use_sqlite_pmc()) {
|
if (text.empty() || !G()->use_sqlite_pmc()) {
|
||||||
promise.set_value(Unit());
|
promise.set_value(Unit());
|
||||||
return {};
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
auto language_codes = get_emoji_language_codes(input_language_codes, text, promise);
|
auto language_codes = get_emoji_language_codes(input_language_codes, text, promise);
|
||||||
if (language_codes.empty()) {
|
if (language_codes.empty()) {
|
||||||
// promise was consumed
|
// promise was consumed
|
||||||
return {};
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
vector<string> languages_to_load;
|
vector<string> languages_to_load;
|
||||||
@ -9878,18 +9877,29 @@ vector<string> StickersManager::search_emojis(const string &text, bool exact_mat
|
|||||||
load_emoji_keywords(language_code, mpas.get_promise());
|
load_emoji_keywords(language_code, mpas.get_promise());
|
||||||
}
|
}
|
||||||
lock.set_value(Unit());
|
lock.set_value(Unit());
|
||||||
return {};
|
return false;
|
||||||
} else {
|
} else {
|
||||||
LOG(ERROR) << "Have no " << languages_to_load << " emoji keywords";
|
LOG(ERROR) << "Have no " << languages_to_load << " emoji keywords";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
auto text_lowered = utf8_to_lower(text);
|
query.text_ = utf8_to_lower(text);
|
||||||
vector<string> result;
|
query.language_codes_ = std::move(language_codes);
|
||||||
for (auto &language_code : language_codes) {
|
return true;
|
||||||
combine(result, search_language_emojis(language_code, text_lowered, exact_match));
|
}
|
||||||
|
|
||||||
|
vector<string> StickersManager::search_emojis(const string &text, bool exact_match,
|
||||||
|
const vector<string> &input_language_codes, bool force,
|
||||||
|
Promise<Unit> &&promise) {
|
||||||
|
SearchEmojiQuery query;
|
||||||
|
if (!prepare_search_emoji_query(text, input_language_codes, force, promise, query)) {
|
||||||
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
vector<string> result;
|
||||||
|
for (auto &language_code : query.language_codes_) {
|
||||||
|
combine(result, search_language_emojis(language_code, query.text_, exact_match));
|
||||||
|
}
|
||||||
td::unique(result);
|
td::unique(result);
|
||||||
|
|
||||||
promise.set_value(Unit());
|
promise.set_value(Unit());
|
||||||
|
@ -933,6 +933,13 @@ class StickersManager final : public Actor {
|
|||||||
|
|
||||||
string get_used_language_codes_string() const;
|
string get_used_language_codes_string() const;
|
||||||
|
|
||||||
|
struct SearchEmojiQuery {
|
||||||
|
string text_;
|
||||||
|
vector<string> language_codes_;
|
||||||
|
};
|
||||||
|
bool prepare_search_emoji_query(const string &text, const vector<string> &input_language_codes, bool force,
|
||||||
|
Promise<Unit> &promise, SearchEmojiQuery &query);
|
||||||
|
|
||||||
vector<string> get_emoji_language_codes(const vector<string> &input_language_codes, Slice text,
|
vector<string> get_emoji_language_codes(const vector<string> &input_language_codes, Slice text,
|
||||||
Promise<Unit> &promise);
|
Promise<Unit> &promise);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user