Allow changing message TTL in non-secret chats.

This commit is contained in:
levlam 2021-02-09 18:51:08 +03:00
parent 5ac0a9bd8a
commit d6da217b9a
7 changed files with 56 additions and 13 deletions

View File

@ -4270,8 +4270,9 @@ setChatTitle chat_id:int53 title:string = Ok;
//@chat_id Chat identifier @photo New chat photo. Pass null to delete the chat photo
setChatPhoto chat_id:int53 photo:InputChatPhoto = Ok;
//@description Changes the message TTL setting (sets a new self-destruct timer) in a chat. Requires can_delete_messages administrator right in basic groups, supergroups and channels @chat_id Chat identifier @ttl New TTL value, in seconds
setChatMessageTtl chat_id:int53 ttl:int32 = Ok;
//@description Changes the message TTL setting (sets a new self-destruct timer) in a chat. Requires can_delete_messages administrator right in basic groups, supergroups and channels
//@chat_id Chat identifier @ttl New TTL value, in seconds; must be one of 0, 86400, 604800 unless chat is secret
setChatMessageTtlSetting chat_id:int53 ttl:int32 = Ok;
//@description Changes the chat members permissions. Supported only for basic groups and supergroups. Requires can_restrict_members administrator right
//@chat_id Chat identifier @permissions New non-administrator members permissions in the chat

Binary file not shown.

View File

@ -1329,6 +1329,47 @@ class EditDialogTitleQuery : public Td::ResultHandler {
}
};
class SetHistoryTtlQuery : public Td::ResultHandler {
Promise<Unit> promise_;
DialogId dialog_id_;
public:
explicit SetHistoryTtlQuery(Promise<Unit> &&promise) : promise_(std::move(promise)) {
}
void send(DialogId dialog_id, int32 period) {
dialog_id_ = dialog_id;
auto input_peer = td->messages_manager_->get_input_peer(dialog_id, AccessRights::Write);
CHECK(input_peer != nullptr);
send_query(G()->net_query_creator().create(telegram_api::messages_setHistoryTTL(std::move(input_peer), period)));
}
void on_result(uint64 id, BufferSlice packet) override {
auto result_ptr = fetch_result<telegram_api::messages_setHistoryTTL>(packet);
if (result_ptr.is_error()) {
return on_error(id, result_ptr.move_as_error());
}
auto ptr = result_ptr.move_as_ok();
LOG(INFO) << "Receive result for SetHistoryTtlQuery: " << to_string(ptr);
td->updates_manager_->on_get_updates(std::move(ptr), std::move(promise_));
}
void on_error(uint64 id, Status status) override {
if (status.message() == "CHAT_NOT_MODIFIED") {
if (!td->auth_manager_->is_bot()) {
promise_.set_value(Unit());
return;
}
} else {
td->messages_manager_->on_get_dialog_error(dialog_id_, status, "SetHistoryTtlQuery");
}
promise_.set_error(std::move(status));
}
};
class EditChatDefaultBannedRightsQuery : public Td::ResultHandler {
Promise<Unit> promise_;
DialogId dialog_id_;
@ -30685,7 +30726,7 @@ void MessagesManager::set_dialog_title(DialogId dialog_id, const string &title,
td_->create_handler<EditDialogTitleQuery>(std::move(promise))->send(dialog_id, new_title);
}
void MessagesManager::set_dialog_message_ttl(DialogId dialog_id, int32 ttl, Promise<Unit> &&promise) {
void MessagesManager::set_dialog_message_ttl_setting(DialogId dialog_id, int32 ttl, Promise<Unit> &&promise) {
if (ttl < 0) {
return promise.set_error(Status::Error(400, "Message TTL can't be negative"));
}
@ -30694,11 +30735,12 @@ void MessagesManager::set_dialog_message_ttl(DialogId dialog_id, int32 ttl, Prom
if (d == nullptr) {
return promise.set_error(Status::Error(400, "Chat not found"));
}
if (!have_input_peer(dialog_id, AccessRights::Write)) {
return promise.set_error(Status::Error(400, "Have no write access to the chat"));
}
LOG(INFO) << "Begin to set message TTL in " << dialog_id << " to " << ttl;
TRY_STATUS_PROMISE(promise, can_send_message(dialog_id));
switch (dialog_id.get_type()) {
case DialogType::User:
break;
@ -30725,7 +30767,8 @@ void MessagesManager::set_dialog_message_ttl(DialogId dialog_id, int32 ttl, Prom
}
if (dialog_id.get_type() != DialogType::SecretChat) {
promise.set_error(Status::Error(5, "Can't set message TTL in non-secret chat"));
// TODO invoke after
td_->create_handler<SetHistoryTtlQuery>(std::move(promise))->send(dialog_id, ttl);
} else {
bool need_update_dialog_pos = false;
Message *m = get_message_to_send(d, MessageId(), MessageId(), MessageSendOptions(),

View File

@ -388,7 +388,7 @@ class MessagesManager : public Actor {
Result<vector<MessageId>> resend_messages(DialogId dialog_id, vector<MessageId> message_ids) TD_WARN_UNUSED_RESULT;
void set_dialog_message_ttl(DialogId dialog_id, int32 ttl, Promise<Unit> &&promise);
void set_dialog_message_ttl_setting(DialogId dialog_id, int32 ttl, Promise<Unit> &&promise);
Status send_screenshot_taken_notification_message(DialogId dialog_id);

View File

@ -6113,10 +6113,9 @@ void Td::on_request(uint64 id, const td_api::setChatPhoto &request) {
messages_manager_->set_dialog_photo(DialogId(request.chat_id_), request.photo_, std::move(promise));
}
void Td::on_request(uint64 id, const td_api::setChatMessageTtl &request) {
DialogId dialog_id(request.chat_id_);
void Td::on_request(uint64 id, const td_api::setChatMessageTtlSetting &request) {
CREATE_OK_REQUEST_PROMISE();
messages_manager_->set_dialog_message_ttl(dialog_id, request.ttl_, std::move(promise));
messages_manager_->set_dialog_message_ttl_setting(DialogId(request.chat_id_), request.ttl_, std::move(promise));
}
void Td::on_request(uint64 id, const td_api::setChatPermissions &request) {

View File

@ -740,7 +740,7 @@ class Td final : public NetQueryCallback {
void on_request(uint64 id, const td_api::setChatPhoto &request);
void on_request(uint64 id, const td_api::setChatMessageTtl &request);
void on_request(uint64 id, const td_api::setChatMessageTtlSetting &request);
void on_request(uint64 id, const td_api::setChatPermissions &request);

View File

@ -3535,11 +3535,11 @@ class CliClient final : public Actor {
send_request(td_api::make_object<td_api::setChatPhoto>(
as_chat_id(chat_id), td_api::make_object<td_api::inputChatPhotoAnimation>(as_input_file(animation),
to_double(main_frame_timestamp))));
} else if (op == "scmt") {
} else if (op == "scmts") {
string chat_id;
int32 ttl;
get_args(args, chat_id, ttl);
send_request(td_api::make_object<td_api::setChatMessageTtl>(as_chat_id(chat_id), ttl));
send_request(td_api::make_object<td_api::setChatMessageTtlSetting>(as_chat_id(chat_id), ttl));
} else if (op == "scperm") {
string chat_id;
string permissions;