From 2e163cfa7bb7ad6e41b090ae394d8955a52b3093 Mon Sep 17 00:00:00 2001 From: levlam Date: Tue, 29 Nov 2022 18:53:36 +0300 Subject: [PATCH] Add td_api::setDefaultMessageTtl. --- td/generate/scheme/td_api.tl | 8 ++++++++ td/telegram/Account.cpp | 34 ++++++++++++++++++++++++++++++++++ td/telegram/Account.h | 2 ++ td/telegram/Td.cpp | 9 +++++++++ td/telegram/Td.h | 2 ++ td/telegram/cli.cpp | 4 ++++ 6 files changed, 59 insertions(+) diff --git a/td/generate/scheme/td_api.tl b/td/generate/scheme/td_api.tl index f39aeffa0..3a383ae98 100644 --- a/td/generate/scheme/td_api.tl +++ b/td/generate/scheme/td_api.tl @@ -3649,6 +3649,10 @@ userPrivacySettingAllowPrivateVoiceAndVideoNoteMessages = UserPrivacySetting; accountTtl days:int32 = AccountTtl; +//@description Contains default message Time To Live setting (self-destruct timer) for new chats @ttl Message TTL setting, in seconds +messageTtl ttl:int32 = MessageTtl; + + //@class SessionType @description Represents the type of a session //@description The session is running on an Android device @@ -6593,6 +6597,10 @@ getAccountTtl = AccountTtl; 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 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 94921c845..d39f7079f 100644 --- a/td/telegram/Account.cpp +++ b/td/telegram/Account.cpp @@ -109,6 +109,36 @@ static td_api::object_ptr convert_authorization_object( authorization->country_, authorization->region_); } +class SetDefaultHistoryTtlQuery final : public Td::ResultHandler { + Promise promise_; + + public: + explicit SetDefaultHistoryTtlQuery(Promise &&promise) : promise_(std::move(promise)) { + } + + void send(int32 account_ttl) { + send_query(G()->net_query_creator().create(telegram_api::messages_setDefaultHistoryTTL(account_ttl), {{"me"}})); + } + + 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()); + } + + bool result = result_ptr.move_as_ok(); + if (!result) { + return on_error(Status::Error(500, "Internal Server Error: failed to set default message TTL")); + } + + promise_.set_value(Unit()); + } + + void on_error(Status status) final { + promise_.set_error(std::move(status)); + } +}; + class SetAccountTtlQuery final : public Td::ResultHandler { Promise promise_; @@ -531,6 +561,10 @@ class SetBotBroadcastDefaultAdminRightsQuery final : public Td::ResultHandler { } }; +void set_default_message_ttl(Td *td, int32 message_ttl, Promise &&promise) { + td->create_handler(std::move(promise))->send(message_ttl); +} + 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 cca9d9f37..5cfa3b4ae 100644 --- a/td/telegram/Account.h +++ b/td/telegram/Account.h @@ -16,6 +16,8 @@ namespace td { class Td; +void set_default_message_ttl(Td *td, int32 message_ttl, 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 e66c5b21b..13c423bd7 100644 --- a/td/telegram/Td.cpp +++ b/td/telegram/Td.cpp @@ -4462,6 +4462,15 @@ void Td::on_request(uint64 id, td_api::setUserPrivacySettingRules &request) { std::move(promise)); } +void Td::on_request(uint64 id, const td_api::setDefaultMessageTtl &request) { + CHECK_IS_USER(); + if (request.ttl_ == nullptr) { + return send_error_raw(id, 400, "New default message TTL must be non-empty"); + } + CREATE_OK_REQUEST_PROMISE(); + set_default_message_ttl(this, request.ttl_->ttl_, std::move(promise)); +} + void Td::on_request(uint64 id, const td_api::getAccountTtl &request) { CHECK_IS_USER(); CREATE_REQUEST_PROMISE(); diff --git a/td/telegram/Td.h b/td/telegram/Td.h index 0c7075db1..e5ca73fd0 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::setDefaultMessageTtl &request); + void on_request(uint64 id, const td_api::getAccountTtl &request); void on_request(uint64 id, const td_api::setAccountTtl &request); diff --git a/td/telegram/cli.cpp b/td/telegram/cli.cpp index 37a069c27..17be3f976 100644 --- a/td/telegram/cli.cpp +++ b/td/telegram/cli.cpp @@ -2518,6 +2518,10 @@ class CliClient final : public Actor { send_request(td_api::make_object(name, td_api::make_object(value))); } else if (op == "me") { send_request(td_api::make_object()); + } else if (op == "sdmttl") { + int32 ttl; + get_args(args, ttl); + send_request(td_api::make_object(td_api::make_object(ttl))); } else if (op == "sattl") { int32 days; get_args(args, days);