about summary refs log tree commit diff
diff options
context:
space:
mode:
authorThibaut Girka <thib@sitedethib.com>2019-10-15 21:52:53 +0200
committerThibG <thib@sitedethib.com>2019-10-17 11:43:58 +0200
commitb4046dc0268cbc81c67ed3f54833b78103697137 (patch)
treed61a47019158a6213f259386a9a0db661d3d3f80
parentfbe1de114fca16d63ff651425f69eb534ba013e9 (diff)
Drop filtered messages if the filter is “irreversible”
… instead of adding them to the timelines and then not showing them.
This fixes timelines showing new items when the only new items are
“irreversibly” filtered toots. This may be an edge case in Mastodon/glitch-soc,
but it is not in Pleroma, which does no filtering server-side whatsoever.
-rw-r--r--app/javascript/flavours/glitch/actions/timelines.js30
1 files changed, 26 insertions, 4 deletions
diff --git a/app/javascript/flavours/glitch/actions/timelines.js b/app/javascript/flavours/glitch/actions/timelines.js
index 16ff4703e..232b010c5 100644
--- a/app/javascript/flavours/glitch/actions/timelines.js
+++ b/app/javascript/flavours/glitch/actions/timelines.js
@@ -2,7 +2,10 @@ import { importFetchedStatus, importFetchedStatuses } from './importer';
 import api, { getLinks } from 'flavours/glitch/util/api';
 import { Map as ImmutableMap, List as ImmutableList } from 'immutable';
 import compareId from 'flavours/glitch/util/compare_id';
-import { usePendingItems as preferPendingItems } from 'flavours/glitch/util/initial_state';
+import { me, usePendingItems as preferPendingItems } from 'flavours/glitch/util/initial_state';
+import { getFiltersRegex } from 'flavours/glitch/selectors';
+
+const domParser = new DOMParser();
 
 export const TIMELINE_UPDATE  = 'TIMELINE_UPDATE';
 export const TIMELINE_DELETE  = 'TIMELINE_DELETE';
@@ -17,17 +20,31 @@ export const TIMELINE_LOAD_PENDING = 'TIMELINE_LOAD_PENDING';
 export const TIMELINE_DISCONNECT   = 'TIMELINE_DISCONNECT';
 export const TIMELINE_CONNECT      = 'TIMELINE_CONNECT';
 
+const searchTextFromRawStatus = (status) => {
+  const spoilerText   = status.spoiler_text || '';
+  const searchContent = ([spoilerText, status.content].concat((status.poll && status.poll.options) ? status.poll.options.map(option => option.title) : [])).join('\n\n').replace(/<br\s*\/?>/g, '\n').replace(/<\/p><p>/g, '\n\n');
+  return domParser.parseFromString(searchContent, 'text/html').documentElement.textContent;
+}
+
 export const loadPending = timeline => ({
   type: TIMELINE_LOAD_PENDING,
   timeline,
 });
 
 export function updateTimeline(timeline, status, accept) {
-  return dispatch => {
+  return (dispatch, getState) => {
     if (typeof accept === 'function' && !accept(status)) {
       return;
     }
 
+    const dropRegex = getFiltersRegex(getState(), { contextType: timeline })[0];
+
+    if (dropRegex && status.account.id !== me) {
+      if (dropRegex.test(searchTextFromRawStatus(status))) {
+        return;
+      }
+    }
+
     dispatch(importFetchedStatus(status));
 
     dispatch({
@@ -96,8 +113,13 @@ export function expandTimeline(timelineId, path, params = {}, done = noOp) {
 
     api(getState).get(path, { params }).then(response => {
       const next = getLinks(response).refs.find(link => link.rel === 'next');
-      dispatch(importFetchedStatuses(response.data));
-      dispatch(expandTimelineSuccess(timelineId, response.data, next ? next.uri : null, response.status === 206, isLoadingRecent, isLoadingMore, isLoadingRecent && preferPendingItems));
+
+      const dropRegex = getFiltersRegex(getState(), { contextType: timelineId })[0];
+
+      const statuses = dropRegex ? response.data.filter(status => status.account.id === me || !dropRegex.test(searchTextFromRawStatus(status))) : response.data;
+
+      dispatch(importFetchedStatuses(statuses));
+      dispatch(expandTimelineSuccess(timelineId, statuses, next ? next.uri : null, response.status === 206, isLoadingRecent, isLoadingMore, isLoadingRecent && preferPendingItems));
       done();
     }).catch(error => {
       dispatch(expandTimelineFail(timelineId, error, isLoadingMore));