about summary refs log tree commit diff
path: root/app/javascript/flavours/glitch/util/content_warning.js
diff options
context:
space:
mode:
authorpluralcafe-docker <git@plural.cafe>2018-09-03 23:46:14 +0000
committerpluralcafe-docker <git@plural.cafe>2018-09-03 23:46:14 +0000
commit1e6f96168146b89df9940d2b77963a7a30ba84cb (patch)
tree06e1a473f10ff6f1c3743e1ff729f95be6d134e5 /app/javascript/flavours/glitch/util/content_warning.js
parentcc7437e25597e24b9a5f06f7991861506d9abe5c (diff)
parent40d04a3209871b9803b27d01f935ab401bf3539f (diff)
Merge branch 'glitch'
Diffstat (limited to 'app/javascript/flavours/glitch/util/content_warning.js')
-rw-r--r--app/javascript/flavours/glitch/util/content_warning.js19
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'));
+}