From a1c7a48958c1f7411097bfce0c2ec20cfef01d5f Mon Sep 17 00:00:00 2001 From: 23rd <23rd@vivaldi.net> Date: Fri, 29 Dec 2023 09:29:12 +0300 Subject: [PATCH] Improved processing of out expired voice messages. --- Telegram/SourceFiles/api/api_updates.cpp | 12 +++++---- .../history/history_item_helpers.cpp | 25 +++++++++++++++++++ .../history/history_item_helpers.h | 2 ++ 3 files changed, 34 insertions(+), 5 deletions(-) diff --git a/Telegram/SourceFiles/api/api_updates.cpp b/Telegram/SourceFiles/api/api_updates.cpp index e8ae9a270..760826e7e 100644 --- a/Telegram/SourceFiles/api/api_updates.cpp +++ b/Telegram/SourceFiles/api/api_updates.cpp @@ -44,6 +44,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "lang/lang_cloud_manager.h" #include "history/history.h" #include "history/history_item.h" +#include "history/history_item_helpers.h" #include "history/history_unread_things.h" #include "core/application.h" #include "storage/storage_account.h" @@ -1204,11 +1205,12 @@ void Updates::applyUpdateNoPtsCheck(const MTPUpdate &update) { item->markMediaAndMentionRead(); _session->data().requestItemRepaint(item); - if (item->out() - && item->history()->peer->isUser() - && !requestingDifference()) { - item->history()->peer->asUser()->madeAction( - base::unixtime::now()); + if (item->out()) { + const auto user = item->history()->peer->asUser(); + if (user && !requestingDifference()) { + user->madeAction(base::unixtime::now()); + } + ClearMediaAsExpired(item); } } } else { diff --git a/Telegram/SourceFiles/history/history_item_helpers.cpp b/Telegram/SourceFiles/history/history_item_helpers.cpp index 78c7a8121..a249195c9 100644 --- a/Telegram/SourceFiles/history/history_item_helpers.cpp +++ b/Telegram/SourceFiles/history/history_item_helpers.cpp @@ -14,6 +14,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "data/data_channel.h" #include "data/data_chat.h" #include "data/data_changes.h" +#include "data/data_document.h" #include "data/data_group_call.h" #include "data/data_forum.h" #include "data/data_forum_topic.h" @@ -783,3 +784,27 @@ void ShowTrialTranscribesToast(int left, TimeId until) { .filter = filter, }); } + +void ClearMediaAsExpired(not_null item) { + if (const auto media = item->media()) { + if (!media->ttlSeconds()) { + return; + } + if (const auto document = media->document()) { + item->applyEditionToHistoryCleared(); + auto text = (document->isVideoFile() + ? tr::lng_ttl_video_expired + : document->isVoiceMessage() + ? tr::lng_ttl_voice_expired + : document->isVideoMessage() + ? tr::lng_ttl_round_expired + : tr::lng_message_empty)(tr::now, Ui::Text::WithEntities); + item->updateServiceText(PreparedServiceText{ std::move(text) }); + } else if (const auto photo = media->photo()) { + item->applyEditionToHistoryCleared(); + item->updateServiceText(PreparedServiceText{ + tr::lng_ttl_photo_expired(tr::now, Ui::Text::WithEntities) + }); + } + } +} diff --git a/Telegram/SourceFiles/history/history_item_helpers.h b/Telegram/SourceFiles/history/history_item_helpers.h index ca972eaa7..c438eccbe 100644 --- a/Telegram/SourceFiles/history/history_item_helpers.h +++ b/Telegram/SourceFiles/history/history_item_helpers.h @@ -156,3 +156,5 @@ ClickHandlerPtr JumpToStoryClickHandler( CallId callId); void ShowTrialTranscribesToast(int left, TimeId until); + +void ClearMediaAsExpired(not_null item);