This repository has been archived on 2024-07-22. You can view files and clone it, but cannot push or open issues or pull requests.
2022-05-15 08:30:40 -07:00
|
|
|
import { expandSpoilers } from 'flavours/glitch/util/initial_state';
|
|
|
|
|
2018-08-28 08:16:30 -07:00
|
|
|
export function autoUnfoldCW (settings, status) {
|
2022-05-15 08:30:40 -07:00
|
|
|
if (!expandSpoilers) {
|
2018-08-28 08:16:30 -07:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
const rawRegex = settings.getIn(['content_warnings', 'filter']);
|
2018-10-12 14:12:39 -07:00
|
|
|
|
|
|
|
if (!rawRegex) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2018-08-28 08:16:30 -07: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'));
|
|
|
|
}
|