From 329df1280b15f89da4abcdde42173b2016c82c53 Mon Sep 17 00:00:00 2001 From: Konrad Pozniak Date: Sat, 12 Feb 2022 09:56:08 +0100 Subject: [PATCH] fix sensitive media in search and notifications (#2335) --- .../tusky/components/search/SearchViewModel.kt | 18 ++++++++++++------ .../tusky/fragment/NotificationsFragment.java | 4 +++- 2 files changed, 15 insertions(+), 7 deletions(-) diff --git a/app/src/main/java/com/keylesspalace/tusky/components/search/SearchViewModel.kt b/app/src/main/java/com/keylesspalace/tusky/components/search/SearchViewModel.kt index c6c17d13..e87c0c41 100644 --- a/app/src/main/java/com/keylesspalace/tusky/components/search/SearchViewModel.kt +++ b/app/src/main/java/com/keylesspalace/tusky/components/search/SearchViewModel.kt @@ -56,10 +56,17 @@ class SearchViewModel @Inject constructor( private val loadedStatuses: MutableList> = mutableListOf() private val statusesPagingSourceFactory = SearchPagingSourceFactory(mastodonApi, SearchType.Status, loadedStatuses) { - it.statuses.map { status -> Pair(status, status.toViewData(alwaysShowSensitiveMedia, alwaysOpenSpoiler, true)) } - .apply { - loadedStatuses.addAll(this) - } + it.statuses.map { status -> + val statusViewData = status.toViewData( + isShowingContent = alwaysShowSensitiveMedia || !status.actionableStatus.sensitive, + isExpanded = alwaysOpenSpoiler, + isCollapsed = true + ) + + Pair(status, statusViewData) + }.apply { + loadedStatuses.addAll(this) + } } private val accountsPagingSourceFactory = SearchPagingSourceFactory(mastodonApi, SearchType.Account) { it.accounts @@ -100,8 +107,7 @@ class SearchViewModel @Inject constructor( if (loadedStatuses.remove(status)) statusesPagingSourceFactory.invalidate() }, - { - err -> + { err -> Log.d(TAG, "Failed to delete status", err) } ) diff --git a/app/src/main/java/com/keylesspalace/tusky/fragment/NotificationsFragment.java b/app/src/main/java/com/keylesspalace/tusky/fragment/NotificationsFragment.java index 571af73f..467ebc8c 100644 --- a/app/src/main/java/com/keylesspalace/tusky/fragment/NotificationsFragment.java +++ b/app/src/main/java/com/keylesspalace/tusky/fragment/NotificationsFragment.java @@ -185,9 +185,11 @@ public class NotificationsFragment extends SFragment implements Notification notification = input.asRight() .rewriteToStatusTypeIfNeeded(accountManager.getActiveAccount().getAccountId()); + boolean sensitiveStatus = notification.getStatus() != null && notification.getStatus().getActionableStatus().getSensitive(); + return ViewDataUtils.notificationToViewData( notification, - alwaysShowSensitiveMedia, + alwaysShowSensitiveMedia || !sensitiveStatus, alwaysOpenSpoiler, true );