From 3d0f92e0cb5a1e46d8e63fc4e4b56422f6b8a511 Mon Sep 17 00:00:00 2001 From: levlam Date: Fri, 21 Jun 2024 14:00:29 +0300 Subject: [PATCH] Add get_expired_message_content_type. --- td/telegram/MessageContentType.cpp | 17 ++++++++++++++++- td/telegram/MessageContentType.h | 2 ++ td/telegram/MessagesManager.cpp | 8 ++------ 3 files changed, 20 insertions(+), 7 deletions(-) diff --git a/td/telegram/MessageContentType.cpp b/td/telegram/MessageContentType.cpp index 4deff6ca2..81452dcb2 100644 --- a/td/telegram/MessageContentType.cpp +++ b/td/telegram/MessageContentType.cpp @@ -158,7 +158,7 @@ bool is_allowed_invert_caption_message_content(MessageContentType content_type) case MessageContentType::Video: return true; default: - return false; + return false; } } @@ -522,6 +522,21 @@ bool is_expired_message_content(MessageContentType content_type) { } } +MessageContentType get_expired_message_content_type(MessageContentType content_type) { + switch (content_type) { + case MessageContentType::Photo: + return MessageContentType::ExpiredPhoto; + case MessageContentType::Video: + return MessageContentType::ExpiredVideo; + case MessageContentType::VideoNote: + return MessageContentType::ExpiredVideoNote; + case MessageContentType::VoiceNote: + return MessageContentType::ExpiredVoiceNote; + default: + return MessageContentType::None; + } +} + bool can_have_message_content_caption(MessageContentType content_type) { switch (content_type) { case MessageContentType::Animation: diff --git a/td/telegram/MessageContentType.h b/td/telegram/MessageContentType.h index 2a7397c87..897acf40d 100644 --- a/td/telegram/MessageContentType.h +++ b/td/telegram/MessageContentType.h @@ -102,6 +102,8 @@ bool is_supported_reply_message_content(MessageContentType content_type); bool is_expired_message_content(MessageContentType content_type); +MessageContentType get_expired_message_content_type(MessageContentType content_type); + bool can_have_message_content_caption(MessageContentType content_type); uint64 get_message_content_chain_id(MessageContentType content_type); diff --git a/td/telegram/MessagesManager.cpp b/td/telegram/MessagesManager.cpp index 788aaf0ee..8a192d4bc 100644 --- a/td/telegram/MessagesManager.cpp +++ b/td/telegram/MessagesManager.cpp @@ -33945,12 +33945,8 @@ bool MessagesManager::update_message_content(DialogId dialog_id, Message *old_me bool need_finish_upload = old_file_id.is_valid() && need_merge_files; if (old_content_type != new_content_type) { if (old_message->ttl.is_valid() && old_message->ttl_expires_at > 0 && - ((new_content_type == MessageContentType::ExpiredPhoto && old_content_type == MessageContentType::Photo) || - (new_content_type == MessageContentType::ExpiredVideo && old_content_type == MessageContentType::Video) || - (new_content_type == MessageContentType::ExpiredVideoNote && - old_content_type == MessageContentType::VideoNote) || - (new_content_type == MessageContentType::ExpiredVoiceNote && - old_content_type == MessageContentType::VoiceNote))) { + is_expired_message_content(new_content_type) && + get_expired_message_content_type(old_content_type) == new_content_type) { LOG(INFO) << "Do not apply expired message content early"; } else { need_update = true;