Add send_copy to inputMessageForwarded.

GitOrigin-RevId: 7327021564789e8ff436e2f56f243684b7ce8183
This commit is contained in:
levlam 2019-08-09 20:28:49 +03:00
parent c71dbc28a0
commit 3bca7b1448
7 changed files with 88 additions and 28 deletions

View File

@ -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<string> = 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

Binary file not shown.

View File

@ -2113,6 +2113,9 @@ static tl_object_ptr<telegram_api::InputMedia> get_input_media(const MessageCont
}
case MessageContentType::Game: {
auto m = static_cast<const MessageGame *>(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<const MessageGame *>(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<const MessagePoll *>(old_content);
auto new_ = static_cast<const MessagePoll *>(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;
}

View File

@ -175,6 +175,8 @@ vector<UserId> 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);

View File

@ -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<MessageId> MessagesManager::send_message(DialogId dialog_id, MessageId re
if (input_message_content->get_id() == td_api::inputMessageForwarded::ID) {
auto input_message = static_cast<const td_api::inputMessageForwarded *>(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<MessageId> MessagesManager::send_message(DialogId dialog_id, MessageId re
}
Result<InputMessageContent> MessagesManager::process_input_message_content(
DialogId dialog_id, tl_object_ptr<td_api::InputMessageContent> &&input_message_content) const {
DialogId dialog_id, tl_object_ptr<td_api::InputMessageContent> &&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<const td_api::inputMessageForwarded *>(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<MessageContent> 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, vector<int
} else {
auto input_media = get_input_media(content, td_, m->ttl, 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<MessageId> 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<vector<MessageId>> 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<MessageForwardInfo> forward_info;
if (!is_game && content_type != MessageContentType::Audio) {
DialogId saved_from_dialog_id;
@ -18696,13 +18743,6 @@ Result<MessageId> 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<MessageId> 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);

View File

@ -1336,7 +1336,7 @@ class MessagesManager : public Actor {
bool have_previous, bool have_next, const char *source);
Result<InputMessageContent> process_input_message_content(
DialogId dialog_id, tl_object_ptr<td_api::InputMessageContent> &&input_message_content) const;
DialogId dialog_id, tl_object_ptr<td_api::InputMessageContent> &&input_message_content);
Message *get_message_to_send(Dialog *d, MessageId reply_to_message_id, bool disable_notification,
bool from_background, unique_ptr<MessageContent> &&content, bool *need_update_dialog_pos,
@ -1383,8 +1383,8 @@ class MessagesManager : public Actor {
const vector<MessageId> &message_ids, uint64 logevent_id);
Result<MessageId> 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<telegram_api::InputFile> input_file,

View File

@ -2924,7 +2924,7 @@ class CliClient final : public Actor {
send_message(chat_id, td_api::make_object<td_api::inputMessageContact>(td_api::make_object<td_api::contact>(
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<td_api::inputMessageForwarded>(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;