2022-10-11 10:17:04 +02:00
|
|
|
import { expandSpoilers } from 'flavours/glitch/initial_state';
|
2022-05-15 17:30:40 +02:00
|
|
|
|
2022-07-24 20:01:30 +02:00
|
|
|
function _autoUnfoldCW(spoiler_text, skip_unfold_regex) {
|
|
|
|
if (!expandSpoilers)
|
2018-08-28 17:16:30 +02:00
|
|
|
return false;
|
2018-10-12 23:12:39 +02:00
|
|
|
|
2022-07-24 20:01:30 +02:00
|
|
|
if (!skip_unfold_regex)
|
2018-10-12 23:12:39 +02:00
|
|
|
return true;
|
|
|
|
|
2022-07-24 20:01:30 +02:00
|
|
|
let regex = null;
|
2018-08-28 17:16:30 +02:00
|
|
|
|
|
|
|
try {
|
2022-07-24 20:01:30 +02:00
|
|
|
regex = new RegExp(skip_unfold_regex.trim(), 'i');
|
2018-08-28 17:16:30 +02:00
|
|
|
} catch (e) {
|
2022-07-24 20:01:30 +02:00
|
|
|
// Bad regex, skip filters
|
|
|
|
return true;
|
2018-08-28 17:16:30 +02:00
|
|
|
}
|
|
|
|
|
2022-07-24 20:01:30 +02: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 17:16:30 +02:00
|
|
|
}
|