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

View File

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