Skip to content

Commit

Permalink
refactor: remove StatusFilterPredicate
Browse files Browse the repository at this point in the history
Removes the deprecated StatusFilterPredicate class, as it has been
replaced upstream. Client-side filters are now directly applied in the
when building a StatusDisplayItem.
  • Loading branch information
FineFindus committed May 8, 2024
1 parent 00726ab commit 28c851a
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 243 deletions.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,14 @@

import org.joinmastodon.android.R;
import org.joinmastodon.android.api.requests.timelines.GetPublicTimeline;
import org.joinmastodon.android.model.Filter;
import org.joinmastodon.android.api.session.AccountSessionManager;
import org.joinmastodon.android.model.FilterContext;
import org.joinmastodon.android.model.Status;
import org.joinmastodon.android.model.TimelineDefinition;
import org.joinmastodon.android.ui.utils.UiUtils;
import org.joinmastodon.android.utils.ProvidesAssistContent;
import org.joinmastodon.android.utils.StatusFilterPredicate;

import java.util.List;
import java.util.stream.Collectors;

import me.grishka.appkit.api.SimpleCallback;

Expand Down Expand Up @@ -53,7 +51,7 @@ public void onSuccess(List<Status> result){
if(!result.isEmpty())
maxID=result.get(result.size()-1).id;
if (getActivity() == null) return;
result=result.stream().filter(new StatusFilterPredicate(accountID, FilterContext.PUBLIC)).collect(Collectors.toList());
AccountSessionManager.get(accountID).filterStatuses(result, FilterContext.PUBLIC);
result.stream().forEach(status -> {
status.account.acct += "@"+domain;
status.mentions.forEach(mention -> mention.id = null);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,19 +1,25 @@
package org.joinmastodon.android.model;

import org.joinmastodon.android.GlobalUserPreferences;
import org.jsoup.internal.StringUtil;

import java.util.EnumSet;

public class AltTextFilter extends LegacyFilter {

public AltTextFilter(FilterAction filterAction, FilterContext firstContext, FilterContext... restContexts) {
public AltTextFilter(FilterAction filterAction, EnumSet<FilterContext> filterContexts) {
this.filterAction = filterAction;
isRemote = false;
context = EnumSet.of(firstContext, restContexts);
context = filterContexts;
}

@Override
public boolean matches(Status status) {
return status.getContentStatus().mediaAttachments.stream().map(attachment -> attachment.description).anyMatch(StringUtil::isBlank);
}

@Override
public boolean isActive(){
return !GlobalUserPreferences.showPostsWithoutAlt;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
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;
Expand All @@ -40,11 +41,11 @@
import org.joinmastodon.android.ui.text.HtmlParser;
import org.joinmastodon.android.ui.utils.UiUtils;
import org.joinmastodon.android.ui.viewholders.AccountViewHolder;
import org.joinmastodon.android.utils.StatusFilterPredicate;
import org.parceler.Parcels;

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 @@ -168,10 +169,6 @@ public static ArrayList<StatusDisplayItem> buildItems(BaseStatusListFragment<?>
args.putString("account", accountID);
ScheduledStatus scheduledStatus = parentObject instanceof ScheduledStatus s ? s : null;

// Hide statuses that have a filter action of hide
if(!new StatusFilterPredicate(accountID, filterContext, FilterAction.HIDE).test(status))
return new ArrayList<StatusDisplayItem>() ;

HeaderStatusDisplayItem header=null;
boolean hideCounts=!AccountSessionManager.get(accountID).getLocalPreferences().showInteractionCounts;

Expand Down Expand Up @@ -233,20 +230,25 @@ public static ArrayList<StatusDisplayItem> buildItems(BaseStatusListFragment<?>

LegacyFilter applyingFilter=null;
if(status.filtered!=null){
for(FilterResult filter:status.filtered){
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);
}

for(FilterResult filter:filters){
LegacyFilter f=filter.filter;
if(f.isActive() && filterContext != null && f.context.contains(filterContext)){
applyingFilter=f;
break;
}
}

// Moshidon
if(applyingFilter==null){
StatusFilterPredicate predicate = new StatusFilterPredicate(accountID, filterContext, FilterAction.WARN);
predicate.test(status);
applyingFilter = predicate.getApplyingFilter();
}
}

ArrayList<StatusDisplayItem> contentItems;
Expand Down

This file was deleted.

0 comments on commit 28c851a

Please sign in to comment.