From 1cca4d71bdeb890210ff69cc5d0e2acf8af992cd Mon Sep 17 00:00:00 2001 From: 23rd <23rd@vivaldi.net> Date: Tue, 21 Dec 2021 17:43:44 +0300 Subject: [PATCH] Provided spoiler info to preview text. --- .../SourceFiles/data/data_media_types.cpp | 31 +++++++++++++------ .../export/view/export_view_top_bar.cpp | 7 ++--- Telegram/SourceFiles/history/history_item.cpp | 9 +++++- .../history/view/history_view_item_preview.h | 1 + 4 files changed, 34 insertions(+), 14 deletions(-) diff --git a/Telegram/SourceFiles/data/data_media_types.cpp b/Telegram/SourceFiles/data/data_media_types.cpp index 96204825e4..a3569bcfb1 100644 --- a/Telegram/SourceFiles/data/data_media_types.cpp +++ b/Telegram/SourceFiles/data/data_media_types.cpp @@ -69,13 +69,14 @@ using ItemPreviewImage = HistoryView::ItemPreviewImage; [[nodiscard]] QString WithCaptionDialogsText( const QString &attachType, const QString &caption, - bool hasMiniImages) { + bool hasMiniImages, + const HistoryView::ToPreviewOptions &options) { if (caption.isEmpty()) { return textcmdLink(1, TextUtilities::Clean(attachType)); } return hasMiniImages - ? TextUtilities::Clean(caption) + ? TextUtilities::Clean(caption, !options.ignoreSpoilers) : tr::lng_dialogs_text_media( tr::now, lt_media_part, @@ -84,7 +85,7 @@ using ItemPreviewImage = HistoryView::ItemPreviewImage; lt_media, TextUtilities::Clean(attachType))), lt_caption, - TextUtilities::Clean(caption)); + TextUtilities::Clean(caption, !options.ignoreSpoilers)); } [[nodiscard]] QString WithCaptionNotificationText( @@ -354,7 +355,11 @@ ItemPreview Media::toPreview(ToPreviewOptions options) const { auto result = notificationText(); auto text = result.isEmpty() ? QString() - : textcmdLink(1, TextUtilities::Clean(std::move(result))); + : textcmdLink( + 1, + TextUtilities::Clean( + std::move(result), + !options.ignoreSpoilers)); return { .text = std::move(text) }; } @@ -565,9 +570,12 @@ ItemPreview MediaPhoto::toPreview(ToPreviewOptions options) const { const auto type = tr::lng_in_dlg_photo(tr::now); const auto caption = options.hideCaption ? QString() - : parent()->originalText().text; + : options.ignoreSpoilers + ? parent()->originalText().text + : TextUtilities::TextWithSpoilerCommands(parent()->originalText()); + const auto hasMiniImages = !images.empty(); return { - .text = WithCaptionDialogsText(type, caption, !images.empty()), + .text = WithCaptionDialogsText(type, caption, hasMiniImages, options), .images = std::move(images), .loadingContext = std::move(context), }; @@ -784,9 +792,12 @@ ItemPreview MediaFile::toPreview(ToPreviewOptions options) const { }(); const auto caption = options.hideCaption ? QString() - : parent()->originalText().text; + : options.ignoreSpoilers + ? parent()->originalText().text + : TextUtilities::TextWithSpoilerCommands(parent()->originalText()); + const auto hasMiniImages = !images.empty(); return { - .text = WithCaptionDialogsText(type, caption, !images.empty()), + .text = WithCaptionDialogsText(type, caption, hasMiniImages, options), .images = std::move(images), .loadingContext = std::move(context), }; @@ -1113,7 +1124,9 @@ Data::CloudImage *MediaLocation::location() const { ItemPreview MediaLocation::toPreview(ToPreviewOptions options) const { const auto type = tr::lng_maps_point(tr::now); const auto hasMiniImages = false; - return { .text = WithCaptionDialogsText(type, _title, hasMiniImages) }; + return { + .text = WithCaptionDialogsText(type, _title, hasMiniImages, options), + }; } QString MediaLocation::notificationText() const { diff --git a/Telegram/SourceFiles/export/view/export_view_top_bar.cpp b/Telegram/SourceFiles/export/view/export_view_top_bar.cpp index 6294b699cf..aabde67d92 100644 --- a/Telegram/SourceFiles/export/view/export_view_top_bar.cpp +++ b/Telegram/SourceFiles/export/view/export_view_top_bar.cpp @@ -39,14 +39,13 @@ void TopBar::updateData(Content &&content) { return; } const auto &row = content.rows[0]; - const auto clean = &TextUtilities::Clean; _info->setRichText(textcmdStartSemibold() - + clean(tr::lng_export_progress_title(tr::now)) + + TextUtilities::Clean(tr::lng_export_progress_title(tr::now)) + textcmdStopSemibold() + QString::fromUtf8(" \xe2\x80\x93 ") - + clean(row.label) + + TextUtilities::Clean(row.label) + ' ' - + textcmdLink(1, clean(row.info))); + + textcmdLink(1, TextUtilities::Clean(row.info))); _progress->setValue(row.progress); } diff --git a/Telegram/SourceFiles/history/history_item.cpp b/Telegram/SourceFiles/history/history_item.cpp index eb36caf03d..cc1d0386a7 100644 --- a/Telegram/SourceFiles/history/history_item.cpp +++ b/Telegram/SourceFiles/history/history_item.cpp @@ -1037,7 +1037,14 @@ ItemPreview HistoryItem::toPreview(ToPreviewOptions options) const { if (_media) { return _media->toPreview(options); } else if (!emptyText()) { - return { .text = TextUtilities::Clean(_text.toString()) }; + return { + .text = TextUtilities::Clean( + options.ignoreSpoilers + ? _text.toString() + : TextUtilities::TextWithSpoilerCommands( + _text.toTextWithEntities()), + !options.ignoreSpoilers), + }; } return {}; }(); diff --git a/Telegram/SourceFiles/history/view/history_view_item_preview.h b/Telegram/SourceFiles/history/view/history_view_item_preview.h index 7b77ece94d..b3e0ea1590 100644 --- a/Telegram/SourceFiles/history/view/history_view_item_preview.h +++ b/Telegram/SourceFiles/history/view/history_view_item_preview.h @@ -31,6 +31,7 @@ struct ToPreviewOptions { bool hideCaption = false; bool generateImages = true; bool ignoreGroup = false; + bool ignoreSpoilers = false; }; } // namespace HistoryView