Allow to replace caption when message is copied.

GitOrigin-RevId: 6e190830d66916de2deb0b371185b7db6ea42b00
This commit is contained in:
levlam 2020-08-11 10:35:19 +03:00
parent c780fc2812
commit 8fb53c6ec2
7 changed files with 38 additions and 22 deletions

View File

@ -1691,8 +1691,9 @@ messageSendOptions disable_notification:Bool from_background:Bool scheduling_sta
//@description Options to be used when a message content is copied without a link to the original message
//@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
messageCopyOptions send_copy:Bool remove_caption:Bool = MessageCopyOptions;
//@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
messageCopyOptions send_copy:Bool replace_caption:Bool new_caption:formattedText = MessageCopyOptions;
//@class InputMessageContent @description The content of a message to send

Binary file not shown.

View File

@ -3964,12 +3964,12 @@ unique_ptr<MessageContent> dup_message_content(Td *td, DialogId dialog_id, const
if (to_secret) {
thumbnail_file_id = get_message_content_thumbnail_file_id(content, td);
}
auto remove_caption = type == MessageContentDupType::Copy && copy_options.remove_caption;
auto replace_caption = type == MessageContentDupType::Copy && copy_options.replace_caption;
switch (content->get_type()) {
case MessageContentType::Animation: {
auto result = make_unique<MessageAnimation>(*static_cast<const MessageAnimation *>(content));
if (remove_caption) {
result->caption = FormattedText();
if (replace_caption) {
result->caption = std::move(copy_options.new_caption);
}
if (td->documents_manager_->has_input_media(result->file_id, thumbnail_file_id, to_secret)) {
return std::move(result);
@ -3980,8 +3980,8 @@ unique_ptr<MessageContent> dup_message_content(Td *td, DialogId dialog_id, const
}
case MessageContentType::Audio: {
auto result = make_unique<MessageAudio>(*static_cast<const MessageAudio *>(content));
if (remove_caption) {
result->caption = FormattedText();
if (replace_caption) {
result->caption = std::move(copy_options.new_caption);
}
if (td->documents_manager_->has_input_media(result->file_id, thumbnail_file_id, to_secret)) {
return std::move(result);
@ -4001,8 +4001,8 @@ unique_ptr<MessageContent> dup_message_content(Td *td, DialogId dialog_id, const
}
case MessageContentType::Document: {
auto result = make_unique<MessageDocument>(*static_cast<const MessageDocument *>(content));
if (remove_caption) {
result->caption = FormattedText();
if (replace_caption) {
result->caption = std::move(copy_options.new_caption);
}
if (td->documents_manager_->has_input_media(result->file_id, thumbnail_file_id, to_secret)) {
return std::move(result);
@ -4025,8 +4025,8 @@ unique_ptr<MessageContent> dup_message_content(Td *td, DialogId dialog_id, const
return make_unique<MessageLocation>(*static_cast<const MessageLocation *>(content));
case MessageContentType::Photo: {
auto result = make_unique<MessagePhoto>(*static_cast<const MessagePhoto *>(content));
if (remove_caption) {
result->caption = FormattedText();
if (replace_caption) {
result->caption = std::move(copy_options.new_caption);
}
CHECK(!result->photo.photos.empty());
@ -4106,8 +4106,8 @@ unique_ptr<MessageContent> dup_message_content(Td *td, DialogId dialog_id, const
return make_unique<MessageVenue>(*static_cast<const MessageVenue *>(content));
case MessageContentType::Video: {
auto result = make_unique<MessageVideo>(*static_cast<const MessageVideo *>(content));
if (remove_caption) {
result->caption = FormattedText();
if (replace_caption) {
result->caption = std::move(copy_options.new_caption);
}
if (td->documents_manager_->has_input_media(result->file_id, thumbnail_file_id, to_secret)) {
return std::move(result);
@ -4128,8 +4128,8 @@ unique_ptr<MessageContent> dup_message_content(Td *td, DialogId dialog_id, const
}
case MessageContentType::VoiceNote: {
auto result = make_unique<MessageVoiceNote>(*static_cast<const MessageVoiceNote *>(content));
if (remove_caption) {
result->caption = FormattedText();
if (replace_caption) {
result->caption = std::move(copy_options.new_caption);
}
result->is_listened = false;
if (td->documents_manager_->has_input_media(result->file_id, thumbnail_file_id, to_secret)) {

View File

@ -6,6 +6,8 @@
//
#pragma once
#include "td/telegram/MessageEntity.h"
#include "td/utils/common.h"
#include "td/utils/StringBuilder.h"
@ -13,16 +15,23 @@ namespace td {
struct MessageCopyOptions {
bool send_copy = false;
bool remove_caption = false;
bool replace_caption = false;
FormattedText new_caption;
MessageCopyOptions() = default;
MessageCopyOptions(bool send_copy, bool remove_caption): send_copy(send_copy), remove_caption(remove_caption) {
MessageCopyOptions(bool send_copy, bool remove_caption) : send_copy(send_copy), replace_caption(remove_caption) {
}
};
inline StringBuilder &operator<<(StringBuilder &string_builder, MessageCopyOptions copy_options) {
if (copy_options.send_copy) {
string_builder << "CopyOptions[remove_caption = " << copy_options.remove_caption << "]";
string_builder << "CopyOptions[replace_caption = " << copy_options.replace_caption;
}
if (copy_options.replace_caption) {
string_builder << ", new_caption = " << copy_options.new_caption;
}
if (copy_options.send_copy) {
string_builder << "]";
}
return string_builder;
}

View File

@ -20651,7 +20651,12 @@ Result<MessageCopyOptions> MessagesManager::process_message_copy_options(
}
MessageCopyOptions result;
result.send_copy = true;
result.remove_caption = options->remove_caption_;
result.replace_caption = options->replace_caption_;
if (result.replace_caption) {
TRY_RESULT_ASSIGN(result.new_caption,
process_input_caption(td_->contacts_manager_.get(), dialog_id, std::move(options->new_caption_),
td_->auth_manager_->is_bot()));
}
return std::move(result);
}

View File

@ -5748,8 +5748,8 @@ void Td::on_request(uint64 id, td_api::forwardMessages &request) {
DialogId dialog_id(request.chat_id_);
auto input_message_ids = MessagesManager::get_message_ids(request.message_ids_);
auto message_copy_options =
transform(input_message_ids, [copy_options = MessageCopyOptions(request.send_copy_, request.remove_caption_)](
MessageId) { return copy_options; });
transform(input_message_ids, [send_copy = request.send_copy_, remove_caption = request.remove_caption_](
MessageId) { return MessageCopyOptions(send_copy, remove_caption); });
auto r_message_ids = messages_manager_->forward_messages(dialog_id, DialogId(request.from_chat_id_),
std::move(input_message_ids), std::move(request.options_),
false, request.as_album_, std::move(message_copy_options));

View File

@ -3200,7 +3200,8 @@ class CliClient final : public Actor {
td_api::object_ptr<td_api::messageCopyOptions> copy_options;
if (op == "scopy") {
copy_options = td_api::make_object<td_api::messageCopyOptions>(true, Random::fast(0, 1) == 0);
copy_options =
td_api::make_object<td_api::messageCopyOptions>(true, Random::fast(0, 1) == 0, as_caption("_as_d"));
}
send_message(chat_id,