Partially Revert "Hard mute (misskey-dev#12376)"

This reverts commit 864827f788 partially.

型定義に関する実装はそのままに
一部型定義に合わない実装の修正
This commit is contained in:
まっちゃとーにゅ 2023-11-25 12:10:31 +09:00
parent 77e676e121
commit d9efde97e4
No known key found for this signature in database
GPG key ID: 6AFBBF529601C1DB
17 changed files with 79 additions and 107 deletions

View file

@ -9,14 +9,7 @@ SPDX-License-Identifier: AGPL-3.0-only
<template #icon><i class="ti ti-message-off"></i></template>
<template #label>{{ i18n.ts.wordMute }}</template>
<XWordMute :muted="$i!.mutedWords" @save="saveMutedWords"/>
</MkFolder>
<MkFolder>
<template #icon><i class="ti ti-message-off"></i></template>
<template #label>{{ i18n.ts.hardWordMute }}</template>
<XWordMute :muted="$i!.hardMutedWords" @save="saveHardMutedWords"/>
<XWordMute/>
</MkFolder>
<MkFolder>
@ -136,7 +129,6 @@ import { definePageMetadata } from '@/scripts/page-metadata.js';
import MkUserCardMini from '@/components/MkUserCardMini.vue';
import * as os from '@/os.js';
import { infoImageUrl } from '@/instance.js';
import { $i } from '@/account.js';
import MkFolder from '@/components/MkFolder.vue';
const renoteMutingPagination = {
@ -215,14 +207,6 @@ async function toggleBlockItem(item) {
}
}
async function saveMutedWords(mutedWords: (string | string[])[]) {
await os.api('i/update', { mutedWords });
}
async function saveHardMutedWords(hardMutedWords: (string | string[])[]) {
await os.api('i/update', { hardMutedWords });
}
const headerActions = $computed(() => []);
const headerTabs = $computed(() => []);

View file

@ -20,17 +20,10 @@ import { ref, watch } from 'vue';
import MkTextarea from '@/components/MkTextarea.vue';
import MkButton from '@/components/MkButton.vue';
import * as os from '@/os.js';
import { $i } from '@/account.js';
import { i18n } from '@/i18n.js';
const props = defineProps<{
muted: (string[] | string)[];
}>();
const emit = defineEmits<{
(ev: 'save', value: (string[] | string)[]): void;
}>();
const render = (mutedWords) => mutedWords.map(x => {
const render = (mutedWords?: (string | string[])[]) => mutedWords?.map(x => {
if (Array.isArray(x)) {
return x.join(' ');
} else {
@ -38,7 +31,7 @@ const render = (mutedWords) => mutedWords.map(x => {
}
}).join('\n');
const mutedWords = ref(render(props.muted));
const mutedWords = ref(render($i?.mutedWords));
const changed = ref(false);
watch(mutedWords, () => {
@ -46,14 +39,14 @@ watch(mutedWords, () => {
});
async function save() {
const parseMutes = (mutes) => {
// split into lines, remove empty lines and unnecessary whitespace
let lines = mutes.trim().split('\n').map(line => line.trim()).filter(line => line !== '');
const parseMutes = (mutes?: string): (string | string[])[] => {
const parsed: (string | string[])[] = [];
if (!mutes) return parsed;
// split into lines, remove empty lines and unnecessary whitespace
// check each line if it is a RegExp or not
for (let i = 0; i < lines.length; i++) {
const line = lines[i];
const regexp = line.match(/^\/(.+)\/(.*)$/);
for (const [i, line] of mutes.trim().split('\n').map(line => line.trim()).filter(line => line !== '').entries()) {
const regexp = RegExp(/^\/(.+)\/(.*)$/).exec(line);
if (regexp) {
// check that the RegExp is valid
try {
@ -69,15 +62,16 @@ async function save() {
// re-throw error so these invalid settings are not saved
throw err;
}
parsed.push(line);
} else {
lines[i] = line.split(' ');
parsed.push(line.split(' '));
}
}
return lines;
return parsed;
};
let parsed;
let parsed: (string | string[])[];
try {
parsed = parseMutes(mutedWords.value);
} catch (err) {
@ -85,7 +79,9 @@ async function save() {
return;
}
emit('save', parsed);
await os.api('i/update', {
mutedWords: parsed,
});
changed.value = false;
}