Add separate get_message_content_media_duration.

This commit is contained in:
levlam 2021-08-05 02:09:04 +03:00
parent c667f6c9bb
commit 9653cc9e3e
5 changed files with 51 additions and 18 deletions

View File

@ -4921,10 +4921,6 @@ 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::Text: {
auto web_page_id = static_cast<const MessageText *>(content)->web_page_id;
return td->web_pages_manager_->get_web_page_duration(web_page_id);
}
case MessageContentType::Video: {
auto video_file_id = static_cast<const MessageVideo *>(content)->file_id;
return td->videos_manager_->get_video_duration(video_file_id);
@ -4942,6 +4938,34 @@ int32 get_message_content_duration(const MessageContent *content, const Td *td)
}
}
int32 get_message_content_media_duration(const MessageContent *content, const Td *td) {
CHECK(content != nullptr);
switch (content->get_type()) {
case MessageContentType::Audio: {
auto audio_file_id = static_cast<const MessageAudio *>(content)->file_id;
return td->audios_manager_->get_audio_duration(audio_file_id);
}
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);
}
case MessageContentType::Video: {
auto video_file_id = static_cast<const MessageVideo *>(content)->file_id;
return td->videos_manager_->get_video_duration(video_file_id);
}
case MessageContentType::VideoNote: {
auto video_note_file_id = static_cast<const MessageVideoNote *>(content)->file_id;
return td->video_notes_manager_->get_video_note_duration(video_note_file_id);
}
case MessageContentType::VoiceNote: {
auto voice_file_id = static_cast<const MessageVoiceNote *>(content)->file_id;
return td->voice_notes_manager_->get_voice_note_duration(voice_file_id);
}
default:
return -1;
}
}
FileId get_message_content_upload_file_id(const MessageContent *content) {
switch (content->get_type()) {
case MessageContentType::Animation:

View File

@ -207,6 +207,8 @@ const FormattedText *get_message_content_caption(const MessageContent *content);
int32 get_message_content_duration(const MessageContent *content, const Td *td);
int32 get_message_content_media_duration(const MessageContent *content, const Td *td);
FileId get_message_content_upload_file_id(const MessageContent *content);
FileId get_message_content_any_file_id(const MessageContent *content);

View File

@ -17369,7 +17369,7 @@ Result<std::pair<string, bool>> MessagesManager::get_message_link(FullMessageId
}
if (media_timestamp != 0) {
for_group = false;
auto duration = get_message_content_duration(m->content.get(), td_);
auto duration = get_message_content_media_duration(m->content.get(), td_);
if (duration != 0 && media_timestamp > duration) {
media_timestamp = 0;
}
@ -17630,7 +17630,7 @@ td_api::object_ptr<td_api::messageLinkInfo> MessagesManager::get_message_link_in
for_album = !info.is_single && m->media_album_id != 0;
for_comment = (info.comment_dialog_id.is_valid() || info.for_comment) && m->top_thread_message_id.is_valid();
if (can_message_content_have_media_timestamp(m->content.get())) {
auto duration = get_message_content_duration(m->content.get(), td_);
auto duration = get_message_content_media_duration(m->content.get(), td_);
if (duration == 0 || info.media_timestamp <= duration) {
media_timestamp = info.media_timestamp;
}
@ -22841,7 +22841,7 @@ tl_object_ptr<td_api::message> MessagesManager::get_message_object(DialogId dial
auto edit_date = m->hide_edit_date ? 0 : m->edit_date;
auto is_pinned = for_event_log || is_scheduled ? false : m->is_pinned;
bool skip_bot_commands = for_event_log ? true : need_skip_bot_commands(dialog_id, m);
int32 max_media_timestamp = for_event_log ? -1 : get_message_content_duration(m->content.get(), td_);
int32 max_media_timestamp = for_event_log ? -1 : get_message_content_media_duration(m->content.get(), td_);
string source = PSTRING() << dialog_id << ' ' << m->message_id;
return make_tl_object<td_api::message>(
m->message_id.get(), get_message_sender_object_const(m->sender_user_id, m->sender_dialog_id, source.c_str()),
@ -28145,7 +28145,7 @@ void MessagesManager::send_update_message_content(DialogId dialog_id, const Mess
void MessagesManager::send_update_message_content_impl(DialogId dialog_id, const Message *m, const char *source) const {
CHECK(m != nullptr);
LOG(INFO) << "Send updateMessageContent for " << m->message_id << " in " << dialog_id << " from " << source;
int32 max_media_timestamp = get_message_content_duration(m->content.get(), td_);
int32 max_media_timestamp = get_message_content_media_duration(m->content.get(), td_);
auto content_object =
get_message_content_object(m->content.get(), td_, dialog_id, m->is_failed_to_send ? 0 : m->date,
m->is_content_secret, need_skip_bot_commands(dialog_id, m), max_media_timestamp);

View File

@ -1254,14 +1254,10 @@ tl_object_ptr<td_api::webPage> WebPagesManager::get_web_page_object(WebPageId we
}
}
int32 max_media_timestamp = -1;
if (web_page->document.type == Document::Type::Audio || web_page->document.type == Document::Type::Video ||
web_page->document.type == Document::Type::VideoNote || web_page->document.type == Document::Type::VoiceNote) {
max_media_timestamp = web_page->duration == 0 ? std::numeric_limits<int32>::max() : web_page->duration;
}
auto duration = get_web_page_media_duration(web_page);
return make_tl_object<td_api::webPage>(
web_page->url, web_page->display_url, web_page->type, web_page->site_name, web_page->title,
get_formatted_text_object(description, true, max_media_timestamp),
get_formatted_text_object(description, true, duration == 0 ? std::numeric_limits<int32>::max() : duration),
get_photo_object(td_->file_manager_.get(), web_page->photo), web_page->embed_url, web_page->embed_type,
web_page->embed_dimensions.width, web_page->embed_dimensions.height, web_page->duration, web_page->author,
web_page->document.type == Document::Type::Animation
@ -1695,12 +1691,21 @@ string WebPagesManager::get_web_page_search_text(WebPageId web_page_id) const {
return PSTRING() << web_page->title + " " + web_page->description;
}
int32 WebPagesManager::get_web_page_duration(WebPageId web_page_id) const {
int32 WebPagesManager::get_web_page_media_duration(WebPageId web_page_id) const {
const WebPage *web_page = get_web_page(web_page_id);
if (web_page == nullptr) {
return 0;
return -1;
}
return web_page->duration;
return get_web_page_media_duration(web_page);
}
int32 WebPagesManager::get_web_page_media_duration(const WebPage *web_page) {
if (web_page->document.type == Document::Type::Audio || web_page->document.type == Document::Type::Video ||
web_page->document.type == Document::Type::VideoNote || web_page->document.type == Document::Type::VoiceNote || web_page->embed_type == "iframe") {
return web_page->duration;
}
return -1;
}
vector<FileId> WebPagesManager::get_web_page_file_ids(const WebPage *web_page) const {

View File

@ -87,7 +87,7 @@ class WebPagesManager final : public Actor {
string get_web_page_search_text(WebPageId web_page_id) const;
int32 get_web_page_duration(WebPageId web_page_id) const;
int32 get_web_page_media_duration(WebPageId web_page_id) const;
private:
static constexpr int32 WEBPAGE_FLAG_HAS_TYPE = 1 << 0;
@ -170,6 +170,8 @@ class WebPagesManager final : public Actor {
void tear_down() final;
static int32 get_web_page_media_duration(const WebPage *web_page);
FileSourceId get_web_page_file_source_id(WebPage *web_page);
vector<FileId> get_web_page_file_ids(const WebPage *web_page) const;