Add separate td_api::getKeywordEmojis.
This commit is contained in:
parent
4dc89d0b8d
commit
f4bafbdc86
@ -8903,9 +8903,13 @@ getStickerEmojis sticker:InputFile = Emojis;
|
|||||||
|
|
||||||
//@description Searches for emojis by keywords. Supported only if the file database is enabled
|
//@description Searches for emojis by keywords. Supported only if the file database is enabled
|
||||||
//@text Text to search for
|
//@text Text to search for
|
||||||
//@exact_match Pass true if only emojis, which exactly match the 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
|
//@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<string> = Emojis;
|
searchEmojis text:string input_language_codes:vector<string> = Emojis;
|
||||||
|
|
||||||
|
//@description Return emojis matching the keyword. Supported only if the file database is enabled
|
||||||
|
//@text Text to search for
|
||||||
|
//@input_language_codes List of possible IETF language tags of the user's input language; may be empty if unknown
|
||||||
|
getKeywordEmojis text:string input_language_codes:vector<string> = Emojis;
|
||||||
|
|
||||||
//@description Returns available emojis categories @type Type of emoji categories to return; pass null to get default emoji categories
|
//@description Returns available emojis categories @type Type of emoji categories to return; pass null to get default emoji categories
|
||||||
getEmojiCategories type:EmojiCategoryType = EmojiCategories;
|
getEmojiCategories type:EmojiCategoryType = EmojiCategories;
|
||||||
|
@ -9478,14 +9478,9 @@ string StickersManager::get_language_emojis_database_key(const string &language_
|
|||||||
return PSTRING() << "emoji$" << language_code << '$' << text;
|
return PSTRING() << "emoji$" << language_code << '$' << text;
|
||||||
}
|
}
|
||||||
|
|
||||||
vector<string> StickersManager::search_language_emojis(const string &language_code, const string &text,
|
vector<string> StickersManager::search_language_emojis(const string &language_code, const string &text) {
|
||||||
bool exact_match) {
|
LOG(INFO) << "Search emoji for \"" << text << "\" in language " << language_code;
|
||||||
LOG(INFO) << "Search for \"" << text << "\" in language " << language_code;
|
|
||||||
auto key = get_language_emojis_database_key(language_code, text);
|
auto key = get_language_emojis_database_key(language_code, text);
|
||||||
if (exact_match) {
|
|
||||||
string emojis = G()->td_db()->get_sqlite_sync_pmc()->get(key);
|
|
||||||
return full_split(emojis, '$');
|
|
||||||
} else {
|
|
||||||
vector<string> result;
|
vector<string> result;
|
||||||
G()->td_db()->get_sqlite_sync_pmc()->get_by_prefix(key, [&result](Slice key, Slice value) {
|
G()->td_db()->get_sqlite_sync_pmc()->get_by_prefix(key, [&result](Slice key, Slice value) {
|
||||||
for (auto &emoji : full_split(value, '$')) {
|
for (auto &emoji : full_split(value, '$')) {
|
||||||
@ -9495,6 +9490,12 @@ vector<string> StickersManager::search_language_emojis(const string &language_co
|
|||||||
});
|
});
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
vector<string> StickersManager::get_keyword_language_emojis(const string &language_code, const string &text) {
|
||||||
|
LOG(INFO) << "Get emoji for \"" << text << "\" in language " << language_code;
|
||||||
|
auto key = get_language_emojis_database_key(language_code, text);
|
||||||
|
string emojis = G()->td_db()->get_sqlite_sync_pmc()->get(key);
|
||||||
|
return full_split(emojis, '$');
|
||||||
}
|
}
|
||||||
|
|
||||||
string StickersManager::get_emoji_language_codes_database_key(const vector<string> &language_codes) {
|
string StickersManager::get_emoji_language_codes_database_key(const vector<string> &language_codes) {
|
||||||
@ -9786,7 +9787,7 @@ void StickersManager::on_get_emoji_keywords_difference(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (is_good) {
|
if (is_good) {
|
||||||
vector<string> emojis = search_language_emojis(language_code, text, true);
|
vector<string> emojis = get_keyword_language_emojis(language_code, text);
|
||||||
bool is_changed = false;
|
bool is_changed = false;
|
||||||
for (auto &emoji : keyword->emoticons_) {
|
for (auto &emoji : keyword->emoticons_) {
|
||||||
if (!td::contains(emojis, emoji)) {
|
if (!td::contains(emojis, emoji)) {
|
||||||
@ -9806,7 +9807,7 @@ void StickersManager::on_get_emoji_keywords_difference(
|
|||||||
case telegram_api::emojiKeywordDeleted::ID: {
|
case telegram_api::emojiKeywordDeleted::ID: {
|
||||||
auto keyword = telegram_api::move_object_as<telegram_api::emojiKeywordDeleted>(keyword_ptr);
|
auto keyword = telegram_api::move_object_as<telegram_api::emojiKeywordDeleted>(keyword_ptr);
|
||||||
auto text = utf8_to_lower(keyword->keyword_);
|
auto text = utf8_to_lower(keyword->keyword_);
|
||||||
vector<string> emojis = search_language_emojis(language_code, text, true);
|
vector<string> emojis = get_keyword_language_emojis(language_code, text);
|
||||||
bool is_changed = false;
|
bool is_changed = false;
|
||||||
for (auto &emoji : keyword->emoticons_) {
|
for (auto &emoji : keyword->emoticons_) {
|
||||||
if (td::remove(emojis, emoji)) {
|
if (td::remove(emojis, emoji)) {
|
||||||
@ -9888,9 +9889,8 @@ bool StickersManager::prepare_search_emoji_query(const string &text, const vecto
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
vector<string> StickersManager::search_emojis(const string &text, bool exact_match,
|
vector<string> StickersManager::search_emojis(const string &text, const vector<string> &input_language_codes,
|
||||||
const vector<string> &input_language_codes, bool force,
|
bool force, Promise<Unit> &&promise) {
|
||||||
Promise<Unit> &&promise) {
|
|
||||||
SearchEmojiQuery query;
|
SearchEmojiQuery query;
|
||||||
if (!prepare_search_emoji_query(text, input_language_codes, force, promise, query)) {
|
if (!prepare_search_emoji_query(text, input_language_codes, force, promise, query)) {
|
||||||
return {};
|
return {};
|
||||||
@ -9898,7 +9898,24 @@ vector<string> StickersManager::search_emojis(const string &text, bool exact_mat
|
|||||||
|
|
||||||
vector<string> result;
|
vector<string> result;
|
||||||
for (auto &language_code : query.language_codes_) {
|
for (auto &language_code : query.language_codes_) {
|
||||||
combine(result, search_language_emojis(language_code, query.text_, exact_match));
|
combine(result, search_language_emojis(language_code, query.text_));
|
||||||
|
}
|
||||||
|
td::unique(result);
|
||||||
|
|
||||||
|
promise.set_value(Unit());
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
vector<string> StickersManager::get_keyword_emojis(const string &text, 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, get_keyword_language_emojis(language_code, query.text_));
|
||||||
}
|
}
|
||||||
td::unique(result);
|
td::unique(result);
|
||||||
|
|
||||||
|
@ -373,8 +373,11 @@ class StickersManager final : public Actor {
|
|||||||
|
|
||||||
vector<string> get_sticker_emojis(const tl_object_ptr<td_api::InputFile> &input_file, Promise<Unit> &&promise);
|
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, const vector<string> &input_language_codes,
|
vector<string> search_emojis(const string &text, const vector<string> &input_language_codes, bool force,
|
||||||
bool force, Promise<Unit> &&promise);
|
Promise<Unit> &&promise);
|
||||||
|
|
||||||
|
vector<string> get_keyword_emojis(const string &text, const vector<string> &input_language_codes, bool force,
|
||||||
|
Promise<Unit> &&promise);
|
||||||
|
|
||||||
int64 get_emoji_suggestions_url(const string &language_code, Promise<Unit> &&promise);
|
int64 get_emoji_suggestions_url(const string &language_code, Promise<Unit> &&promise);
|
||||||
|
|
||||||
@ -947,7 +950,9 @@ class StickersManager final : public Actor {
|
|||||||
|
|
||||||
void on_get_language_codes(const string &key, Result<vector<string>> &&result);
|
void on_get_language_codes(const string &key, Result<vector<string>> &&result);
|
||||||
|
|
||||||
static vector<string> search_language_emojis(const string &language_code, const string &text, bool exact_match);
|
static vector<string> search_language_emojis(const string &language_code, const string &text);
|
||||||
|
|
||||||
|
static vector<string> get_keyword_language_emojis(const string &language_code, const string &text);
|
||||||
|
|
||||||
void load_emoji_keywords(const string &language_code, Promise<Unit> &&promise);
|
void load_emoji_keywords(const string &language_code, Promise<Unit> &&promise);
|
||||||
|
|
||||||
|
@ -2292,14 +2292,12 @@ class GetStickerEmojisRequest final : public RequestActor<> {
|
|||||||
|
|
||||||
class SearchEmojisRequest final : public RequestActor<> {
|
class SearchEmojisRequest final : public RequestActor<> {
|
||||||
string text_;
|
string text_;
|
||||||
bool exact_match_;
|
|
||||||
vector<string> input_language_codes_;
|
vector<string> input_language_codes_;
|
||||||
|
|
||||||
vector<string> emojis_;
|
vector<string> emojis_;
|
||||||
|
|
||||||
void do_run(Promise<Unit> &&promise) final {
|
void do_run(Promise<Unit> &&promise) final {
|
||||||
emojis_ = td_->stickers_manager_->search_emojis(text_, exact_match_, input_language_codes_, get_tries() < 2,
|
emojis_ = td_->stickers_manager_->search_emojis(text_, input_language_codes_, get_tries() < 2, std::move(promise));
|
||||||
std::move(promise));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void do_send_result() final {
|
void do_send_result() final {
|
||||||
@ -2307,11 +2305,33 @@ class SearchEmojisRequest final : public RequestActor<> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public:
|
public:
|
||||||
SearchEmojisRequest(ActorShared<Td> td, uint64 request_id, string &&text, bool exact_match,
|
SearchEmojisRequest(ActorShared<Td> td, uint64 request_id, string &&text, vector<string> &&input_language_codes)
|
||||||
vector<string> &&input_language_codes)
|
: RequestActor(std::move(td), request_id)
|
||||||
|
, text_(std::move(text))
|
||||||
|
, input_language_codes_(std::move(input_language_codes)) {
|
||||||
|
set_tries(3);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
class GetKeywordEmojisRequest final : public RequestActor<> {
|
||||||
|
string text_;
|
||||||
|
vector<string> input_language_codes_;
|
||||||
|
|
||||||
|
vector<string> emojis_;
|
||||||
|
|
||||||
|
void do_run(Promise<Unit> &&promise) final {
|
||||||
|
emojis_ =
|
||||||
|
td_->stickers_manager_->get_keyword_emojis(text_, input_language_codes_, get_tries() < 2, std::move(promise));
|
||||||
|
}
|
||||||
|
|
||||||
|
void do_send_result() final {
|
||||||
|
send_result(td_api::make_object<td_api::emojis>(std::move(emojis_)));
|
||||||
|
}
|
||||||
|
|
||||||
|
public:
|
||||||
|
GetKeywordEmojisRequest(ActorShared<Td> td, uint64 request_id, string &&text, vector<string> &&input_language_codes)
|
||||||
: RequestActor(std::move(td), request_id)
|
: RequestActor(std::move(td), request_id)
|
||||||
, text_(std::move(text))
|
, text_(std::move(text))
|
||||||
, exact_match_(exact_match)
|
|
||||||
, input_language_codes_(std::move(input_language_codes)) {
|
, input_language_codes_(std::move(input_language_codes)) {
|
||||||
set_tries(3);
|
set_tries(3);
|
||||||
}
|
}
|
||||||
@ -7939,8 +7959,16 @@ void Td::on_request(uint64 id, td_api::searchEmojis &request) {
|
|||||||
for (auto &input_language_code : request.input_language_codes_) {
|
for (auto &input_language_code : request.input_language_codes_) {
|
||||||
CLEAN_INPUT_STRING(input_language_code);
|
CLEAN_INPUT_STRING(input_language_code);
|
||||||
}
|
}
|
||||||
CREATE_REQUEST(SearchEmojisRequest, std::move(request.text_), request.exact_match_,
|
CREATE_REQUEST(SearchEmojisRequest, std::move(request.text_), std::move(request.input_language_codes_));
|
||||||
std::move(request.input_language_codes_));
|
}
|
||||||
|
|
||||||
|
void Td::on_request(uint64 id, td_api::getKeywordEmojis &request) {
|
||||||
|
CHECK_IS_USER();
|
||||||
|
CLEAN_INPUT_STRING(request.text_);
|
||||||
|
for (auto &input_language_code : request.input_language_codes_) {
|
||||||
|
CLEAN_INPUT_STRING(input_language_code);
|
||||||
|
}
|
||||||
|
CREATE_REQUEST(GetKeywordEmojisRequest, std::move(request.text_), std::move(request.input_language_codes_));
|
||||||
}
|
}
|
||||||
|
|
||||||
void Td::on_request(uint64 id, const td_api::getEmojiCategories &request) {
|
void Td::on_request(uint64 id, const td_api::getEmojiCategories &request) {
|
||||||
|
@ -1445,6 +1445,8 @@ class Td final : public Actor {
|
|||||||
|
|
||||||
void on_request(uint64 id, td_api::searchEmojis &request);
|
void on_request(uint64 id, td_api::searchEmojis &request);
|
||||||
|
|
||||||
|
void on_request(uint64 id, td_api::getKeywordEmojis &request);
|
||||||
|
|
||||||
void on_request(uint64 id, const td_api::getEmojiCategories &request);
|
void on_request(uint64 id, const td_api::getEmojiCategories &request);
|
||||||
|
|
||||||
void on_request(uint64 id, td_api::getAnimatedEmoji &request);
|
void on_request(uint64 id, td_api::getAnimatedEmoji &request);
|
||||||
|
@ -3454,11 +3454,13 @@ class CliClient final : public Actor {
|
|||||||
} else if (op == "gse") {
|
} else if (op == "gse") {
|
||||||
send_request(td_api::make_object<td_api::getStickerEmojis>(as_input_file_id(args)));
|
send_request(td_api::make_object<td_api::getStickerEmojis>(as_input_file_id(args)));
|
||||||
} else if (op == "se") {
|
} else if (op == "se") {
|
||||||
send_request(td_api::make_object<td_api::searchEmojis>(args, false, vector<string>()));
|
send_request(td_api::make_object<td_api::searchEmojis>(args, vector<string>()));
|
||||||
} else if (op == "see") {
|
|
||||||
send_request(td_api::make_object<td_api::searchEmojis>(args, true, vector<string>()));
|
|
||||||
} else if (op == "seru") {
|
} else if (op == "seru") {
|
||||||
send_request(td_api::make_object<td_api::searchEmojis>(args, false, vector<string>{"ru_RU"}));
|
send_request(td_api::make_object<td_api::searchEmojis>(args, vector<string>{"ru_RU"}));
|
||||||
|
} else if (op == "gke") {
|
||||||
|
send_request(td_api::make_object<td_api::getKeywordEmojis>(args, vector<string>()));
|
||||||
|
} else if (op == "gkeru") {
|
||||||
|
send_request(td_api::make_object<td_api::getKeywordEmojis>(args, vector<string>{"ru_RU"}));
|
||||||
} else if (op == "gec" || op == "geces" || op == "geccp") {
|
} else if (op == "gec" || op == "geces" || op == "geccp") {
|
||||||
auto type = [&]() -> td_api::object_ptr<td_api::EmojiCategoryType> {
|
auto type = [&]() -> td_api::object_ptr<td_api::EmojiCategoryType> {
|
||||||
if (op == "geces") {
|
if (op == "geces") {
|
||||||
|
Loading…
Reference in New Issue
Block a user