From db5a7bb198224eb3de6b67135399330d805748f3 Mon Sep 17 00:00:00 2001 From: levlam Date: Tue, 29 Nov 2022 19:51:33 +0300 Subject: [PATCH] Add td_api::getDefaultMessageTtl. --- td/generate/scheme/td_api.tl | 3 +++ td/telegram/Account.cpp | 32 ++++++++++++++++++++++++++++++++ td/telegram/Account.h | 2 ++ td/telegram/Td.cpp | 13 +++++++++++++ td/telegram/Td.h | 2 ++ td/telegram/cli.cpp | 2 ++ 6 files changed, 54 insertions(+) diff --git a/td/generate/scheme/td_api.tl b/td/generate/scheme/td_api.tl index 3a383ae98..15b9efcd6 100644 --- a/td/generate/scheme/td_api.tl +++ b/td/generate/scheme/td_api.tl @@ -6600,6 +6600,9 @@ deleteAccount reason:string password:string = Ok; //@description Changes the default message Time To Live setting (self-destruct timer) for new chats @ttl New account TTL; must be from 0 up to 365 * 86400 and be divisible by 86400 setDefaultMessageTtl ttl:messageTtl = Ok; +//@description Returns default message Time To Live setting (self-destruct timer) for new chats +getDefaultMessageTtl = MessageTtl; + //@description Removes a chat action bar without any other action @chat_id Chat identifier removeChatActionBar chat_id:int53 = Ok; diff --git a/td/telegram/Account.cpp b/td/telegram/Account.cpp index d39f7079f..2eed622c3 100644 --- a/td/telegram/Account.cpp +++ b/td/telegram/Account.cpp @@ -139,6 +139,34 @@ class SetDefaultHistoryTtlQuery final : public Td::ResultHandler { } }; +class GetDefaultHistoryTtlQuery final : public Td::ResultHandler { + Promise promise_; + + public: + explicit GetDefaultHistoryTtlQuery(Promise &&promise) : promise_(std::move(promise)) { + } + + void send() { + send_query(G()->net_query_creator().create(telegram_api::messages_getDefaultHistoryTTL())); + } + + void on_result(BufferSlice packet) final { + auto result_ptr = fetch_result(packet); + if (result_ptr.is_error()) { + return on_error(result_ptr.move_as_error()); + } + + auto ptr = result_ptr.move_as_ok(); + LOG(INFO) << "Receive result for GetDefaultHistoryTtlQuery: " << to_string(ptr); + + promise_.set_value(std::move(ptr->period_)); + } + + void on_error(Status status) final { + promise_.set_error(std::move(status)); + } +}; + class SetAccountTtlQuery final : public Td::ResultHandler { Promise promise_; @@ -565,6 +593,10 @@ void set_default_message_ttl(Td *td, int32 message_ttl, Promise &&promise) td->create_handler(std::move(promise))->send(message_ttl); } +void get_default_message_ttl(Td *td, Promise &&promise) { + td->create_handler(std::move(promise))->send(); +} + void set_account_ttl(Td *td, int32 account_ttl, Promise &&promise) { td->create_handler(std::move(promise))->send(account_ttl); } diff --git a/td/telegram/Account.h b/td/telegram/Account.h index 5cfa3b4ae..993bed710 100644 --- a/td/telegram/Account.h +++ b/td/telegram/Account.h @@ -18,6 +18,8 @@ class Td; void set_default_message_ttl(Td *td, int32 message_ttl, Promise &&promise); +void get_default_message_ttl(Td *td, Promise &&promise); + void set_account_ttl(Td *td, int32 account_ttl, Promise &&promise); void get_account_ttl(Td *td, Promise &&promise); diff --git a/td/telegram/Td.cpp b/td/telegram/Td.cpp index 13c423bd7..2bbf370a8 100644 --- a/td/telegram/Td.cpp +++ b/td/telegram/Td.cpp @@ -4462,6 +4462,19 @@ void Td::on_request(uint64 id, td_api::setUserPrivacySettingRules &request) { std::move(promise)); } +void Td::on_request(uint64 id, const td_api::getDefaultMessageTtl &request) { + CHECK_IS_USER(); + CREATE_REQUEST_PROMISE(); + auto query_promise = PromiseCreator::lambda([promise = std::move(promise)](Result result) mutable { + if (result.is_error()) { + promise.set_error(result.move_as_error()); + } else { + promise.set_value(td_api::make_object(result.ok())); + } + }); + get_default_message_ttl(this, std::move(query_promise)); +} + void Td::on_request(uint64 id, const td_api::setDefaultMessageTtl &request) { CHECK_IS_USER(); if (request.ttl_ == nullptr) { diff --git a/td/telegram/Td.h b/td/telegram/Td.h index e5ca73fd0..ea1726360 100644 --- a/td/telegram/Td.h +++ b/td/telegram/Td.h @@ -470,6 +470,8 @@ class Td final : public Actor { void on_request(uint64 id, td_api::setUserPrivacySettingRules &request); + void on_request(uint64 id, const td_api::getDefaultMessageTtl &request); + void on_request(uint64 id, const td_api::setDefaultMessageTtl &request); void on_request(uint64 id, const td_api::getAccountTtl &request); diff --git a/td/telegram/cli.cpp b/td/telegram/cli.cpp index 17be3f976..46abbd7cc 100644 --- a/td/telegram/cli.cpp +++ b/td/telegram/cli.cpp @@ -2522,6 +2522,8 @@ class CliClient final : public Actor { int32 ttl; get_args(args, ttl); send_request(td_api::make_object(td_api::make_object(ttl))); + } else if (op == "gdmttl") { + send_request(td_api::make_object()); } else if (op == "sattl") { int32 days; get_args(args, days);