From 3bca7b1448ba85fef2cf04cedd84f02e114db153 Mon Sep 17 00:00:00 2001 From: levlam Date: Fri, 9 Aug 2019 20:28:49 +0300 Subject: [PATCH] Add send_copy to inputMessageForwarded. GitOrigin-RevId: 7327021564789e8ff436e2f56f243684b7ce8183 --- td/generate/scheme/td_api.tl | 7 ++- td/generate/scheme/td_api.tlo | Bin 157212 -> 157288 bytes td/telegram/MessageContent.cpp | 18 ++++++-- td/telegram/MessageContent.h | 2 + td/telegram/MessagesManager.cpp | 78 +++++++++++++++++++++++++------- td/telegram/MessagesManager.h | 6 +-- td/telegram/cli.cpp | 5 +- 7 files changed, 88 insertions(+), 28 deletions(-) diff --git a/td/generate/scheme/td_api.tl b/td/generate/scheme/td_api.tl index a4fd5ad3..16a8f063 100644 --- a/td/generate/scheme/td_api.tl +++ b/td/generate/scheme/td_api.tl @@ -1447,8 +1447,11 @@ inputMessageInvoice invoice:invoice title:string description:string photo_url:st //@description A message with a poll. Polls can't be sent to private or secret chats @question Poll question, 1-255 characters @options List of poll answer options, 2-10 strings 1-100 characters each inputMessagePoll question:string options:vector = InputMessageContent; -//@description A forwarded message @from_chat_id Identifier for the chat this forwarded message came from @message_id Identifier of the message to forward @in_game_share True, if a game message should be shared within a launched game; applies only to game messages -inputMessageForwarded from_chat_id:int53 message_id:int53 in_game_share:Bool = InputMessageContent; +//@description A forwarded message @from_chat_id Identifier for the chat this forwarded message came from @message_id Identifier of the message to forward +//@in_game_share True, if a game message should be shared within a launched game; applies only to game messages +//@send_copy True, if content of the message needs to be copied without a link to the original message. Always true if the message is forwarded to a secret chat +//@remove_caption True, if media caption of the message copy needs to be removed. Ignored if send_copy is false +inputMessageForwarded from_chat_id:int53 message_id:int53 in_game_share:Bool send_copy:Bool remove_caption:Bool = InputMessageContent; //@class SearchMessagesFilter @description Represents a filter for message search results diff --git a/td/generate/scheme/td_api.tlo b/td/generate/scheme/td_api.tlo index 18347e838aa0115944a94ff7cdab198434f756d7..2e794bb64ebe9a71ec09016778bc0b2a3692a97f 100644 GIT binary patch delta 682 zcmbPphV#W4&J7OyEK}!r3U7AdKave$@l;Pxgs>LOnZpQSIn3JuVNG5zM`5$f0u>}) z%0d$)-kwEEka#UibeO;z`Z^MaKDNa7-^_aO1Utl>fMCabKIfEeen zt^>k2vrYrT__6K|gmGiN3Yalz!wZPOn++PAAV1zbCgj6B*|17_@|sx!lN+|GOwQQ| zQ95}Fl(BiwMiHoWS2jWA{%o28F=xtVh{)zWn^T~QRJKBG57;^fqUZxmL}nXQWY0E) z^-Pl;pLkC$(Byz9cG(WK)(k)oM-1*Ijvsl~;K>8Wn{MdgV_ zDXA$846vYLo&5Hb{&azbjH;6}cPmdfC}3or-us%-A8cdujNRL3>}H(83g&G$ILIiV z#0s`$y5dPjh3%=28Lc4>nLZ(cNpbtpCyd^(lyFaByUBCL7^piJ0J&RUFq(uy1K^&* QavnP-h~#zwdnO)r0Qe*f_y7O^ delta 687 zcmaEHhI7st&J7OyEXSUl6W{E@e2Y{1u96q zl!YcpygiGSAn{t3=rDmz0PDN5tN=+aV+B;-<^?MQkiD zT?d45W}OBn$OAWz3Hh*1H$1|qK6%0{mdOoUJth~dPl2epv0eqtn6%*qMBvQ^geK<6 zhE>v&*USQR}Tvk{_n@)Rgz^PY_&PzPMu1eN=kNXjF|o(;GDaGnYsz diff --git a/td/telegram/MessageContent.cpp b/td/telegram/MessageContent.cpp index 90ad6bea..5572001d 100644 --- a/td/telegram/MessageContent.cpp +++ b/td/telegram/MessageContent.cpp @@ -2113,6 +2113,9 @@ static tl_object_ptr get_input_media(const MessageCont } case MessageContentType::Game: { auto m = static_cast(content); + if (!m->game.get_bot_user_id().is_valid()) { + return nullptr; + } return m->game.get_input_media_game(td); } case MessageContentType::Invoice: { @@ -2680,6 +2683,15 @@ int32 get_message_content_live_location_period(const MessageContent *content) { } } +UserId get_message_content_game_bot_user_id(const MessageContent *content) { + switch (content->get_type()) { + case MessageContentType::Game: + return static_cast(content)->game.get_bot_user_id(); + default: + return UserId(); + } +} + bool get_message_content_poll_is_closed(const Td *td, const MessageContent *content) { switch (content->get_type()) { case MessageContentType::Poll: @@ -3159,11 +3171,7 @@ void merge_message_contents(Td *td, const MessageContent *old_content, MessageCo auto old_ = static_cast(old_content); auto new_ = static_cast(new_content); if (old_->poll_id != new_->poll_id) { - if (!PollManager::is_local_poll_id(old_->poll_id)) { - LOG(ERROR) << "Poll id has changed from " << old_->poll_id << " to " << new_->poll_id; - } - // polls are updated in a different way - is_content_changed = true; + need_update = true; } break; } diff --git a/td/telegram/MessageContent.h b/td/telegram/MessageContent.h index 15dbbed8..7574e078 100644 --- a/td/telegram/MessageContent.h +++ b/td/telegram/MessageContent.h @@ -175,6 +175,8 @@ vector get_message_content_added_user_ids(const MessageContent *content) UserId get_message_content_deleted_user_id(const MessageContent *content); +UserId get_message_content_game_bot_user_id(const MessageContent *content); + int32 get_message_content_live_location_period(const MessageContent *content); bool get_message_content_poll_is_closed(const Td *td, const MessageContent *content); diff --git a/td/telegram/MessagesManager.cpp b/td/telegram/MessagesManager.cpp index 87701f4d..927b23bb 100644 --- a/td/telegram/MessagesManager.cpp +++ b/td/telegram/MessagesManager.cpp @@ -15840,6 +15840,9 @@ Status MessagesManager::can_send_message_content(DialogId dialog_id, const Messa if (!can_send_games) { return Status::Error(400, "Not enough rights to send games to the chat"); } + if (!is_forward && !get_message_content_game_bot_user_id(content).is_valid()) { + return Status::Error(400, "Games can't be copied"); + } break; case MessageContentType::Invoice: if (!is_forward) { @@ -16196,7 +16199,8 @@ Result MessagesManager::send_message(DialogId dialog_id, MessageId re if (input_message_content->get_id() == td_api::inputMessageForwarded::ID) { auto input_message = static_cast(input_message_content.get()); return forward_message(dialog_id, DialogId(input_message->from_chat_id_), MessageId(input_message->message_id_), - disable_notification, from_background, input_message->in_game_share_); + disable_notification, from_background, input_message->in_game_share_, + input_message->send_copy_, input_message->remove_caption_); } Dialog *d = get_dialog_force(dialog_id); @@ -16239,9 +16243,45 @@ Result MessagesManager::send_message(DialogId dialog_id, MessageId re } Result MessagesManager::process_input_message_content( - DialogId dialog_id, tl_object_ptr &&input_message_content) const { + DialogId dialog_id, tl_object_ptr &&input_message_content) { if (input_message_content == nullptr) { - return Status::Error(5, "Can't send message without content"); + return Status::Error(400, "Can't send message without content"); + } + + if (input_message_content->get_id() == td_api::inputMessageForwarded::ID) { + auto input_message = static_cast(input_message_content.get()); + if (!input_message->send_copy_) { + return Status::Error(400, "Can't use forwarded message"); + } + + DialogId from_dialog_id(input_message->from_chat_id_); + Dialog *from_dialog = get_dialog_force(from_dialog_id); + if (from_dialog == nullptr) { + return Status::Error(400, "Chat to copy message from not found"); + } + if (!have_input_peer(from_dialog_id, AccessRights::Read)) { + return Status::Error(400, "Can't access the chat to copy message from"); + } + if (from_dialog_id.get_type() == DialogType::SecretChat) { + return Status::Error(400, "Can't copy message from secret chats"); + } + MessageId message_id = get_persistent_message_id(from_dialog, MessageId(input_message->message_id_)); + + const Message *copied_message = get_message_force(from_dialog, message_id, "process_input_message_content"); + if (copied_message == nullptr) { + return Status::Error(400, "Can't find message to copy"); + } + if (!can_forward_message(from_dialog_id, copied_message)) { + return Status::Error(400, "Can't copy message"); + } + + unique_ptr content = + dup_message_content(td_, dialog_id, copied_message->content.get(), true, input_message->remove_caption_); + if (content == nullptr) { + return Status::Error(400, "Can't copy message content"); + } + + return InputMessageContent(std::move(content), copied_message->disable_web_page_preview, false, 0, UserId()); } TRY_RESULT(content, get_input_message_content(dialog_id, std::move(input_message_content), td_)); @@ -16397,6 +16437,9 @@ void MessagesManager::do_send_message(DialogId dialog_id, Message *m, vectorttl, false); if (input_media == nullptr) { + if (content_type == MessageContentType::Game) { + return; + } if (content_type == MessageContentType::Photo) { thumbnail_file_id = FileId(); } @@ -18313,10 +18356,10 @@ void MessagesManager::do_forward_messages(DialogId to_dialog_id, DialogId from_d } Result MessagesManager::forward_message(DialogId to_dialog_id, DialogId from_dialog_id, MessageId message_id, - bool disable_notification, bool from_background, - bool in_game_share) { + bool disable_notification, bool from_background, bool in_game_share, + bool send_copy, bool remove_caption) { TRY_RESULT(result, forward_messages(to_dialog_id, from_dialog_id, {message_id}, disable_notification, from_background, - in_game_share, false, false, false)); + in_game_share, false, send_copy, remove_caption)); CHECK(result.size() == 1); auto sent_message_id = result[0]; if (sent_message_id == MessageId()) { @@ -18403,13 +18446,17 @@ Result> MessagesManager::forward_messages(DialogId to_dialog_i continue; } + auto content_type = content->get_type(); + bool is_game = content_type == MessageContentType::Game; if (need_copy) { + if (is_game) { + LOG(INFO) << "Can't copy game from " << message_id; + continue; + } copied_messages.push_back({std::move(content), forwarded_message->disable_web_page_preview, i}); continue; } - auto content_type = content->get_type(); - bool is_game = content_type == MessageContentType::Game; unique_ptr forward_info; if (!is_game && content_type != MessageContentType::Audio) { DialogId saved_from_dialog_id; @@ -18696,13 +18743,6 @@ Result MessagesManager::add_local_message( } LOG(INFO) << "Begin to add local message to " << dialog_id << " in reply to " << reply_to_message_id; - if (input_message_content->get_id() == td_api::inputMessageForwarded::ID) { - return Status::Error(5, "Can't add forwarded local message"); - } - if (input_message_content->get_id() == td_api::inputMessageGame::ID) { - return Status::Error(5, "Can't add local game message"); - } - Dialog *d = get_dialog_force(dialog_id); if (d == nullptr) { return Status::Error(5, "Chat not found"); @@ -18712,6 +18752,12 @@ Result MessagesManager::add_local_message( return Status::Error(400, "Can't access the chat"); } TRY_RESULT(message_content, process_input_message_content(dialog_id, std::move(input_message_content))); + if (message_content.content->get_type() == MessageContentType::Poll) { + return Status::Error(400, "Can't add local poll message"); + } + if (message_content.content->get_type() == MessageContentType::Game) { + return Status::Error(400, "Can't add local game message"); + } bool is_channel_post = is_broadcast_channel(dialog_id); if (sender_user_id != UserId() && !td_->contacts_manager_->have_user_force(sender_user_id)) { @@ -25898,7 +25944,7 @@ MessagesManager::Message *MessagesManager::continue_send_message(DialogId dialog send_update_new_message(d, result_message); if (need_update_dialog_pos) { - send_update_chat_last_message(d, "on_resend_message"); + send_update_chat_last_message(d, "continue_send_message"); } auto can_send_status = can_send_message(dialog_id); diff --git a/td/telegram/MessagesManager.h b/td/telegram/MessagesManager.h index d87494be..1b6a4d26 100644 --- a/td/telegram/MessagesManager.h +++ b/td/telegram/MessagesManager.h @@ -1336,7 +1336,7 @@ class MessagesManager : public Actor { bool have_previous, bool have_next, const char *source); Result process_input_message_content( - DialogId dialog_id, tl_object_ptr &&input_message_content) const; + DialogId dialog_id, tl_object_ptr &&input_message_content); Message *get_message_to_send(Dialog *d, MessageId reply_to_message_id, bool disable_notification, bool from_background, unique_ptr &&content, bool *need_update_dialog_pos, @@ -1383,8 +1383,8 @@ class MessagesManager : public Actor { const vector &message_ids, uint64 logevent_id); Result forward_message(DialogId to_dialog_id, DialogId from_dialog_id, MessageId message_id, - bool disable_notification, bool from_background, - bool in_game_share) TD_WARN_UNUSED_RESULT; + bool disable_notification, bool from_background, bool in_game_share, bool send_copy, + bool remove_caption) TD_WARN_UNUSED_RESULT; void do_send_media(DialogId dialog_id, Message *m, FileId file_id, FileId thumbnail_file_id, tl_object_ptr input_file, diff --git a/td/telegram/cli.cpp b/td/telegram/cli.cpp index 60abcdfb..de43050d 100644 --- a/td/telegram/cli.cpp +++ b/td/telegram/cli.cpp @@ -2924,7 +2924,7 @@ class CliClient final : public Actor { send_message(chat_id, td_api::make_object(td_api::make_object( phone_number, first_name, last_name, string(), as_user_id(user_id)))); - } else if (op == "sf") { + } else if (op == "sf" || op == "scopy") { string chat_id; string from_chat_id; string from_message_id; @@ -2932,7 +2932,8 @@ class CliClient final : public Actor { std::tie(from_chat_id, from_message_id) = split(args); send_message(chat_id, td_api::make_object(as_chat_id(from_chat_id), - as_message_id(from_message_id), true)); + as_message_id(from_message_id), true, + op == "scopy", Random::fast(0, 1) == 0)); } else if (op == "sd") { string chat_id; string document_path;