From edcfac8da3f141318bc712840348e56943dc1516 Mon Sep 17 00:00:00 2001 From: 23rd <23rd@vivaldi.net> Date: Mon, 25 Apr 2022 21:09:51 +0300 Subject: [PATCH] Slightly improved display of media replacement in admin log. --- Telegram/Resources/langs/lang.strings | 5 ++- .../SourceFiles/data/data_file_origin.cpp | 4 ++ Telegram/SourceFiles/data/data_file_origin.h | 3 ++ .../admin_log/history_admin_log_item.cpp | 37 ++++++++++++++++--- 4 files changed, 43 insertions(+), 6 deletions(-) diff --git a/Telegram/Resources/langs/lang.strings b/Telegram/Resources/langs/lang.strings index 662881f42f..0a07b55d1b 100644 --- a/Telegram/Resources/langs/lang.strings +++ b/Telegram/Resources/langs/lang.strings @@ -2661,7 +2661,10 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL "lng_admin_log_pinned_message" = "{from} pinned this message:"; "lng_admin_log_unpinned_message" = "{from} unpinned this message"; "lng_admin_log_edited_caption" = "{from} edited caption:"; -"lng_admin_log_removed_caption" = "{from} removed caption"; +"lng_admin_log_edited_media" = "{from} edited media:"; +"lng_admin_log_edited_media_and_caption" = "{from} edited media and caption:"; +"lng_admin_log_edited_media_and_removed_caption" = "{from} edited media and removed caption:"; +"lng_admin_log_removed_caption" = "{from} removed caption:"; "lng_admin_log_previous_caption" = "Original caption"; "lng_admin_log_edited_message" = "{from} edited this message:"; "lng_admin_log_previous_message" = "Original message"; diff --git a/Telegram/SourceFiles/data/data_file_origin.cpp b/Telegram/SourceFiles/data/data_file_origin.cpp index fadc30fa7e..c7324ed3cf 100644 --- a/Telegram/SourceFiles/data/data_file_origin.cpp +++ b/Telegram/SourceFiles/data/data_file_origin.cpp @@ -208,4 +208,8 @@ UpdatedFileReferences GetFileReferences( return GetFileReferencesHelper(data); } +UpdatedFileReferences GetFileReferences(const MTPMessageMedia &data) { + return GetFileReferencesHelper(data); +} + } // namespace Data diff --git a/Telegram/SourceFiles/data/data_file_origin.h b/Telegram/SourceFiles/data/data_file_origin.h index 85a8349b19..84b382fb1b 100644 --- a/Telegram/SourceFiles/data/data_file_origin.h +++ b/Telegram/SourceFiles/data/data_file_origin.h @@ -179,4 +179,7 @@ UpdatedFileReferences GetFileReferences(const MTPTheme &data); UpdatedFileReferences GetFileReferences( const MTPaccount_SavedRingtones &data); +// Admin Log Event. +UpdatedFileReferences GetFileReferences(const MTPMessageMedia &data); + } // namespace Data diff --git a/Telegram/SourceFiles/history/admin_log/history_admin_log_item.cpp b/Telegram/SourceFiles/history/admin_log/history_admin_log_item.cpp index 683ee4b264..5a5c9492a4 100644 --- a/Telegram/SourceFiles/history/admin_log/history_admin_log_item.cpp +++ b/Telegram/SourceFiles/history/admin_log/history_admin_log_item.cpp @@ -16,6 +16,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "api/api_chat_participants.h" #include "api/api_text_entities.h" #include "data/data_channel.h" +#include "data/data_file_origin.h" #include "data/data_user.h" #include "data/data_session.h" #include "lang/lang_keys.h" @@ -136,6 +137,18 @@ bool MediaCanHaveCaption(const MTPMessage &message) { || (mediaType == mtpc_messageMediaPhoto); } +uint64 MediaId(const MTPMessage &message) { + if (!MediaCanHaveCaption(message)) { + return 0; + } + const auto &media = message.c_message().vmedia(); + return media + ? v::match( + Data::GetFileReferences(*media).data.begin()->first, + [](const auto &d) { return d.id; }) + : 0; +} + TextWithEntities ExtractEditedText( not_null session, const MTPMessage &message) { @@ -868,22 +881,36 @@ void GenerateItems( const auto newValue = ExtractEditedText( session, action.vnew_message()); + auto oldValue = ExtractEditedText( + session, + action.vprev_message()); + const auto canHaveCaption = MediaCanHaveCaption( action.vnew_message()); + const auto changedCaption = (newValue != oldValue); + const auto changedMedia = MediaId(action.vnew_message()) + != MediaId(action.vprev_message()); + const auto removedCaption = !oldValue.text.isEmpty() + && newValue.text.isEmpty(); const auto text = (!canHaveCaption ? tr::lng_admin_log_edited_message - : newValue.text.isEmpty() + : (changedMedia && removedCaption) + ? tr::lng_admin_log_edited_media_and_removed_caption + : (changedMedia && changedCaption) + ? tr::lng_admin_log_edited_media_and_caption + : changedMedia + ? tr::lng_admin_log_edited_media + : removedCaption ? tr::lng_admin_log_removed_caption - : tr::lng_admin_log_edited_caption)( + : changedCaption + ? tr::lng_admin_log_edited_caption + : tr::lng_admin_log_edited_message)( tr::now, lt_from, fromLinkText, Ui::Text::WithEntities); addSimpleServiceMessage(text); - auto oldValue = ExtractEditedText( - session, - action.vprev_message()); const auto detachExistingItem = false; const auto body = history->createItem( history->nextNonHistoryEntryId(),