Skip to content

Commit

Permalink
refactor(filter-predicate): move client filters to its own function. …
Browse files Browse the repository at this point in the history
…Also allows for Client filters to completely hide posts
  • Loading branch information
LucasGGamerM committed Sep 30, 2023
1 parent 49c2365 commit 63338a1
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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<StatusDisplayItem>() ;

return statusForContent.filterRevealed ? items :
new ArrayList<>(List.of(new WarningFilteredStatusDisplayItem(parentID, fragment, statusForContent, items, applyingFilter)));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -39,8 +40,7 @@ public StatusFilterPredicate(List<LegacyFilter> 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<LegacyFilter> filters, FilterContext context){
Expand All @@ -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<LegacyFilter> getClientFilters() {
List<LegacyFilter> filters = new ArrayList<>();
if(!GlobalUserPreferences.showPostsWithoutAlt) {
filters.add(new AltTextFilter(WARN, HOME, PUBLIC, ACCOUNT, THREAD, NOTIFICATIONS));
}
return filters;
}

/**
Expand Down

0 comments on commit 63338a1

Please sign in to comment.