Disallow messageInvoice copying.

This commit is contained in:
levlam 2021-04-13 17:29:49 +03:00
parent a78fe2dfe5
commit 6b0637f402
3 changed files with 7 additions and 2 deletions

View File

@ -1867,7 +1867,7 @@ messageSchedulingStateSendWhenOnline = MessageSchedulingState;
//@scheduling_state Message scheduling state. Messages sent to a secret chat, live location messages and self-destructing messages can't be scheduled
messageSendOptions disable_notification:Bool from_background:Bool scheduling_state:MessageSchedulingState = MessageSendOptions;
//@description Options to be used when a message content is copied without a link to the original message
//@description Options to be used when a message content is copied without a link to the original message. Service messages and messageInvoice can't be copied
//@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
//@replace_caption True, if media caption of the message copy needs to be replaced. Ignored if send_copy is false
//@new_caption New message caption. Ignored if replace_caption is false

View File

@ -4235,6 +4235,9 @@ unique_ptr<MessageContent> dup_message_content(Td *td, DialogId dialog_id, const
case MessageContentType::Game:
return make_unique<MessageGame>(*static_cast<const MessageGame *>(content));
case MessageContentType::Invoice:
if (type == MessageContentDupType::Copy) {
return nullptr;
}
return make_unique<MessageInvoice>(*static_cast<const MessageInvoice *>(content));
case MessageContentType::LiveLocation:
if (!to_secret && (type == MessageContentDupType::Send || type == MessageContentDupType::SendViaBot)) {

View File

@ -25946,6 +25946,7 @@ 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,
tl_object_ptr<td_api::messageSendOptions> &&options,
bool in_game_share, MessageCopyOptions &&copy_options) {
bool need_copy = copy_options.send_copy;
vector<MessageCopyOptions> all_copy_options;
all_copy_options.push_back(std::move(copy_options));
TRY_RESULT(result, forward_messages(to_dialog_id, from_dialog_id, {message_id}, std::move(options), in_game_share,
@ -25953,7 +25954,8 @@ Result<MessageId> MessagesManager::forward_message(DialogId to_dialog_id, Dialog
CHECK(result.size() == 1);
auto sent_message_id = result[0];
if (sent_message_id == MessageId()) {
return Status::Error(11, "Message can't be forwarded");
return Status::Error(400,
need_copy ? Slice("The message can't be copied") : Slice("The message can't be forwarded"));
}
return sent_message_id;
}