diff options
author | Thibaut Girka <thib@sitedethib.com> | 2019-10-15 22:55:27 +0200 |
---|---|---|
committer | ThibG <thib@sitedethib.com> | 2019-10-17 11:43:58 +0200 |
commit | 003bb6ca1a3f57ffb51092161d8f851b8dc93ab6 (patch) | |
tree | 94f2a00cad7a921d885cbf3ed17f858df0791c28 /app/javascript | |
parent | b4046dc0268cbc81c67ed3f54833b78103697137 (diff) |
Refactor timeline filtering code
Diffstat (limited to 'app/javascript')
-rw-r--r-- | app/javascript/flavours/glitch/actions/importer/normalizer.js | 6 | ||||
-rw-r--r-- | app/javascript/flavours/glitch/actions/timelines.js | 9 |
2 files changed, 7 insertions, 8 deletions
diff --git a/app/javascript/flavours/glitch/actions/importer/normalizer.js b/app/javascript/flavours/glitch/actions/importer/normalizer.js index b35c4d7bd..2bc603930 100644 --- a/app/javascript/flavours/glitch/actions/importer/normalizer.js +++ b/app/javascript/flavours/glitch/actions/importer/normalizer.js @@ -10,6 +10,12 @@ const makeEmojiMap = record => record.emojis.reduce((obj, emoji) => { return obj; }, {}); +export function 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 function normalizeAccount(account) { account = { ...account }; diff --git a/app/javascript/flavours/glitch/actions/timelines.js b/app/javascript/flavours/glitch/actions/timelines.js index 232b010c5..482762e35 100644 --- a/app/javascript/flavours/glitch/actions/timelines.js +++ b/app/javascript/flavours/glitch/actions/timelines.js @@ -4,8 +4,7 @@ import { Map as ImmutableMap, List as ImmutableList } from 'immutable'; import compareId from 'flavours/glitch/util/compare_id'; import { me, usePendingItems as preferPendingItems } from 'flavours/glitch/util/initial_state'; import { getFiltersRegex } from 'flavours/glitch/selectors'; - -const domParser = new DOMParser(); +import { searchTextFromRawStatus } from 'flavours/glitch/actions/importer/normalizer'; export const TIMELINE_UPDATE = 'TIMELINE_UPDATE'; export const TIMELINE_DELETE = 'TIMELINE_DELETE'; @@ -20,12 +19,6 @@ 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, |