From 0d3480435936b6b9d85684f7bc9fdead52b329a6 Mon Sep 17 00:00:00 2001 From: Konrad Pozniak Date: Tue, 5 Nov 2024 20:43:52 +0100 Subject: [PATCH] never filter own posts (#4742) This is to match Mastodon web behavior. Also, make revealing filtered boosts in non-cached timelines work (can only happen on user profiles, other timelines don't have boosts). found thanks to this: https://tech.lgbt/@darkfox/113378644538792719 --- .../notifications/NotificationsViewModel.kt | 3 +++ .../viewmodel/CachedTimelineViewModel.kt | 2 -- .../viewmodel/NetworkTimelineViewModel.kt | 2 +- .../timeline/viewmodel/TimelineViewModel.kt | 6 ++++++ .../components/viewthread/ViewThreadViewModel.kt | 16 +++++++--------- 5 files changed, 17 insertions(+), 12 deletions(-) diff --git a/app/src/main/java/com/keylesspalace/tusky/components/notifications/NotificationsViewModel.kt b/app/src/main/java/com/keylesspalace/tusky/components/notifications/NotificationsViewModel.kt index 5e74003ec..838aecee0 100644 --- a/app/src/main/java/com/keylesspalace/tusky/components/notifications/NotificationsViewModel.kt +++ b/app/src/main/java/com/keylesspalace/tusky/components/notifications/NotificationsViewModel.kt @@ -153,6 +153,9 @@ class NotificationsViewModel @Inject constructor( return when ((notificationViewData as? NotificationViewData.Concrete)?.type) { Notification.Type.MENTION, Notification.Type.POLL -> { notificationViewData.statusViewData?.let { statusViewData -> + if (statusViewData.status.account.id == account.accountId) { + return Filter.Action.NONE + } statusViewData.filterAction = filterModel.shouldFilterStatus(statusViewData.actionable) return statusViewData.filterAction } diff --git a/app/src/main/java/com/keylesspalace/tusky/components/timeline/viewmodel/CachedTimelineViewModel.kt b/app/src/main/java/com/keylesspalace/tusky/components/timeline/viewmodel/CachedTimelineViewModel.kt index 2685fda14..e315d5252 100644 --- a/app/src/main/java/com/keylesspalace/tusky/components/timeline/viewmodel/CachedTimelineViewModel.kt +++ b/app/src/main/java/com/keylesspalace/tusky/components/timeline/viewmodel/CachedTimelineViewModel.kt @@ -76,8 +76,6 @@ class CachedTimelineViewModel @Inject constructor( filterModel ) { - private val account = accountManager.activeAccount!! - private var currentPagingSource: PagingSource? = null /** Map from status id to translation. */ diff --git a/app/src/main/java/com/keylesspalace/tusky/components/timeline/viewmodel/NetworkTimelineViewModel.kt b/app/src/main/java/com/keylesspalace/tusky/components/timeline/viewmodel/NetworkTimelineViewModel.kt index 41b5eb0bf..ff95bc214 100644 --- a/app/src/main/java/com/keylesspalace/tusky/components/timeline/viewmodel/NetworkTimelineViewModel.kt +++ b/app/src/main/java/com/keylesspalace/tusky/components/timeline/viewmodel/NetworkTimelineViewModel.kt @@ -304,7 +304,7 @@ class NetworkTimelineViewModel @Inject constructor( } override fun clearWarning(status: StatusViewData.Concrete) { - updateStatusByActionableId(status.id) { + updateStatusByActionableId(status.actionableId) { it.copy(filtered = emptyList()) } } diff --git a/app/src/main/java/com/keylesspalace/tusky/components/timeline/viewmodel/TimelineViewModel.kt b/app/src/main/java/com/keylesspalace/tusky/components/timeline/viewmodel/TimelineViewModel.kt index 015725660..ff915ea7b 100644 --- a/app/src/main/java/com/keylesspalace/tusky/components/timeline/viewmodel/TimelineViewModel.kt +++ b/app/src/main/java/com/keylesspalace/tusky/components/timeline/viewmodel/TimelineViewModel.kt @@ -46,6 +46,8 @@ abstract class TimelineViewModel( private val filterModel: FilterModel ) : ViewModel() { + protected val account = accountManager.activeAccount!! + abstract val statuses: Flow> var kind: Kind = Kind.HOME @@ -179,6 +181,10 @@ abstract class TimelineViewModel( protected fun shouldFilterStatus(statusViewData: StatusViewData): Filter.Action { val status = statusViewData.asStatusOrNull()?.status ?: return Filter.Action.NONE + if (status.actionableStatus.account.id == account.accountId) { + // never filter own posts + return Filter.Action.NONE + } return if ( (status.inReplyToId != null && filterRemoveReplies) || (status.reblog != null && filterRemoveReblogs) || diff --git a/app/src/main/java/com/keylesspalace/tusky/components/viewthread/ViewThreadViewModel.kt b/app/src/main/java/com/keylesspalace/tusky/components/viewthread/ViewThreadViewModel.kt index 8f659c57b..13d1afa8e 100644 --- a/app/src/main/java/com/keylesspalace/tusky/components/viewthread/ViewThreadViewModel.kt +++ b/app/src/main/java/com/keylesspalace/tusky/components/viewthread/ViewThreadViewModel.kt @@ -68,6 +68,8 @@ class ViewThreadViewModel @Inject constructor( private val moshi: Moshi ) : ViewModel() { + private val activeAccount = accountManager.activeAccount!! + private val _uiState = MutableStateFlow(ThreadUiState.Loading as ThreadUiState) val uiState: Flow = _uiState.asStateFlow() @@ -80,14 +82,10 @@ class ViewThreadViewModel @Inject constructor( var isInitialLoad: Boolean = true - private val alwaysShowSensitiveMedia: Boolean - private val alwaysOpenSpoiler: Boolean + private val alwaysShowSensitiveMedia: Boolean = activeAccount.alwaysShowSensitiveMedia + private val alwaysOpenSpoiler: Boolean = activeAccount.alwaysOpenSpoiler init { - val activeAccount = accountManager.activeAccount - alwaysShowSensitiveMedia = activeAccount?.alwaysShowSensitiveMedia ?: false - alwaysOpenSpoiler = activeAccount?.alwaysOpenSpoiler ?: false - viewModelScope.launch { eventHub.events .collect { event -> @@ -109,7 +107,7 @@ class ViewThreadViewModel @Inject constructor( val filterCall = async { filterModel.init(Filter.Kind.THREAD) } val contextCall = async { api.statusContext(id) } - val statusAndAccount = db.timelineStatusDao().getStatusWithAccount(accountManager.activeAccount!!.id, id) + val statusAndAccount = db.timelineStatusDao().getStatusWithAccount(activeAccount.id, id) var detailedStatus = if (statusAndAccount != null) { Log.d(TAG, "Loaded status from local timeline") @@ -142,7 +140,7 @@ class ViewThreadViewModel @Inject constructor( if (statusAndAccount != null) { api.status(id).onSuccess { result -> db.timelineStatusDao().update( - tuskyAccountId = accountManager.activeAccount!!.id, + tuskyAccountId = activeAccount.id, status = result, moshi = moshi ) @@ -421,7 +419,7 @@ class ViewThreadViewModel @Inject constructor( private fun List.filter(): List { return filter { status -> - if (status.isDetailed) { + if (status.isDetailed || status.status.account.id == activeAccount.accountId) { true } else { status.filterAction = filterModel.shouldFilterStatus(status.status)