about summary refs log tree commit diff
path: root/app/javascript/flavours/glitch/util/content_warning.js
blob: baeb97881f6489eab8c99b2bb39c9fd44c179769 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
import { expandSpoilers } from 'flavours/glitch/util/initial_state';

export function autoUnfoldCW (settings, status) {
  if (!expandSpoilers) {
    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'));
}