Replace toggleChatIsBlocked with toggleMessageSenderIsBlocked.

GitOrigin-RevId: cec3ba4ba139593e8cbf9422711e79b4a736b6f3
This commit is contained in:
levlam 2020-10-18 01:54:32 +03:00
parent 62fbb88969
commit 0834d6164b
7 changed files with 53 additions and 24 deletions

View File

@ -4073,9 +4073,6 @@ setChatNotificationSettings chat_id:int53 notification_settings:chatNotification
//@description Changes the marked as unread state of a chat @chat_id Chat identifier @is_marked_as_unread New value of is_marked_as_unread
toggleChatIsMarkedAsUnread chat_id:int53 is_marked_as_unread:Bool = Ok;
//@description Changes the block state of a chat. Currently, only private chats and supergroups can be blocked @chat_id Chat identifier @is_blocked New value of is_blocked
toggleChatIsBlocked chat_id:int53 is_blocked:Bool = Ok;
//@description Changes the value of the default disable_notification parameter, used when a message is sent to a chat @chat_id Chat identifier @default_disable_notification New value of default_disable_notification
toggleChatDefaultDisableNotification chat_id:int53 default_disable_notification:Bool = Ok;
@ -4239,6 +4236,9 @@ sendCallRating call_id:int32 rating:int32 comment:string problems:vector<CallPro
sendCallDebugInformation call_id:int32 debug_information:string = Ok;
//@description Changes the block state of a message sender. Currently, only users and supergroup chats can be blocked @sender Message Sender @is_blocked New value of is_blocked
toggleMessageSenderIsBlocked sender:MessageSender is_blocked:Bool = Ok;
//@description Blocks an original sender of a message in the Replies chat
//@message_id The identifier of an incoming message in the Replies chat
//@delete_message Pass true if the message must be deleted

Binary file not shown.

View File

@ -17990,27 +17990,50 @@ void MessagesManager::toggle_dialog_is_marked_as_unread_on_server(DialogId dialo
->send(dialog_id, is_marked_as_unread);
}
Status MessagesManager::toggle_dialog_is_blocked(DialogId dialog_id, bool is_blocked) {
Dialog *d = get_dialog_force(dialog_id);
if (d == nullptr) {
return Status::Error(6, "Chat not found");
Status MessagesManager::toggle_message_sender_is_blocked(const td_api::object_ptr<td_api::MessageSender> &sender,
bool is_blocked) {
if (sender == nullptr) {
return Status::Error(400, "Message sender must be non-empty");
}
if (dialog_id.get_type() == DialogType::SecretChat) {
auto user_id = td_->contacts_manager_->get_secret_chat_user_id(dialog_id.get_secret_chat_id());
dialog_id = DialogId(user_id);
d = get_dialog_force(dialog_id);
if (d == nullptr) {
return Status::Error(6, "Chat info not found");
DialogId dialog_id;
switch (sender->get_id()) {
case td_api::messageSenderUser::ID: {
auto sender_user_id = UserId(static_cast<const td_api::messageSenderUser *>(sender.get())->user_id_);
if (!td_->contacts_manager_->have_user_force(sender_user_id)) {
return Status::Error(400, "Sender user not found");
}
dialog_id = DialogId(sender_user_id);
break;
}
case td_api::messageSenderChat::ID: {
auto sender_dialog_id = DialogId(static_cast<const td_api::messageSenderChat *>(sender.get())->chat_id_);
if (!have_dialog_force(sender_dialog_id)) {
return Status::Error(400, "Sender chat not found");
}
if (sender_dialog_id.get_type() != DialogType::Channel) {
return Status::Error(400, "Sender chat must be a supergroup or channel");
}
dialog_id = sender_dialog_id;
break;
}
default:
UNREACHABLE();
}
if (dialog_id == get_my_dialog_id()) {
return Status::Error(5, is_blocked ? Slice("Can't block self") : Slice("Can't unblock self"));
}
if (is_blocked == d->is_blocked) {
return Status::OK();
Dialog *d = get_dialog_force(dialog_id);
if (d != nullptr) {
if (is_blocked == d->is_blocked) {
return Status::OK();
}
set_dialog_is_blocked(d, is_blocked);
} else {
CHECK(dialog_id.get_type() == DialogType::User);
td_->contacts_manager_->on_update_user_is_blocked(dialog_id.get_user_id(), is_blocked);
}
set_dialog_is_blocked(d, is_blocked);
toggle_dialog_is_blocked_on_server(dialog_id, is_blocked, 0);
return Status::OK();
@ -28185,6 +28208,8 @@ void MessagesManager::set_dialog_is_blocked(Dialog *d, bool is_blocked) {
make_tl_object<td_api::updateChatIsBlocked>(d->dialog_id.get(), is_blocked));
if (d->dialog_id.get_type() == DialogType::User) {
td_->contacts_manager_->on_update_user_is_blocked(d->dialog_id.get_user_id(), is_blocked);
if (d->know_action_bar) {
if (is_blocked) {
if (d->can_report_spam || d->can_share_phone_number || d->can_block_user || d->can_add_contact ||
@ -35131,8 +35156,10 @@ void MessagesManager::on_binlog_events(vector<BinlogEvent> &&events) {
log_event_parse(log_event, event.data_).ensure();
auto dialog_id = log_event.dialog_id_;
Dialog *d = get_dialog_force(dialog_id);
if (d == nullptr || !have_input_peer(dialog_id, AccessRights::Read)) {
bool have_info = dialog_id.get_type() == DialogType::User
? td_->contacts_manager_->have_user_force(dialog_id.get_user_id())
: have_dialog_force(dialog_id);
if (!have_info || !have_input_peer(dialog_id, AccessRights::Know)) {
binlog_erase(G()->td_db()->get_binlog(), event.id_);
break;
}

View File

@ -646,7 +646,8 @@ class MessagesManager : public Actor {
Status toggle_dialog_is_marked_as_unread(DialogId dialog_id, bool is_marked_as_unread) TD_WARN_UNUSED_RESULT;
Status toggle_dialog_is_blocked(DialogId dialog_id, bool is_blocked) TD_WARN_UNUSED_RESULT;
Status toggle_message_sender_is_blocked(const td_api::object_ptr<td_api::MessageSender> &sender,
bool is_blocked) TD_WARN_UNUSED_RESULT;
Status toggle_dialog_silent_send_message(DialogId dialog_id, bool silent_send_message) TD_WARN_UNUSED_RESULT;

View File

@ -6085,9 +6085,9 @@ void Td::on_request(uint64 id, const td_api::toggleChatIsMarkedAsUnread &request
request.is_marked_as_unread_));
}
void Td::on_request(uint64 id, const td_api::toggleChatIsBlocked &request) {
void Td::on_request(uint64 id, const td_api::toggleMessageSenderIsBlocked &request) {
CHECK_IS_USER();
answer_ok_query(id, messages_manager_->toggle_dialog_is_blocked(DialogId(request.chat_id_), request.is_blocked_));
answer_ok_query(id, messages_manager_->toggle_message_sender_is_blocked(request.sender_, request.is_blocked_));
}
void Td::on_request(uint64 id, const td_api::toggleChatDefaultDisableNotification &request) {

View File

@ -717,7 +717,7 @@ class Td final : public NetQueryCallback {
void on_request(uint64 id, const td_api::toggleChatIsMarkedAsUnread &request);
void on_request(uint64 id, const td_api::toggleChatIsBlocked &request);
void on_request(uint64 id, const td_api::toggleMessageSenderIsBlocked &request);
void on_request(uint64 id, const td_api::toggleChatDefaultDisableNotification &request);

View File

@ -2939,11 +2939,12 @@ class CliClient final : public Actor {
std::tie(chat_id, is_marked_as_read) = split(args);
send_request(
td_api::make_object<td_api::toggleChatIsMarkedAsUnread>(as_chat_id(chat_id), as_bool(is_marked_as_read)));
} else if (op == "tcib") {
} else if (op == "tmsib") {
string chat_id;
string is_blocked;
std::tie(chat_id, is_blocked) = split(args);
send_request(td_api::make_object<td_api::toggleChatIsBlocked>(as_chat_id(chat_id), as_bool(is_blocked)));
send_request(
td_api::make_object<td_api::toggleMessageSenderIsBlocked>(as_message_sender(chat_id), as_bool(is_blocked)));
} else if (op == "bmsfr") {
string message_id;
string delete_message;