From 65246318bbde934f83567de84ab096f7f9ea3a43 Mon Sep 17 00:00:00 2001 From: levlam Date: Fri, 23 Oct 2020 02:12:32 +0300 Subject: [PATCH] Allow to pin chat messages only for self in private chats. GitOrigin-RevId: 57f71b2728a47469ff8f2a53478300dd3c96f658 --- td/generate/scheme/td_api.tl | 8 ++++++-- td/generate/scheme/td_api.tlo | Bin 185120 -> 185160 bytes td/generate/scheme/telegram_api.tl | 2 +- td/generate/scheme/telegram_api.tlo | Bin 218284 -> 218328 bytes td/telegram/MessagesManager.cpp | 18 +++++++++++++----- td/telegram/MessagesManager.h | 4 ++-- td/telegram/Td.cpp | 5 +++-- td/telegram/cli.cpp | 6 +++--- 8 files changed, 28 insertions(+), 15 deletions(-) diff --git a/td/generate/scheme/td_api.tl b/td/generate/scheme/td_api.tl index c328a02ce..767d5d37e 100644 --- a/td/generate/scheme/td_api.tl +++ b/td/generate/scheme/td_api.tl @@ -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; diff --git a/td/generate/scheme/td_api.tlo b/td/generate/scheme/td_api.tlo index 7fcaed7b22d3e0da191ef90f6beda1e22f7d00a2..1fced662939fea566685171273a58a2c83ea5580 100644 GIT binary patch delta 61 zcmZ3mjQhkg?uHh|ElfF$EbF7)E2kGUGD%DqImPHReSrv*fdFrQUQT6vT7FS{acWK) R1H*I!1ty*C5=~4TfdIFS6mb9m delta 44 zcmV+{0Mq}-rVF5^3xI?Hv;u5_1mVK(-j{HJ0vMOrpaLkDuz>; messages.markDialogUnread#c286d98f flags:# unread:flags.0?true peer:InputDialogPeer = Bool; messages.getDialogUnreadMarks#22e24e22 = Vector; 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 = Updates; messages.getPollResults#73bb643b peer:InputPeer msg_id:int = Updates; messages.getOnlines#6e2be050 peer:InputPeer = ChatOnlines; diff --git a/td/generate/scheme/telegram_api.tlo b/td/generate/scheme/telegram_api.tlo index 818e4f17ebb1bef0d8eb749c1d1009281eaa9ef5..9b8820048286f4ed96392897c269516508e88125 100644 GIT binary patch delta 61 zcmV-D0K)&QsSVhv4S<9JgaWh!EH#%nz5*gyY^8f$< diff --git a/td/telegram/MessagesManager.cpp b/td/telegram/MessagesManager.cpp index eea7b4ca4..fbcac1b02 100644 --- a/td/telegram/MessagesManager.cpp +++ b/td/telegram/MessagesManager.cpp @@ -611,7 +611,7 @@ class UpdateDialogPinnedMessageQuery : public Td::ResultHandler { explicit UpdateDialogPinnedMessageQuery(Promise &&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 &&promise) { + bool only_for_self, bool is_unpin, Promise &&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(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 &&promise) { diff --git a/td/telegram/MessagesManager.h b/td/telegram/MessagesManager.h index e76c423b2..17ddce4ef 100644 --- a/td/telegram/MessagesManager.h +++ b/td/telegram/MessagesManager.h @@ -505,8 +505,8 @@ class MessagesManager : public Actor { void set_dialog_permissions(DialogId dialog_id, const td_api::object_ptr &permissions, Promise &&promise); - void pin_dialog_message(DialogId dialog_id, MessageId message_id, bool disable_notification, bool is_unpin, - Promise &&promise); + void pin_dialog_message(DialogId dialog_id, MessageId message_id, bool disable_notification, bool only_for_self, + bool is_unpin, Promise &&promise); void unpin_all_dialog_messages(DialogId dialog_id, Promise &&promise); diff --git a/td/telegram/Td.cpp b/td/telegram/Td.cpp index 44af288f4..476cf5b15 100644 --- a/td/telegram/Td.cpp +++ b/td/telegram/Td.cpp @@ -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)); } diff --git a/td/telegram/cli.cpp b/td/telegram/cli.cpp index 5ef88add6..8601d636c 100644 --- a/td/telegram/cli.cpp +++ b/td/telegram/cli.cpp @@ -3964,13 +3964,13 @@ class CliClient final : public Actor { std::tie(chat_id, slow_mode_delay) = split(args); send_request( td_api::make_object(as_chat_id(chat_id), to_integer(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(as_chat_id(chat_id), as_message_id(message_id), op == "pcms")); + send_request(td_api::make_object(as_chat_id(chat_id), as_message_id(message_id), + op == "pcms", op == "pcmo")); } else if (op == "upcm") { string chat_id; string message_id;