You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

24 lines
502 B

  1. export function autoUnfoldCW (settings, status) {
  2. if (!settings.getIn(['content_warnings', 'auto_unfold'])) {
  3. return false;
  4. }
  5. const rawRegex = settings.getIn(['content_warnings', 'filter']);
  6. if (!rawRegex) {
  7. return true;
  8. }
  9. let regex = null;
  10. try {
  11. regex = rawRegex && new RegExp(rawRegex.trim(), 'i');
  12. } catch (e) {
  13. // Bad regex, don't affect filters
  14. }
  15. if (!(status && regex)) {
  16. return undefined;
  17. }
  18. return !regex.test(status.get('spoiler_text'));
  19. }