From 003bb6ca1a3f57ffb51092161d8f851b8dc93ab6 Mon Sep 17 00:00:00 2001 From: Thibaut Girka Date: Tue, 15 Oct 2019 22:55:27 +0200 Subject: Refactor timeline filtering code --- app/javascript/flavours/glitch/actions/importer/normalizer.js | 6 ++++++ app/javascript/flavours/glitch/actions/timelines.js | 9 +-------- 2 files changed, 7 insertions(+), 8 deletions(-) (limited to 'app/javascript/flavours') 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(//g, '\n').replace(/<\/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(//g, '\n').replace(/<\/p>

/g, '\n\n'); - return domParser.parseFromString(searchContent, 'text/html').documentElement.textContent; -} - export const loadPending = timeline => ({ type: TIMELINE_LOAD_PENDING, timeline, -- cgit