Add is_uploaded_input_media.
This commit is contained in:
parent
c24222546e
commit
30f1e339d6
@ -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),
|
||||
file_id, thumbnail_file_id, message->ttl_, message->send_emoji_, true);
|
||||
CHECK(input_media != nullptr);
|
||||
auto input_media_id = input_media->get_id();
|
||||
if (input_media_id == telegram_api::inputMediaDocument::ID || input_media_id == telegram_api::inputMediaPhoto::ID) {
|
||||
// can use input media directly
|
||||
if (is_uploaded_input_media(input_media)) {
|
||||
UploadMediaResult result;
|
||||
result.message_ = std::move(being_uploaded_media.message_);
|
||||
result.input_media_ = std::move(input_media);
|
||||
return being_uploaded_media.promise_.set_value(std::move(result));
|
||||
}
|
||||
|
||||
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_))
|
||||
->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"));
|
||||
} else {
|
||||
td_->create_handler<UploadBusinessMediaQuery>(std::move(being_uploaded_media.promise_))
|
||||
->send(std::move(being_uploaded_media.message_), std::move(input_media));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -3659,6 +3659,26 @@ telegram_api::object_ptr<telegram_api::InputMedia> get_message_content_input_med
|
||||
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) {
|
||||
switch (content->get_type()) {
|
||||
case MessageContentType::Animation: {
|
||||
|
@ -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(
|
||||
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);
|
||||
|
||||
Status can_send_message_content(DialogId dialog_id, const MessageContent *content, bool is_forward,
|
||||
|
@ -24099,27 +24099,12 @@ void MessagesManager::on_message_media_uploaded(DialogId dialog_id, const Messag
|
||||
m->is_copy, random_id, &m->send_query_ref);
|
||||
}));
|
||||
} else {
|
||||
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:
|
||||
LOG(INFO) << "Upload media from " << message_id << " in " << dialog_id;
|
||||
td_->create_handler<UploadMediaQuery>()->send(dialog_id, message_id, file_id, thumbnail_file_id,
|
||||
std::move(input_media));
|
||||
break;
|
||||
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,
|
||||
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"));
|
||||
if (!is_uploaded_input_media(input_media)) {
|
||||
td_->create_handler<UploadMediaQuery>()->send(dialog_id, message_id, file_id, thumbnail_file_id,
|
||||
std::move(input_media));
|
||||
} else {
|
||||
send_closure_later(actor_id(this), &MessagesManager::on_upload_message_media_finished, m->media_album_id,
|
||||
dialog_id, message_id, Status::OK());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -2368,26 +2368,11 @@ void QuickReplyManager::on_message_media_uploaded(const QuickReplyMessage *m,
|
||||
}
|
||||
|
||||
if (m->media_album_id != 0) {
|
||||
// must use UploadMedia and wait for other messages
|
||||
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));
|
||||
break;
|
||||
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,
|
||||
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"));
|
||||
if (!is_uploaded_input_media(input_media)) {
|
||||
td_->create_handler<UploadQuickReplyMediaQuery>()->send(file_id, thumbnail_file_id, m, std::move(input_media));
|
||||
} else {
|
||||
send_closure_later(actor_id(this), &QuickReplyManager::on_upload_message_media_finished, m->media_album_id,
|
||||
m->shortcut_id, m->message_id, Status::OK());
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user