From c6942a528332e99b605efa95ffa1c710324d368c Mon Sep 17 00:00:00 2001 From: Thibaut Girka Date: Tue, 28 Aug 2018 17:16:30 +0200 Subject: Add option to not automatically unfold content warnings matching a regexp Fixes #678 --- .../flavours/glitch/util/content_warning.js | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 app/javascript/flavours/glitch/util/content_warning.js (limited to 'app/javascript/flavours/glitch/util/content_warning.js') 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')); +} -- cgit