Introduce MessageContentDupType.
GitOrigin-RevId: 06e0728b6853f0c7ec065a1b5eba8e448a8e9835
This commit is contained in:
parent
4317cc3ef5
commit
ebaea15679
@ -4031,7 +4031,7 @@ unique_ptr<MessageContent> get_message_content(Td *td, FormattedText message,
|
|||||||
}
|
}
|
||||||
|
|
||||||
unique_ptr<MessageContent> dup_message_content(Td *td, DialogId dialog_id, const MessageContent *content,
|
unique_ptr<MessageContent> dup_message_content(Td *td, DialogId dialog_id, const MessageContent *content,
|
||||||
bool for_forward, bool remove_caption) {
|
MessageContentDupType type) {
|
||||||
CHECK(content != nullptr);
|
CHECK(content != nullptr);
|
||||||
|
|
||||||
bool to_secret = dialog_id.get_type() == DialogType::SecretChat;
|
bool to_secret = dialog_id.get_type() == DialogType::SecretChat;
|
||||||
@ -4051,6 +4051,7 @@ unique_ptr<MessageContent> dup_message_content(Td *td, DialogId dialog_id, const
|
|||||||
if (to_secret) {
|
if (to_secret) {
|
||||||
thumbnail_file_id = get_message_content_thumbnail_file_id(content, td);
|
thumbnail_file_id = get_message_content_thumbnail_file_id(content, td);
|
||||||
}
|
}
|
||||||
|
auto remove_caption = type == MessageContentDupType::CopyWithoutCaption;
|
||||||
switch (content->get_type()) {
|
switch (content->get_type()) {
|
||||||
case MessageContentType::Animation: {
|
case MessageContentType::Animation: {
|
||||||
auto result = make_unique<MessageAnimation>(*static_cast<const MessageAnimation *>(content));
|
auto result = make_unique<MessageAnimation>(*static_cast<const MessageAnimation *>(content));
|
||||||
@ -4095,7 +4096,7 @@ unique_ptr<MessageContent> dup_message_content(Td *td, DialogId dialog_id, const
|
|||||||
case MessageContentType::Invoice:
|
case MessageContentType::Invoice:
|
||||||
return make_unique<MessageInvoice>(*static_cast<const MessageInvoice *>(content));
|
return make_unique<MessageInvoice>(*static_cast<const MessageInvoice *>(content));
|
||||||
case MessageContentType::LiveLocation:
|
case MessageContentType::LiveLocation:
|
||||||
if (to_secret || for_forward) {
|
if (to_secret || type != MessageContentDupType::Send) {
|
||||||
return make_unique<MessageLocation>(Location(static_cast<const MessageLiveLocation *>(content)->location));
|
return make_unique<MessageLocation>(Location(static_cast<const MessageLiveLocation *>(content)->location));
|
||||||
} else {
|
} else {
|
||||||
return make_unique<MessageLiveLocation>(*static_cast<const MessageLiveLocation *>(content));
|
return make_unique<MessageLiveLocation>(*static_cast<const MessageLiveLocation *>(content));
|
||||||
|
@ -221,8 +221,10 @@ unique_ptr<MessageContent> get_message_content(Td *td, FormattedText message_tex
|
|||||||
DialogId owner_dialog_id, bool is_content_read, UserId via_bot_user_id,
|
DialogId owner_dialog_id, bool is_content_read, UserId via_bot_user_id,
|
||||||
int32 *ttl);
|
int32 *ttl);
|
||||||
|
|
||||||
|
enum class MessageContentDupType : int32 { Send, Forward, Copy, CopyWithoutCaption };
|
||||||
|
|
||||||
unique_ptr<MessageContent> dup_message_content(Td *td, DialogId dialog_id, const MessageContent *content,
|
unique_ptr<MessageContent> dup_message_content(Td *td, DialogId dialog_id, const MessageContent *content,
|
||||||
bool for_forward, bool remove_caption = false);
|
MessageContentDupType type);
|
||||||
|
|
||||||
unique_ptr<MessageContent> get_action_message_content(Td *td, tl_object_ptr<telegram_api::MessageAction> &&action,
|
unique_ptr<MessageContent> get_action_message_content(Td *td, tl_object_ptr<telegram_api::MessageAction> &&action,
|
||||||
DialogId owner_dialog_id, MessageId reply_to_message_id);
|
DialogId owner_dialog_id, MessageId reply_to_message_id);
|
||||||
|
@ -18236,9 +18236,10 @@ Result<MessageId> MessagesManager::send_message(DialogId dialog_id, MessageId re
|
|||||||
// there must be no errors after get_message_to_send call
|
// there must be no errors after get_message_to_send call
|
||||||
|
|
||||||
bool need_update_dialog_pos = false;
|
bool need_update_dialog_pos = false;
|
||||||
Message *m = get_message_to_send(d, get_reply_to_message_id(d, reply_to_message_id), send_message_options,
|
Message *m = get_message_to_send(
|
||||||
dup_message_content(td_, dialog_id, message_content.content.get(), false),
|
d, get_reply_to_message_id(d, reply_to_message_id), send_message_options,
|
||||||
&need_update_dialog_pos, nullptr, message_content.via_bot_user_id.is_valid());
|
dup_message_content(td_, dialog_id, message_content.content.get(), MessageContentDupType::Send),
|
||||||
|
&need_update_dialog_pos, nullptr, message_content.via_bot_user_id.is_valid());
|
||||||
m->reply_markup = std::move(message_reply_markup);
|
m->reply_markup = std::move(message_reply_markup);
|
||||||
m->via_bot_user_id = message_content.via_bot_user_id;
|
m->via_bot_user_id = message_content.via_bot_user_id;
|
||||||
m->disable_web_page_preview = message_content.disable_web_page_preview;
|
m->disable_web_page_preview = message_content.disable_web_page_preview;
|
||||||
@ -18296,8 +18297,9 @@ Result<InputMessageContent> MessagesManager::process_input_message_content(
|
|||||||
return Status::Error(400, "Can't copy message");
|
return Status::Error(400, "Can't copy message");
|
||||||
}
|
}
|
||||||
|
|
||||||
unique_ptr<MessageContent> content =
|
unique_ptr<MessageContent> content = dup_message_content(
|
||||||
dup_message_content(td_, dialog_id, copied_message->content.get(), true, input_message->remove_caption_);
|
td_, dialog_id, copied_message->content.get(),
|
||||||
|
input_message->remove_caption_ ? MessageContentDupType::CopyWithoutCaption : MessageContentDupType::Copy);
|
||||||
if (content == nullptr) {
|
if (content == nullptr) {
|
||||||
return Status::Error(400, "Can't copy message content");
|
return Status::Error(400, "Can't copy message content");
|
||||||
}
|
}
|
||||||
@ -18423,9 +18425,10 @@ Result<vector<MessageId>> MessagesManager::send_message_group(
|
|||||||
vector<MessageId> result;
|
vector<MessageId> result;
|
||||||
bool need_update_dialog_pos = false;
|
bool need_update_dialog_pos = false;
|
||||||
for (auto &message_content : message_contents) {
|
for (auto &message_content : message_contents) {
|
||||||
Message *m = get_message_to_send(d, reply_to_message_id, send_message_options,
|
Message *m = get_message_to_send(
|
||||||
dup_message_content(td_, dialog_id, message_content.first.get(), false),
|
d, reply_to_message_id, send_message_options,
|
||||||
&need_update_dialog_pos);
|
dup_message_content(td_, dialog_id, message_content.first.get(), MessageContentDupType::Send),
|
||||||
|
&need_update_dialog_pos);
|
||||||
result.push_back(m->message_id);
|
result.push_back(m->message_id);
|
||||||
auto ttl = message_content.second;
|
auto ttl = message_content.second;
|
||||||
if (ttl > 0) {
|
if (ttl > 0) {
|
||||||
@ -19168,9 +19171,10 @@ Result<MessageId> MessagesManager::send_inline_query_result_message(DialogId dia
|
|||||||
TRY_STATUS(can_send_message_content(dialog_id, content->message_content.get(), false, true));
|
TRY_STATUS(can_send_message_content(dialog_id, content->message_content.get(), false, true));
|
||||||
|
|
||||||
bool need_update_dialog_pos = false;
|
bool need_update_dialog_pos = false;
|
||||||
Message *m = get_message_to_send(d, get_reply_to_message_id(d, reply_to_message_id), send_message_options,
|
Message *m = get_message_to_send(
|
||||||
dup_message_content(td_, dialog_id, content->message_content.get(), false),
|
d, get_reply_to_message_id(d, reply_to_message_id), send_message_options,
|
||||||
&need_update_dialog_pos, nullptr, true);
|
dup_message_content(td_, dialog_id, content->message_content.get(), MessageContentDupType::Send),
|
||||||
|
&need_update_dialog_pos, nullptr, true);
|
||||||
m->hide_via_bot = hide_via_bot;
|
m->hide_via_bot = hide_via_bot;
|
||||||
if (!hide_via_bot) {
|
if (!hide_via_bot) {
|
||||||
m->via_bot_user_id = td_->inline_queries_manager_->get_inline_bot_user_id(query_id);
|
m->via_bot_user_id = td_->inline_queries_manager_->get_inline_bot_user_id(query_id);
|
||||||
@ -19734,7 +19738,7 @@ void MessagesManager::edit_message_media(FullMessageId full_message_id,
|
|||||||
|
|
||||||
cancel_edit_message_media(dialog_id, m, "Cancelled by new editMessageMedia request");
|
cancel_edit_message_media(dialog_id, m, "Cancelled by new editMessageMedia request");
|
||||||
|
|
||||||
m->edited_content = dup_message_content(td_, dialog_id, content.content.get(), false);
|
m->edited_content = dup_message_content(td_, dialog_id, content.content.get(), MessageContentDupType::Send);
|
||||||
CHECK(m->edited_content != nullptr);
|
CHECK(m->edited_content != nullptr);
|
||||||
m->edited_reply_markup = r_new_reply_markup.move_as_ok();
|
m->edited_reply_markup = r_new_reply_markup.move_as_ok();
|
||||||
m->edit_generation = ++current_message_edit_generation_;
|
m->edit_generation = ++current_message_edit_generation_;
|
||||||
@ -20654,8 +20658,9 @@ Result<vector<MessageId>> MessagesManager::forward_messages(DialogId to_dialog_i
|
|||||||
}
|
}
|
||||||
|
|
||||||
bool need_copy = !message_id.is_server() || to_secret || send_copy;
|
bool need_copy = !message_id.is_server() || to_secret || send_copy;
|
||||||
unique_ptr<MessageContent> content =
|
auto type = need_copy ? (remove_caption ? MessageContentDupType::CopyWithoutCaption : MessageContentDupType::Copy)
|
||||||
dup_message_content(td_, to_dialog_id, forwarded_message->content.get(), true, need_copy && remove_caption);
|
: MessageContentDupType::Forward;
|
||||||
|
unique_ptr<MessageContent> content = dup_message_content(td_, to_dialog_id, forwarded_message->content.get(), type);
|
||||||
if (content == nullptr) {
|
if (content == nullptr) {
|
||||||
LOG(INFO) << "Can't forward " << message_id;
|
LOG(INFO) << "Can't forward " << message_id;
|
||||||
continue;
|
continue;
|
||||||
@ -20885,7 +20890,8 @@ Result<vector<MessageId>> MessagesManager::resend_messages(DialogId dialog_id, v
|
|||||||
const Message *m = get_message(d, message_id);
|
const Message *m = get_message(d, message_id);
|
||||||
CHECK(m != nullptr);
|
CHECK(m != nullptr);
|
||||||
|
|
||||||
unique_ptr<MessageContent> content = dup_message_content(td_, dialog_id, m->content.get(), false);
|
unique_ptr<MessageContent> content =
|
||||||
|
dup_message_content(td_, dialog_id, m->content.get(), MessageContentDupType::Send);
|
||||||
if (content == nullptr) {
|
if (content == nullptr) {
|
||||||
LOG(INFO) << "Can't resend " << m->message_id;
|
LOG(INFO) << "Can't resend " << m->message_id;
|
||||||
continue;
|
continue;
|
||||||
@ -29266,7 +29272,7 @@ void MessagesManager::on_binlog_events(vector<BinlogEvent> &&events) {
|
|||||||
add_message_dependencies(dependencies, dialog_id, m.get());
|
add_message_dependencies(dependencies, dialog_id, m.get());
|
||||||
resolve_dependencies_force(dependencies);
|
resolve_dependencies_force(dependencies);
|
||||||
|
|
||||||
m->content = dup_message_content(td_, dialog_id, m->content.get(), false);
|
m->content = dup_message_content(td_, dialog_id, m->content.get(), MessageContentDupType::Send);
|
||||||
|
|
||||||
auto result_message = continue_send_message(dialog_id, std::move(m), event.id_);
|
auto result_message = continue_send_message(dialog_id, std::move(m), event.id_);
|
||||||
if (result_message != nullptr) {
|
if (result_message != nullptr) {
|
||||||
@ -29331,7 +29337,7 @@ void MessagesManager::on_binlog_events(vector<BinlogEvent> &&events) {
|
|||||||
add_message_dependencies(dependencies, dialog_id, m.get());
|
add_message_dependencies(dependencies, dialog_id, m.get());
|
||||||
resolve_dependencies_force(dependencies);
|
resolve_dependencies_force(dependencies);
|
||||||
|
|
||||||
m->content = dup_message_content(td_, dialog_id, m->content.get(), false);
|
m->content = dup_message_content(td_, dialog_id, m->content.get(), MessageContentDupType::Send);
|
||||||
|
|
||||||
auto result_message = continue_send_message(dialog_id, std::move(m), event.id_);
|
auto result_message = continue_send_message(dialog_id, std::move(m), event.id_);
|
||||||
if (result_message != nullptr) {
|
if (result_message != nullptr) {
|
||||||
@ -29420,7 +29426,7 @@ void MessagesManager::on_binlog_events(vector<BinlogEvent> &&events) {
|
|||||||
set_message_id(m, get_next_yet_unsent_message_id(to_dialog));
|
set_message_id(m, get_next_yet_unsent_message_id(to_dialog));
|
||||||
m->date = now;
|
m->date = now;
|
||||||
}
|
}
|
||||||
m->content = dup_message_content(td_, to_dialog_id, m->content.get(), true);
|
m->content = dup_message_content(td_, to_dialog_id, m->content.get(), MessageContentDupType::Forward);
|
||||||
CHECK(m->content != nullptr);
|
CHECK(m->content != nullptr);
|
||||||
m->have_previous = true;
|
m->have_previous = true;
|
||||||
m->have_next = true;
|
m->have_next = true;
|
||||||
|
Reference in New Issue
Block a user