Add StickersManager::reload_found_stickers helper.

This commit is contained in:
levlam 2023-01-23 19:58:34 +03:00
parent 94819c2218
commit b6fc03e3bb
2 changed files with 11 additions and 10 deletions

View File

@ -214,7 +214,7 @@ class SearchStickersQuery final : public Td::ResultHandler {
string emoji_; string emoji_;
public: public:
void send(string emoji, int64 hash) { void send(string &&emoji, int64 hash) {
emoji_ = std::move(emoji); emoji_ = std::move(emoji);
send_query(G()->net_query_creator().create(telegram_api::messages_getStickers(emoji_, hash))); send_query(G()->net_query_creator().create(telegram_api::messages_getStickers(emoji_, hash)));
} }
@ -4746,11 +4746,8 @@ void StickersManager::search_stickers(string emoji, int32 limit,
auto &promises = search_stickers_queries_[emoji]; auto &promises = search_stickers_queries_[emoji];
promises.emplace_back(limit, std::move(promise)); promises.emplace_back(limit, std::move(promise));
if (promises.size() == 1u) { if (promises.size() == 1u) {
int64 hash = 0;
if (it != found_stickers_.end()) { if (it != found_stickers_.end()) {
hash = get_recent_stickers_hash(it->second.sticker_ids_); return reload_found_stickers(std::move(emoji), get_recent_stickers_hash(it->second.sticker_ids_));
td_->create_handler<SearchStickersQuery>()->send(std::move(emoji), hash);
return;
} }
if (G()->parameters().use_file_db) { if (G()->parameters().use_file_db) {
@ -4761,11 +4758,15 @@ void StickersManager::search_stickers(string emoji, int32 limit,
std::move(emoji), std::move(value)); std::move(emoji), std::move(value));
})); }));
} else { } else {
td_->create_handler<SearchStickersQuery>()->send(std::move(emoji), 0); return reload_found_stickers(std::move(emoji), 0);
} }
} }
} }
void StickersManager::reload_found_stickers(string &&emoji, int64 hash) {
td_->create_handler<SearchStickersQuery>()->send(std::move(emoji), hash);
}
void StickersManager::on_load_found_stickers_from_database(string emoji, string value) { void StickersManager::on_load_found_stickers_from_database(string emoji, string value) {
if (G()->close_flag()) { if (G()->close_flag()) {
on_search_stickers_failed(emoji, G()->close_status()); on_search_stickers_failed(emoji, G()->close_status());
@ -4773,8 +4774,7 @@ void StickersManager::on_load_found_stickers_from_database(string emoji, string
} }
if (value.empty()) { if (value.empty()) {
LOG(INFO) << "Stickers for " << emoji << " aren't found in database"; LOG(INFO) << "Stickers for " << emoji << " aren't found in database";
td_->create_handler<SearchStickersQuery>()->send(std::move(emoji), 0); return reload_found_stickers(std::move(emoji), 0);
return;
} }
LOG(INFO) << "Successfully loaded stickers for " << emoji << " from database"; LOG(INFO) << "Successfully loaded stickers for " << emoji << " from database";
@ -4785,8 +4785,7 @@ void StickersManager::on_load_found_stickers_from_database(string emoji, string
if (status.is_error()) { if (status.is_error()) {
LOG(ERROR) << "Can't load stickers for emoji: " << status << ' ' << format::as_hex_dump<4>(Slice(value)); LOG(ERROR) << "Can't load stickers for emoji: " << status << ' ' << format::as_hex_dump<4>(Slice(value));
found_stickers_.erase(emoji); found_stickers_.erase(emoji);
td_->create_handler<SearchStickersQuery>()->send(std::move(emoji), 0); return reload_found_stickers(std::move(emoji), 0);
return;
} }
on_search_stickers_finished(emoji, found_stickers); on_search_stickers_finished(emoji, found_stickers);

View File

@ -633,6 +633,8 @@ class StickersManager final : public Actor {
static string get_found_stickers_database_key(const string &emoji); static string get_found_stickers_database_key(const string &emoji);
void reload_found_stickers(string &&emoji, int64 hash);
void on_load_found_stickers_from_database(string emoji, string value); void on_load_found_stickers_from_database(string emoji, string value);
void on_search_stickers_finished(const string &emoji, const FoundStickers &found_stickers); void on_search_stickers_finished(const string &emoji, const FoundStickers &found_stickers);