summaryrefslogtreecommitdiff
path: root/packages
diff options
context:
space:
mode:
authorHazelnoot <acomputerdog@gmail.com>2025-02-01 23:49:03 -0500
committerHazelnoot <acomputerdog@gmail.com>2025-02-05 14:22:50 -0500
commit90e71ba413cc1ab86df18b57bcb9df331183dc8f (patch)
treef83611730d81165893ade4280c1cbd50f0314697 /packages
parentadd settings UI to configure defaultCW and defaultCWPriority (diff)
downloadsharkey-90e71ba413cc1ab86df18b57bcb9df331183dc8f.tar.gz
sharkey-90e71ba413cc1ab86df18b57bcb9df331183dc8f.tar.bz2
sharkey-90e71ba413cc1ab86df18b57bcb9df331183dc8f.zip
apply default content warning to new posts
Diffstat (limited to 'packages')
-rw-r--r--packages/frontend/src/components/MkPostForm.vue22
1 files changed, 22 insertions, 0 deletions
diff --git a/packages/frontend/src/components/MkPostForm.vue b/packages/frontend/src/components/MkPostForm.vue
index 11ae6dbd6a..935915cf31 100644
--- a/packages/frontend/src/components/MkPostForm.vue
+++ b/packages/frontend/src/components/MkPostForm.vue
@@ -364,6 +364,28 @@ if (defaultStore.state.keepCw && props.reply && props.reply.cw) {
cw.value = props.reply.cw;
}
+// apply default CW
+if ($i.defaultCW) {
+ useCw.value = true;
+
+ if (!cw.value || $i.defaultCWPriority === 'default') {
+ cw.value = $i.defaultCW;
+ } else if ($i.defaultCWPriority !== 'parent') {
+ // This is a fancy way of simulating /\bsearch\b/ without a regular expression.
+ // We're checking to see whether the default CW appears inside the existing CW, but *only* if there's word boundaries.
+ const parts = cw.value.split($i.defaultCW);
+ if (parts.length !== 2 || /\w$/.test(parts[0]) || /^\w/.test(parts[1])) {
+ // We need to merge the CWs
+ if ($i.defaultCWPriority === 'defaultParent') {
+ cw.value = `${$i.defaultCW}, ${cw.value}`;
+ } else if ($i.defaultCWPriority === 'parentDefault') {
+ cw.value = `${cw.value}, ${$i.defaultCW}`;
+ }
+ }
+ }
+ // else { do nothing, because existing CW takes priority. }
+}
+
function watchForDraft() {
watch(text, () => saveDraft());
watch(useCw, () => saveDraft());