Allow changing message TTL in non-secret chats.
This commit is contained in:
parent
5ac0a9bd8a
commit
d6da217b9a
|
@ -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
|
//@chat_id Chat identifier @photo New chat photo. Pass null to delete the chat photo
|
||||||
setChatPhoto chat_id:int53 photo:InputChatPhoto = Ok;
|
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
|
//@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
|
||||||
setChatMessageTtl chat_id:int53 ttl:int32 = Ok;
|
//@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
|
//@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
|
//@chat_id Chat identifier @permissions New non-administrator members permissions in the chat
|
||||||
|
|
Binary file not shown.
|
@ -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 {
|
class EditChatDefaultBannedRightsQuery : public Td::ResultHandler {
|
||||||
Promise<Unit> promise_;
|
Promise<Unit> promise_;
|
||||||
DialogId dialog_id_;
|
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);
|
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) {
|
if (ttl < 0) {
|
||||||
return promise.set_error(Status::Error(400, "Message TTL can't be negative"));
|
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) {
|
if (d == nullptr) {
|
||||||
return promise.set_error(Status::Error(400, "Chat not found"));
|
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;
|
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()) {
|
switch (dialog_id.get_type()) {
|
||||||
case DialogType::User:
|
case DialogType::User:
|
||||||
break;
|
break;
|
||||||
|
@ -30725,7 +30767,8 @@ void MessagesManager::set_dialog_message_ttl(DialogId dialog_id, int32 ttl, Prom
|
||||||
}
|
}
|
||||||
|
|
||||||
if (dialog_id.get_type() != DialogType::SecretChat) {
|
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 {
|
} else {
|
||||||
bool need_update_dialog_pos = false;
|
bool need_update_dialog_pos = false;
|
||||||
Message *m = get_message_to_send(d, MessageId(), MessageId(), MessageSendOptions(),
|
Message *m = get_message_to_send(d, MessageId(), MessageId(), MessageSendOptions(),
|
||||||
|
|
|
@ -388,7 +388,7 @@ class MessagesManager : public Actor {
|
||||||
|
|
||||||
Result<vector<MessageId>> resend_messages(DialogId dialog_id, vector<MessageId> message_ids) TD_WARN_UNUSED_RESULT;
|
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);
|
Status send_screenshot_taken_notification_message(DialogId dialog_id);
|
||||||
|
|
||||||
|
|
|
@ -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));
|
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) {
|
void Td::on_request(uint64 id, const td_api::setChatMessageTtlSetting &request) {
|
||||||
DialogId dialog_id(request.chat_id_);
|
|
||||||
CREATE_OK_REQUEST_PROMISE();
|
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) {
|
void Td::on_request(uint64 id, const td_api::setChatPermissions &request) {
|
||||||
|
|
|
@ -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::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);
|
void on_request(uint64 id, const td_api::setChatPermissions &request);
|
||||||
|
|
||||||
|
|
|
@ -3535,11 +3535,11 @@ class CliClient final : public Actor {
|
||||||
send_request(td_api::make_object<td_api::setChatPhoto>(
|
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),
|
as_chat_id(chat_id), td_api::make_object<td_api::inputChatPhotoAnimation>(as_input_file(animation),
|
||||||
to_double(main_frame_timestamp))));
|
to_double(main_frame_timestamp))));
|
||||||
} else if (op == "scmt") {
|
} else if (op == "scmts") {
|
||||||
string chat_id;
|
string chat_id;
|
||||||
int32 ttl;
|
int32 ttl;
|
||||||
get_args(args, chat_id, 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") {
|
} else if (op == "scperm") {
|
||||||
string chat_id;
|
string chat_id;
|
||||||
string permissions;
|
string permissions;
|
||||||
|
|
Loading…
Reference in New Issue
Block a user