Add option to share CW toggle state across instances of a post

This commit is contained in:
Claire
2022-07-24 20:01:30 +02:00
parent eacde1a130
commit 18346f4044
12 changed files with 191 additions and 69 deletions

View File

@@ -1,26 +1,31 @@
import { expandSpoilers } from 'flavours/glitch/util/initial_state';
export function autoUnfoldCW (settings, status) {
if (!expandSpoilers) {
function _autoUnfoldCW(spoiler_text, skip_unfold_regex) {
if (!expandSpoilers)
return false;
}
const rawRegex = settings.getIn(['content_warnings', 'filter']);
if (!skip_unfold_regex)
return true;
if (!rawRegex) {
let regex = null;
try {
regex = new RegExp(skip_unfold_regex.trim(), 'i');
} catch (e) {
// Bad regex, skip filters
return true;
}
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'));
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']));
}