Replace td_api::sendChatSetTtlMessage with td_api::setChatMessageTtl.

This commit is contained in:
levlam 2021-02-05 14:21:16 +03:00
parent 9d9e093640
commit 313a58b952
7 changed files with 77 additions and 58 deletions

View File

@ -3996,9 +3996,6 @@ forwardMessages chat_id:int53 from_chat_id:int53 message_ids:vector<int53> optio
//@chat_id Identifier of the chat to send messages @message_ids Identifiers of the messages to resend. Message identifiers must be in a strictly increasing order
resendMessages chat_id:int53 message_ids:vector<int53> = Messages;
//@description Changes the current TTL setting (sets a new self-destruct timer) in a secret chat and sends the corresponding message @chat_id Chat identifier @ttl New TTL value, in seconds
sendChatSetTtlMessage chat_id:int53 ttl:int32 = Message;
//@description Sends a notification about a screenshot taken in a chat. Supported only in private and secret chats @chat_id Chat identifier
sendChatScreenshotTakenNotification chat_id:int53 = Ok;
@ -4266,6 +4263,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 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
setChatPermissions chat_id:int53 permissions:chatPermissions = Ok;

Binary file not shown.

View File

@ -26261,40 +26261,6 @@ Result<vector<MessageId>> MessagesManager::resend_messages(DialogId dialog_id, v
return result;
}
Result<MessageId> MessagesManager::send_dialog_set_ttl_message(DialogId dialog_id, int32 ttl) {
if (dialog_id.get_type() != DialogType::SecretChat) {
return Status::Error(5, "Can't set message TTL in non-secret chat");
}
if (ttl < 0) {
return Status::Error(5, "Message TTL can't be negative");
}
LOG(INFO) << "Begin to set message TTL in " << dialog_id << " to " << ttl;
Dialog *d = get_dialog_force(dialog_id);
if (d == nullptr) {
return Status::Error(5, "Chat not found");
}
TRY_STATUS(can_send_message(dialog_id));
bool need_update_dialog_pos = false;
Message *m = get_message_to_send(d, MessageId(), MessageId(), MessageSendOptions(),
create_chat_set_ttl_message_content(ttl), &need_update_dialog_pos);
send_update_new_message(d, m);
if (need_update_dialog_pos) {
send_update_chat_last_message(d, "send_dialog_set_ttl_message");
}
int64 random_id = begin_send_message(dialog_id, m);
send_closure(td_->secret_chats_manager_, &SecretChatsManager::send_set_ttl_message, dialog_id.get_secret_chat_id(),
ttl, random_id, Promise<>()); // TODO Promise
return m->message_id;
}
Status MessagesManager::send_screenshot_taken_notification_message(DialogId dialog_id) {
auto dialog_type = dialog_id.get_type();
if (dialog_type != DialogType::User && dialog_type != DialogType::SecretChat) {
@ -30630,6 +30596,64 @@ 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) {
if (ttl < 0) {
return promise.set_error(Status::Error(400, "Message TTL can't be negative"));
}
Dialog *d = get_dialog_force(dialog_id);
if (d == nullptr) {
return promise.set_error(Status::Error(400, "Chat not found"));
}
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;
case DialogType::Chat: {
auto chat_id = dialog_id.get_chat_id();
auto status = td_->contacts_manager_->get_chat_permissions(chat_id);
if (!status.can_delete_messages()) {
return promise.set_error(Status::Error(400, "Not enough rights to set message TTL in the chat"));
}
break;
}
case DialogType::Channel: {
auto status = td_->contacts_manager_->get_channel_permissions(dialog_id.get_channel_id());
if (!status.can_change_info_and_settings()) {
return promise.set_error(Status::Error(400, "Not enough rights to set message TTL in the chat"));
}
break;
}
case DialogType::SecretChat:
break;
case DialogType::None:
default:
UNREACHABLE();
}
if (dialog_id.get_type() != DialogType::SecretChat) {
promise.set_error(Status::Error(5, "Can't set message TTL in non-secret chat"));
} else {
bool need_update_dialog_pos = false;
Message *m = get_message_to_send(d, MessageId(), MessageId(), MessageSendOptions(),
create_chat_set_ttl_message_content(ttl), &need_update_dialog_pos);
send_update_new_message(d, m);
if (need_update_dialog_pos) {
send_update_chat_last_message(d, "send_dialog_set_ttl_message");
}
int64 random_id = begin_send_message(dialog_id, m);
send_closure(td_->secret_chats_manager_, &SecretChatsManager::send_set_ttl_message, dialog_id.get_secret_chat_id(),
ttl, random_id, std::move(promise));
}
}
void MessagesManager::set_dialog_permissions(DialogId dialog_id,
const td_api::object_ptr<td_api::chatPermissions> &permissions,
Promise<Unit> &&promise) {

View File

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

View File

@ -5674,18 +5674,6 @@ void Td::on_request(uint64 id, td_api::sendInlineQueryResultMessage &request) {
messages_manager_->get_message_object({dialog_id, r_new_message_id.ok()}));
}
void Td::on_request(uint64 id, const td_api::sendChatSetTtlMessage &request) {
DialogId dialog_id(request.chat_id_);
auto r_new_message_id = messages_manager_->send_dialog_set_ttl_message(dialog_id, request.ttl_);
if (r_new_message_id.is_error()) {
return send_closure(actor_id(this), &Td::send_error, id, r_new_message_id.move_as_error());
}
CHECK(r_new_message_id.ok().is_valid());
send_closure(actor_id(this), &Td::send_result, id,
messages_manager_->get_message_object({dialog_id, r_new_message_id.ok()}));
}
void Td::on_request(uint64 id, td_api::addLocalMessage &request) {
CHECK_IS_USER();
@ -6125,6 +6113,12 @@ 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_);
CREATE_OK_REQUEST_PROMISE();
messages_manager_->set_dialog_message_ttl(dialog_id, request.ttl_, std::move(promise));
}
void Td::on_request(uint64 id, const td_api::setChatPermissions &request) {
CREATE_OK_REQUEST_PROMISE();
messages_manager_->set_dialog_permissions(DialogId(request.chat_id_), request.permissions_, std::move(promise));

View File

@ -624,8 +624,6 @@ class Td final : public NetQueryCallback {
void on_request(uint64 id, td_api::sendInlineQueryResultMessage &request);
void on_request(uint64 id, const td_api::sendChatSetTtlMessage &request);
void on_request(uint64 id, td_api::addLocalMessage &request);
void on_request(uint64 id, td_api::editMessageText &request);
@ -742,6 +740,8 @@ 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::setChatPermissions &request);
void on_request(uint64 id, td_api::setChatDraftMessage &request);

View File

@ -2600,11 +2600,6 @@ class CliClient final : public Actor {
send_request(td_api::make_object<td_api::createNewSecretChat>(as_user_id(args)));
} else if (op == "scstn") {
send_request(td_api::make_object<td_api::sendChatScreenshotTakenNotification>(as_chat_id(args)));
} else if (op == "sscttl" || op == "setSecretChatTtl") {
string chat_id;
int32 ttl;
get_args(args, chat_id, ttl);
send_request(td_api::make_object<td_api::sendChatSetTtlMessage>(as_chat_id(chat_id), ttl));
} else if (op == "closeSC" || op == "cancelSC") {
send_request(td_api::make_object<td_api::closeSecretChat>(as_secret_chat_id(args)));
} else if (op == "cc" || op == "CreateCall") {
@ -2747,7 +2742,8 @@ class CliClient final : public Actor {
string chat_id;
string administrator_user_id;
get_args(args, chat_id, administrator_user_id);
send_request(td_api::make_object<td_api::deleteAllRevokedChatInviteLinks>(as_chat_id(chat_id), as_user_id(administrator_user_id)));
send_request(td_api::make_object<td_api::deleteAllRevokedChatInviteLinks>(as_chat_id(chat_id),
as_user_id(administrator_user_id)));
} else if (op == "ccil") {
send_request(td_api::make_object<td_api::checkChatInviteLink>(args));
} else if (op == "jcbil") {
@ -3539,6 +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") {
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));
} else if (op == "scperm") {
string chat_id;
string permissions;