forked from mirrors/Fedilab
Comment issue #412 - Filters not applied
This commit is contained in:
parent
730468ee72
commit
c640505fe6
2 changed files with 17 additions and 19 deletions
|
@ -100,7 +100,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) {
|
||||
|
@ -113,13 +112,13 @@ public class TimelineHelper {
|
|||
for (String filterContext : filter.context) {
|
||||
if (filterTimeLineType.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 (Status status : statuses) {
|
||||
String content;
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N)
|
||||
content = Html.fromHtml(status.content, Html.FROM_HTML_MODE_LEGACY).toString();
|
||||
content = Html.fromHtml(status.reblog != null ? status.reblog.content : status.content, Html.FROM_HTML_MODE_LEGACY).toString();
|
||||
else
|
||||
content = Html.fromHtml(status.content).toString();
|
||||
content = Html.fromHtml(status.reblog != null ? status.reblog.content : status.content).toString();
|
||||
Matcher m = p.matcher(content);
|
||||
if (m.find()) {
|
||||
statusesToRemove.add(status);
|
||||
|
@ -128,9 +127,9 @@ public class TimelineHelper {
|
|||
if (status.spoiler_text != null) {
|
||||
String spoilerText;
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N)
|
||||
spoilerText = Html.fromHtml(status.spoiler_text, Html.FROM_HTML_MODE_LEGACY).toString();
|
||||
spoilerText = Html.fromHtml(status.reblog != null ? status.reblog.spoiler_text : status.spoiler_text, Html.FROM_HTML_MODE_LEGACY).toString();
|
||||
else
|
||||
spoilerText = Html.fromHtml(status.spoiler_text).toString();
|
||||
spoilerText = Html.fromHtml(status.reblog != null ? status.reblog.spoiler_text : status.spoiler_text).toString();
|
||||
Matcher ms = p.matcher(spoilerText);
|
||||
if (ms.find()) {
|
||||
statusesToRemove.add(status);
|
||||
|
@ -141,9 +140,9 @@ public class TimelineHelper {
|
|||
for (Status status : statuses) {
|
||||
String content;
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N)
|
||||
content = Html.fromHtml(status.content, Html.FROM_HTML_MODE_LEGACY).toString();
|
||||
content = Html.fromHtml(status.reblog != null ? status.reblog.content : status.content, Html.FROM_HTML_MODE_LEGACY).toString();
|
||||
else
|
||||
content = Html.fromHtml(status.content).toString();
|
||||
content = Html.fromHtml(status.reblog != null ? status.reblog.content : status.content).toString();
|
||||
if (content.contains(filter.phrase)) {
|
||||
statusesToRemove.add(status);
|
||||
continue;
|
||||
|
@ -152,9 +151,9 @@ public class TimelineHelper {
|
|||
if (status.spoiler_text != null) {
|
||||
String spoilerText;
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N)
|
||||
spoilerText = Html.fromHtml(status.spoiler_text, Html.FROM_HTML_MODE_LEGACY).toString();
|
||||
spoilerText = Html.fromHtml(status.reblog != null ? status.reblog.spoiler_text : status.spoiler_text, Html.FROM_HTML_MODE_LEGACY).toString();
|
||||
else
|
||||
spoilerText = Html.fromHtml(status.spoiler_text).toString();
|
||||
spoilerText = Html.fromHtml(status.reblog != null ? status.reblog.spoiler_text : status.spoiler_text).toString();
|
||||
if (spoilerText.contains(filter.phrase)) {
|
||||
statusesToRemove.add(status);
|
||||
}
|
||||
|
|
|
@ -414,7 +414,6 @@ public class TimelinesVM extends AndroidViewModel {
|
|||
statuses.statuses = TimelineHelper.filterStatus(getApplication().getApplicationContext(), statusList, timelineParams.type);
|
||||
statuses.pagination = MastodonHelper.getPagination(timelineResponse.headers());
|
||||
if (statusList != null && statusList.size() > 0) {
|
||||
|
||||
addFetchMore(statusList, timelineStatuses, timelineParams);
|
||||
for (Status status : statuses.statuses) {
|
||||
StatusCache statusCacheDAO = new StatusCache(getApplication().getApplicationContext());
|
||||
|
@ -434,6 +433,7 @@ public class TimelinesVM extends AndroidViewModel {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
|
@ -450,22 +450,22 @@ public class TimelinesVM extends AndroidViewModel {
|
|||
statusesMutableLiveData = new MutableLiveData<>();
|
||||
new Thread(() -> {
|
||||
StatusCache statusCacheDAO = new StatusCache(getApplication().getApplicationContext());
|
||||
Statuses statuses = null;
|
||||
Statuses statuses = new Statuses();
|
||||
try {
|
||||
statuses = statusCacheDAO.geStatuses(timelineParams.slug, timelineParams.instance, timelineParams.userId, timelineParams.maxId, timelineParams.minId, timelineParams.sinceId);
|
||||
if (statuses != null && statuses.statuses != null && statuses.statuses.size() > 0) {
|
||||
Statuses statusesDb = statusCacheDAO.geStatuses(timelineParams.slug, timelineParams.instance, timelineParams.userId, timelineParams.maxId, timelineParams.minId, timelineParams.sinceId);
|
||||
if (statusesDb != null && statusesDb.statuses != null && statusesDb.statuses.size() > 0) {
|
||||
if (timelineStatuses != null) {
|
||||
List<Status> notPresentStatuses = new ArrayList<>();
|
||||
for (Status status : statuses.statuses) {
|
||||
for (Status status : statusesDb.statuses) {
|
||||
if (!timelineStatuses.contains(status)) {
|
||||
status.cached = true;
|
||||
notPresentStatuses.add(status);
|
||||
}
|
||||
}
|
||||
//Only not already present statuses are added
|
||||
statuses.statuses = notPresentStatuses;
|
||||
statusesDb.statuses = notPresentStatuses;
|
||||
}
|
||||
TimelineHelper.filterStatus(getApplication().getApplicationContext(), statuses.statuses, timelineParams.type, true);
|
||||
statuses.statuses = TimelineHelper.filterStatus(getApplication().getApplicationContext(), statusesDb.statuses, timelineParams.type, true);
|
||||
if (statuses.statuses != null && statuses.statuses.size() > 0) {
|
||||
addFetchMore(statuses.statuses, timelineStatuses, timelineParams);
|
||||
statuses.pagination = new Pagination();
|
||||
|
@ -477,8 +477,7 @@ public class TimelinesVM extends AndroidViewModel {
|
|||
e.printStackTrace();
|
||||
}
|
||||
Handler mainHandler = new Handler(Looper.getMainLooper());
|
||||
Statuses finalStatuses = statuses;
|
||||
Runnable myRunnable = () -> statusesMutableLiveData.setValue(finalStatuses);
|
||||
Runnable myRunnable = () -> statusesMutableLiveData.setValue(statuses);
|
||||
mainHandler.post(myRunnable);
|
||||
}).start();
|
||||
return statusesMutableLiveData;
|
||||
|
|
Loading…
Reference in a new issue