Add get_uploaded_message_content.

This commit is contained in:
levlam 2024-06-26 16:32:15 +03:00
parent 8a2f6c761e
commit 3f4607cbdc
5 changed files with 25 additions and 27 deletions

View File

@ -1024,14 +1024,9 @@ void BusinessConnectionManager::do_upload_media(BeingUploadedMedia &&being_uploa
void BusinessConnectionManager::complete_upload_media(unique_ptr<PendingMessage> &&message,
telegram_api::object_ptr<telegram_api::MessageMedia> &&media,
Promise<UploadMediaResult> &&promise) {
auto *content = message->content_.get();
auto *caption = get_message_content_caption(content);
auto has_spoiler = get_message_content_has_spoiler(content);
auto new_content = get_message_content(td_, caption == nullptr ? FormattedText() : *caption, std::move(media),
td_->dialog_manager_->get_my_dialog_id(), G()->unix_time(), false, UserId(),
nullptr, nullptr, "complete_upload_media");
set_message_content_has_spoiler(new_content.get(), has_spoiler);
auto new_content =
get_uploaded_message_content(td_, message->content_.get(), std::move(media),
td_->dialog_manager_->get_my_dialog_id(), G()->unix_time(), "complete_upload_media");
bool is_content_changed = false;
bool need_update = false;

View File

@ -7736,7 +7736,7 @@ const FormattedText *get_message_content_caption(const MessageContent *content)
}
}
bool get_message_content_has_spoiler(const MessageContent *content) {
static bool get_message_content_has_spoiler(const MessageContent *content) {
switch (content->get_type()) {
case MessageContentType::Animation:
return static_cast<const MessageAnimation *>(content)->has_spoiler;
@ -7749,7 +7749,7 @@ bool get_message_content_has_spoiler(const MessageContent *content) {
}
}
void set_message_content_has_spoiler(MessageContent *content, bool has_spoiler) {
static void set_message_content_has_spoiler(MessageContent *content, bool has_spoiler) {
switch (content->get_type()) {
case MessageContentType::Animation:
static_cast<MessageAnimation *>(content)->has_spoiler = has_spoiler;
@ -7765,6 +7765,17 @@ void set_message_content_has_spoiler(MessageContent *content, bool has_spoiler)
}
}
unique_ptr<MessageContent> get_uploaded_message_content(
Td *td, const MessageContent *old_content, telegram_api::object_ptr<telegram_api::MessageMedia> &&media_ptr,
DialogId owner_dialog_id, int32 message_date, const char *source) {
auto caption = get_message_content_caption(old_content);
auto has_spoiler = get_message_content_has_spoiler(old_content);
auto content = get_message_content(td, caption == nullptr ? FormattedText() : *caption, std::move(media_ptr),
owner_dialog_id, message_date, false, UserId(), nullptr, nullptr, source);
set_message_content_has_spoiler(content.get(), has_spoiler);
return content;
}
int32 get_message_content_duration(const MessageContent *content, const Td *td) {
CHECK(content != nullptr);
switch (content->get_type()) {

View File

@ -238,6 +238,10 @@ unique_ptr<MessageContent> get_message_content(Td *td, FormattedText message_tex
UserId via_bot_user_id, MessageSelfDestructType *ttl,
bool *disable_web_page_preview, const char *source);
unique_ptr<MessageContent> get_uploaded_message_content(
Td *td, const MessageContent *old_content, telegram_api::object_ptr<telegram_api::MessageMedia> &&media_ptr,
DialogId owner_dialog_id, int32 message_date, const char *source);
enum class MessageContentDupType : int32 {
Send, // normal message sending
SendViaBot, // message sending via bot
@ -266,10 +270,6 @@ const FormattedText *get_message_content_text(const MessageContent *content);
const FormattedText *get_message_content_caption(const MessageContent *content);
bool get_message_content_has_spoiler(const MessageContent *content);
void set_message_content_has_spoiler(MessageContent *content, bool has_spoiler);
int32 get_message_content_duration(const MessageContent *content, const Td *td);
int32 get_message_content_media_duration(const MessageContent *content, const Td *td);

View File

@ -24243,12 +24243,8 @@ void MessagesManager::on_upload_message_media_success(DialogId dialog_id, Messag
return; // the message should be deleted soon
}
auto caption = get_message_content_caption(m->content.get());
auto has_spoiler = get_message_content_has_spoiler(m->content.get());
auto content = get_message_content(td_, caption == nullptr ? FormattedText() : *caption, std::move(media), dialog_id,
m->date, false, UserId(), nullptr, nullptr, "on_upload_message_media_success");
set_message_content_has_spoiler(content.get(), has_spoiler);
auto content = get_uploaded_message_content(td_, m->content.get(), std::move(media), dialog_id, m->date,
"on_upload_message_media_success");
bool is_content_changed = false;
bool need_update = update_message_content(dialog_id, m, std::move(content), true, true, is_content_changed);
if (need_update) {

View File

@ -2391,13 +2391,9 @@ void QuickReplyManager::on_upload_message_media_success(QuickReplyShortcutId sho
CHECK(message_id.is_yet_unsent());
auto caption = get_message_content_caption(m->content.get());
auto has_spoiler = get_message_content_has_spoiler(m->content.get());
auto content = get_message_content(td_, caption == nullptr ? FormattedText() : *caption, std::move(media),
td_->dialog_manager_->get_my_dialog_id(), 0, false, UserId(), nullptr, nullptr,
"on_upload_message_media_success");
set_message_content_has_spoiler(content.get(), has_spoiler);
auto content =
get_uploaded_message_content(td_, m->content.get(), std::move(media), td_->dialog_manager_->get_my_dialog_id(), 0,
"on_upload_message_media_success");
update_sent_message_content_from_temporary_message(m->content, content, true);
save_quick_reply_shortcuts();