about summary refs log tree commit diff
path: root/app/javascript/flavours/glitch/util/content_warning.js
blob: 5e874a49c0cd1a1d387991afe5e9e4925f4a10ac (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
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'));
}