2022-05-15 18:30:40 +03:00
|
|
|
import { expandSpoilers } from 'flavours/glitch/util/initial_state';
|
|
|
|
|
2022-07-24 21:01:30 +03:00
|
|
|
function _autoUnfoldCW(spoiler_text, skip_unfold_regex) {
|
|
|
|
if (!expandSpoilers)
|
2018-08-28 18:16:30 +03:00
|
|
|
return false;
|
2018-10-13 00:12:39 +03:00
|
|
|
|
2022-07-24 21:01:30 +03:00
|
|
|
if (!skip_unfold_regex)
|
2018-10-13 00:12:39 +03:00
|
|
|
return true;
|
|
|
|
|
2022-07-24 21:01:30 +03:00
|
|
|
let regex = null;
|
2018-08-28 18:16:30 +03:00
|
|
|
|
|
|
|
try {
|
2022-07-24 21:01:30 +03:00
|
|
|
regex = new RegExp(skip_unfold_regex.trim(), 'i');
|
2018-08-28 18:16:30 +03:00
|
|
|
} catch (e) {
|
2022-07-24 21:01:30 +03:00
|
|
|
// Bad regex, skip filters
|
|
|
|
return true;
|
2018-08-28 18:16:30 +03:00
|
|
|
}
|
|
|
|
|
2022-07-24 21:01:30 +03:00
|
|
|
return !regex.test(spoiler_text);
|
|
|
|
}
|
|
|
|
|
|
|
|
export function autoHideCW(settings, spoiler_text) {
|
|
|
|
return !_autoUnfoldCW(spoiler_text, settings.getIn(['content_warnings', 'filter']));
|
|
|
|
}
|
|
|
|
|
|
|
|
export function autoUnfoldCW(settings, status) {
|
|
|
|
if (!status)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
return _autoUnfoldCW(status.get('spoiler_text'), settings.getIn(['content_warnings', 'filter']));
|
2018-08-28 18:16:30 +03:00
|
|
|
}
|