Support unpinning chat messages.

GitOrigin-RevId: 5cc4f2f5642114fd31c8a2ae71c8fda501dc73f7
This commit is contained in:
levlam 2020-10-20 15:48:13 +03:00
parent 01447bb3f3
commit 14f5df397d
5 changed files with 24 additions and 24 deletions

View File

@ -4124,11 +4124,11 @@ setChatLocation chat_id:int53 location:chatLocation = Ok;
//@description Changes the slow mode delay of a chat. Available only for supergroups; requires can_restrict_members rights @chat_id Chat identifier @slow_mode_delay New slow mode delay for the chat; must be one of 0, 10, 30, 60, 300, 900, 3600
setChatSlowModeDelay chat_id:int53 slow_mode_delay:int32 = Ok;
//@description Pins a message in a chat; requires can_pin_messages rights @chat_id Identifier of the chat @message_id Identifier of the new pinned message @disable_notification True, if there should be no notification about the pinned message
//@description Pins a message in a chat; requires can_pin_messages rights or can_edit_messages rights in the channel @chat_id Identifier of the chat @message_id Identifier of the new pinned message @disable_notification True, if there should be no notification about the pinned message
pinChatMessage chat_id:int53 message_id:int53 disable_notification:Bool = Ok;
//@description Removes the pinned message from a chat; requires can_pin_messages rights in the group or channel @chat_id Identifier of the chat
unpinChatMessage chat_id:int53 = Ok;
//@description Removes a pinned message from a chat; requires can_pin_messages rights in the group or can_edit_messages rights in the channel @chat_id Identifier of the chat @message_id Identifier of the removed pinned message
unpinChatMessage chat_id:int53 message_id:int53 = Ok;
//@description Adds current user as a new member to a chat. Private and secret chats can't be joined using this method @chat_id Chat identifier

Binary file not shown.

View File

@ -606,15 +606,13 @@ class GetScheduledMessagesQuery : public Td::ResultHandler {
class UpdateDialogPinnedMessageQuery : public Td::ResultHandler {
Promise<Unit> promise_;
DialogId dialog_id_;
MessageId message_id_;
public:
explicit UpdateDialogPinnedMessageQuery(Promise<Unit> &&promise) : promise_(std::move(promise)) {
}
void send(DialogId dialog_id, MessageId message_id, bool disable_notification) {
void send(DialogId dialog_id, MessageId message_id, bool is_unpin, bool disable_notification) {
dialog_id_ = dialog_id;
message_id_ = message_id;
auto input_peer = td->messages_manager_->get_input_peer(dialog_id, AccessRights::Write);
if (input_peer == nullptr) {
LOG(INFO) << "Can't update pinned message because have no write access to " << dialog_id;
@ -625,7 +623,9 @@ class UpdateDialogPinnedMessageQuery : public Td::ResultHandler {
if (disable_notification) {
flags |= telegram_api::messages_updatePinnedMessage::SILENT_MASK;
}
if (is_unpin) {
flags |= telegram_api::messages_updatePinnedMessage::UNPIN_MASK;
}
send_query(G()->net_query_creator().create(telegram_api::messages_updatePinnedMessage(
flags, false /*ignored*/, false /*ignored*/, std::move(input_peer), message_id.get_server_message_id().get())));
}
@ -645,7 +645,6 @@ class UpdateDialogPinnedMessageQuery : public Td::ResultHandler {
void on_error(uint64 id, Status status) override {
if (status.message() == "CHAT_NOT_MODIFIED") {
td->messages_manager_->on_update_dialog_pinned_message_id(dialog_id_, message_id_);
if (!td->auth_manager_->is_bot()) {
promise_.set_value(Unit());
return;
@ -29760,6 +29759,7 @@ void MessagesManager::pin_dialog_message(DialogId dialog_id, MessageId message_i
Slice action = is_unpin ? Slice("unpin") : Slice("pin");
switch (dialog_id.get_type()) {
case DialogType::User:
// OK
break;
case DialogType::Chat: {
auto chat_id = dialog_id.get_chat_id();
@ -29785,24 +29785,19 @@ void MessagesManager::pin_dialog_message(DialogId dialog_id, MessageId message_i
UNREACHABLE();
}
if (is_unpin) {
CHECK(message_id == MessageId());
} else {
if (!have_message_force({dialog_id, message_id}, "pin_dialog_message")) {
return promise.set_error(Status::Error(6, "Message not found"));
}
if (message_id.is_scheduled()) {
return promise.set_error(Status::Error(6, "Scheduled message can't be pinned"));
}
if (!message_id.is_server()) {
return promise.set_error(Status::Error(6, "Message can't be pinned"));
}
if (!have_message_force({dialog_id, message_id}, "pin_dialog_message")) {
return promise.set_error(Status::Error(6, "Message not found"));
}
if (message_id.is_scheduled()) {
return promise.set_error(Status::Error(6, "Scheduled message can't be pinned"));
}
if (!message_id.is_server()) {
return promise.set_error(Status::Error(6, "Message can't be pinned"));
}
// TODO log event
td_->create_handler<UpdateDialogPinnedMessageQuery>(std::move(promise))
->send(dialog_id, message_id, disable_notification);
->send(dialog_id, message_id, is_unpin, disable_notification);
}
void MessagesManager::add_dialog_participant(DialogId dialog_id, UserId user_id, int32 forward_limit,

View File

@ -6164,7 +6164,8 @@ void Td::on_request(uint64 id, const td_api::pinChatMessage &request) {
void Td::on_request(uint64 id, const td_api::unpinChatMessage &request) {
CREATE_OK_REQUEST_PROMISE();
messages_manager_->pin_dialog_message(DialogId(request.chat_id_), MessageId(), false, true, std::move(promise));
messages_manager_->pin_dialog_message(DialogId(request.chat_id_), MessageId(request.message_id_), false, true,
std::move(promise));
}
void Td::on_request(uint64 id, const td_api::joinChat &request) {

View File

@ -3972,7 +3972,11 @@ class CliClient final : public Actor {
send_request(
td_api::make_object<td_api::pinChatMessage>(as_chat_id(chat_id), as_message_id(message_id), op == "pcms"));
} else if (op == "upcm") {
send_request(td_api::make_object<td_api::unpinChatMessage>(as_chat_id(args)));
string chat_id;
string message_id;
std::tie(chat_id, message_id) = split(args);
send_request(td_api::make_object<td_api::unpinChatMessage>(as_chat_id(chat_id), as_message_id(message_id)));
} else if (op == "grib") {
send_request(td_api::make_object<td_api::getRecentInlineBots>());
} else if (op == "spc" || op == "su" || op == "sch") {