Fix filters

This commit is contained in:
Thomas 2022-11-07 10:42:09 +01:00
parent 2625101883
commit ee68f4fc7d
2 changed files with 23 additions and 33 deletions

View File

@ -60,17 +60,6 @@ public class TimelineHelper {
return retrofit.create(MastodonAccountsService.class);
}
/**
* Allows to filter statuses, should be called in API calls (background)
*
* @param context - Context
* @param statuses - List of {@link Status}
* @param filterTimeLineType - {@link Timeline.TimeLineEnum}
* @return filtered List<Status>
*/
public static List<Status> filterStatus(Context context, List<Status> statuses, Timeline.TimeLineEnum filterTimeLineType) {
return filterStatus(context, statuses, filterTimeLineType, false);
}
/**
* Allows to filter statuses, should be called in API calls (background)
@ -80,7 +69,7 @@ public class TimelineHelper {
* @param filterTimeLineType - {@link Timeline.TimeLineEnum}
* @return filtered List<Status>
*/
public static List<Status> filterStatus(Context context, List<Status> statuses, Timeline.TimeLineEnum filterTimeLineType, boolean cached) {
public static List<Status> filterStatus(Context context, List<Status> statuses, Timeline.TimeLineEnum filterTimeLineType) {
//A security to make sure filters have been fetched before displaying messages
List<Status> statusesToRemove = new ArrayList<>();
if (!BaseMainActivity.filterFetched) {
@ -102,9 +91,6 @@ public class TimelineHelper {
}
//If there are filters:
if (BaseMainActivity.mainFilters != null && BaseMainActivity.mainFilters.size() > 0 && statuses != null && statuses.size() > 0) {
for (Status status : statuses) {
status.cached = cached;
}
for (Filter filter : BaseMainActivity.mainFilters) {
if (filter.irreversible) { //Dealt by the server
continue;
@ -200,7 +186,7 @@ public class TimelineHelper {
for (String filterContext : filter.context) {
if (Timeline.TimeLineEnum.NOTIFICATION.getValue().equalsIgnoreCase(filterContext)) {
if (filter.whole_word) {
Pattern p = Pattern.compile("(^" + Pattern.quote(filter.phrase) + "\\b|\\b" + Pattern.quote(filter.phrase) + "$)");
Pattern p = Pattern.compile("(^" + Pattern.quote(filter.phrase) + "\\b|\\b" + Pattern.quote(filter.phrase) + "$)", Pattern.CASE_INSENSITIVE);
for (Notification notification : notifications) {
notification.cached = cached;
if (notification.status != null) {

View File

@ -413,9 +413,12 @@ public class TimelinesVM extends AndroidViewModel {
List<Status> statusList = timelineResponse.body();
statuses.statuses = TimelineHelper.filterStatus(getApplication().getApplicationContext(), statusList, timelineParams.type);
statuses.pagination = MastodonHelper.getPagination(timelineResponse.headers());
if (statuses.statuses != null && statuses.statuses.size() > 0) {
//Fetch More is added on filtered statuses
addFetchMore(statuses.statuses, timelineStatuses, timelineParams);
//All statuses (even filtered will be added to cache)
if (statusList != null && statusList.size() > 0) {
addFetchMore(statusList, timelineStatuses, timelineParams);
for (Status status : statuses.statuses) {
for (Status status : statusList) {
StatusCache statusCacheDAO = new StatusCache(getApplication().getApplicationContext());
StatusCache statusCache = new StatusCache();
statusCache.instance = timelineParams.instance;
@ -433,6 +436,7 @@ public class TimelinesVM extends AndroidViewModel {
}
}
}
}
}
} catch (Exception e) {
@ -465,7 +469,7 @@ public class TimelinesVM extends AndroidViewModel {
//Only not already present statuses are added
statusesDb.statuses = notPresentStatuses;
}
statuses.statuses = TimelineHelper.filterStatus(getApplication().getApplicationContext(), statusesDb.statuses, timelineParams.type, true);
statuses.statuses = TimelineHelper.filterStatus(getApplication().getApplicationContext(), statusesDb.statuses, timelineParams.type);
if (statuses.statuses != null && statuses.statuses.size() > 0) {
addFetchMore(statuses.statuses, timelineStatuses, timelineParams);
statuses.pagination = new Pagination();