From 18346f40443f1c01b45d94be1b0edce20b2c27be Mon Sep 17 00:00:00 2001 From: Claire Date: Sun, 24 Jul 2022 20:01:30 +0200 Subject: Add option to share CW toggle state across instances of a post --- .../flavours/glitch/util/content_warning.js | 33 +++++++++++++--------- 1 file changed, 19 insertions(+), 14 deletions(-) (limited to 'app/javascript/flavours/glitch/util') 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'])); } -- cgit