diff options
author | Thibaut Girka <thib@sitedethib.com> | 2018-08-28 17:16:30 +0200 |
---|---|---|
committer | ThibG <thib@sitedethib.com> | 2018-08-31 18:35:03 +0200 |
commit | c6942a528332e99b605efa95ffa1c710324d368c (patch) | |
tree | 857b96004ccae2b5a7005afe681604db82661680 /app/javascript/flavours/glitch/util | |
parent | 5c400a28422121df01fc5ae73bc201f3b9aa5288 (diff) |
Add option to not automatically unfold content warnings matching a regexp
Fixes #678
Diffstat (limited to 'app/javascript/flavours/glitch/util')
-rw-r--r-- | app/javascript/flavours/glitch/util/content_warning.js | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/app/javascript/flavours/glitch/util/content_warning.js b/app/javascript/flavours/glitch/util/content_warning.js new file mode 100644 index 000000000..29e221c8e --- /dev/null +++ b/app/javascript/flavours/glitch/util/content_warning.js @@ -0,0 +1,19 @@ +export function autoUnfoldCW (settings, status) { + if (!settings.getIn(['content_warnings', 'auto_unfold'])) { + return false; + } + + const rawRegex = settings.getIn(['content_warnings', 'filter']); + let regex = null; + + try { + regex = rawRegex && new RegExp(rawRegex.trim(), 'i'); + } catch (e) { + // Bad regex, don't affect filters + } + + if (!(status && regex)) { + return undefined; + } + return !regex.test(status.get('spoiler_text')); +} |