Allow to pin chat messages only for self in private chats.

GitOrigin-RevId: 57f71b2728a47469ff8f2a53478300dd3c96f658
This commit is contained in:
levlam 2020-10-23 02:12:32 +03:00
parent 793e8409de
commit 65246318bb
8 changed files with 28 additions and 15 deletions

View File

@ -4120,8 +4120,12 @@ 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 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 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
//@only_for_self True, if the message needs to be pinned only for self; private chats only
pinChatMessage chat_id:int53 message_id:int53 disable_notification:Bool only_for_self:Bool = 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;

Binary file not shown.

View File

@ -1383,7 +1383,7 @@ messages.getSplitRanges#1cff7e08 = Vector<MessageRange>;
messages.markDialogUnread#c286d98f flags:# unread:flags.0?true peer:InputDialogPeer = Bool;
messages.getDialogUnreadMarks#22e24e22 = Vector<DialogPeer>;
messages.clearAllDrafts#7e58ee9c = Bool;
messages.updatePinnedMessage#d2aaf7ec flags:# silent:flags.0?true unpin:flags.1?true peer:InputPeer id:int = Updates;
messages.updatePinnedMessage#d2aaf7ec flags:# silent:flags.0?true unpin:flags.1?true pm_oneside:flags.2?true peer:InputPeer id:int = Updates;
messages.sendVote#10ea6184 peer:InputPeer msg_id:int options:Vector<bytes> = Updates;
messages.getPollResults#73bb643b peer:InputPeer msg_id:int = Updates;
messages.getOnlines#6e2be050 peer:InputPeer = ChatOnlines;

Binary file not shown.

View File

@ -611,7 +611,7 @@ class UpdateDialogPinnedMessageQuery : public Td::ResultHandler {
explicit UpdateDialogPinnedMessageQuery(Promise<Unit> &&promise) : promise_(std::move(promise)) {
}
void send(DialogId dialog_id, MessageId message_id, bool is_unpin, bool disable_notification) {
void send(DialogId dialog_id, MessageId message_id, bool is_unpin, bool disable_notification, bool only_for_self) {
dialog_id_ = dialog_id;
auto input_peer = td->messages_manager_->get_input_peer(dialog_id, AccessRights::Write);
if (input_peer == nullptr) {
@ -626,8 +626,12 @@ class UpdateDialogPinnedMessageQuery : public Td::ResultHandler {
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())));
if (only_for_self) {
flags |= telegram_api::messages_updatePinnedMessage::PM_ONESIDE_MASK;
}
send_query(G()->net_query_creator().create(
telegram_api::messages_updatePinnedMessage(flags, false /*ignored*/, false /*ignored*/, false /*ignored*/,
std::move(input_peer), message_id.get_server_message_id().get())));
}
void on_result(uint64 id, BufferSlice packet) override {
@ -29860,7 +29864,7 @@ Status MessagesManager::can_pin_messages(DialogId dialog_id) const {
}
void MessagesManager::pin_dialog_message(DialogId dialog_id, MessageId message_id, bool disable_notification,
bool is_unpin, Promise<Unit> &&promise) {
bool only_for_self, bool is_unpin, Promise<Unit> &&promise) {
auto d = get_dialog_force(dialog_id);
if (d == nullptr) {
return promise.set_error(Status::Error(400, "Chat not found"));
@ -29877,9 +29881,13 @@ void MessagesManager::pin_dialog_message(DialogId dialog_id, MessageId message_i
return promise.set_error(Status::Error(6, "Message can't be pinned"));
}
if (only_for_self && dialog_id.get_type() != DialogType::User) {
return promise.set_error(Status::Error(6, "Messages can't be pinned only for self in the chat"));
}
// TODO log event
td_->create_handler<UpdateDialogPinnedMessageQuery>(std::move(promise))
->send(dialog_id, message_id, is_unpin, disable_notification);
->send(dialog_id, message_id, is_unpin, disable_notification, only_for_self);
}
void MessagesManager::unpin_all_dialog_messages(DialogId dialog_id, Promise<Unit> &&promise) {

View File

@ -505,8 +505,8 @@ class MessagesManager : public Actor {
void set_dialog_permissions(DialogId dialog_id, const td_api::object_ptr<td_api::chatPermissions> &permissions,
Promise<Unit> &&promise);
void pin_dialog_message(DialogId dialog_id, MessageId message_id, bool disable_notification, bool is_unpin,
Promise<Unit> &&promise);
void pin_dialog_message(DialogId dialog_id, MessageId message_id, bool disable_notification, bool only_for_self,
bool is_unpin, Promise<Unit> &&promise);
void unpin_all_dialog_messages(DialogId dialog_id, Promise<Unit> &&promise);

View File

@ -6159,12 +6159,13 @@ void Td::on_request(uint64 id, const td_api::setChatSlowModeDelay &request) {
void Td::on_request(uint64 id, const td_api::pinChatMessage &request) {
CREATE_OK_REQUEST_PROMISE();
messages_manager_->pin_dialog_message(DialogId(request.chat_id_), MessageId(request.message_id_),
request.disable_notification_, false, std::move(promise));
request.disable_notification_, request.only_for_self_, false,
std::move(promise));
}
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(request.message_id_), false, true,
messages_manager_->pin_dialog_message(DialogId(request.chat_id_), MessageId(request.message_id_), false, false, true,
std::move(promise));
}

View File

@ -3964,13 +3964,13 @@ class CliClient final : public Actor {
std::tie(chat_id, slow_mode_delay) = split(args);
send_request(
td_api::make_object<td_api::setChatSlowModeDelay>(as_chat_id(chat_id), to_integer<int32>(slow_mode_delay)));
} else if (op == "pcm" || op == "pcms") {
} else if (op == "pcm" || op == "pcms" || op == "pcmo") {
string chat_id;
string message_id;
std::tie(chat_id, message_id) = split(args);
send_request(
td_api::make_object<td_api::pinChatMessage>(as_chat_id(chat_id), as_message_id(message_id), op == "pcms"));
send_request(td_api::make_object<td_api::pinChatMessage>(as_chat_id(chat_id), as_message_id(message_id),
op == "pcms", op == "pcmo"));
} else if (op == "upcm") {
string chat_id;
string message_id;