Return GlobalPrivacySettings from get_global_privacy_settings.

This commit is contained in:
levlam 2024-01-09 15:14:45 +03:00
parent b2f8a8e5d6
commit 9802119ff7
3 changed files with 14 additions and 10 deletions

View File

@ -21,11 +21,10 @@
namespace td { namespace td {
class GetGlobalPrivacySettingsQuery final : public Td::ResultHandler { class GetGlobalPrivacySettingsQuery final : public Td::ResultHandler {
Promise<td_api::object_ptr<td_api::archiveChatListSettings>> promise_; Promise<GlobalPrivacySettings> promise_;
public: public:
explicit GetGlobalPrivacySettingsQuery(Promise<td_api::object_ptr<td_api::archiveChatListSettings>> &&promise) explicit GetGlobalPrivacySettingsQuery(Promise<GlobalPrivacySettings> &&promise) : promise_(std::move(promise)) {
: promise_(std::move(promise)) {
} }
void send() { void send() {
@ -38,8 +37,7 @@ class GetGlobalPrivacySettingsQuery final : public Td::ResultHandler {
return on_error(result_ptr.move_as_error()); return on_error(result_ptr.move_as_error());
} }
auto settings = GlobalPrivacySettings(result_ptr.move_as_ok()); promise_.set_value(GlobalPrivacySettings(result_ptr.move_as_ok()));
promise_.set_value(settings.get_archive_chat_list_settings_object());
} }
void on_error(Status status) final { void on_error(Status status) final {
@ -109,8 +107,7 @@ td_api::object_ptr<td_api::archiveChatListSettings> GlobalPrivacySettings::get_a
keep_archived_unmuted_, keep_archived_folders_); keep_archived_unmuted_, keep_archived_folders_);
} }
void GlobalPrivacySettings::get_global_privacy_settings( void GlobalPrivacySettings::get_global_privacy_settings(Td *td, Promise<GlobalPrivacySettings> &&promise) {
Td *td, Promise<td_api::object_ptr<td_api::archiveChatListSettings>> &&promise) {
td->create_handler<GetGlobalPrivacySettingsQuery>(std::move(promise))->send(); td->create_handler<GetGlobalPrivacySettingsQuery>(std::move(promise))->send();
} }

View File

@ -30,8 +30,7 @@ class GlobalPrivacySettings {
td_api::object_ptr<td_api::archiveChatListSettings> get_archive_chat_list_settings_object() const; td_api::object_ptr<td_api::archiveChatListSettings> get_archive_chat_list_settings_object() const;
static void get_global_privacy_settings(Td *td, static void get_global_privacy_settings(Td *td, Promise<GlobalPrivacySettings> &&promise);
Promise<td_api::object_ptr<td_api::archiveChatListSettings>> &&promise);
static void set_global_privacy_settings(Td *td, GlobalPrivacySettings settings, Promise<Unit> &&promise); static void set_global_privacy_settings(Td *td, GlobalPrivacySettings settings, Promise<Unit> &&promise);
}; };

View File

@ -6468,7 +6468,15 @@ void Td::on_request(uint64 id, const td_api::processChatFolderNewChats &request)
void Td::on_request(uint64 id, const td_api::getArchiveChatListSettings &request) { void Td::on_request(uint64 id, const td_api::getArchiveChatListSettings &request) {
CHECK_IS_USER(); CHECK_IS_USER();
CREATE_REQUEST_PROMISE(); CREATE_REQUEST_PROMISE();
GlobalPrivacySettings::get_global_privacy_settings(this, std::move(promise)); auto query_promise =
PromiseCreator::lambda([promise = std::move(promise)](Result<GlobalPrivacySettings> result) mutable {
if (result.is_error()) {
promise.set_error(result.move_as_error());
} else {
promise.set_value(result.ok().get_archive_chat_list_settings_object());
}
});
GlobalPrivacySettings::get_global_privacy_settings(this, std::move(query_promise));
} }
void Td::on_request(uint64 id, td_api::setArchiveChatListSettings &request) { void Td::on_request(uint64 id, td_api::setArchiveChatListSettings &request) {