2020-10-17 13:12:00 +02:00
|
|
|
<template>
|
2021-11-28 12:07:37 +01:00
|
|
|
<div class="_formRoot">
|
|
|
|
<MkTab v-model="tab" class="_formBlock">
|
2022-05-05 15:51:58 +02:00
|
|
|
<option value="soft">{{ i18n.ts._wordMute.soft }}</option>
|
|
|
|
<option value="hard">{{ i18n.ts._wordMute.hard }}</option>
|
2020-11-25 13:31:34 +01:00
|
|
|
</MkTab>
|
2021-11-28 12:07:37 +01:00
|
|
|
<div class="_formBlock">
|
|
|
|
<div v-show="tab === 'soft'">
|
2022-05-05 15:51:58 +02:00
|
|
|
<MkInfo class="_formBlock">{{ i18n.ts._wordMute.softDescription }}</MkInfo>
|
2021-11-28 12:07:37 +01:00
|
|
|
<FormTextarea v-model="softMutedWords" class="_formBlock">
|
2022-05-05 15:51:58 +02:00
|
|
|
<span>{{ i18n.ts._wordMute.muteWords }}</span>
|
|
|
|
<template #caption>{{ i18n.ts._wordMute.muteWordsDescription }}<br>{{ i18n.ts._wordMute.muteWordsDescription2 }}</template>
|
2021-11-28 12:07:37 +01:00
|
|
|
</FormTextarea>
|
2020-10-17 13:12:00 +02:00
|
|
|
</div>
|
2021-11-28 12:07:37 +01:00
|
|
|
<div v-show="tab === 'hard'">
|
2022-05-05 15:51:58 +02:00
|
|
|
<MkInfo class="_formBlock">{{ i18n.ts._wordMute.hardDescription }} {{ i18n.ts.reflectMayTakeTime }}</MkInfo>
|
2021-11-28 12:07:37 +01:00
|
|
|
<FormTextarea v-model="hardMutedWords" class="_formBlock">
|
2022-05-05 15:51:58 +02:00
|
|
|
<span>{{ i18n.ts._wordMute.muteWords }}</span>
|
|
|
|
<template #caption>{{ i18n.ts._wordMute.muteWordsDescription }}<br>{{ i18n.ts._wordMute.muteWordsDescription2 }}</template>
|
2021-11-28 12:07:37 +01:00
|
|
|
</FormTextarea>
|
|
|
|
<MkKeyValue v-if="hardWordMutedNotesCount != null" class="_formBlock">
|
2022-05-05 15:51:58 +02:00
|
|
|
<template #key>{{ i18n.ts._wordMute.mutedNotes }}</template>
|
2021-11-28 12:07:37 +01:00
|
|
|
<template #value>{{ number(hardWordMutedNotesCount) }}</template>
|
|
|
|
</MkKeyValue>
|
|
|
|
</div>
|
|
|
|
</div>
|
2022-05-05 15:51:58 +02:00
|
|
|
<MkButton primary inline :disabled="!changed" @click="save()"><i class="fas fa-save"></i> {{ i18n.ts.save }}</MkButton>
|
2020-10-17 13:12:00 +02:00
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
|
2022-05-05 15:51:58 +02:00
|
|
|
<script lang="ts" setup>
|
2022-06-20 10:38:49 +02:00
|
|
|
import { ref, watch } from 'vue';
|
2021-11-11 18:02:25 +01:00
|
|
|
import FormTextarea from '@/components/form/textarea.vue';
|
2021-11-28 12:07:37 +01:00
|
|
|
import MkKeyValue from '@/components/key-value.vue';
|
|
|
|
import MkButton from '@/components/ui/button.vue';
|
|
|
|
import MkInfo from '@/components/ui/info.vue';
|
2021-11-11 18:02:25 +01:00
|
|
|
import MkTab from '@/components/tab.vue';
|
|
|
|
import * as os from '@/os';
|
|
|
|
import number from '@/filters/number';
|
2022-05-05 15:51:58 +02:00
|
|
|
import { defaultStore } from '@/store';
|
|
|
|
import { $i } from '@/account';
|
|
|
|
import { i18n } from '@/i18n';
|
2022-06-20 10:38:49 +02:00
|
|
|
import { definePageMetadata } from '@/scripts/page-metadata';
|
2020-10-17 13:12:00 +02:00
|
|
|
|
2022-05-05 15:51:58 +02:00
|
|
|
const render = (mutedWords) => mutedWords.map(x => {
|
|
|
|
if (Array.isArray(x)) {
|
|
|
|
return x.join(' ');
|
|
|
|
} else {
|
|
|
|
return x;
|
|
|
|
}
|
|
|
|
}).join('\n');
|
2020-10-17 13:12:00 +02:00
|
|
|
|
2022-05-05 15:51:58 +02:00
|
|
|
const tab = ref('soft');
|
|
|
|
const softMutedWords = ref(render(defaultStore.state.mutedWords));
|
|
|
|
const hardMutedWords = ref(render($i!.mutedWords));
|
|
|
|
const hardWordMutedNotesCount = ref(null);
|
|
|
|
const changed = ref(false);
|
2020-10-17 13:12:00 +02:00
|
|
|
|
2022-05-05 15:51:58 +02:00
|
|
|
os.api('i/get-word-muted-notes-count', {}).then(response => {
|
|
|
|
hardWordMutedNotesCount.value = response?.count;
|
|
|
|
});
|
2022-02-10 11:47:46 +01:00
|
|
|
|
2022-05-05 15:51:58 +02:00
|
|
|
watch(softMutedWords, () => {
|
|
|
|
changed.value = true;
|
|
|
|
});
|
2020-10-17 13:12:00 +02:00
|
|
|
|
2022-05-05 15:51:58 +02:00
|
|
|
watch(hardMutedWords, () => {
|
|
|
|
changed.value = true;
|
|
|
|
});
|
2020-10-17 13:12:00 +02:00
|
|
|
|
2022-05-05 15:51:58 +02:00
|
|
|
async function save() {
|
|
|
|
const parseMutes = (mutes, tab) => {
|
|
|
|
// split into lines, remove empty lines and unnecessary whitespace
|
2022-05-26 15:53:09 +02:00
|
|
|
let lines = mutes.trim().split('\n').map(line => line.trim()).filter(line => line !== '');
|
2022-02-10 11:47:46 +01:00
|
|
|
|
2022-05-05 15:51:58 +02:00
|
|
|
// check each line if it is a RegExp or not
|
|
|
|
for (let i = 0; i < lines.length; i++) {
|
2022-06-10 07:36:55 +02:00
|
|
|
const line = lines[i];
|
2022-05-05 15:51:58 +02:00
|
|
|
const regexp = line.match(/^\/(.+)\/(.*)$/);
|
|
|
|
if (regexp) {
|
|
|
|
// check that the RegExp is valid
|
|
|
|
try {
|
|
|
|
new RegExp(regexp[1], regexp[2]);
|
|
|
|
// note that regex lines will not be split by spaces!
|
|
|
|
} catch (err: any) {
|
|
|
|
// invalid syntax: do not save, do not reset changed flag
|
|
|
|
os.alert({
|
|
|
|
type: 'error',
|
|
|
|
title: i18n.ts.regexpError,
|
2022-06-20 10:38:49 +02:00
|
|
|
text: i18n.t('regexpErrorDescription', { tab, line: i + 1 }) + '\n' + err.toString(),
|
2022-05-05 15:51:58 +02:00
|
|
|
});
|
|
|
|
// re-throw error so these invalid settings are not saved
|
|
|
|
throw err;
|
2022-02-10 11:47:46 +01:00
|
|
|
}
|
2022-05-05 15:51:58 +02:00
|
|
|
} else {
|
|
|
|
lines[i] = line.split(' ');
|
|
|
|
}
|
|
|
|
}
|
2022-02-11 11:44:56 +01:00
|
|
|
|
2022-05-05 15:51:58 +02:00
|
|
|
return lines;
|
|
|
|
};
|
2022-02-10 11:47:46 +01:00
|
|
|
|
2022-05-05 15:51:58 +02:00
|
|
|
let softMutes, hardMutes;
|
|
|
|
try {
|
|
|
|
softMutes = parseMutes(softMutedWords.value, i18n.ts._wordMute.soft);
|
|
|
|
hardMutes = parseMutes(hardMutedWords.value, i18n.ts._wordMute.hard);
|
|
|
|
} catch (err) {
|
|
|
|
// already displayed error message in parseMutes
|
|
|
|
return;
|
|
|
|
}
|
2022-02-10 11:47:46 +01:00
|
|
|
|
2022-05-05 15:51:58 +02:00
|
|
|
defaultStore.set('mutedWords', softMutes);
|
|
|
|
await os.api('i/update', {
|
|
|
|
mutedWords: hardMutes,
|
|
|
|
});
|
2022-02-10 11:47:46 +01:00
|
|
|
|
2022-05-05 15:51:58 +02:00
|
|
|
changed.value = false;
|
|
|
|
}
|
2020-11-25 13:31:34 +01:00
|
|
|
|
2022-06-20 10:38:49 +02:00
|
|
|
const headerActions = $computed(() => []);
|
|
|
|
|
|
|
|
const headerTabs = $computed(() => []);
|
|
|
|
|
|
|
|
definePageMetadata({
|
|
|
|
title: i18n.ts.wordMute,
|
|
|
|
icon: 'fas fa-comment-slash',
|
2020-10-17 13:12:00 +02:00
|
|
|
});
|
|
|
|
</script>
|