From 1f2f4d51b5d48d1807d4d516bab59e435bffbc92 Mon Sep 17 00:00:00 2001 From: sanao Date: Tue, 24 Oct 2023 05:47:11 +0900 Subject: [PATCH] feat: Add a preference to hide "self-boosts" A "self-boost" is someone boosting their own post. Some people are particularly prolific at this, and it can clutter the timeline. Provide a new preference that allows the user to show/hide these boosts from their timeline. --- .../preference/TabFilterPreferencesFragment.kt | 8 ++++++++ .../timeline/viewmodel/TimelineViewModel.kt | 15 ++++++++++++++- .../java/app/pachli/settings/SettingsConstants.kt | 1 + app/src/main/res/values/strings.xml | 2 ++ 4 files changed, 25 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/app/pachli/components/preference/TabFilterPreferencesFragment.kt b/app/src/main/java/app/pachli/components/preference/TabFilterPreferencesFragment.kt index 186e436df..09631da00 100644 --- a/app/src/main/java/app/pachli/components/preference/TabFilterPreferencesFragment.kt +++ b/app/src/main/java/app/pachli/components/preference/TabFilterPreferencesFragment.kt @@ -36,6 +36,14 @@ class TabFilterPreferencesFragment : PreferenceFragmentCompat() { isIconSpaceReserved = false } + switchPreference { + setTitle(R.string.pref_title_show_self_boosts) + setSummary(R.string.pref_title_show_self_boosts_description) + key = PrefKeys.TAB_SHOW_HOME_SELF_BOOSTS + setDefaultValue(true) + isIconSpaceReserved = false + }.apply { dependency = PrefKeys.TAB_FILTER_HOME_BOOSTS } + switchPreference { setTitle(R.string.pref_title_show_replies) key = PrefKeys.TAB_FILTER_HOME_REPLIES diff --git a/app/src/main/java/app/pachli/components/timeline/viewmodel/TimelineViewModel.kt b/app/src/main/java/app/pachli/components/timeline/viewmodel/TimelineViewModel.kt index 07d856ece..1105aff58 100644 --- a/app/src/main/java/app/pachli/components/timeline/viewmodel/TimelineViewModel.kt +++ b/app/src/main/java/app/pachli/components/timeline/viewmodel/TimelineViewModel.kt @@ -301,6 +301,7 @@ abstract class TimelineViewModel( private var filterRemoveReplies = false private var filterRemoveReblogs = false + private var filterRemoveSelfReblogs = false protected val activeAccount = accountManager.activeAccount!! @@ -397,6 +398,8 @@ abstract class TimelineViewModel( !sharedPreferencesRepository.getBoolean(PrefKeys.TAB_FILTER_HOME_REPLIES, true) filterRemoveReblogs = !sharedPreferencesRepository.getBoolean(PrefKeys.TAB_FILTER_HOME_BOOSTS, true) + filterRemoveSelfReblogs = + !sharedPreferencesRepository.getBoolean(PrefKeys.TAB_SHOW_HOME_SELF_BOOSTS, true) } // Save the visible status ID (if it's the home timeline) @@ -492,7 +495,9 @@ abstract class TimelineViewModel( val status = statusViewData.status return if ( (status.inReplyToId != null && filterRemoveReplies) || - (status.reblog != null && filterRemoveReblogs) + (status.reblog != null && filterRemoveReblogs) || + // To determine if the boost is boosting your own toot + ((status.account.id == status.reblog?.account?.id) && filterRemoveSelfReblogs) ) { return Filter.Action.HIDE } else { @@ -560,6 +565,14 @@ abstract class TimelineViewModel( reloadKeepingReadingPosition() } } + PrefKeys.TAB_SHOW_HOME_SELF_BOOSTS -> { + val filter = sharedPreferencesRepository.getBoolean(PrefKeys.TAB_SHOW_HOME_SELF_BOOSTS, true) + val oldRemoveSelfReblogs = filterRemoveSelfReblogs + filterRemoveSelfReblogs = timelineKind is TimelineKind.Home && !filter + if (oldRemoveSelfReblogs != filterRemoveSelfReblogs) { + reloadKeepingReadingPosition() + } + } } } diff --git a/app/src/main/java/app/pachli/settings/SettingsConstants.kt b/app/src/main/java/app/pachli/settings/SettingsConstants.kt index f7df073ce..5ca210635 100644 --- a/app/src/main/java/app/pachli/settings/SettingsConstants.kt +++ b/app/src/main/java/app/pachli/settings/SettingsConstants.kt @@ -103,6 +103,7 @@ object PrefKeys { const val TAB_FILTER_HOME_REPLIES = "tabFilterHomeReplies_v2" // This was changed once to reset an unintentionally set default. const val TAB_FILTER_HOME_BOOSTS = "tabFilterHomeBoosts" + const val TAB_SHOW_HOME_SELF_BOOSTS = "tabShowHomeSelfBoosts" /** UI text scaling factor, stored as float, 100 = 100% = no scaling */ const val UI_TEXT_SCALE_RATIO = "uiTextScaleRatio" diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 206279233..db97f769f 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -144,6 +144,8 @@ Share username of account Hide boosts Show boosts + Show self-boosts + Someone boosting their own post Report Edit Delete