Skip to content

Commit

Permalink
Improve can_message_content_have_media_timestamp.
Browse files Browse the repository at this point in the history
  • Loading branch information
levlam committed Jul 26, 2021
1 parent 5d579af commit bc5efb7
Showing 5 changed files with 17 additions and 10 deletions.
13 changes: 13 additions & 0 deletions td/telegram/MessageContent.cpp
Original file line number Diff line number Diff line change
@@ -2810,6 +2810,19 @@ void remove_message_content_web_page(MessageContent *content) {
static_cast<MessageText *>(content)->web_page_id = WebPageId();
}

bool can_message_content_have_media_timestamp(const MessageContent *content) {
CHECK(content != nullptr);
switch (content->get_type()) {
case MessageContentType::Audio:
case MessageContentType::Video:
case MessageContentType::VideoNote:
case MessageContentType::VoiceNote:
return true;
default:
return has_message_content_web_page(content);
}
}

void set_message_content_poll_answer(Td *td, const MessageContent *content, FullMessageId full_message_id,
vector<int32> &&option_ids, Promise<Unit> &&promise) {
CHECK(content->get_type() == MessageContentType::Poll);
2 changes: 2 additions & 0 deletions td/telegram/MessageContent.h
Original file line number Diff line number Diff line change
@@ -149,6 +149,8 @@ bool has_message_content_web_page(const MessageContent *content);

void remove_message_content_web_page(MessageContent *content);

bool can_message_content_have_media_timestamp(const MessageContent *content);

void set_message_content_poll_answer(Td *td, const MessageContent *content, FullMessageId full_message_id,
vector<int32> &&option_ids, Promise<Unit> &&promise);

6 changes: 0 additions & 6 deletions td/telegram/MessageContentType.cpp
Original file line number Diff line number Diff line change
@@ -335,10 +335,4 @@ bool can_have_message_content_caption(MessageContentType content_type) {
}
}

bool can_have_media_timestamp(MessageContentType content_type) {
return content_type == MessageContentType::Audio || content_type == MessageContentType::Text ||
content_type == MessageContentType::Video || content_type == MessageContentType::VideoNote ||
content_type == MessageContentType::VoiceNote;
}

} // namespace td
2 changes: 0 additions & 2 deletions td/telegram/MessageContentType.h
Original file line number Diff line number Diff line change
@@ -75,8 +75,6 @@ bool is_service_message_content(MessageContentType content_type);

bool can_have_message_content_caption(MessageContentType content_type);

bool can_have_media_timestamp(MessageContentType content_type);

struct MessageContentTypeHash {
std::size_t operator()(MessageContentType content_type) const {
return std::hash<int32>()(static_cast<int32>(content_type));
4 changes: 2 additions & 2 deletions td/telegram/MessagesManager.cpp
Original file line number Diff line number Diff line change
@@ -17318,7 +17318,7 @@ Result<std::pair<string, bool>> MessagesManager::get_message_link(FullMessageId
for_comment = false;
}

if (media_timestamp <= 0 || !can_have_media_timestamp(m->content->get_type())) {
if (media_timestamp <= 0 || !can_message_content_have_media_timestamp(m->content.get())) {
media_timestamp = 0;
}
if (media_timestamp != 0) {
@@ -17581,7 +17581,7 @@ td_api::object_ptr<td_api::messageLinkInfo> MessagesManager::get_message_link_in
message = get_message_object(dialog_id, m);
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_have_media_timestamp(m->content->get_type())) {
if (can_message_content_have_media_timestamp(m->content.get())) {
auto duration = get_message_content_duration(m->content.get(), td_);
if (duration == 0 || info.media_timestamp <= duration) {
media_timestamp = info.media_timestamp;

0 comments on commit bc5efb7

Please sign in to comment.