Add forwardMessages.only_preview.

This commit is contained in:
levlam 2021-08-31 23:37:21 +03:00
parent 23a4c2c8a8
commit b1db807868
5 changed files with 77 additions and 39 deletions

View File

@ -1391,7 +1391,7 @@ paymentForm id:int64 invoice:invoice url:string seller_bot_user_id:int32 payment
//@description Contains a temporary identifier of validated order information, which is stored for one hour. Also contains the available shipping options @order_info_id Temporary identifier of the order information @shipping_options Available shipping options //@description Contains a temporary identifier of validated order information, which is stored for one hour. Also contains the available shipping options @order_info_id Temporary identifier of the order information @shipping_options Available shipping options
validatedOrderInfo order_info_id:string shipping_options:vector<shippingOption> = ValidatedOrderInfo; validatedOrderInfo order_info_id:string shipping_options:vector<shippingOption> = ValidatedOrderInfo;
//@description Contains the result of a payment request @success True, if the payment request was successful; otherwise the verification_url will be not empty @verification_url URL for additional payment credentials verification //@description Contains the result of a payment request @success True, if the payment request was successful; otherwise the verification_url will be non-empty @verification_url URL for additional payment credentials verification
paymentResult success:Bool verification_url:string = PaymentResult; paymentResult success:Bool verification_url:string = PaymentResult;
//@description Contains information about a successful payment //@description Contains information about a successful payment
@ -4302,9 +4302,10 @@ sendInlineQueryResultMessage chat_id:int53 message_thread_id:int53 reply_to_mess
//@from_chat_id Identifier of the chat from which to forward messages //@from_chat_id Identifier of the chat from which to forward messages
//@message_ids Identifiers of the messages to forward. Message identifiers must be in a strictly increasing order. At most 100 messages can be forwarded simultaneously //@message_ids Identifiers of the messages to forward. Message identifiers must be in a strictly increasing order. At most 100 messages can be forwarded simultaneously
//@options Options to be used to send the messages //@options Options to be used to send the messages
//@send_copy True, if content of the messages needs to be copied without links to the original messages. Always true if the messages are forwarded to a secret chat //@send_copy If true, content of the messages will be copied without links to the original messages. Always true if the messages are forwarded to a secret chat
//@remove_caption True, if media caption of message copies needs to be removed. Ignored if send_copy is false //@remove_caption If true, media caption of message copies will be removed. Ignored if send_copy is false
forwardMessages chat_id:int53 from_chat_id:int53 message_ids:vector<int53> options:messageSendOptions send_copy:Bool remove_caption:Bool = Messages; //@only_preview If true, messages will not be forwarded and instead fake messages will be returned
forwardMessages chat_id:int53 from_chat_id:int53 message_ids:vector<int53> options:messageSendOptions send_copy:Bool remove_caption:Bool only_preview:Bool = Messages;
//@description Resends messages which failed to send. Can be called only for messages for which messageSendingStateFailed.can_retry is true and after specified in messageSendingStateFailed.retry_after time passed. //@description Resends messages which failed to send. Can be called only for messages for which messageSendingStateFailed.can_retry is true and after specified in messageSendingStateFailed.retry_after time passed.
//-If a message is re-sent, the corresponding failed to send message is deleted. Returns the sent messages in the same order as the message identifiers passed in message_ids. If a message can't be re-sent, null will be returned instead of the message //-If a message is re-sent, the corresponding failed to send message is deleted. Returns the sent messages in the same order as the message identifiers passed in message_ids. If a message can't be re-sent, null will be returned instead of the message

View File

@ -23215,24 +23215,25 @@ MessagesManager::Message *MessagesManager::get_message_to_send(
unique_ptr<MessageForwardInfo> forward_info, bool is_copy) { unique_ptr<MessageForwardInfo> forward_info, bool is_copy) {
d->was_opened = true; d->was_opened = true;
auto m = create_message_to_send(d, top_thread_message_id, reply_to_message_id, options, std::move(content), auto message = create_message_to_send(d, top_thread_message_id, reply_to_message_id, options, std::move(content),
suppress_reply_info, std::move(forward_info), is_copy); suppress_reply_info, std::move(forward_info), is_copy);
MessageId message_id = options.schedule_date != 0 ? get_next_yet_unsent_scheduled_message_id(d, options.schedule_date) MessageId message_id = options.schedule_date != 0 ? get_next_yet_unsent_scheduled_message_id(d, options.schedule_date)
: get_next_yet_unsent_message_id(d); : get_next_yet_unsent_message_id(d);
set_message_id(m, message_id); set_message_id(message, message_id);
m->have_previous = true; message->have_previous = true;
m->have_next = true; message->have_next = true;
do { do {
m->random_id = Random::secure_int64(); message->random_id = Random::secure_int64();
} while (m->random_id == 0 || message_random_ids_.find(m->random_id) != message_random_ids_.end()); } while (message->random_id == 0 || message_random_ids_.find(message->random_id) != message_random_ids_.end());
message_random_ids_.insert(m->random_id); message_random_ids_.insert(message->random_id);
bool need_update = false; bool need_update = false;
CHECK(have_input_peer(d->dialog_id, AccessRights::Read)); CHECK(have_input_peer(d->dialog_id, AccessRights::Read));
auto result = add_message_to_dialog(d, std::move(m), true, &need_update, need_update_dialog_pos, "send message"); auto result =
add_message_to_dialog(d, std::move(message), true, &need_update, need_update_dialog_pos, "send message");
LOG_CHECK(result != nullptr) << message_id << " " << debug_add_message_to_dialog_fail_reason_; LOG_CHECK(result != nullptr) << message_id << " " << debug_add_message_to_dialog_fail_reason_;
if (result->message_id.is_scheduled()) { if (result->message_id.is_scheduled()) {
send_update_chat_has_scheduled_messages(d, false); send_update_chat_has_scheduled_messages(d, false);
@ -26280,7 +26281,7 @@ Result<td_api::object_ptr<td_api::message>> MessagesManager::forward_message(
vector<MessageCopyOptions> all_copy_options; vector<MessageCopyOptions> all_copy_options;
all_copy_options.push_back(std::move(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, TRY_RESULT(result, forward_messages(to_dialog_id, from_dialog_id, {message_id}, std::move(options), in_game_share,
std::move(all_copy_options))); std::move(all_copy_options), false));
CHECK(result->messages_.size() == 1); CHECK(result->messages_.size() == 1);
if (result->messages_[0] == nullptr) { if (result->messages_[0] == nullptr) {
return Status::Error(400, return Status::Error(400,
@ -26454,7 +26455,7 @@ Result<MessagesManager::ForwardedMessages> MessagesManager::get_forwarded_messag
for (size_t i = 0; i < message_ids.size(); i++) { for (size_t i = 0; i < message_ids.size(); i++) {
MessageId message_id = get_persistent_message_id(from_dialog, message_ids[i]); MessageId message_id = get_persistent_message_id(from_dialog, message_ids[i]);
const Message *forwarded_message = get_message_force(from_dialog, message_id, "forward_messages"); const Message *forwarded_message = get_message_force(from_dialog, message_id, "get_forwarded_messages");
if (forwarded_message == nullptr) { if (forwarded_message == nullptr) {
LOG(INFO) << "Can't find " << message_id << " to forward"; LOG(INFO) << "Can't find " << message_id << " to forward";
continue; continue;
@ -26562,8 +26563,8 @@ Result<MessagesManager::ForwardedMessages> MessagesManager::get_forwarded_messag
Result<td_api::object_ptr<td_api::messages>> MessagesManager::forward_messages( Result<td_api::object_ptr<td_api::messages>> MessagesManager::forward_messages(
DialogId to_dialog_id, DialogId from_dialog_id, vector<MessageId> message_ids, DialogId to_dialog_id, DialogId from_dialog_id, vector<MessageId> message_ids,
tl_object_ptr<td_api::messageSendOptions> &&options, bool in_game_share, tl_object_ptr<td_api::messageSendOptions> &&options, bool in_game_share, vector<MessageCopyOptions> &&copy_options,
vector<MessageCopyOptions> &&copy_options) { bool only_preview) {
TRY_RESULT(forwarded_messages_info, TRY_RESULT(forwarded_messages_info,
get_forwarded_messages(to_dialog_id, from_dialog_id, message_ids, std::move(options), in_game_share, get_forwarded_messages(to_dialog_id, from_dialog_id, message_ids, std::move(options), in_game_share,
std::move(copy_options))); std::move(copy_options)));
@ -26584,41 +26585,75 @@ Result<td_api::object_ptr<td_api::messages>> MessagesManager::forward_messages(
auto content = std::move(forwarded_message_contents[j].content); auto content = std::move(forwarded_message_contents[j].content);
auto forward_info = create_message_forward_info(from_dialog_id, to_dialog_id, forwarded_message); auto forward_info = create_message_forward_info(from_dialog_id, to_dialog_id, forwarded_message);
Message *m = get_message_to_send(to_dialog, MessageId(), MessageId(), message_send_options, std::move(content),
&need_update_dialog_pos, j + 1 != forwarded_message_contents.size(), unique_ptr<Message> message;
std::move(forward_info)); Message *m;
if (only_preview) {
message = create_message_to_send(to_dialog, MessageId(), MessageId(), message_send_options, std::move(content),
j + 1 != forwarded_message_contents.size(), std::move(forward_info), false);
MessageId new_message_id =
message_send_options.schedule_date != 0
? get_next_yet_unsent_scheduled_message_id(to_dialog, message_send_options.schedule_date)
: get_next_yet_unsent_message_id(to_dialog);
set_message_id(message, new_message_id);
m = message.get();
} else {
m = get_message_to_send(to_dialog, MessageId(), MessageId(), message_send_options, std::move(content),
&need_update_dialog_pos, j + 1 != forwarded_message_contents.size(),
std::move(forward_info));
}
fix_forwarded_message(m, to_dialog_id, forwarded_message, forwarded_message_contents[j].media_album_id); fix_forwarded_message(m, to_dialog_id, forwarded_message, forwarded_message_contents[j].media_album_id);
m->in_game_share = in_game_share; m->in_game_share = in_game_share;
m->real_forward_from_dialog_id = from_dialog_id; m->real_forward_from_dialog_id = from_dialog_id;
m->real_forward_from_message_id = message_id; m->real_forward_from_message_id = message_id;
send_update_new_message(to_dialog, m); if (!only_preview) {
send_update_new_message(to_dialog, m);
forwarded_messages.push_back(m);
forwarded_message_ids.push_back(message_id);
}
result[forwarded_message_contents[j].index] = get_message_object(to_dialog_id, m, false); result[forwarded_message_contents[j].index] = get_message_object(to_dialog_id, m, false);
forwarded_messages.push_back(m);
forwarded_message_ids.push_back(message_id);
} }
if (!forwarded_messages.empty()) { if (!forwarded_messages.empty()) {
CHECK(!only_preview);
do_forward_messages(to_dialog_id, from_dialog_id, forwarded_messages, forwarded_message_ids, 0); do_forward_messages(to_dialog_id, from_dialog_id, forwarded_messages, forwarded_message_ids, 0);
} }
for (auto &copied_message : copied_messages) { for (auto &copied_message : copied_messages) {
Message *m = get_message_to_send(to_dialog, copied_message.top_thread_message_id, unique_ptr<Message> message;
copied_message.reply_to_message_id, message_send_options, Message *m;
std::move(copied_message.content), &need_update_dialog_pos, false, nullptr, true); if (only_preview) {
message =
create_message_to_send(to_dialog, copied_message.top_thread_message_id, copied_message.reply_to_message_id,
message_send_options, std::move(copied_message.content), false, nullptr, true);
MessageId new_message_id =
message_send_options.schedule_date != 0
? get_next_yet_unsent_scheduled_message_id(to_dialog, message_send_options.schedule_date)
: get_next_yet_unsent_message_id(to_dialog);
set_message_id(message, new_message_id);
m = message.get();
} else {
m = get_message_to_send(to_dialog, copied_message.top_thread_message_id, copied_message.reply_to_message_id,
message_send_options, std::move(copied_message.content), &need_update_dialog_pos, false,
nullptr, true);
}
m->disable_web_page_preview = copied_message.disable_web_page_preview; m->disable_web_page_preview = copied_message.disable_web_page_preview;
m->media_album_id = copied_message.media_album_id; m->media_album_id = copied_message.media_album_id;
m->reply_markup = std::move(copied_message.reply_markup); m->reply_markup = std::move(copied_message.reply_markup);
save_send_message_log_event(to_dialog_id, m); if (!only_preview) {
do_send_message(to_dialog_id, m); save_send_message_log_event(to_dialog_id, m);
result[copied_message.index] = get_message_object(to_dialog_id, m, false); do_send_message(to_dialog_id, m);
send_update_new_message(to_dialog, m);
}
send_update_new_message(to_dialog, m); result[copied_message.index] = get_message_object(to_dialog_id, m, false);
} }
if (need_update_dialog_pos) { if (need_update_dialog_pos) {
CHECK(!only_preview);
send_update_chat_last_message(to_dialog, "forward_messages"); send_update_chat_last_message(to_dialog, "forward_messages");
} }

View File

@ -393,10 +393,12 @@ class MessagesManager final : public Actor {
int64 query_id, const string &result_id, int64 query_id, const string &result_id,
bool hide_via_bot) TD_WARN_UNUSED_RESULT; bool hide_via_bot) TD_WARN_UNUSED_RESULT;
Result<td_api::object_ptr<td_api::messages>> forward_messages( Result<td_api::object_ptr<td_api::messages>> forward_messages(DialogId to_dialog_id, DialogId from_dialog_id,
DialogId to_dialog_id, DialogId from_dialog_id, vector<MessageId> message_ids, vector<MessageId> message_ids,
tl_object_ptr<td_api::messageSendOptions> &&options, bool in_game_share, tl_object_ptr<td_api::messageSendOptions> &&options,
vector<MessageCopyOptions> &&copy_options) TD_WARN_UNUSED_RESULT; bool in_game_share,
vector<MessageCopyOptions> &&copy_options,
bool only_preview) TD_WARN_UNUSED_RESULT;
Result<vector<MessageId>> resend_messages(DialogId dialog_id, vector<MessageId> message_ids) TD_WARN_UNUSED_RESULT; Result<vector<MessageId>> resend_messages(DialogId dialog_id, vector<MessageId> message_ids) TD_WARN_UNUSED_RESULT;

View File

@ -5837,7 +5837,7 @@ void Td::on_request(uint64 id, td_api::forwardMessages &request) {
MessageId) { return MessageCopyOptions(send_copy, remove_caption); }); MessageId) { return MessageCopyOptions(send_copy, remove_caption); });
auto r_messages = messages_manager_->forward_messages(DialogId(request.chat_id_), DialogId(request.from_chat_id_), auto r_messages = messages_manager_->forward_messages(DialogId(request.chat_id_), DialogId(request.from_chat_id_),
std::move(input_message_ids), std::move(request.options_), std::move(input_message_ids), std::move(request.options_),
false, std::move(message_copy_options)); false, std::move(message_copy_options), request.only_preview_);
if (r_messages.is_error()) { if (r_messages.is_error()) {
send_closure(actor_id(this), &Td::send_error, id, r_messages.move_as_error()); send_closure(actor_id(this), &Td::send_error, id, r_messages.move_as_error());
} else { } else {

View File

@ -2698,15 +2698,15 @@ class CliClient final : public Actor {
get_args(args, chat_id, message_ids); get_args(args, chat_id, message_ids);
send_request( send_request(
td_api::make_object<td_api::deleteMessages>(as_chat_id(chat_id), as_message_ids(message_ids), op == "dmr")); td_api::make_object<td_api::deleteMessages>(as_chat_id(chat_id), as_message_ids(message_ids), op == "dmr"));
} else if (op == "fm" || op == "cm") { } else if (op == "fm" || op == "cm" || op == "fmp" || op == "cmp") {
string chat_id; string chat_id;
string from_chat_id; string from_chat_id;
string message_ids; string message_ids;
get_args(args, chat_id, from_chat_id, message_ids); get_args(args, chat_id, from_chat_id, message_ids);
auto chat = as_chat_id(chat_id); auto chat = as_chat_id(chat_id);
send_request( send_request(td_api::make_object<td_api::forwardMessages>(
td_api::make_object<td_api::forwardMessages>(chat, as_chat_id(from_chat_id), as_message_ids(message_ids), chat, as_chat_id(from_chat_id), as_message_ids(message_ids), default_message_send_options(), op[0] == 'c',
default_message_send_options(), op[0] == 'c', rand_bool())); rand_bool(), op.back() == 'p'));
} else if (op == "resend") { } else if (op == "resend") {
string chat_id; string chat_id;
string message_ids; string message_ids;