Support ExtendedMedia in MessageContent.

This commit is contained in:
levlam 2022-09-22 18:05:58 +03:00
parent 1fd5452c8f
commit e9b181ec42
7 changed files with 187 additions and 12 deletions

View File

@ -2545,6 +2545,10 @@ void delete_message_content_thumbnail(MessageContent *content, Td *td) {
auto *m = static_cast<MessageDocument *>(content);
return td->documents_manager_->delete_document_thumbnail(m->file_id);
}
case MessageContentType::Invoice: {
auto *m = static_cast<MessageInvoice *>(content);
return input_invoice_delete_thumbnail(td, m->input_invoice);
}
case MessageContentType::Photo: {
auto *m = static_cast<MessagePhoto *>(content);
return photo_delete_thumbnail(m->photo);
@ -2564,7 +2568,6 @@ void delete_message_content_thumbnail(MessageContent *content, Td *td) {
case MessageContentType::Contact:
case MessageContentType::Dice:
case MessageContentType::Game:
case MessageContentType::Invoice:
case MessageContentType::LiveLocation:
case MessageContentType::Location:
case MessageContentType::Venue:
@ -3036,6 +3039,10 @@ bool can_message_content_have_media_timestamp(const MessageContent *content) {
case MessageContentType::VideoNote:
case MessageContentType::VoiceNote:
return true;
case MessageContentType::Invoice: {
const auto *m = static_cast<const MessageInvoice *>(content);
return has_input_invoice_media_timestamp(m->input_invoice);
}
default:
return has_message_content_web_page(content);
}
@ -5365,6 +5372,8 @@ const FormattedText *get_message_content_caption(const MessageContent *content)
return &static_cast<const MessageAudio *>(content)->caption;
case MessageContentType::Document:
return &static_cast<const MessageDocument *>(content)->caption;
case MessageContentType::Invoice:
return get_input_invoice_caption(static_cast<const MessageInvoice *>(content)->input_invoice);
case MessageContentType::Photo:
return &static_cast<const MessagePhoto *>(content)->caption;
case MessageContentType::Video:
@ -5387,6 +5396,8 @@ int32 get_message_content_duration(const MessageContent *content, const Td *td)
auto audio_file_id = static_cast<const MessageAudio *>(content)->file_id;
return td->audios_manager_->get_audio_duration(audio_file_id);
}
case MessageContentType::Invoice:
return get_input_invoice_duration(td, static_cast<const MessageInvoice *>(content)->input_invoice);
case MessageContentType::Video: {
auto video_file_id = static_cast<const MessageVideo *>(content)->file_id;
return td->videos_manager_->get_video_duration(video_file_id);
@ -5411,6 +5422,8 @@ int32 get_message_content_media_duration(const MessageContent *content, const Td
auto audio_file_id = static_cast<const MessageAudio *>(content)->file_id;
return td->audios_manager_->get_audio_duration(audio_file_id);
}
case MessageContentType::Invoice:
return get_input_invoice_duration(td, static_cast<const MessageInvoice *>(content)->input_invoice);
case MessageContentType::Text: {
auto web_page_id = static_cast<const MessageText *>(content)->web_page_id;
return td->web_pages_manager_->get_web_page_media_duration(web_page_id);
@ -5440,6 +5453,8 @@ FileId get_message_content_upload_file_id(const MessageContent *content) {
return static_cast<const MessageAudio *>(content)->file_id;
case MessageContentType::Document:
return static_cast<const MessageDocument *>(content)->file_id;
case MessageContentType::Invoice:
return get_input_invoice_upload_file_id(static_cast<const MessageInvoice *>(content)->input_invoice);
case MessageContentType::Photo:
for (auto &size : static_cast<const MessagePhoto *>(content)->photo.photos) {
if (size.type == 'i') {
@ -5463,10 +5478,14 @@ FileId get_message_content_upload_file_id(const MessageContent *content) {
FileId get_message_content_any_file_id(const MessageContent *content) {
FileId result = get_message_content_upload_file_id(content);
if (!result.is_valid() && content->get_type() == MessageContentType::Photo) {
const auto &sizes = static_cast<const MessagePhoto *>(content)->photo.photos;
if (!sizes.empty()) {
result = sizes.back().file_id;
if (!result.is_valid()) {
if (content->get_type() == MessageContentType::Photo) {
const auto &sizes = static_cast<const MessagePhoto *>(content)->photo.photos;
if (!sizes.empty()) {
result = sizes.back().file_id;
}
} else if (content->get_type() == MessageContentType::Invoice) {
result = get_input_invoice_any_file_id(static_cast<const MessageInvoice *>(content)->input_invoice);
}
}
return result;
@ -5511,6 +5530,8 @@ FileId get_message_content_thumbnail_file_id(const MessageContent *content, cons
case MessageContentType::Document:
return td->documents_manager_->get_document_thumbnail_file_id(
static_cast<const MessageDocument *>(content)->file_id);
case MessageContentType::Invoice:
return get_input_invoice_thumbnail_file_id(td, static_cast<const MessageInvoice *>(content)->input_invoice);
case MessageContentType::Photo:
for (auto &size : static_cast<const MessagePhoto *>(content)->photo.photos) {
if (size.type == 't') {
@ -5606,22 +5627,26 @@ string get_message_content_search_text(const Td *td, const MessageContent *conte
if (!text->web_page_id.is_valid()) {
return text->text.text;
}
return PSTRING() << text->text.text << " " << td->web_pages_manager_->get_web_page_search_text(text->web_page_id);
return PSTRING() << text->text.text << ' ' << td->web_pages_manager_->get_web_page_search_text(text->web_page_id);
}
case MessageContentType::Animation: {
const auto *animation = static_cast<const MessageAnimation *>(content);
return PSTRING() << td->animations_manager_->get_animation_search_text(animation->file_id) << " "
return PSTRING() << td->animations_manager_->get_animation_search_text(animation->file_id) << ' '
<< animation->caption.text;
}
case MessageContentType::Audio: {
const auto *audio = static_cast<const MessageAudio *>(content);
return PSTRING() << td->audios_manager_->get_audio_search_text(audio->file_id) << " " << audio->caption.text;
return PSTRING() << td->audios_manager_->get_audio_search_text(audio->file_id) << ' ' << audio->caption.text;
}
case MessageContentType::Document: {
const auto *document = static_cast<const MessageDocument *>(content);
return PSTRING() << td->documents_manager_->get_document_search_text(document->file_id) << " "
return PSTRING() << td->documents_manager_->get_document_search_text(document->file_id) << ' '
<< document->caption.text;
}
case MessageContentType::Invoice: {
const auto *invoice = static_cast<const MessageInvoice *>(content);
return get_input_invoice_caption(invoice->input_invoice)->text;
}
case MessageContentType::Photo: {
const auto *photo = static_cast<const MessagePhoto *>(content);
return photo->caption.text;
@ -5636,7 +5661,6 @@ string get_message_content_search_text(const Td *td, const MessageContent *conte
}
case MessageContentType::Contact:
case MessageContentType::Game:
case MessageContentType::Invoice:
case MessageContentType::LiveLocation:
case MessageContentType::Location:
case MessageContentType::Sticker:

View File

@ -364,6 +364,7 @@ uint64 get_message_content_chain_id(MessageContentType content_type) {
case MessageContentType::Animation:
case MessageContentType::Audio:
case MessageContentType::Document:
case MessageContentType::Invoice:
case MessageContentType::Photo:
case MessageContentType::Sticker:
case MessageContentType::Video:

View File

@ -144,6 +144,96 @@ void MessageExtendedMedia::append_file_ids(const Td *td, vector<FileId> &file_id
}
}
void MessageExtendedMedia::delete_thumbnail(Td *td) {
switch (type_) {
case Type::Empty:
case Type::Unsupported:
case Type::Preview:
break;
case Type::Photo:
photo_delete_thumbnail(photo_);
break;
case Type::Video:
td->videos_manager_->delete_video_thumbnail(video_file_id_);
break;
default:
UNREACHABLE();
break;
}
}
int32 MessageExtendedMedia::get_duration(const Td *td) const {
if (!has_media_timestamp()) {
return 0;
}
return td->videos_manager_->get_video_duration(video_file_id_);
}
FileId MessageExtendedMedia::get_upload_file_id() const {
switch (type_) {
case Type::Empty:
case Type::Unsupported:
case Type::Preview:
break;
case Type::Photo:
for (auto &size : photo_.photos) {
if (size.type == 'i') {
return size.file_id;
}
}
break;
case Type::Video:
return video_file_id_;
default:
UNREACHABLE();
break;
}
return FileId();
}
FileId MessageExtendedMedia::get_any_file_id() const {
switch (type_) {
case Type::Empty:
case Type::Unsupported:
case Type::Preview:
break;
case Type::Photo: {
if (!photo_.photos.empty()) {
return photo_.photos.back().file_id;
}
break;
}
case Type::Video:
return video_file_id_;
default:
UNREACHABLE();
break;
}
return FileId();
}
FileId MessageExtendedMedia::get_thumbnail_file_id(const Td *td) const {
switch (type_) {
case Type::Empty:
case Type::Unsupported:
case Type::Preview:
break;
case Type::Photo:
for (auto &size : photo_.photos) {
if (size.type == 't') {
return size.file_id;
}
}
break;
case Type::Video:
return td->videos_manager_->get_video_thumbnail_file_id(video_file_id_);
default:
UNREACHABLE();
break;
}
return FileId();
}
bool operator==(const MessageExtendedMedia &lhs, const MessageExtendedMedia &rhs) {
if (lhs.type_ != rhs.type_ || lhs.caption_ != rhs.caption_) {
return false;

View File

@ -62,6 +62,8 @@ class MessageExtendedMedia {
void append_file_ids(const Td *td, vector<FileId> &file_ids) const;
void delete_thumbnail(Td *td);
int32 get_unsupported_version() const {
return unsupported_version_;
}
@ -70,6 +72,22 @@ class MessageExtendedMedia {
return type_ == Type::Unsupported && unsupported_version_ < CURRENT_VERSION;
}
bool has_media_timestamp() const {
return type_ == Type::Video;
}
int32 get_duration(const Td *td) const;
const FormattedText *get_caption() const {
return &caption_;
}
FileId get_upload_file_id() const;
FileId get_any_file_id() const;
FileId get_thumbnail_file_id(const Td *td) const;
template <class StorerT>
void store(StorerT &storer) const;

View File

@ -26053,7 +26053,7 @@ void MessagesManager::do_send_message(DialogId dialog_id, const Message *m, vect
if (content_type == MessageContentType::Game || content_type == MessageContentType::Poll) {
return;
}
if (content_type == MessageContentType::Photo) {
if (file_view.get_type() == FileType::Photo) {
thumbnail_file_id = FileId();
}
@ -31517,7 +31517,7 @@ FullMessageId MessagesManager::on_send_message_success(int64 random_id, MessageI
bool need_update = true;
Message *m = add_message_to_dialog(d, std::move(sent_message), true, &need_update, &need_update_dialog_pos, source);
if (need_update_dialog_pos) {
send_update_chat_last_message(d, "on_send_message_success");
send_update_chat_last_message(d, source);
}
if (m == nullptr) {

View File

@ -1065,6 +1065,34 @@ vector<FileId> get_input_invoice_file_ids(const Td *td, const InputInvoice &inpu
return file_ids;
}
void input_invoice_delete_thumbnail(Td *td, InputInvoice &input_invoice) {
input_invoice.extended_media.delete_thumbnail(td);
}
bool has_input_invoice_media_timestamp(const InputInvoice &input_invoice) {
return input_invoice.extended_media.has_media_timestamp();
}
const FormattedText *get_input_invoice_caption(const InputInvoice &input_invoice) {
return input_invoice.extended_media.get_caption();
}
int32 get_input_invoice_duration(const Td *td, const InputInvoice &input_invoice) {
return input_invoice.extended_media.get_duration(td);
}
FileId get_input_invoice_upload_file_id(const InputInvoice &input_invoice) {
return input_invoice.extended_media.get_upload_file_id();
}
FileId get_input_invoice_any_file_id(const InputInvoice &input_invoice) {
return input_invoice.extended_media.get_any_file_id();
}
FileId get_input_invoice_thumbnail_file_id(const Td *td, const InputInvoice &input_invoice) {
return input_invoice.extended_media.get_thumbnail_file_id(td);
}
bool operator==(const Address &lhs, const Address &rhs) {
return lhs.country_code == rhs.country_code && lhs.state == rhs.state && lhs.city == rhs.city &&
lhs.street_line1 == rhs.street_line1 && lhs.street_line2 == rhs.street_line2 &&

View File

@ -143,6 +143,20 @@ tl_object_ptr<telegram_api::inputBotInlineMessageMediaInvoice> get_input_bot_inl
vector<FileId> get_input_invoice_file_ids(const Td *td, const InputInvoice &input_invoice);
void input_invoice_delete_thumbnail(Td *td, InputInvoice &input_invoice);
bool has_input_invoice_media_timestamp(const InputInvoice &input_invoice);
const FormattedText *get_input_invoice_caption(const InputInvoice &input_invoice);
int32 get_input_invoice_duration(const Td *td, const InputInvoice &input_invoice);
FileId get_input_invoice_upload_file_id(const InputInvoice &input_invoice);
FileId get_input_invoice_any_file_id(const InputInvoice &input_invoice);
FileId get_input_invoice_thumbnail_file_id(const Td *td, const InputInvoice &input_invoice);
bool operator==(const Address &lhs, const Address &rhs);
bool operator!=(const Address &lhs, const Address &rhs);