From d1d8f2ef45143780a67c8c973fb227c904e7e325 Mon Sep 17 00:00:00 2001 From: FineFindus Date: Thu, 9 May 2024 06:39:50 +0200 Subject: [PATCH] refactor(StatusDisplayItem): move client filters to AccountSession --- .../android/api/session/AccountSession.java | 17 +++++++++++++++++ .../ui/displayitems/StatusDisplayItem.java | 16 ++-------------- 2 files changed, 19 insertions(+), 14 deletions(-) diff --git a/mastodon/src/main/java/org/joinmastodon/android/api/session/AccountSession.java b/mastodon/src/main/java/org/joinmastodon/android/api/session/AccountSession.java index 55da7e8e36..e2cd5bf91a 100644 --- a/mastodon/src/main/java/org/joinmastodon/android/api/session/AccountSession.java +++ b/mastodon/src/main/java/org/joinmastodon/android/api/session/AccountSession.java @@ -21,6 +21,7 @@ import org.joinmastodon.android.api.requests.oauth.RevokeOauthToken; import org.joinmastodon.android.events.NotificationsMarkerUpdatedEvent; import org.joinmastodon.android.model.Account; +import org.joinmastodon.android.model.AltTextFilter; import org.joinmastodon.android.model.Application; import org.joinmastodon.android.model.FilterAction; import org.joinmastodon.android.model.FilterContext; @@ -37,6 +38,7 @@ import java.io.File; import java.util.ArrayList; +import java.util.EnumSet; import java.util.List; import java.util.Objects; import java.util.Optional; @@ -326,6 +328,21 @@ public boolean filterStatusContainingObject(T object, Function ex return false; } + public List getClientSideFilters(Status status) { + List filters = List.of(); + + // filter post that have no alt text + // it only applies when activated in the settings + AltTextFilter altTextFilter=new AltTextFilter(FilterAction.WARN, EnumSet.allOf(FilterContext.class)); + if(altTextFilter.matches(status)){ + FilterResult filterResult=new FilterResult(); + filterResult.filter=altTextFilter; + filterResult.keywordMatches=List.of(); + filters.add(filterResult); + } + return filters; + } + public void updateAccountInfo(){ AccountSessionManager.getInstance().updateSessionLocalInfo(this); } 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 10a4a48cc6..9d5e5dbb8b 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 @@ -26,13 +26,11 @@ import org.joinmastodon.android.fragments.StatusListFragment; import org.joinmastodon.android.fragments.ThreadFragment; import org.joinmastodon.android.model.Account; -import org.joinmastodon.android.model.AltTextFilter; import org.joinmastodon.android.model.Attachment; import org.joinmastodon.android.model.DisplayItemsParent; -import org.joinmastodon.android.model.FilterAction; -import org.joinmastodon.android.model.LegacyFilter; import org.joinmastodon.android.model.FilterContext; import org.joinmastodon.android.model.FilterResult; +import org.joinmastodon.android.model.LegacyFilter; import org.joinmastodon.android.model.Notification; import org.joinmastodon.android.model.Poll; import org.joinmastodon.android.model.ScheduledStatus; @@ -45,7 +43,6 @@ import java.util.ArrayList; import java.util.Collections; -import java.util.EnumSet; import java.util.List; import java.util.Map; import java.util.Optional; @@ -231,16 +228,7 @@ public static ArrayList buildItems(BaseStatusListFragment LegacyFilter applyingFilter=null; if(status.filtered!=null){ List filters = status.filtered; - - //add a client side filter to filter posts that have no alt text - //it only applies when activated in the settings - AltTextFilter altTextFilter=new AltTextFilter(FilterAction.WARN, EnumSet.allOf(FilterContext.class)); - if(altTextFilter.matches(status)){ - FilterResult filterResult=new FilterResult(); - filterResult.filter=altTextFilter; - filterResult.keywordMatches=List.of(); - filters.add(filterResult); - } + filters.addAll(AccountSessionManager.get(accountID).getClientSideFilters(status)); for(FilterResult filter:filters){ LegacyFilter f=filter.filter;