Provided spoiler info to preview text.

This commit is contained in:
23rd 2021-12-21 17:43:44 +03:00 committed by John Preston
parent a027a02130
commit 1cca4d71bd
4 changed files with 34 additions and 14 deletions

View File

@ -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 {

View File

@ -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);
}

View File

@ -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 {};
}();

View File

@ -31,6 +31,7 @@ struct ToPreviewOptions {
bool hideCaption = false;
bool generateImages = true;
bool ignoreGroup = false;
bool ignoreSpoilers = false;
};
} // namespace HistoryView