Add td_api::getDefaultProfilePhotoCustomEmojiStickers.

This commit is contained in:
levlam 2023-01-10 15:40:52 +03:00
parent 84077d72dc
commit 6f3d7ac308
6 changed files with 86 additions and 57 deletions

View File

@ -7192,6 +7192,9 @@ getCustomEmojiStickers custom_emoji_ids:vector<int64> = Stickers;
//@description Returns default list of custom emoji stickers for placing on a chat photo //@description Returns default list of custom emoji stickers for placing on a chat photo
getDefaultChatPhotoCustomEmojiStickers = Stickers; getDefaultChatPhotoCustomEmojiStickers = Stickers;
//@description Returns default list of custom emoji stickers for placing on a profile photo
getDefaultProfilePhotoCustomEmojiStickers = Stickers;
//@description Returns saved animations //@description Returns saved animations
getSavedAnimations = Animations; getSavedAnimations = Animations;

View File

@ -1325,11 +1325,18 @@ class GetDefaultDialogPhotoEmojisQuery final : public Td::ResultHandler {
: promise_(std::move(promise)) { : promise_(std::move(promise)) {
} }
void send(int64 hash) { void send(bool for_user, int64 hash) {
send_query(G()->net_query_creator().create(telegram_api::account_getDefaultGroupPhotoEmojis(hash))); if (for_user) {
send_query(G()->net_query_creator().create(telegram_api::account_getDefaultProfilePhotoEmojis(hash)));
} else {
send_query(G()->net_query_creator().create(telegram_api::account_getDefaultGroupPhotoEmojis(hash)));
}
} }
void on_result(BufferSlice packet) final { void on_result(BufferSlice packet) final {
static_assert(std::is_same<telegram_api::account_getDefaultProfilePhotoEmojis::ReturnType,
telegram_api::account_getDefaultGroupPhotoEmojis::ReturnType>::value,
"");
auto result_ptr = fetch_result<telegram_api::account_getDefaultGroupPhotoEmojis>(packet); auto result_ptr = fetch_result<telegram_api::account_getDefaultGroupPhotoEmojis>(packet);
if (result_ptr.is_error()) { if (result_ptr.is_error()) {
return on_error(result_ptr.move_as_error()); return on_error(result_ptr.move_as_error());
@ -6304,32 +6311,35 @@ void StickersManager::on_get_custom_emoji_documents(
promise.set_value(get_custom_emoji_stickers_object(custom_emoji_ids)); promise.set_value(get_custom_emoji_stickers_object(custom_emoji_ids));
} }
string StickersManager::get_default_dialog_photo_custom_emoji_ids_database_key() { string StickersManager::get_default_dialog_photo_custom_emoji_ids_database_key(bool for_user) {
return "default_dialog_photo_custom_emoji_ids"; return for_user ? "default_profile_photo_custom_emoji_ids" : "default_dialog_photo_custom_emoji_ids";
} }
void StickersManager::get_default_dialog_photo_custom_emoji_stickers( void StickersManager::get_default_dialog_photo_custom_emoji_stickers(
Promise<td_api::object_ptr<td_api::stickers>> &&promise) { bool for_user, Promise<td_api::object_ptr<td_api::stickers>> &&promise) {
if (are_default_dialog_photo_custom_emoji_ids_loaded_) { if (are_default_dialog_photo_custom_emoji_ids_loaded_[for_user]) {
return get_custom_emoji_stickers(default_dialog_photo_custom_emoji_ids_, true, std::move(promise)); return get_custom_emoji_stickers(default_dialog_photo_custom_emoji_ids_[for_user], true, std::move(promise));
} }
auto &queries = default_dialog_photo_custom_emoji_ids_load_queries_; auto &queries = default_dialog_photo_custom_emoji_ids_load_queries_[for_user];
queries.push_back(std::move(promise)); queries.push_back(std::move(promise));
if (queries.size() != 1) { if (queries.size() != 1) {
// query has already been sent, just wait for the result // query has already been sent, just wait for the result
return; return;
} }
if (G()->parameters().use_file_db) { if (G()->parameters().use_file_db) {
LOG(INFO) << "Trying to load chat photo custom emoji identifiers from database"; LOG(INFO) << "Trying to load " << (for_user ? "profile" : "chat")
<< " photo custom emoji identifiers from database";
return G()->td_db()->get_sqlite_pmc()->get( return G()->td_db()->get_sqlite_pmc()->get(
get_default_dialog_photo_custom_emoji_ids_database_key(), PromiseCreator::lambda([](string value) { get_default_dialog_photo_custom_emoji_ids_database_key(for_user),
PromiseCreator::lambda([for_user](string value) {
send_closure(G()->stickers_manager(), send_closure(G()->stickers_manager(),
&StickersManager::on_load_default_dialog_photo_custom_emoji_ids_from_database, std::move(value)); &StickersManager::on_load_default_dialog_photo_custom_emoji_ids_from_database, for_user,
std::move(value));
})); }));
} }
reload_default_dialog_photo_custom_emoji_ids(); reload_default_dialog_photo_custom_emoji_ids(for_user);
} }
class StickersManager::CustomEmojiIdsLogEvent { class StickersManager::CustomEmojiIdsLogEvent {
@ -6356,68 +6366,72 @@ class StickersManager::CustomEmojiIdsLogEvent {
} }
}; };
void StickersManager::on_load_default_dialog_photo_custom_emoji_ids_from_database(string value) { void StickersManager::on_load_default_dialog_photo_custom_emoji_ids_from_database(bool for_user, string value) {
if (G()->close_flag()) { if (G()->close_flag()) {
fail_promises(default_dialog_photo_custom_emoji_ids_load_queries_, G()->close_status()); fail_promises(default_dialog_photo_custom_emoji_ids_load_queries_[for_user], G()->close_status());
return; return;
} }
if (value.empty()) { if (value.empty()) {
return reload_default_dialog_photo_custom_emoji_ids(); return reload_default_dialog_photo_custom_emoji_ids(for_user);
} }
LOG(INFO) << "Successfully loaded default chat photo custom emoji identifiers of size " << value.size() LOG(INFO) << "Successfully loaded default " << (for_user ? "profile" : "chat")
<< " from database"; << " photo custom emoji identifiers of size " << value.size() << " from database";
CustomEmojiIdsLogEvent log_event; CustomEmojiIdsLogEvent log_event;
if (log_event_parse(log_event, value).is_error()) { if (log_event_parse(log_event, value).is_error()) {
LOG(ERROR) << "Delete invalid default chat photo custom emoji identifiers from database"; LOG(ERROR) << "Delete invalid default " << (for_user ? "profile" : "chat")
G()->td_db()->get_sqlite_pmc()->erase(get_default_dialog_photo_custom_emoji_ids_database_key(), Auto()); << " photo custom emoji identifiers from database";
return reload_default_dialog_photo_custom_emoji_ids(); G()->td_db()->get_sqlite_pmc()->erase(get_default_dialog_photo_custom_emoji_ids_database_key(for_user), Auto());
return reload_default_dialog_photo_custom_emoji_ids(for_user);
} }
on_get_default_dialog_photo_custom_emoji_ids_success(std::move(log_event.custom_emoji_ids_), log_event.hash_); on_get_default_dialog_photo_custom_emoji_ids_success(for_user, std::move(log_event.custom_emoji_ids_),
log_event.hash_);
} }
void StickersManager::reload_default_dialog_photo_custom_emoji_ids() { void StickersManager::reload_default_dialog_photo_custom_emoji_ids(bool for_user) {
if (are_default_dialog_photo_custom_emoji_ids_being_loaded_) { if (are_default_dialog_photo_custom_emoji_ids_being_loaded_[for_user]) {
return; return;
} }
if (G()->close_flag()) { if (G()->close_flag()) {
fail_promises(default_dialog_photo_custom_emoji_ids_load_queries_, G()->close_status()); fail_promises(default_dialog_photo_custom_emoji_ids_load_queries_[for_user], G()->close_status());
return; return;
} }
CHECK(!td_->auth_manager_->is_bot()); CHECK(!td_->auth_manager_->is_bot());
are_default_dialog_photo_custom_emoji_ids_being_loaded_ = true; are_default_dialog_photo_custom_emoji_ids_being_loaded_[for_user] = true;
auto query_promise = PromiseCreator::lambda( auto query_promise =
[actor_id = actor_id(this)](Result<telegram_api::object_ptr<telegram_api::EmojiList>> r_emoji_list) mutable { PromiseCreator::lambda([actor_id = actor_id(this), for_user](
send_closure(actor_id, &StickersManager::on_get_default_dialog_photo_custom_emoji_ids, std::move(r_emoji_list)); Result<telegram_api::object_ptr<telegram_api::EmojiList>> r_emoji_list) mutable {
send_closure(actor_id, &StickersManager::on_get_default_dialog_photo_custom_emoji_ids, for_user,
std::move(r_emoji_list));
}); });
td_->create_handler<GetDefaultDialogPhotoEmojisQuery>(std::move(query_promise)) td_->create_handler<GetDefaultDialogPhotoEmojisQuery>(std::move(query_promise))
->send(default_dialog_photo_custom_emoji_ids_hash_); ->send(for_user, default_dialog_photo_custom_emoji_ids_hash_[for_user]);
} }
void StickersManager::on_get_default_dialog_photo_custom_emoji_ids( void StickersManager::on_get_default_dialog_photo_custom_emoji_ids(
Result<telegram_api::object_ptr<telegram_api::EmojiList>> r_emoji_list) { bool for_user, Result<telegram_api::object_ptr<telegram_api::EmojiList>> r_emoji_list) {
CHECK(are_default_dialog_photo_custom_emoji_ids_being_loaded_); CHECK(are_default_dialog_photo_custom_emoji_ids_being_loaded_[for_user]);
are_default_dialog_photo_custom_emoji_ids_being_loaded_ = false; are_default_dialog_photo_custom_emoji_ids_being_loaded_[for_user] = false;
if (G()->close_flag()) { if (G()->close_flag()) {
r_emoji_list = G()->close_status(); r_emoji_list = G()->close_status();
} }
if (r_emoji_list.is_error()) { if (r_emoji_list.is_error()) {
fail_promises(default_dialog_photo_custom_emoji_ids_load_queries_, r_emoji_list.move_as_error()); fail_promises(default_dialog_photo_custom_emoji_ids_load_queries_[for_user], r_emoji_list.move_as_error());
return; return;
} }
auto emoji_list_ptr = r_emoji_list.move_as_ok(); auto emoji_list_ptr = r_emoji_list.move_as_ok();
int32 constructor_id = emoji_list_ptr->get_id(); int32 constructor_id = emoji_list_ptr->get_id();
if (constructor_id == telegram_api::emojiListNotModified::ID) { if (constructor_id == telegram_api::emojiListNotModified::ID) {
LOG(INFO) << "Default chat photo custom emoji identifiers aren't modified"; LOG(INFO) << "Default " << (for_user ? "profile" : "chat") << " photo custom emoji identifiers aren't modified";
if (!are_default_dialog_photo_custom_emoji_ids_loaded_) { if (!are_default_dialog_photo_custom_emoji_ids_loaded_[for_user]) {
on_get_default_dialog_photo_custom_emoji_ids_success({}, 0); on_get_default_dialog_photo_custom_emoji_ids_success(for_user, {}, 0);
} }
CHECK(default_dialog_photo_custom_emoji_ids_load_queries_.empty()); CHECK(default_dialog_photo_custom_emoji_ids_load_queries_[for_user].empty());
return; return;
} }
CHECK(constructor_id == telegram_api::emojiList::ID); CHECK(constructor_id == telegram_api::emojiList::ID);
@ -6427,21 +6441,22 @@ void StickersManager::on_get_default_dialog_photo_custom_emoji_ids(
auto hash = emoji_list->hash_; auto hash = emoji_list->hash_;
CustomEmojiIdsLogEvent log_event(custom_emoji_ids, hash); CustomEmojiIdsLogEvent log_event(custom_emoji_ids, hash);
G()->td_db()->get_sqlite_pmc()->set(get_default_dialog_photo_custom_emoji_ids_database_key(), G()->td_db()->get_sqlite_pmc()->set(get_default_dialog_photo_custom_emoji_ids_database_key(for_user),
log_event_store(log_event).as_slice().str(), Auto()); log_event_store(log_event).as_slice().str(), Auto());
on_get_default_dialog_photo_custom_emoji_ids_success(std::move(custom_emoji_ids), hash); on_get_default_dialog_photo_custom_emoji_ids_success(for_user, std::move(custom_emoji_ids), hash);
} }
void StickersManager::on_get_default_dialog_photo_custom_emoji_ids_success(vector<CustomEmojiId> custom_emoji_ids, void StickersManager::on_get_default_dialog_photo_custom_emoji_ids_success(bool for_user,
vector<CustomEmojiId> custom_emoji_ids,
int64 hash) { int64 hash) {
default_dialog_photo_custom_emoji_ids_ = std::move(custom_emoji_ids); default_dialog_photo_custom_emoji_ids_[for_user] = std::move(custom_emoji_ids);
default_dialog_photo_custom_emoji_ids_hash_ = hash; default_dialog_photo_custom_emoji_ids_hash_[for_user] = hash;
are_default_dialog_photo_custom_emoji_ids_loaded_ = true; are_default_dialog_photo_custom_emoji_ids_loaded_[for_user] = true;
auto promises = std::move(default_dialog_photo_custom_emoji_ids_load_queries_); auto promises = std::move(default_dialog_photo_custom_emoji_ids_load_queries_[for_user]);
for (auto &promise : promises) { for (auto &promise : promises) {
get_custom_emoji_stickers(default_dialog_photo_custom_emoji_ids_, true, std::move(promise)); get_custom_emoji_stickers(default_dialog_photo_custom_emoji_ids_[for_user], true, std::move(promise));
} }
} }

View File

@ -122,7 +122,8 @@ class StickersManager final : public Actor {
void get_custom_emoji_stickers(vector<CustomEmojiId> custom_emoji_ids, bool use_database, void get_custom_emoji_stickers(vector<CustomEmojiId> custom_emoji_ids, bool use_database,
Promise<td_api::object_ptr<td_api::stickers>> &&promise); Promise<td_api::object_ptr<td_api::stickers>> &&promise);
void get_default_dialog_photo_custom_emoji_stickers(Promise<td_api::object_ptr<td_api::stickers>> &&promise); void get_default_dialog_photo_custom_emoji_stickers(bool for_user,
Promise<td_api::object_ptr<td_api::stickers>> &&promise);
void get_premium_gift_option_sticker(int32 month_count, bool is_recursive, void get_premium_gift_option_sticker(int32 month_count, bool is_recursive,
Promise<td_api::object_ptr<td_api::sticker>> &&promise); Promise<td_api::object_ptr<td_api::sticker>> &&promise);
@ -640,14 +641,15 @@ class StickersManager final : public Actor {
void on_load_custom_emoji_from_database(CustomEmojiId custom_emoji_id, string value); void on_load_custom_emoji_from_database(CustomEmojiId custom_emoji_id, string value);
void on_load_default_dialog_photo_custom_emoji_ids_from_database(string value); void on_load_default_dialog_photo_custom_emoji_ids_from_database(bool for_user, string value);
void reload_default_dialog_photo_custom_emoji_ids(); void reload_default_dialog_photo_custom_emoji_ids(bool for_user);
void on_get_default_dialog_photo_custom_emoji_ids( void on_get_default_dialog_photo_custom_emoji_ids(
Result<telegram_api::object_ptr<telegram_api::EmojiList>> r_emoji_list); bool for_user, Result<telegram_api::object_ptr<telegram_api::EmojiList>> r_emoji_list);
void on_get_default_dialog_photo_custom_emoji_ids_success(vector<CustomEmojiId> custom_emoji_ids, int64 hash); void on_get_default_dialog_photo_custom_emoji_ids_success(bool for_user, vector<CustomEmojiId> custom_emoji_ids,
int64 hash);
FileId on_get_sticker(unique_ptr<Sticker> new_sticker, bool replace); FileId on_get_sticker(unique_ptr<Sticker> new_sticker, bool replace);
@ -945,7 +947,7 @@ class StickersManager final : public Actor {
static string get_emoji_language_codes_database_key(const vector<string> &language_codes); static string get_emoji_language_codes_database_key(const vector<string> &language_codes);
static string get_default_dialog_photo_custom_emoji_ids_database_key(); static string get_default_dialog_photo_custom_emoji_ids_database_key(bool for_user);
int32 get_emoji_language_code_version(const string &language_code); int32 get_emoji_language_code_version(const string &language_code);
@ -1152,11 +1154,11 @@ class StickersManager final : public Actor {
string emoji_sounds_str_; string emoji_sounds_str_;
FlatHashMap<string, FileId> emoji_sounds_; FlatHashMap<string, FileId> emoji_sounds_;
vector<CustomEmojiId> default_dialog_photo_custom_emoji_ids_; vector<CustomEmojiId> default_dialog_photo_custom_emoji_ids_[2];
int64 default_dialog_photo_custom_emoji_ids_hash_ = 0; int64 default_dialog_photo_custom_emoji_ids_hash_[2] = {0, 0};
vector<Promise<td_api::object_ptr<td_api::stickers>>> default_dialog_photo_custom_emoji_ids_load_queries_; vector<Promise<td_api::object_ptr<td_api::stickers>>> default_dialog_photo_custom_emoji_ids_load_queries_[2];
bool are_default_dialog_photo_custom_emoji_ids_loaded_ = false; bool are_default_dialog_photo_custom_emoji_ids_loaded_[2] = {false, false};
bool are_default_dialog_photo_custom_emoji_ids_being_loaded_ = false; bool are_default_dialog_photo_custom_emoji_ids_being_loaded_[2] = {false, false};
WaitFreeHashMap<CustomEmojiId, FileId, CustomEmojiIdHash> custom_emoji_to_sticker_id_; WaitFreeHashMap<CustomEmojiId, FileId, CustomEmojiIdHash> custom_emoji_to_sticker_id_;

View File

@ -7337,7 +7337,12 @@ void Td::on_request(uint64 id, const td_api::getCustomEmojiStickers &request) {
void Td::on_request(uint64 id, const td_api::getDefaultChatPhotoCustomEmojiStickers &request) { void Td::on_request(uint64 id, const td_api::getDefaultChatPhotoCustomEmojiStickers &request) {
CREATE_REQUEST_PROMISE(); CREATE_REQUEST_PROMISE();
stickers_manager_->get_default_dialog_photo_custom_emoji_stickers(std::move(promise)); stickers_manager_->get_default_dialog_photo_custom_emoji_stickers(false, std::move(promise));
}
void Td::on_request(uint64 id, const td_api::getDefaultProfilePhotoCustomEmojiStickers &request) {
CREATE_REQUEST_PROMISE();
stickers_manager_->get_default_dialog_photo_custom_emoji_stickers(true, std::move(promise));
} }
void Td::on_request(uint64 id, const td_api::getSavedAnimations &request) { void Td::on_request(uint64 id, const td_api::getSavedAnimations &request) {

View File

@ -1212,6 +1212,8 @@ class Td final : public Actor {
void on_request(uint64 id, const td_api::getDefaultChatPhotoCustomEmojiStickers &request); void on_request(uint64 id, const td_api::getDefaultChatPhotoCustomEmojiStickers &request);
void on_request(uint64 id, const td_api::getDefaultProfilePhotoCustomEmojiStickers &request);
void on_request(uint64 id, const td_api::getFavoriteStickers &request); void on_request(uint64 id, const td_api::getFavoriteStickers &request);
void on_request(uint64 id, td_api::addFavoriteSticker &request); void on_request(uint64 id, td_api::addFavoriteSticker &request);

View File

@ -2904,6 +2904,8 @@ class CliClient final : public Actor {
send_request(td_api::make_object<td_api::getCustomEmojiStickers>(to_integers<int64>(args))); send_request(td_api::make_object<td_api::getCustomEmojiStickers>(to_integers<int64>(args)));
} else if (op == "gdcpces") { } else if (op == "gdcpces") {
send_request(td_api::make_object<td_api::getDefaultChatPhotoCustomEmojiStickers>()); send_request(td_api::make_object<td_api::getDefaultChatPhotoCustomEmojiStickers>());
} else if (op == "gdppces") {
send_request(td_api::make_object<td_api::getDefaultProfilePhotoCustomEmojiStickers>());
} else if (op == "gsan") { } else if (op == "gsan") {
send_request(td_api::make_object<td_api::getSavedAnimations>()); send_request(td_api::make_object<td_api::getSavedAnimations>());
} else if (op == "asan") { } else if (op == "asan") {