cleanup, simplify, and merge duplicate word mute implementations

This commit is contained in:
Hazelnoot 2025-05-13 22:58:24 -04:00
parent b52db71e18
commit 8348a36f24
6 changed files with 44 additions and 72 deletions

View file

@ -4,7 +4,7 @@ SPDX-License-Identifier: AGPL-3.0-only
-->
<template>
<div :class="$style.root" @click="$emit('select', note.user)">
<div v-if="!hardMuted" :class="$style.root" @click="$emit('select', note.user)">
<div :class="$style.avatar">
<MkAvatar :class="$style.icon" :user="note.user" indictor/>
</div>
@ -18,36 +18,39 @@ SPDX-License-Identifier: AGPL-3.0-only
</MkA>
</header>
<div>
<div v-if="mutedWords" :class="[$style.text, $style.muted]">
<template v-if="prefer.s.showSoftWordMutedWord">{{ i18n.tsx.userSaysSomethingAbout({ name: i18n.ts.user, word: mutedWords}) }}</template>
<template v-else>{{ i18n.ts.postFiltered }}</template>
<div v-if="muted" :class="[$style.text, $style.muted]">
<SkMutedNote :muted="muted" :note="note"></SkMutedNote>
</div>
<Mfm v-else :class="$style.text" :text="getNoteSummary(note)" :isBlock="true" :plain="true" :nowrap="false" :isNote="true" nyaize="respect" :author="note.user"/>
</div>
</div>
</div>
<div v-else>
<!--
MkDateSeparatedList uses TransitionGroup which requires single element in the child elements
so MkNote create empty div instead of no elements
-->
</div>
</template>
<script lang="ts" setup>
import * as Misskey from 'misskey-js';
import { computed } from 'vue';
import { getNoteSummary } from '@/utility/get-note-summary.js';
import { userPage } from '@/filters/user.js';
import { notePage } from '@/filters/note.js';
import { i18n } from '@/i18n.js';
import { getSoftMutedWords } from '@/utility/following-feed-utils';
import { prefer } from '@/preferences';
import { checkMutes } from '@/utility/check-word-mute';
import SkMutedNote from '@/components/SkMutedNote.vue';
const props = defineProps<{
note: Misskey.entities.Note,
}>();
const mutedWords = computed(() => getSoftMutedWords(props.note));
defineEmits<{
(event: 'select', user: Misskey.entities.UserLite): void
}>();
// eslint-disable-next-line vue/no-setup-props-reactivity-loss
const { muted, hardMuted } = checkMutes(props.note);
</script>
<style lang="scss" module>

View file

@ -15,7 +15,7 @@ SPDX-License-Identifier: AGPL-3.0-only
<template #default="{ items: notes }">
<MkDateSeparatedList v-slot="{ item: note }" :items="notes" :class="$style.panel" :noGap="true">
<SkFollowingFeedEntry v-if="!getHardMutedWords(note)" :note="note" :class="props.selectedUserId == note.userId && $style.selected" @select="u => selectUser(u.id)"/>
<SkFollowingFeedEntry :note="note" :class="props.selectedUserId == note.userId && $style.selected" @select="u => selectUser(u.id)"/>
</MkDateSeparatedList>
</template>
</MkPagination>
@ -26,7 +26,6 @@ SPDX-License-Identifier: AGPL-3.0-only
import { computed, shallowRef } from 'vue';
import type { Paging } from '@/components/MkPagination.vue';
import type { FollowingFeedTab } from '@/types/following-feed.js';
import { getHardMutedWords } from '@/utility/following-feed-utils.js';
import { infoImageUrl } from '@/instance.js';
import { i18n } from '@/i18n.js';
import MkDateSeparatedList from '@/components/MkDateSeparatedList.vue';

View file

@ -31,13 +31,12 @@ import { i18n } from '@/i18n.js';
import { prefer } from '@/preferences.js';
const props = defineProps<{
muted: false | 'sensitiveMute' | (string | string[])[];
muted: false | 'sensitiveMute' | string[];
note: Misskey.entities.Note;
}>();
const mutedWords = computed(() => Array.isArray(props.muted)
? props.muted.map(words => Array.isArray(words) ? words.join() : words).join(' ')
? props.muted.join(', ')
: props.muted);
</script>

View file

@ -12,7 +12,7 @@ SPDX-License-Identifier: AGPL-3.0-only
<template #caption>{{ i18n.ts.wordMuteTestDescription }}</template>
</MkTextarea>
<div><MkButton :disabled="!testWords" @click="testWordMutes">{{ i18n.ts.wordMuteTestTest }}</MkButton></div>
<div v-if="testMatches == null">{{ i18n.ts.wordMuteTestNoResults}}</div>
<div v-if="testMatches == null">{{ i18n.ts.wordMuteTestNoResults }}</div>
<div v-else-if="testMatches === ''">{{ i18n.ts.wordMuteTestNoMatch }}</div>
<div v-else>{{ i18n.tsx.wordMuteTestMatch({ words: testMatches }) }}</div>
</div>
@ -44,7 +44,7 @@ function testWordMutes() {
try {
const mutes = parseMutes(props.mutedWords);
const matches = checkWordMute(testWords.value, null, mutes);
testMatches.value = matches ? matches.flat(2).join(', ') : '';
testMatches.value = matches ? matches.join(', ') : '';
} catch {
// Error is displayed by above function
testMatches.value = null;