2020-10-17 14:12:00 +03:00
|
|
|
<template>
|
2021-11-28 13:07:37 +02:00
|
|
|
<div class="_formRoot">
|
|
|
|
<MkTab v-model="tab" class="_formBlock">
|
2020-12-26 03:47:36 +02:00
|
|
|
<option value="soft">{{ $ts._wordMute.soft }}</option>
|
|
|
|
<option value="hard">{{ $ts._wordMute.hard }}</option>
|
2020-11-25 14:31:34 +02:00
|
|
|
</MkTab>
|
2021-11-28 13:07:37 +02:00
|
|
|
<div class="_formBlock">
|
|
|
|
<div v-show="tab === 'soft'">
|
|
|
|
<MkInfo class="_formBlock">{{ $ts._wordMute.softDescription }}</MkInfo>
|
|
|
|
<FormTextarea v-model="softMutedWords" class="_formBlock">
|
|
|
|
<span>{{ $ts._wordMute.muteWords }}</span>
|
|
|
|
<template #caption>{{ $ts._wordMute.muteWordsDescription }}<br>{{ $ts._wordMute.muteWordsDescription2 }}</template>
|
|
|
|
</FormTextarea>
|
2020-10-17 14:12:00 +03:00
|
|
|
</div>
|
2021-11-28 13:07:37 +02:00
|
|
|
<div v-show="tab === 'hard'">
|
2022-03-21 13:43:43 +02:00
|
|
|
<MkInfo class="_formBlock">{{ $ts._wordMute.hardDescription }} {{ $ts.reflectMayTakeTime }}</MkInfo>
|
2021-11-28 13:07:37 +02:00
|
|
|
<FormTextarea v-model="hardMutedWords" class="_formBlock">
|
|
|
|
<span>{{ $ts._wordMute.muteWords }}</span>
|
|
|
|
<template #caption>{{ $ts._wordMute.muteWordsDescription }}<br>{{ $ts._wordMute.muteWordsDescription2 }}</template>
|
|
|
|
</FormTextarea>
|
|
|
|
<MkKeyValue v-if="hardWordMutedNotesCount != null" class="_formBlock">
|
|
|
|
<template #key>{{ $ts._wordMute.mutedNotes }}</template>
|
|
|
|
<template #value>{{ number(hardWordMutedNotesCount) }}</template>
|
|
|
|
</MkKeyValue>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
<MkButton primary inline :disabled="!changed" @click="save()"><i class="fas fa-save"></i> {{ $ts.save }}</MkButton>
|
2020-10-17 14:12:00 +03:00
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<script lang="ts">
|
|
|
|
import { defineComponent } from 'vue';
|
2021-11-11 19:02:25 +02:00
|
|
|
import FormTextarea from '@/components/form/textarea.vue';
|
2021-11-28 13:07:37 +02: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 19:02:25 +02:00
|
|
|
import MkTab from '@/components/tab.vue';
|
|
|
|
import * as os from '@/os';
|
|
|
|
import number from '@/filters/number';
|
|
|
|
import * as symbols from '@/symbols';
|
2020-10-17 14:12:00 +03:00
|
|
|
|
|
|
|
export default defineComponent({
|
|
|
|
components: {
|
2021-11-28 13:07:37 +02:00
|
|
|
MkButton,
|
2020-11-25 14:31:34 +02:00
|
|
|
FormTextarea,
|
2021-11-28 13:07:37 +02:00
|
|
|
MkKeyValue,
|
2020-10-17 14:12:00 +03:00
|
|
|
MkTab,
|
2021-11-28 13:07:37 +02:00
|
|
|
MkInfo,
|
2020-10-17 14:12:00 +03:00
|
|
|
},
|
|
|
|
|
|
|
|
emits: ['info'],
|
|
|
|
|
|
|
|
data() {
|
|
|
|
return {
|
2021-04-10 06:54:12 +03:00
|
|
|
[symbols.PAGE_INFO]: {
|
2020-12-26 03:47:36 +02:00
|
|
|
title: this.$ts.wordMute,
|
2021-09-29 18:50:45 +03:00
|
|
|
icon: 'fas fa-comment-slash',
|
|
|
|
bg: 'var(--bg)',
|
2020-10-17 14:12:00 +03:00
|
|
|
},
|
|
|
|
tab: 'soft',
|
|
|
|
softMutedWords: '',
|
|
|
|
hardMutedWords: '',
|
|
|
|
hardWordMutedNotesCount: null,
|
|
|
|
changed: false,
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
watch: {
|
|
|
|
softMutedWords: {
|
|
|
|
handler() {
|
|
|
|
this.changed = true;
|
|
|
|
},
|
|
|
|
deep: true
|
|
|
|
},
|
|
|
|
hardMutedWords: {
|
|
|
|
handler() {
|
|
|
|
this.changed = true;
|
|
|
|
},
|
|
|
|
deep: true
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
|
|
|
async created() {
|
2022-02-10 12:47:46 +02:00
|
|
|
const render = (mutedWords) => mutedWords.map(x => {
|
|
|
|
if (Array.isArray(x)) {
|
|
|
|
return x.join(' ');
|
|
|
|
} else {
|
|
|
|
return x;
|
|
|
|
}
|
|
|
|
}).join('\n');
|
|
|
|
|
|
|
|
this.softMutedWords = render(this.$store.state.mutedWords);
|
|
|
|
this.hardMutedWords = render(this.$i.mutedWords);
|
2020-10-17 14:12:00 +03:00
|
|
|
|
|
|
|
this.hardWordMutedNotesCount = (await os.api('i/get-word-muted-notes-count', {})).count;
|
|
|
|
},
|
|
|
|
|
|
|
|
methods: {
|
|
|
|
async save() {
|
2022-02-10 12:47:46 +02:00
|
|
|
const parseMutes = (mutes, tab) => {
|
|
|
|
// split into lines, remove empty lines and unnecessary whitespace
|
|
|
|
let lines = mutes.trim().split('\n').map(line => line.trim()).filter(line => line != '');
|
|
|
|
|
|
|
|
// check each line if it is a RegExp or not
|
2022-02-11 12:44:56 +02:00
|
|
|
for (let i = 0; i < lines.length; i++) {
|
2022-02-10 12:47:46 +02:00
|
|
|
const line = lines[i]
|
|
|
|
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) {
|
|
|
|
// invalid syntax: do not save, do not reset changed flag
|
|
|
|
os.alert({
|
|
|
|
type: 'error',
|
|
|
|
title: this.$ts.regexpError,
|
|
|
|
text: this.$t('regexpErrorDescription', { tab, line: i + 1 }) + "\n" + err.toString()
|
|
|
|
});
|
|
|
|
// re-throw error so these invalid settings are not saved
|
|
|
|
throw err;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
lines[i] = line.split(' ');
|
|
|
|
}
|
|
|
|
}
|
2022-02-11 12:44:56 +02:00
|
|
|
|
|
|
|
return lines;
|
2022-02-10 12:47:46 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
let softMutes, hardMutes;
|
|
|
|
try {
|
|
|
|
softMutes = parseMutes(this.softMutedWords, this.$ts._wordMute.soft);
|
|
|
|
hardMutes = parseMutes(this.hardMutedWords, this.$ts._wordMute.hard);
|
|
|
|
} catch (err) {
|
|
|
|
// already displayed error message in parseMutes
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
this.$store.set('mutedWords', softMutes);
|
2020-10-17 14:12:00 +03:00
|
|
|
await os.api('i/update', {
|
2022-02-10 12:47:46 +02:00
|
|
|
mutedWords: hardMutes,
|
2020-10-17 14:12:00 +03:00
|
|
|
});
|
2022-02-10 12:47:46 +02:00
|
|
|
|
2020-10-17 14:12:00 +03:00
|
|
|
this.changed = false;
|
|
|
|
},
|
2020-11-25 14:31:34 +02:00
|
|
|
|
|
|
|
number
|
2020-10-17 14:12:00 +03:00
|
|
|
}
|
|
|
|
});
|
|
|
|
</script>
|