fix: Only enable accessible actions on notifications attached to a status

Fixes #669
This commit is contained in:
Nik Clayton 2024-04-29 18:43:39 +02:00
parent fc5061f777
commit 22729df1b7
No known key found for this signature in database
GPG Key ID: F95268159C2EC897
2 changed files with 8 additions and 0 deletions

View File

@ -20,6 +20,7 @@ import app.pachli.core.activity.openLink
import app.pachli.core.network.model.Status.Companion.MAX_MEDIA_ATTACHMENTS import app.pachli.core.network.model.Status.Companion.MAX_MEDIA_ATTACHMENTS
import app.pachli.interfaces.StatusActionListener import app.pachli.interfaces.StatusActionListener
import app.pachli.viewdata.IStatusViewData import app.pachli.viewdata.IStatusViewData
import app.pachli.viewdata.NotificationViewData
import app.pachli.viewdata.StatusViewData import app.pachli.viewdata.StatusViewData
import kotlin.math.min import kotlin.math.min
@ -50,6 +51,11 @@ class ListStatusAccessibilityDelegate<T : IStatusViewData>(
val pos = recyclerView.getChildAdapterPosition(host) val pos = recyclerView.getChildAdapterPosition(host)
val status = statusProvider.getStatus(pos) ?: return 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()) { if (status.spoilerText.isNotEmpty()) {
info.addAction(if (status.isExpanded) collapseCwAction else expandCwAction) info.addAction(if (status.isExpanded) collapseCwAction else expandCwAction)
} }

View File

@ -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 // 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. // `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 override val username: String
get() = statusViewData?.username ?: throw IllegalStateException() get() = statusViewData?.username ?: throw IllegalStateException()
override val rebloggedAvatar: String? override val rebloggedAvatar: String?