Skip to content

Commit

Permalink
refactor(StatusDisplayItem): move client filters to AccountSession
Browse files Browse the repository at this point in the history
  • Loading branch information
FineFindus committed May 9, 2024
1 parent ebf3b07 commit d1d8f2e
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -326,6 +328,21 @@ public <T> boolean filterStatusContainingObject(T object, Function<T, Status> ex
return false;
}

public List<FilterResult> getClientSideFilters(Status status) {
List<FilterResult> 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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -231,16 +228,7 @@ public static ArrayList<StatusDisplayItem> buildItems(BaseStatusListFragment<?>
LegacyFilter applyingFilter=null;
if(status.filtered!=null){
List<FilterResult> 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;
Expand Down

0 comments on commit d1d8f2e

Please sign in to comment.