From 63338a139a1144cf120d03b9a1f8e8a066bf640c Mon Sep 17 00:00:00 2001 From: LucasGGamerM Date: Sat, 30 Sep 2023 19:05:45 -0300 Subject: [PATCH] refactor(filter-predicate): move client filters to its own function. Also allows for Client filters to completely hide posts --- .../ui/displayitems/StatusDisplayItem.java | 4 ++++ .../android/utils/StatusFilterPredicate.java | 15 +++++++++++---- 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/mastodon/src/main/java/org/joinmastodon/android/ui/displayitems/StatusDisplayItem.java b/mastodon/src/main/java/org/joinmastodon/android/ui/displayitems/StatusDisplayItem.java index 5763bf203a..80baea9aa2 100644 --- a/mastodon/src/main/java/org/joinmastodon/android/ui/displayitems/StatusDisplayItem.java +++ b/mastodon/src/main/java/org/joinmastodon/android/ui/displayitems/StatusDisplayItem.java @@ -331,6 +331,10 @@ else if(statusForContent.sensitive && AccountSessionManager.get(accountID).getLo applyingFilter = predicate.getApplyingFilter(); } + // Hide statuses that have a filter action of hide + if(!new StatusFilterPredicate(accountID, filterContext, FilterAction.HIDE).test(status)) + return new ArrayList() ; + return statusForContent.filterRevealed ? items : new ArrayList<>(List.of(new WarningFilteredStatusDisplayItem(parentID, fragment, statusForContent, items, applyingFilter))); } diff --git a/mastodon/src/main/java/org/joinmastodon/android/utils/StatusFilterPredicate.java b/mastodon/src/main/java/org/joinmastodon/android/utils/StatusFilterPredicate.java index 5a1be6a0d8..7d4652f79d 100644 --- a/mastodon/src/main/java/org/joinmastodon/android/utils/StatusFilterPredicate.java +++ b/mastodon/src/main/java/org/joinmastodon/android/utils/StatusFilterPredicate.java @@ -17,6 +17,7 @@ import org.joinmastodon.android.model.Status; import java.time.Instant; +import java.util.ArrayList; import java.util.List; import java.util.Optional; import java.util.function.Predicate; @@ -39,8 +40,7 @@ public StatusFilterPredicate(List filters, FilterContext context, this.filters = filters; this.context = context; this.action = action; - this.clientFilters = GlobalUserPreferences.showPostsWithoutAlt ? List.of() - : List.of(new AltTextFilter(WARN, HOME, PUBLIC, ACCOUNT, THREAD, NOTIFICATIONS)); + this.clientFilters = getClientFilters(); } public StatusFilterPredicate(List filters, FilterContext context){ @@ -56,8 +56,15 @@ public StatusFilterPredicate(String accountID, FilterContext context, FilterActi filters=AccountSessionManager.getInstance().getAccount(accountID).wordFilters.stream().filter(f->f.context.contains(context)).collect(Collectors.toList()); this.context = context; this.action = action; - this.clientFilters = GlobalUserPreferences.showPostsWithoutAlt ? List.of() - : List.of(new AltTextFilter(WARN, HOME, PUBLIC, ACCOUNT, THREAD, NOTIFICATIONS)); + this.clientFilters = getClientFilters(); + } + + private List getClientFilters() { + List filters = new ArrayList<>(); + if(!GlobalUserPreferences.showPostsWithoutAlt) { + filters.add(new AltTextFilter(WARN, HOME, PUBLIC, ACCOUNT, THREAD, NOTIFICATIONS)); + } + return filters; } /**