Add td_api::setDefaultMessageTtl.

This commit is contained in:
levlam 2022-11-29 18:53:36 +03:00
parent b11a5b8ad4
commit 2e163cfa7b
6 changed files with 59 additions and 0 deletions

View File

@ -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;

View File

@ -109,6 +109,36 @@ static td_api::object_ptr<td_api::session> convert_authorization_object(
authorization->country_, authorization->region_);
}
class SetDefaultHistoryTtlQuery final : public Td::ResultHandler {
Promise<Unit> promise_;
public:
explicit SetDefaultHistoryTtlQuery(Promise<Unit> &&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<telegram_api::messages_setDefaultHistoryTTL>(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<Unit> promise_;
@ -531,6 +561,10 @@ class SetBotBroadcastDefaultAdminRightsQuery final : public Td::ResultHandler {
}
};
void set_default_message_ttl(Td *td, int32 message_ttl, Promise<Unit> &&promise) {
td->create_handler<SetDefaultHistoryTtlQuery>(std::move(promise))->send(message_ttl);
}
void set_account_ttl(Td *td, int32 account_ttl, Promise<Unit> &&promise) {
td->create_handler<SetAccountTtlQuery>(std::move(promise))->send(account_ttl);
}

View File

@ -16,6 +16,8 @@ namespace td {
class Td;
void set_default_message_ttl(Td *td, int32 message_ttl, Promise<Unit> &&promise);
void set_account_ttl(Td *td, int32 account_ttl, Promise<Unit> &&promise);
void get_account_ttl(Td *td, Promise<int32> &&promise);

View File

@ -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();

View File

@ -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);

View File

@ -2518,6 +2518,10 @@ class CliClient final : public Actor {
send_request(td_api::make_object<td_api::setOption>(name, td_api::make_object<td_api::optionValueString>(value)));
} else if (op == "me") {
send_request(td_api::make_object<td_api::getMe>());
} else if (op == "sdmttl") {
int32 ttl;
get_args(args, ttl);
send_request(td_api::make_object<td_api::setDefaultMessageTtl>(td_api::make_object<td_api::messageTtl>(ttl)));
} else if (op == "sattl") {
int32 days;
get_args(args, days);