Add td_api::getDefaultChatEmojiStatuses.

This commit is contained in:
levlam 2023-12-22 12:29:12 +03:00
parent e2747b6c76
commit f07d21ac6b
7 changed files with 76 additions and 4 deletions

View File

@ -8259,22 +8259,25 @@ getAttachmentMenuBot bot_user_id:int53 = AttachmentMenuBot;
toggleBotIsAddedToAttachmentMenu bot_user_id:int53 is_added:Bool allow_write_access:Bool = Ok; toggleBotIsAddedToAttachmentMenu bot_user_id:int53 is_added:Bool allow_write_access:Bool = Ok;
//@description Returns up to 8 emoji statuses, which must be shown right after the default Premium Badge in the emoji status list for users //@description Returns up to 8 emoji statuses, which must be shown right after the default Premium Badge in the emoji status list for self status
getThemedEmojiStatuses = EmojiStatuses; getThemedEmojiStatuses = EmojiStatuses;
//@description Returns recent emoji statuses //@description Returns recent emoji statuses for self status
getRecentEmojiStatuses = EmojiStatuses; getRecentEmojiStatuses = EmojiStatuses;
//@description Returns default emoji statuses //@description Returns default emoji statuses for self status
getDefaultEmojiStatuses = EmojiStatuses; getDefaultEmojiStatuses = EmojiStatuses;
//@description Clears the list of recently used emoji statuses //@description Clears the list of recently used emoji statuses for self status
clearRecentEmojiStatuses = Ok; clearRecentEmojiStatuses = Ok;
//@description Returns up to 8 emoji statuses, which must be shown in the emoji status list for chats //@description Returns up to 8 emoji statuses, which must be shown in the emoji status list for chats
getThemedChatEmojiStatuses = EmojiStatuses; getThemedChatEmojiStatuses = EmojiStatuses;
//@description Returns default emoji statuses for chats
getDefaultChatEmojiStatuses = 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

@ -70,6 +70,11 @@ static const string &get_default_emoji_statuses_database_key() {
return key; return key;
} }
static const string &get_default_channel_emoji_statuses_database_key() {
static string key = "def_ch_emoji_statuses";
return key;
}
static const string &get_recent_emoji_statuses_database_key() { static const string &get_recent_emoji_statuses_database_key() {
static string key = "rec_emoji_statuses"; static string key = "rec_emoji_statuses";
return key; return key;
@ -132,6 +137,48 @@ class GetDefaultEmojiStatusesQuery final : public Td::ResultHandler {
} }
}; };
class GetChannelDefaultEmojiStatusesQuery final : public Td::ResultHandler {
Promise<td_api::object_ptr<td_api::emojiStatuses>> promise_;
public:
explicit GetChannelDefaultEmojiStatusesQuery(Promise<td_api::object_ptr<td_api::emojiStatuses>> &&promise)
: promise_(std::move(promise)) {
}
void send(int64 hash) {
send_query(G()->net_query_creator().create(telegram_api::account_getChannelDefaultEmojiStatuses(hash), {{"me"}}));
}
void on_result(BufferSlice packet) final {
auto result_ptr = fetch_result<telegram_api::account_getChannelDefaultEmojiStatuses>(packet);
if (result_ptr.is_error()) {
return on_error(result_ptr.move_as_error());
}
auto emoji_statuses_ptr = result_ptr.move_as_ok();
LOG(INFO) << "Receive result for GetChannelDefaultEmojiStatusesQuery: " << to_string(emoji_statuses_ptr);
if (emoji_statuses_ptr->get_id() == telegram_api::account_emojiStatusesNotModified::ID) {
if (promise_) {
promise_.set_error(Status::Error(500, "Receive wrong server response"));
}
return;
}
CHECK(emoji_statuses_ptr->get_id() == telegram_api::account_emojiStatuses::ID);
EmojiStatuses emoji_statuses(move_tl_object_as<telegram_api::account_emojiStatuses>(emoji_statuses_ptr));
save_emoji_statuses(get_default_channel_emoji_statuses_database_key(), emoji_statuses);
if (promise_) {
promise_.set_value(emoji_statuses.get_emoji_statuses_object());
}
}
void on_error(Status status) final {
promise_.set_error(std::move(status));
}
};
class GetRecentEmojiStatusesQuery final : public Td::ResultHandler { class GetRecentEmojiStatusesQuery final : public Td::ResultHandler {
Promise<td_api::object_ptr<td_api::emojiStatuses>> promise_; Promise<td_api::object_ptr<td_api::emojiStatuses>> promise_;
@ -286,6 +333,15 @@ void get_default_emoji_statuses(Td *td, Promise<td_api::object_ptr<td_api::emoji
td->create_handler<GetDefaultEmojiStatusesQuery>(std::move(promise))->send(statuses.hash_); td->create_handler<GetDefaultEmojiStatusesQuery>(std::move(promise))->send(statuses.hash_);
} }
void get_default_channel_emoji_statuses(Td *td, Promise<td_api::object_ptr<td_api::emojiStatuses>> &&promise) {
auto statuses = load_emoji_statuses(get_default_channel_emoji_statuses_database_key());
if (statuses.hash_ != -1 && promise) {
promise.set_value(statuses.get_emoji_statuses_object());
promise = Promise<td_api::object_ptr<td_api::emojiStatuses>>();
}
td->create_handler<GetChannelDefaultEmojiStatusesQuery>(std::move(promise))->send(statuses.hash_);
}
void get_recent_emoji_statuses(Td *td, Promise<td_api::object_ptr<td_api::emojiStatuses>> &&promise) { void get_recent_emoji_statuses(Td *td, Promise<td_api::object_ptr<td_api::emojiStatuses>> &&promise) {
auto statuses = load_emoji_statuses(get_recent_emoji_statuses_database_key()); auto statuses = load_emoji_statuses(get_recent_emoji_statuses_database_key());
if (statuses.hash_ != -1 && promise) { if (statuses.hash_ != -1 && promise) {

View File

@ -101,6 +101,8 @@ StringBuilder &operator<<(StringBuilder &string_builder, const EmojiStatus &emoj
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_recent_emoji_statuses(Td *td, Promise<td_api::object_ptr<td_api::emojiStatuses>> &&promise); void get_recent_emoji_statuses(Td *td, Promise<td_api::object_ptr<td_api::emojiStatuses>> &&promise);
void add_recent_emoji_status(Td *td, EmojiStatus emoji_status); void add_recent_emoji_status(Td *td, EmojiStatus emoji_status);

View File

@ -7468,6 +7468,12 @@ void Td::on_request(uint64 id, const td_api::getDefaultEmojiStatuses &request) {
get_default_emoji_statuses(this, std::move(promise)); get_default_emoji_statuses(this, std::move(promise));
} }
void Td::on_request(uint64 id, const td_api::getDefaultChatEmojiStatuses &request) {
CHECK_IS_USER();
CREATE_REQUEST_PROMISE();
get_default_channel_emoji_statuses(this, std::move(promise));
}
void Td::on_request(uint64 id, const td_api::getRecentEmojiStatuses &request) { void Td::on_request(uint64 id, const td_api::getRecentEmojiStatuses &request) {
CHECK_IS_USER(); CHECK_IS_USER();
CREATE_REQUEST_PROMISE(); CREATE_REQUEST_PROMISE();

View File

@ -1251,6 +1251,8 @@ class Td final : public Actor {
void on_request(uint64 id, const td_api::getDefaultEmojiStatuses &request); void on_request(uint64 id, const td_api::getDefaultEmojiStatuses &request);
void on_request(uint64 id, const td_api::getDefaultChatEmojiStatuses &request);
void on_request(uint64 id, const td_api::getRecentEmojiStatuses &request); void on_request(uint64 id, const td_api::getRecentEmojiStatuses &request);
void on_request(uint64 id, const td_api::clearRecentEmojiStatuses &request); void on_request(uint64 id, const td_api::clearRecentEmojiStatuses &request);

View File

@ -2250,6 +2250,7 @@ void UpdatesManager::try_reload_data() {
td_->contacts_manager_->reload_created_public_dialogs(PublicDialogType::HasUsername, std::move(promise)); td_->contacts_manager_->reload_created_public_dialogs(PublicDialogType::HasUsername, std::move(promise));
td_->contacts_manager_->reload_created_public_dialogs(PublicDialogType::IsLocationBased, Auto()); td_->contacts_manager_->reload_created_public_dialogs(PublicDialogType::IsLocationBased, Auto());
get_default_emoji_statuses(td_, Auto()); get_default_emoji_statuses(td_, Auto());
get_default_channel_emoji_statuses(td_, Auto());
td_->notification_settings_manager_->reload_saved_ringtones(Auto()); td_->notification_settings_manager_->reload_saved_ringtones(Auto());
td_->notification_settings_manager_->send_get_scope_notification_settings_query(NotificationSettingsScope::Private, td_->notification_settings_manager_->send_get_scope_notification_settings_query(NotificationSettingsScope::Private,
Auto()); Auto());

View File

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