about summary refs log tree commit diff
path: root/app/javascript/flavours/glitch/util/content_warning.js
diff options
context:
space:
mode:
Diffstat (limited to 'app/javascript/flavours/glitch/util/content_warning.js')
-rw-r--r--app/javascript/flavours/glitch/util/content_warning.js24
1 files changed, 24 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..5e874a49c
--- /dev/null
+++ b/app/javascript/flavours/glitch/util/content_warning.js
@@ -0,0 +1,24 @@
+export function autoUnfoldCW (settings, status) {
+  if (!settings.getIn(['content_warnings', 'auto_unfold'])) {
+    return false;
+  }
+
+  const rawRegex = settings.getIn(['content_warnings', 'filter']);
+
+  if (!rawRegex) {
+    return true;
+  }
+
+  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'));
+}