2018-08-28 11:16:30 -04:00
|
|
|
export function autoUnfoldCW (settings, status) {
|
|
|
|
if (!settings.getIn(['content_warnings', 'auto_unfold'])) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
const rawRegex = settings.getIn(['content_warnings', 'filter']);
|
2018-10-12 17:12:39 -04:00
|
|
|
|
|
|
|
if (!rawRegex) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2018-08-28 11:16:30 -04:00
|
|
|
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'));
|
|
|
|
}
|