Respect "Always expand posts marked with content warnings" pref in notifications (#3154)

Fixes https://github.com/tuskyapp/Tusky/issues/3139
This commit is contained in:
Nik Clayton 2023-01-12 19:40:01 +01:00 committed by GitHub
parent 8eb195cff6
commit 5498386be1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 6 additions and 5 deletions

View File

@ -174,11 +174,11 @@ public class NotificationHelper {
notificationId++;
builder.setContentTitle(titleForType(context, body, account))
.setContentText(bodyForType(body, context));
.setContentText(bodyForType(body, context, account.getAlwaysOpenSpoiler()));
if (body.getType() == Notification.Type.MENTION || body.getType() == Notification.Type.POLL) {
builder.setStyle(new NotificationCompat.BigTextStyle()
.bigText(bodyForType(body, context)));
.bigText(bodyForType(body, context, account.getAlwaysOpenSpoiler())));
}
//load the avatar synchronously
@ -695,7 +695,7 @@ public class NotificationHelper {
return null;
}
private static String bodyForType(Notification notification, Context context) {
private static String bodyForType(Notification notification, Context context, Boolean alwaysOpenSpoiler) {
switch (notification.getType()) {
case FOLLOW:
case FOLLOW_REQUEST:
@ -705,13 +705,13 @@ public class NotificationHelper {
case FAVOURITE:
case REBLOG:
case STATUS:
if (!TextUtils.isEmpty(notification.getStatus().getSpoilerText())) {
if (!TextUtils.isEmpty(notification.getStatus().getSpoilerText()) && !alwaysOpenSpoiler) {
return notification.getStatus().getSpoilerText();
} else {
return parseAsMastodonHtml(notification.getStatus().getContent()).toString();
}
case POLL:
if (!TextUtils.isEmpty(notification.getStatus().getSpoilerText())) {
if (!TextUtils.isEmpty(notification.getStatus().getSpoilerText()) && !alwaysOpenSpoiler) {
return notification.getStatus().getSpoilerText();
} else {
StringBuilder builder = new StringBuilder(parseAsMastodonHtml(notification.getStatus().getContent()));

View File

@ -62,6 +62,7 @@ data class AccountEntity(
var defaultMediaSensitivity: Boolean = false,
var defaultPostLanguage: String = "",
var alwaysShowSensitiveMedia: Boolean = false,
/** True if content behind a content warning is shown by default */
var alwaysOpenSpoiler: Boolean = false,
var mediaPreviewEnabled: Boolean = true,
var lastNotificationId: String = "0",