Add td_api::getDisallowedChatEmojiStatuses.

This commit is contained in:
levlam 2023-12-24 02:30:49 +03:00
parent 8090aac1c1
commit 1494d5fcdf
11 changed files with 82 additions and 11 deletions

View File

@ -769,7 +769,7 @@ profileAccentColor id:int32 light_theme_colors:profileAccentColors dark_theme_co
//@expiration_date Point in time (Unix timestamp) when the status will expire; 0 if never //@expiration_date Point in time (Unix timestamp) when the status will expire; 0 if never
emojiStatus custom_emoji_id:int64 expiration_date:int32 = EmojiStatus; emojiStatus custom_emoji_id:int64 expiration_date:int32 = EmojiStatus;
//@description Contains a list of custom emoji identifiers, which can be set as emoji statuses @custom_emoji_ids The list of custom emoji identifiers //@description Contains a list of custom emoji identifiers for emoji statuses @custom_emoji_ids The list of custom emoji identifiers
emojiStatuses custom_emoji_ids:vector<int64> = EmojiStatuses; emojiStatuses custom_emoji_ids:vector<int64> = EmojiStatuses;
@ -8281,6 +8281,9 @@ getThemedChatEmojiStatuses = EmojiStatuses;
//@description Returns default emoji statuses for chats //@description Returns default emoji statuses for chats
getDefaultChatEmojiStatuses = EmojiStatuses; getDefaultChatEmojiStatuses = EmojiStatuses;
//@description Returns the list of emoji statuses, which can't be used as chat emoji status, even they are from a sticker set with is_allowed_as_chat_emoji_status == true
getDisallowedChatEmojiStatuses = EmojiStatuses;
//@description Downloads a file from the cloud. Download progress and completion of the download will be notified through updateFile updates //@description Downloads a file from the cloud. Download progress and completion of the download will be notified through updateFile updates
//@file_id Identifier of the file to download //@file_id Identifier of the file to download

View File

@ -324,6 +324,11 @@ StringBuilder &operator<<(StringBuilder &string_builder, const EmojiStatus &emoj
return string_builder; return string_builder;
} }
td_api::object_ptr<td_api::emojiStatuses> get_emoji_statuses_object(const vector<CustomEmojiId> &custom_emoji_ids) {
return td_api::make_object<td_api::emojiStatuses>(
transform(custom_emoji_ids, [](CustomEmojiId custom_emoji_id) { return custom_emoji_id.get(); }));
}
void get_default_emoji_statuses(Td *td, Promise<td_api::object_ptr<td_api::emojiStatuses>> &&promise) { void get_default_emoji_statuses(Td *td, Promise<td_api::object_ptr<td_api::emojiStatuses>> &&promise) {
auto statuses = load_emoji_statuses(get_default_emoji_statuses_database_key()); auto statuses = load_emoji_statuses(get_default_emoji_statuses_database_key());
if (statuses.hash_ != -1 && promise) { if (statuses.hash_ != -1 && promise) {

View File

@ -99,6 +99,8 @@ inline bool operator!=(const EmojiStatus &lhs, const EmojiStatus &rhs) {
StringBuilder &operator<<(StringBuilder &string_builder, const EmojiStatus &emoji_status); StringBuilder &operator<<(StringBuilder &string_builder, const EmojiStatus &emoji_status);
td_api::object_ptr<td_api::emojiStatuses> get_emoji_statuses_object(const vector<CustomEmojiId> &custom_emoji_ids);
void get_default_emoji_statuses(Td *td, Promise<td_api::object_ptr<td_api::emojiStatuses>> &&promise); void get_default_emoji_statuses(Td *td, Promise<td_api::object_ptr<td_api::emojiStatuses>> &&promise);
void get_default_channel_emoji_statuses(Td *td, Promise<td_api::object_ptr<td_api::emojiStatuses>> &&promise); void get_default_channel_emoji_statuses(Td *td, Promise<td_api::object_ptr<td_api::emojiStatuses>> &&promise);

View File

@ -16,6 +16,8 @@ string get_sticker_list_type_database_key(StickerListType sticker_list_type) {
return "default_profile_photo_custom_emoji_ids"; return "default_profile_photo_custom_emoji_ids";
case StickerListType::Background: case StickerListType::Background:
return "default_background_custom_emoji_ids"; return "default_background_custom_emoji_ids";
case StickerListType::DisallowedChannelEmojiStatus:
return "disallowed_channel_emoji_status_custom_emoji_ids";
default: default:
UNREACHABLE(); UNREACHABLE();
return string(); return string();
@ -30,6 +32,8 @@ StringBuilder &operator<<(StringBuilder &string_builder, StickerListType sticker
return string_builder << "default user profile photo custom emoji identifiers"; return string_builder << "default user profile photo custom emoji identifiers";
case StickerListType::Background: case StickerListType::Background:
return string_builder << "default background custom emoji identifiers"; return string_builder << "default background custom emoji identifiers";
case StickerListType::DisallowedChannelEmojiStatus:
return string_builder << "disallowed chat emoji status custom emoji identifiers";
default: default:
UNREACHABLE(); UNREACHABLE();
return string_builder; return string_builder;

View File

@ -11,9 +11,9 @@
namespace td { namespace td {
enum class StickerListType : int32 { DialogPhoto, UserProfilePhoto, Background }; enum class StickerListType : int32 { DialogPhoto, UserProfilePhoto, Background, DisallowedChannelEmojiStatus };
static constexpr int32 MAX_STICKER_LIST_TYPE = 3; static constexpr int32 MAX_STICKER_LIST_TYPE = 4;
string get_sticker_list_type_database_key(StickerListType sticker_list_type); string get_sticker_list_type_database_key(StickerListType sticker_list_type);

View File

@ -14,6 +14,7 @@
#include "td/telegram/Document.h" #include "td/telegram/Document.h"
#include "td/telegram/DocumentsManager.h" #include "td/telegram/DocumentsManager.h"
#include "td/telegram/EmojiGroup.hpp" #include "td/telegram/EmojiGroup.hpp"
#include "td/telegram/EmojiStatus.h"
#include "td/telegram/FileReferenceManager.h" #include "td/telegram/FileReferenceManager.h"
#include "td/telegram/files/FileLocation.h" #include "td/telegram/files/FileLocation.h"
#include "td/telegram/files/FileManager.h" #include "td/telegram/files/FileManager.h"
@ -1472,6 +1473,9 @@ class GetDefaultDialogPhotoEmojisQuery final : public Td::ResultHandler {
case StickerListType::Background: case StickerListType::Background:
send_query(G()->net_query_creator().create(telegram_api::account_getDefaultBackgroundEmojis(hash))); send_query(G()->net_query_creator().create(telegram_api::account_getDefaultBackgroundEmojis(hash)));
break; break;
case StickerListType::DisallowedChannelEmojiStatus:
send_query(G()->net_query_creator().create(telegram_api::account_getChannelRestrictedStatusEmojis(hash)));
break;
default: default:
UNREACHABLE(); UNREACHABLE();
break; break;
@ -1485,6 +1489,9 @@ class GetDefaultDialogPhotoEmojisQuery final : public Td::ResultHandler {
static_assert(std::is_same<telegram_api::account_getDefaultBackgroundEmojis::ReturnType, static_assert(std::is_same<telegram_api::account_getDefaultBackgroundEmojis::ReturnType,
telegram_api::account_getDefaultGroupPhotoEmojis::ReturnType>::value, telegram_api::account_getDefaultGroupPhotoEmojis::ReturnType>::value,
""); "");
static_assert(std::is_same<telegram_api::account_getChannelRestrictedStatusEmojis::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());
@ -6349,7 +6356,24 @@ void StickersManager::get_default_custom_emoji_stickers(StickerListType sticker_
auto &queries = default_custom_emoji_ids_load_queries_[index]; auto &queries = default_custom_emoji_ids_load_queries_[index];
queries.push_back(std::move(promise)); queries.push_back(std::move(promise));
if (queries.size() != 1) { load_default_custom_emoji_ids(sticker_list_type, force_reload);
}
void StickersManager::get_sticker_list_emoji_statuses(StickerListType sticker_list_type, bool force_reload,
Promise<td_api::object_ptr<td_api::emojiStatuses>> &&promise) {
auto index = static_cast<int32>(sticker_list_type);
if (are_default_custom_emoji_ids_loaded_[index] && !force_reload) {
return promise.set_value(get_emoji_statuses_object(default_custom_emoji_ids_[index]));
}
auto &queries = default_emoji_statuses_load_queries_[index];
queries.push_back(std::move(promise));
load_default_custom_emoji_ids(sticker_list_type, force_reload);
}
void StickersManager::load_default_custom_emoji_ids(StickerListType sticker_list_type, bool force_reload) {
auto index = static_cast<int32>(sticker_list_type);
if (default_custom_emoji_ids_load_queries_[index].size() + default_emoji_statuses_load_queries_[index].size() != 1) {
// query has already been sent, just wait for the result // query has already been sent, just wait for the result
return; return;
} }
@ -6396,6 +6420,7 @@ void StickersManager::on_load_default_custom_emoji_ids_from_database(StickerList
if (G()->close_flag()) { if (G()->close_flag()) {
auto index = static_cast<int32>(sticker_list_type); auto index = static_cast<int32>(sticker_list_type);
fail_promises(default_custom_emoji_ids_load_queries_[index], Global::request_aborted_error()); fail_promises(default_custom_emoji_ids_load_queries_[index], Global::request_aborted_error());
fail_promises(default_emoji_statuses_load_queries_[index], Global::request_aborted_error());
return; return;
} }
@ -6421,6 +6446,7 @@ void StickersManager::reload_default_custom_emoji_ids(StickerListType sticker_li
if (G()->close_flag()) { if (G()->close_flag()) {
auto index = static_cast<int32>(sticker_list_type); auto index = static_cast<int32>(sticker_list_type);
fail_promises(default_custom_emoji_ids_load_queries_[index], Global::request_aborted_error()); fail_promises(default_custom_emoji_ids_load_queries_[index], Global::request_aborted_error());
fail_promises(default_emoji_statuses_load_queries_[index], Global::request_aborted_error());
return; return;
} }
CHECK(!td_->auth_manager_->is_bot()); CHECK(!td_->auth_manager_->is_bot());
@ -6450,6 +6476,7 @@ void StickersManager::on_get_default_custom_emoji_ids(
if (r_emoji_list.is_error()) { if (r_emoji_list.is_error()) {
fail_promises(default_custom_emoji_ids_load_queries_[index], r_emoji_list.move_as_error()); fail_promises(default_custom_emoji_ids_load_queries_[index], r_emoji_list.move_as_error());
fail_promises(default_emoji_statuses_load_queries_[index], r_emoji_list.move_as_error());
return; return;
} }
@ -6460,9 +6487,14 @@ void StickersManager::on_get_default_custom_emoji_ids(
if (!are_default_custom_emoji_ids_loaded_[index]) { if (!are_default_custom_emoji_ids_loaded_[index]) {
on_get_default_custom_emoji_ids_success(sticker_list_type, {}, 0); on_get_default_custom_emoji_ids_success(sticker_list_type, {}, 0);
} }
auto promises = std::move(default_custom_emoji_ids_load_queries_[index]); auto sticker_promises = std::move(default_custom_emoji_ids_load_queries_[index]);
auto status_promises = std::move(default_emoji_statuses_load_queries_[index]);
reset_to_empty(default_custom_emoji_ids_load_queries_[index]); reset_to_empty(default_custom_emoji_ids_load_queries_[index]);
for (auto &promise : promises) { reset_to_empty(default_emoji_statuses_load_queries_[index]);
for (auto &promise : sticker_promises) {
CHECK(!promise);
}
for (auto &promise : status_promises) {
CHECK(!promise); CHECK(!promise);
} }
return; return;
@ -6489,11 +6521,16 @@ void StickersManager::on_get_default_custom_emoji_ids_success(StickerListType st
default_custom_emoji_ids_hash_[index] = hash; default_custom_emoji_ids_hash_[index] = hash;
are_default_custom_emoji_ids_loaded_[index] = true; are_default_custom_emoji_ids_loaded_[index] = true;
auto promises = std::move(default_custom_emoji_ids_load_queries_[index]); auto sticker_promises = std::move(default_custom_emoji_ids_load_queries_[index]);
auto status_promises = std::move(default_emoji_statuses_load_queries_[index]);
reset_to_empty(default_custom_emoji_ids_load_queries_[index]); reset_to_empty(default_custom_emoji_ids_load_queries_[index]);
for (auto &promise : promises) { reset_to_empty(default_emoji_statuses_load_queries_[index]);
for (auto &promise : sticker_promises) {
get_custom_emoji_stickers_unlimited(default_custom_emoji_ids_[index], std::move(promise)); get_custom_emoji_stickers_unlimited(default_custom_emoji_ids_[index], std::move(promise));
} }
for (auto &promise : status_promises) {
promise.set_value(get_emoji_statuses_object(default_custom_emoji_ids_[index]));
}
} }
void StickersManager::get_premium_gift_option_sticker(int32 month_count, bool is_recursive, void StickersManager::get_premium_gift_option_sticker(int32 month_count, bool is_recursive,

View File

@ -141,6 +141,9 @@ class StickersManager final : public Actor {
void get_default_custom_emoji_stickers(StickerListType sticker_list_type, bool force_reload, void get_default_custom_emoji_stickers(StickerListType sticker_list_type, bool force_reload,
Promise<td_api::object_ptr<td_api::stickers>> &&promise); Promise<td_api::object_ptr<td_api::stickers>> &&promise);
void get_sticker_list_emoji_statuses(StickerListType sticker_list_type, bool force_reload,
Promise<td_api::object_ptr<td_api::emojiStatuses>> &&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);
@ -624,6 +627,8 @@ 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 load_default_custom_emoji_ids(StickerListType sticker_list_type, bool force_reload);
void on_load_default_custom_emoji_ids_from_database(StickerListType sticker_list_type, bool force_reload, void on_load_default_custom_emoji_ids_from_database(StickerListType sticker_list_type, bool force_reload,
string value); string value);
@ -1130,10 +1135,12 @@ class StickersManager final : public Actor {
vector<Promise<td_api::object_ptr<td_api::emojiCategories>>> emoji_group_load_queries_[MAX_EMOJI_GROUP_TYPE]; vector<Promise<td_api::object_ptr<td_api::emojiCategories>>> emoji_group_load_queries_[MAX_EMOJI_GROUP_TYPE];
vector<CustomEmojiId> default_custom_emoji_ids_[MAX_STICKER_LIST_TYPE]; vector<CustomEmojiId> default_custom_emoji_ids_[MAX_STICKER_LIST_TYPE];
int64 default_custom_emoji_ids_hash_[MAX_STICKER_LIST_TYPE] = {0, 0, 0}; int64 default_custom_emoji_ids_hash_[MAX_STICKER_LIST_TYPE] = {0, 0, 0, 0};
vector<Promise<td_api::object_ptr<td_api::stickers>>> default_custom_emoji_ids_load_queries_[MAX_STICKER_LIST_TYPE]; vector<Promise<td_api::object_ptr<td_api::stickers>>> default_custom_emoji_ids_load_queries_[MAX_STICKER_LIST_TYPE];
bool are_default_custom_emoji_ids_loaded_[MAX_STICKER_LIST_TYPE] = {false, false, false}; vector<Promise<td_api::object_ptr<td_api::emojiStatuses>>>
bool are_default_custom_emoji_ids_being_loaded_[MAX_STICKER_LIST_TYPE] = {false, false, false}; default_emoji_statuses_load_queries_[MAX_STICKER_LIST_TYPE];
bool are_default_custom_emoji_ids_loaded_[MAX_STICKER_LIST_TYPE] = {false, false, false, false};
bool are_default_custom_emoji_ids_being_loaded_[MAX_STICKER_LIST_TYPE] = {false, false, false, false};
WaitFreeHashMap<CustomEmojiId, FileId, CustomEmojiIdHash> custom_emoji_to_sticker_id_; WaitFreeHashMap<CustomEmojiId, FileId, CustomEmojiIdHash> custom_emoji_to_sticker_id_;

View File

@ -8103,6 +8103,13 @@ void Td::on_request(uint64 id, const td_api::getDefaultBackgroundCustomEmojiStic
stickers_manager_->get_default_custom_emoji_stickers(StickerListType::Background, false, std::move(promise)); stickers_manager_->get_default_custom_emoji_stickers(StickerListType::Background, false, std::move(promise));
} }
void Td::on_request(uint64 id, const td_api::getDisallowedChatEmojiStatuses &request) {
CHECK_IS_USER();
CREATE_REQUEST_PROMISE();
stickers_manager_->get_sticker_list_emoji_statuses(StickerListType::DisallowedChannelEmojiStatus, false,
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) {
CHECK_IS_USER(); CHECK_IS_USER();
CREATE_NO_ARGS_REQUEST(GetSavedAnimationsRequest); CREATE_NO_ARGS_REQUEST(GetSavedAnimationsRequest);

View File

@ -1431,6 +1431,8 @@ class Td final : public Actor {
void on_request(uint64 id, const td_api::getDefaultBackgroundCustomEmojiStickers &request); void on_request(uint64 id, const td_api::getDefaultBackgroundCustomEmojiStickers &request);
void on_request(uint64 id, const td_api::getDisallowedChatEmojiStatuses &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

@ -2278,6 +2278,8 @@ void UpdatesManager::try_reload_data() {
td_->stickers_manager_->reload_special_sticker_set_by_type(SpecialStickerSetType::default_topic_icons()); td_->stickers_manager_->reload_special_sticker_set_by_type(SpecialStickerSetType::default_topic_icons());
td_->stickers_manager_->get_default_custom_emoji_stickers(StickerListType::DialogPhoto, true, Auto()); td_->stickers_manager_->get_default_custom_emoji_stickers(StickerListType::DialogPhoto, true, Auto());
td_->stickers_manager_->get_default_custom_emoji_stickers(StickerListType::UserProfilePhoto, true, Auto()); td_->stickers_manager_->get_default_custom_emoji_stickers(StickerListType::UserProfilePhoto, true, Auto());
td_->stickers_manager_->get_default_custom_emoji_stickers(StickerListType::Background, true, Auto());
td_->stickers_manager_->get_sticker_list_emoji_statuses(StickerListType::DisallowedChannelEmojiStatus, true, Auto());
td_->story_manager_->reload_active_stories(); td_->story_manager_->reload_active_stories();
td_->story_manager_->reload_all_read_stories(); td_->story_manager_->reload_all_read_stories();
td_->theme_manager_->reload_accent_colors(); td_->theme_manager_->reload_accent_colors();

View File

@ -5591,6 +5591,8 @@ class CliClient final : public Actor {
send_request(td_api::make_object<td_api::getThemedChatEmojiStatuses>()); send_request(td_api::make_object<td_api::getThemedChatEmojiStatuses>());
} else if (op == "gdces") { } else if (op == "gdces") {
send_request(td_api::make_object<td_api::getDefaultChatEmojiStatuses>()); send_request(td_api::make_object<td_api::getDefaultChatEmojiStatuses>());
} else if (op == "gdices") {
send_request(td_api::make_object<td_api::getDisallowedChatEmojiStatuses>());
} else if (op == "ccun") { } else if (op == "ccun") {
ChatId chat_id; ChatId chat_id;
string username; string username;