mirror of
https://codeberg.org/yeentown/barkey.git
synced 2025-07-08 04:54:32 +00:00
cleanup, simplify, and merge duplicate word mute implementations
This commit is contained in:
parent
b52db71e18
commit
8348a36f24
6 changed files with 44 additions and 72 deletions
|
@ -4,7 +4,7 @@ SPDX-License-Identifier: AGPL-3.0-only
|
||||||
-->
|
-->
|
||||||
|
|
||||||
<template>
|
<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">
|
<div :class="$style.avatar">
|
||||||
<MkAvatar :class="$style.icon" :user="note.user" indictor/>
|
<MkAvatar :class="$style.icon" :user="note.user" indictor/>
|
||||||
</div>
|
</div>
|
||||||
|
@ -18,36 +18,39 @@ SPDX-License-Identifier: AGPL-3.0-only
|
||||||
</MkA>
|
</MkA>
|
||||||
</header>
|
</header>
|
||||||
<div>
|
<div>
|
||||||
<div v-if="mutedWords" :class="[$style.text, $style.muted]">
|
<div v-if="muted" :class="[$style.text, $style.muted]">
|
||||||
<template v-if="prefer.s.showSoftWordMutedWord">{{ i18n.tsx.userSaysSomethingAbout({ name: i18n.ts.user, word: mutedWords}) }}</template>
|
<SkMutedNote :muted="muted" :note="note"></SkMutedNote>
|
||||||
<template v-else>{{ i18n.ts.postFiltered }}</template>
|
|
||||||
</div>
|
</div>
|
||||||
<Mfm v-else :class="$style.text" :text="getNoteSummary(note)" :isBlock="true" :plain="true" :nowrap="false" :isNote="true" nyaize="respect" :author="note.user"/>
|
<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>
|
||||||
</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>
|
</template>
|
||||||
|
|
||||||
<script lang="ts" setup>
|
<script lang="ts" setup>
|
||||||
import * as Misskey from 'misskey-js';
|
import * as Misskey from 'misskey-js';
|
||||||
import { computed } from 'vue';
|
|
||||||
import { getNoteSummary } from '@/utility/get-note-summary.js';
|
import { getNoteSummary } from '@/utility/get-note-summary.js';
|
||||||
import { userPage } from '@/filters/user.js';
|
import { userPage } from '@/filters/user.js';
|
||||||
import { notePage } from '@/filters/note.js';
|
import { notePage } from '@/filters/note.js';
|
||||||
import { i18n } from '@/i18n.js';
|
import { checkMutes } from '@/utility/check-word-mute';
|
||||||
import { getSoftMutedWords } from '@/utility/following-feed-utils';
|
import SkMutedNote from '@/components/SkMutedNote.vue';
|
||||||
import { prefer } from '@/preferences';
|
|
||||||
|
|
||||||
const props = defineProps<{
|
const props = defineProps<{
|
||||||
note: Misskey.entities.Note,
|
note: Misskey.entities.Note,
|
||||||
}>();
|
}>();
|
||||||
|
|
||||||
const mutedWords = computed(() => getSoftMutedWords(props.note));
|
|
||||||
|
|
||||||
defineEmits<{
|
defineEmits<{
|
||||||
(event: 'select', user: Misskey.entities.UserLite): void
|
(event: 'select', user: Misskey.entities.UserLite): void
|
||||||
}>();
|
}>();
|
||||||
|
|
||||||
|
// eslint-disable-next-line vue/no-setup-props-reactivity-loss
|
||||||
|
const { muted, hardMuted } = checkMutes(props.note);
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<style lang="scss" module>
|
<style lang="scss" module>
|
||||||
|
|
|
@ -15,7 +15,7 @@ SPDX-License-Identifier: AGPL-3.0-only
|
||||||
|
|
||||||
<template #default="{ items: notes }">
|
<template #default="{ items: notes }">
|
||||||
<MkDateSeparatedList v-slot="{ item: note }" :items="notes" :class="$style.panel" :noGap="true">
|
<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>
|
</MkDateSeparatedList>
|
||||||
</template>
|
</template>
|
||||||
</MkPagination>
|
</MkPagination>
|
||||||
|
@ -26,7 +26,6 @@ SPDX-License-Identifier: AGPL-3.0-only
|
||||||
import { computed, shallowRef } from 'vue';
|
import { computed, shallowRef } from 'vue';
|
||||||
import type { Paging } from '@/components/MkPagination.vue';
|
import type { Paging } from '@/components/MkPagination.vue';
|
||||||
import type { FollowingFeedTab } from '@/types/following-feed.js';
|
import type { FollowingFeedTab } from '@/types/following-feed.js';
|
||||||
import { getHardMutedWords } from '@/utility/following-feed-utils.js';
|
|
||||||
import { infoImageUrl } from '@/instance.js';
|
import { infoImageUrl } from '@/instance.js';
|
||||||
import { i18n } from '@/i18n.js';
|
import { i18n } from '@/i18n.js';
|
||||||
import MkDateSeparatedList from '@/components/MkDateSeparatedList.vue';
|
import MkDateSeparatedList from '@/components/MkDateSeparatedList.vue';
|
||||||
|
|
|
@ -31,13 +31,12 @@ import { i18n } from '@/i18n.js';
|
||||||
import { prefer } from '@/preferences.js';
|
import { prefer } from '@/preferences.js';
|
||||||
|
|
||||||
const props = defineProps<{
|
const props = defineProps<{
|
||||||
muted: false | 'sensitiveMute' | (string | string[])[];
|
muted: false | 'sensitiveMute' | string[];
|
||||||
note: Misskey.entities.Note;
|
note: Misskey.entities.Note;
|
||||||
|
|
||||||
}>();
|
}>();
|
||||||
|
|
||||||
const mutedWords = computed(() => Array.isArray(props.muted)
|
const mutedWords = computed(() => Array.isArray(props.muted)
|
||||||
? props.muted.map(words => Array.isArray(words) ? words.join() : words).join(' ')
|
? props.muted.join(', ')
|
||||||
: props.muted);
|
: props.muted);
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
|
|
@ -44,7 +44,7 @@ function testWordMutes() {
|
||||||
try {
|
try {
|
||||||
const mutes = parseMutes(props.mutedWords);
|
const mutes = parseMutes(props.mutedWords);
|
||||||
const matches = checkWordMute(testWords.value, null, mutes);
|
const matches = checkWordMute(testWords.value, null, mutes);
|
||||||
testMatches.value = matches ? matches.flat(2).join(', ') : '';
|
testMatches.value = matches ? matches.join(', ') : '';
|
||||||
} catch {
|
} catch {
|
||||||
// Error is displayed by above function
|
// Error is displayed by above function
|
||||||
testMatches.value = null;
|
testMatches.value = null;
|
||||||
|
|
|
@ -13,34 +13,39 @@ export function checkMutes(noteToCheck: Misskey.entities.Note, withHardMute = fa
|
||||||
return { muted, hardMuted };
|
return { muted, hardMuted };
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Overload FunctionにLintが対応していないのでコメントアウト
|
export function checkMute(note: Misskey.entities.Note, mutes: undefined | null): false;
|
||||||
function checkMute(noteToCheck: Misskey.entities.Note, mutedWords: Array<string | string[]> | undefined | null, checkOnly: true): boolean;
|
export function checkMute(note: Misskey.entities.Note, mutes: undefined | null, checkOnly: false): false;
|
||||||
function checkMute(noteToCheck: Misskey.entities.Note, mutedWords: Array<string | string[]> | undefined | null, checkOnly: false): Array<string | string[]> | false | 'sensitiveMute';
|
export function checkMute(note: Misskey.entities.Note, mutes: undefined | null, checkOnly?: boolean): false | 'sensitiveMute';
|
||||||
*/
|
export function checkMute(note: Misskey.entities.Note, mutes: Array<string | string[]> | undefined | null): string[] | false;
|
||||||
export function checkMute(noteToCheck: Misskey.entities.Note, mutedWords: Array<string | string[]> | undefined | null, checkOnly = false): Array<string | string[]> | false | 'sensitiveMute' {
|
export function checkMute(note: Misskey.entities.Note, mutes: Array<string | string[]> | undefined | null, checkOnly: false): string[] | false;
|
||||||
if (mutedWords != null) {
|
export function checkMute(note: Misskey.entities.Note, mutes: Array<string | string[]> | undefined | null, checkOnly?: boolean): string[] | false | 'sensitiveMute';
|
||||||
const result = checkWordMute(noteToCheck, $i, mutedWords);
|
export function checkMute(note: Misskey.entities.Note, mutes: Array<string | string[]> | undefined | null, checkOnly = false): string[] | false | 'sensitiveMute' {
|
||||||
if (Array.isArray(result)) return result;
|
if (mutes != null) {
|
||||||
|
const result =
|
||||||
|
checkWordMute(note, $i, mutes)
|
||||||
|
|| checkWordMute(note.reply, $i, mutes)
|
||||||
|
|| checkWordMute(note.renote, $i, mutes);
|
||||||
|
|
||||||
const replyResult = noteToCheck.reply && checkWordMute(noteToCheck.reply, $i, mutedWords);
|
// Only continue to sensitiveMute if we don't match any *actual* mutes
|
||||||
if (Array.isArray(replyResult)) return replyResult;
|
if (result) {
|
||||||
|
return result;
|
||||||
const renoteResult = noteToCheck.renote && checkWordMute(noteToCheck.renote, $i, mutedWords);
|
}
|
||||||
if (Array.isArray(renoteResult)) return renoteResult;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (checkOnly) return false;
|
if (checkOnly) {
|
||||||
|
|
||||||
const inTimeline = inject<boolean>('inTimeline', false);
|
const inTimeline = inject<boolean>('inTimeline', false);
|
||||||
const tl_withSensitive = inject<Ref<boolean> | null>('tl_withSensitive', null);
|
const tl_withSensitive = inject<Ref<boolean> | null>('tl_withSensitive', null);
|
||||||
if (inTimeline && tl_withSensitive?.value === false && noteToCheck.files?.some((v) => v.isSensitive)) {
|
if (inTimeline && tl_withSensitive?.value === false && note.files?.some((v) => v.isSensitive)) {
|
||||||
return 'sensitiveMute';
|
return 'sensitiveMute';
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function checkWordMute(note: string | Misskey.entities.Note, me: Misskey.entities.UserLite | null | undefined, mutedWords: Array<string | string[]>): Array<string | string[]> | false {
|
export function checkWordMute(note: string | Misskey.entities.Note | undefined | null, me: Misskey.entities.UserLite | null | undefined, mutedWords: Array<string | string[]>): string[] | false {
|
||||||
|
if (note == null) return false;
|
||||||
|
|
||||||
// 自分自身
|
// 自分自身
|
||||||
if (me && typeof(note) === 'object' && (note.userId === me.id)) return false;
|
if (me && typeof(note) === 'object' && (note.userId === me.id)) return false;
|
||||||
|
|
||||||
|
@ -79,7 +84,7 @@ export function checkWordMute(note: string | Misskey.entities.Note, me: Misskey.
|
||||||
}, new Set<string>());
|
}, new Set<string>());
|
||||||
|
|
||||||
// Nested arrays are intentional, otherwise the note components will join with space (" ") and it's confusing.
|
// Nested arrays are intentional, otherwise the note components will join with space (" ") and it's confusing.
|
||||||
if (matched.size > 0) return [[Array.from(matched).join(', ')]];
|
if (matched.size > 0) return Array.from(matched);
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
|
|
|
@ -4,7 +4,6 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import { computed } from 'vue';
|
import { computed } from 'vue';
|
||||||
import * as Misskey from 'misskey-js';
|
|
||||||
import type { Ref, WritableComputedRef } from 'vue';
|
import type { Ref, WritableComputedRef } from 'vue';
|
||||||
import type { PageHeaderItem } from '@/types/page-header.js';
|
import type { PageHeaderItem } from '@/types/page-header.js';
|
||||||
import type { MenuItem } from '@/types/menu.js';
|
import type { MenuItem } from '@/types/menu.js';
|
||||||
|
@ -14,8 +13,6 @@ import { i18n } from '@/i18n.js';
|
||||||
import { popupMenu } from '@/os.js';
|
import { popupMenu } from '@/os.js';
|
||||||
import { prefer } from '@/preferences.js';
|
import { prefer } from '@/preferences.js';
|
||||||
import { followingTab, followersTab, mutualsTab, defaultFollowingFeedState } from '@/types/following-feed.js';
|
import { followingTab, followersTab, mutualsTab, defaultFollowingFeedState } from '@/types/following-feed.js';
|
||||||
import { $i } from '@/i';
|
|
||||||
import { checkWordMute } from '@/utility/check-word-mute';
|
|
||||||
|
|
||||||
export function followingTabName(tab: FollowingFeedTab): string;
|
export function followingTabName(tab: FollowingFeedTab): string;
|
||||||
export function followingTabName(tab: FollowingFeedTab | null | undefined): null;
|
export function followingTabName(tab: FollowingFeedTab | null | undefined): null;
|
||||||
|
@ -153,34 +150,3 @@ function createDefaultStorage(): Ref<StorageInterface> {
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
|
|
||||||
export function getSoftMutedWords(note: Misskey.entities.Note): string | null {
|
|
||||||
return getMutedWords(note, $i?.mutedWords);
|
|
||||||
}
|
|
||||||
|
|
||||||
export function getHardMutedWords(note: Misskey.entities.Note): string | null {
|
|
||||||
return getMutedWords(note, $i?.hardMutedWords);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Match the typing used by Misskey
|
|
||||||
type Mutes = (string | string[])[] | null | undefined;
|
|
||||||
|
|
||||||
// Adapted from MkNote.ts
|
|
||||||
function getMutedWords(note: Misskey.entities.Note, mutes: Mutes): string | null {
|
|
||||||
return checkMute(note, mutes)
|
|
||||||
?? checkMute(note.reply, mutes)
|
|
||||||
?? checkMute(note.renote, mutes);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Adapted from check-word-mute.ts
|
|
||||||
function checkMute(note: Misskey.entities.Note | undefined | null, mutes: Mutes): string | null {
|
|
||||||
if (!note) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!mutes || mutes.length < 1) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
const mutedWords = checkWordMute(note, $i, mutes);
|
|
||||||
return mutedWords ? mutedWords.flat(2).join(', ') : null;
|
|
||||||
}
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue