From 22729df1b76fad8acf7ccb831e41faf1d8f15606 Mon Sep 17 00:00:00 2001 From: Nik Clayton Date: Mon, 29 Apr 2024 18:43:39 +0200 Subject: [PATCH] fix: Only enable accessible actions on notifications attached to a status Fixes #669 --- .../java/app/pachli/util/ListStatusAccessibilityDelegate.kt | 6 ++++++ .../main/java/app/pachli/viewdata/NotificationViewData.kt | 2 ++ 2 files changed, 8 insertions(+) diff --git a/app/src/main/java/app/pachli/util/ListStatusAccessibilityDelegate.kt b/app/src/main/java/app/pachli/util/ListStatusAccessibilityDelegate.kt index ca10b2996..614094b1c 100644 --- a/app/src/main/java/app/pachli/util/ListStatusAccessibilityDelegate.kt +++ b/app/src/main/java/app/pachli/util/ListStatusAccessibilityDelegate.kt @@ -20,6 +20,7 @@ import app.pachli.core.activity.openLink import app.pachli.core.network.model.Status.Companion.MAX_MEDIA_ATTACHMENTS import app.pachli.interfaces.StatusActionListener import app.pachli.viewdata.IStatusViewData +import app.pachli.viewdata.NotificationViewData import app.pachli.viewdata.StatusViewData import kotlin.math.min @@ -50,6 +51,11 @@ class ListStatusAccessibilityDelegate( val pos = recyclerView.getChildAdapterPosition(host) val status = statusProvider.getStatus(pos) ?: return + // Ignore notifications that don't have an associated statusViewData, + // otherwise the accessors throw IllegalStateException. + // See https://github.com/pachli/pachli-android/issues/669 + if ((status as? NotificationViewData)?.statusViewData == null) return + if (status.spoilerText.isNotEmpty()) { info.addAction(if (status.isExpanded) collapseCwAction else expandCwAction) } diff --git a/app/src/main/java/app/pachli/viewdata/NotificationViewData.kt b/app/src/main/java/app/pachli/viewdata/NotificationViewData.kt index 43f23aa75..b0d0cf3d0 100644 --- a/app/src/main/java/app/pachli/viewdata/NotificationViewData.kt +++ b/app/src/main/java/app/pachli/viewdata/NotificationViewData.kt @@ -72,6 +72,8 @@ data class NotificationViewData( // as that might be null. It's up to the calling code to only check these properties if // `statusViewData` is not null; not doing that is an illegal state, hence the exception. + // TODO: Don't do this, it's a significant footgun, see + // https://github.com/pachli/pachli-android/issues/669 override val username: String get() = statusViewData?.username ?: throw IllegalStateException() override val rebloggedAvatar: String?