Add is_uploaded_input_media.

This commit is contained in:
levlam 2024-06-26 13:03:32 +03:00
parent c24222546e
commit 30f1e339d6
5 changed files with 37 additions and 62 deletions

View File

@ -1010,31 +1010,14 @@ void BusinessConnectionManager::do_upload_media(BeingUploadedMedia &&being_uploa
get_message_content_input_media(message->content_.get(), td_, std::move(input_file), std::move(input_thumbnail), get_message_content_input_media(message->content_.get(), td_, std::move(input_file), std::move(input_thumbnail),
file_id, thumbnail_file_id, message->ttl_, message->send_emoji_, true); file_id, thumbnail_file_id, message->ttl_, message->send_emoji_, true);
CHECK(input_media != nullptr); CHECK(input_media != nullptr);
auto input_media_id = input_media->get_id(); if (is_uploaded_input_media(input_media)) {
if (input_media_id == telegram_api::inputMediaDocument::ID || input_media_id == telegram_api::inputMediaPhoto::ID) {
// can use input media directly
UploadMediaResult result; UploadMediaResult result;
result.message_ = std::move(being_uploaded_media.message_); result.message_ = std::move(being_uploaded_media.message_);
result.input_media_ = std::move(input_media); result.input_media_ = std::move(input_media);
return being_uploaded_media.promise_.set_value(std::move(result)); return being_uploaded_media.promise_.set_value(std::move(result));
} } else {
switch (input_media->get_id()) {
case telegram_api::inputMediaUploadedDocument::ID:
if (message->content_->get_type() != MessageContentType::Animation) {
static_cast<telegram_api::inputMediaUploadedDocument *>(input_media.get())->flags_ |=
telegram_api::inputMediaUploadedDocument::NOSOUND_VIDEO_MASK;
}
// fallthrough
case telegram_api::inputMediaUploadedPhoto::ID:
case telegram_api::inputMediaDocumentExternal::ID:
case telegram_api::inputMediaPhotoExternal::ID:
td_->create_handler<UploadBusinessMediaQuery>(std::move(being_uploaded_media.promise_)) td_->create_handler<UploadBusinessMediaQuery>(std::move(being_uploaded_media.promise_))
->send(std::move(being_uploaded_media.message_), std::move(input_media)); ->send(std::move(being_uploaded_media.message_), std::move(input_media));
break;
default:
LOG(ERROR) << "Have wrong input media " << to_string(input_media);
being_uploaded_media.promise_.set_error(Status::Error(400, "Invalid input media"));
} }
} }

View File

@ -3659,6 +3659,26 @@ telegram_api::object_ptr<telegram_api::InputMedia> get_message_content_input_med
false /*ignored*/, text->web_page_url); false /*ignored*/, text->web_page_url);
} }
bool is_uploaded_input_media(telegram_api::object_ptr<telegram_api::InputMedia> &input_media) {
CHECK(input_media != nullptr);
switch (input_media->get_id()) {
case telegram_api::inputMediaUploadedDocument::ID:
static_cast<telegram_api::inputMediaUploadedDocument *>(input_media.get())->flags_ |=
telegram_api::inputMediaUploadedDocument::NOSOUND_VIDEO_MASK;
// fallthrough
case telegram_api::inputMediaUploadedPhoto::ID:
case telegram_api::inputMediaDocumentExternal::ID:
case telegram_api::inputMediaPhotoExternal::ID:
return false;
case telegram_api::inputMediaDocument::ID:
case telegram_api::inputMediaPhoto::ID:
return true;
default:
UNREACHABLE();
return false;
}
}
void delete_message_content_thumbnail(MessageContent *content, Td *td) { void delete_message_content_thumbnail(MessageContent *content, Td *td) {
switch (content->get_type()) { switch (content->get_type()) {
case MessageContentType::Animation: { case MessageContentType::Animation: {

View File

@ -142,6 +142,8 @@ telegram_api::object_ptr<telegram_api::InputMedia> get_message_content_fake_inpu
telegram_api::object_ptr<telegram_api::InputMedia> get_message_content_input_media_web_page( telegram_api::object_ptr<telegram_api::InputMedia> get_message_content_input_media_web_page(
const Td *td, const MessageContent *content); const Td *td, const MessageContent *content);
bool is_uploaded_input_media(telegram_api::object_ptr<telegram_api::InputMedia> &input_media);
void delete_message_content_thumbnail(MessageContent *content, Td *td); void delete_message_content_thumbnail(MessageContent *content, Td *td);
Status can_send_message_content(DialogId dialog_id, const MessageContent *content, bool is_forward, Status can_send_message_content(DialogId dialog_id, const MessageContent *content, bool is_forward,

View File

@ -24099,27 +24099,12 @@ void MessagesManager::on_message_media_uploaded(DialogId dialog_id, const Messag
m->is_copy, random_id, &m->send_query_ref); m->is_copy, random_id, &m->send_query_ref);
})); }));
} else { } else {
switch (input_media->get_id()) { if (!is_uploaded_input_media(input_media)) {
case telegram_api::inputMediaUploadedDocument::ID:
static_cast<telegram_api::inputMediaUploadedDocument *>(input_media.get())->flags_ |=
telegram_api::inputMediaUploadedDocument::NOSOUND_VIDEO_MASK;
// fallthrough
case telegram_api::inputMediaUploadedPhoto::ID:
case telegram_api::inputMediaDocumentExternal::ID:
case telegram_api::inputMediaPhotoExternal::ID:
LOG(INFO) << "Upload media from " << message_id << " in " << dialog_id;
td_->create_handler<UploadMediaQuery>()->send(dialog_id, message_id, file_id, thumbnail_file_id, td_->create_handler<UploadMediaQuery>()->send(dialog_id, message_id, file_id, thumbnail_file_id,
std::move(input_media)); std::move(input_media));
break; } else {
case telegram_api::inputMediaDocument::ID:
case telegram_api::inputMediaPhoto::ID:
send_closure_later(actor_id(this), &MessagesManager::on_upload_message_media_finished, m->media_album_id, send_closure_later(actor_id(this), &MessagesManager::on_upload_message_media_finished, m->media_album_id,
dialog_id, message_id, Status::OK()); dialog_id, message_id, Status::OK());
break;
default:
LOG(ERROR) << "Have wrong input media " << to_string(input_media);
send_closure_later(actor_id(this), &MessagesManager::on_upload_message_media_finished, m->media_album_id,
dialog_id, message_id, Status::Error(400, "Invalid input media"));
} }
} }
} }

View File

@ -2368,26 +2368,11 @@ void QuickReplyManager::on_message_media_uploaded(const QuickReplyMessage *m,
} }
if (m->media_album_id != 0) { if (m->media_album_id != 0) {
// must use UploadMedia and wait for other messages if (!is_uploaded_input_media(input_media)) {
switch (input_media->get_id()) {
case telegram_api::inputMediaUploadedDocument::ID:
static_cast<telegram_api::inputMediaUploadedDocument *>(input_media.get())->flags_ |=
telegram_api::inputMediaUploadedDocument::NOSOUND_VIDEO_MASK;
// fallthrough
case telegram_api::inputMediaUploadedPhoto::ID:
case telegram_api::inputMediaDocumentExternal::ID:
case telegram_api::inputMediaPhotoExternal::ID:
td_->create_handler<UploadQuickReplyMediaQuery>()->send(file_id, thumbnail_file_id, m, std::move(input_media)); td_->create_handler<UploadQuickReplyMediaQuery>()->send(file_id, thumbnail_file_id, m, std::move(input_media));
break; } else {
case telegram_api::inputMediaDocument::ID:
case telegram_api::inputMediaPhoto::ID:
send_closure_later(actor_id(this), &QuickReplyManager::on_upload_message_media_finished, m->media_album_id, send_closure_later(actor_id(this), &QuickReplyManager::on_upload_message_media_finished, m->media_album_id,
m->shortcut_id, m->message_id, Status::OK()); m->shortcut_id, m->message_id, Status::OK());
break;
default:
LOG(ERROR) << "Have wrong input media " << to_string(input_media);
send_closure_later(actor_id(this), &QuickReplyManager::on_upload_message_media_finished, m->media_album_id,
m->shortcut_id, m->message_id, Status::Error(400, "Invalid input media"));
} }
return; return;
} }