diff options
author | Claire <claire.github-309c@sitedethib.com> | 2022-07-25 13:30:17 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-07-25 13:30:17 +0200 |
commit | 3a7c641dd4db1d67b172f731518b472d58dd2262 (patch) | |
tree | b78b33927842f5dfd374fa5fb9509a809849e358 /app/javascript/flavours/glitch/util | |
parent | 82f1e0945eed6e80a4e626580df45f7f73427755 (diff) | |
parent | 18346f40443f1c01b45d94be1b0edce20b2c27be (diff) |
Merge pull request #1815 from ClearlyClaire/glitch-soc/features/upstream-cw-reveal
Add option to share CW toggle state across instances of a post
Diffstat (limited to 'app/javascript/flavours/glitch/util')
-rw-r--r-- | app/javascript/flavours/glitch/util/content_warning.js | 33 |
1 files changed, 19 insertions, 14 deletions
diff --git a/app/javascript/flavours/glitch/util/content_warning.js b/app/javascript/flavours/glitch/util/content_warning.js index baeb97881..383a34226 100644 --- a/app/javascript/flavours/glitch/util/content_warning.js +++ b/app/javascript/flavours/glitch/util/content_warning.js @@ -1,26 +1,31 @@ import { expandSpoilers } from 'flavours/glitch/util/initial_state'; -export function autoUnfoldCW (settings, status) { - if (!expandSpoilers) { +function _autoUnfoldCW(spoiler_text, skip_unfold_regex) { + if (!expandSpoilers) return false; - } - - const rawRegex = settings.getIn(['content_warnings', 'filter']); - if (!rawRegex) { + if (!skip_unfold_regex) return true; - } - let regex = null; + let regex = null; try { - regex = rawRegex && new RegExp(rawRegex.trim(), 'i'); + regex = new RegExp(skip_unfold_regex.trim(), 'i'); } catch (e) { - // Bad regex, don't affect filters + // Bad regex, skip filters + return true; } - if (!(status && regex)) { - return undefined; - } - return !regex.test(status.get('spoiler_text')); + return !regex.test(spoiler_text); +} + +export function autoHideCW(settings, spoiler_text) { + return !_autoUnfoldCW(spoiler_text, settings.getIn(['content_warnings', 'filter'])); +} + +export function autoUnfoldCW(settings, status) { + if (!status) + return false; + + return _autoUnfoldCW(status.get('spoiler_text'), settings.getIn(['content_warnings', 'filter'])); } |