Refactor soft word mutes
This commit is contained in:
parent
075e5a1c7a
commit
cdd876ba03
@ -663,6 +663,9 @@ regexpErrorDescription: "An error occurred in the regular expression on line {li
|
|||||||
instanceMute: "Instance Mutes"
|
instanceMute: "Instance Mutes"
|
||||||
userSaysSomething: "{name} said something"
|
userSaysSomething: "{name} said something"
|
||||||
userSaysSomethingReason: "{name} said {reason}"
|
userSaysSomethingReason: "{name} said {reason}"
|
||||||
|
userSaysSomethingReasonReply: "{name} replied to a post containing {reason}"
|
||||||
|
userSaysSomethingReasonRenote: "{name} boosted a post containing {reason}"
|
||||||
|
userSaysSomethingReasonQuote: "{name} quoted a post containing {reason}"
|
||||||
makeActive: "Activate"
|
makeActive: "Activate"
|
||||||
display: "Display"
|
display: "Display"
|
||||||
copy: "Copy"
|
copy: "Copy"
|
||||||
|
@ -619,6 +619,9 @@ regexpErrorDescription: "{tab}ワードミュートの{line}行目の正規表
|
|||||||
instanceMute: "インスタンスミュート"
|
instanceMute: "インスタンスミュート"
|
||||||
userSaysSomething: "{name}が何かを言いました"
|
userSaysSomething: "{name}が何かを言いました"
|
||||||
userSaysSomethingReason: "{name}が{reason}と言いました"
|
userSaysSomethingReason: "{name}が{reason}と言いました"
|
||||||
|
userSaysSomethingReasonReply: "{name}が{reason}を含む投稿に返信しました"
|
||||||
|
userSaysSomethingReasonRenote: "{name}が{reason}を含む投稿をブーストしました"
|
||||||
|
userSaysSomethingReasonQuote: "{name}が{reason}を含む投稿を引用しました"
|
||||||
makeActive: "アクティブにする"
|
makeActive: "アクティブにする"
|
||||||
display: "表示"
|
display: "表示"
|
||||||
copy: "コピー"
|
copy: "コピー"
|
||||||
|
@ -198,7 +198,7 @@
|
|||||||
</article>
|
</article>
|
||||||
</div>
|
</div>
|
||||||
<div v-else class="muted" @click="muted.muted = false">
|
<div v-else class="muted" @click="muted.muted = false">
|
||||||
<I18n :src="i18n.ts.userSaysSomethingReason" tag="small">
|
<I18n :src="softMuteReasonI18nSrc(muted.what)" tag="small">
|
||||||
<template #name>
|
<template #name>
|
||||||
<MkA
|
<MkA
|
||||||
v-user-preview="appearNote.userId"
|
v-user-preview="appearNote.userId"
|
||||||
@ -261,6 +261,20 @@ const inChannel = inject("inChannel", null);
|
|||||||
|
|
||||||
let note = $ref(deepClone(props.note));
|
let note = $ref(deepClone(props.note));
|
||||||
|
|
||||||
|
const softMuteReasonI18nSrc = (what?: string) => {
|
||||||
|
if (what === "note")
|
||||||
|
return i18n.ts.userSaysSomethingReason;
|
||||||
|
if (what === "reply")
|
||||||
|
return i18n.ts.userSaysSomethingReasonReply;
|
||||||
|
if (what === "renote")
|
||||||
|
return i18n.ts.userSaysSomethingReasonRenote;
|
||||||
|
if (what === "quote")
|
||||||
|
return i18n.ts.userSaysSomethingReasonQuote;
|
||||||
|
|
||||||
|
// I don't think here is reachable, but just in case
|
||||||
|
return i18n.ts.userSaysSomething;
|
||||||
|
}
|
||||||
|
|
||||||
// plugin
|
// plugin
|
||||||
if (noteViewInterruptors.length > 0) {
|
if (noteViewInterruptors.length > 0) {
|
||||||
onMounted(async () => {
|
onMounted(async () => {
|
||||||
|
@ -39,7 +39,7 @@
|
|||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
<div v-else class="_panel muted" @click="muted.muted = false">
|
<div v-else class="_panel muted" @click="muted.muted = false">
|
||||||
<I18n :src="i18n.ts.userSaysSomethingReason" tag="small">
|
<I18n :src="softMuteReasonI18nSrc(muted.what)" tag="small">
|
||||||
<template #name>
|
<template #name>
|
||||||
<MkA
|
<MkA
|
||||||
v-user-preview="appearNote.userId"
|
v-user-preview="appearNote.userId"
|
||||||
@ -110,6 +110,20 @@ const inChannel = inject("inChannel", null);
|
|||||||
|
|
||||||
let note = $ref(deepClone(props.note));
|
let note = $ref(deepClone(props.note));
|
||||||
|
|
||||||
|
const softMuteReasonI18nSrc = (what?: string) => {
|
||||||
|
if (what === "note")
|
||||||
|
return i18n.ts.userSaysSomethingReason;
|
||||||
|
if (what === "reply")
|
||||||
|
return i18n.ts.userSaysSomethingReasonReply;
|
||||||
|
if (what === "renote")
|
||||||
|
return i18n.ts.userSaysSomethingReasonRenote;
|
||||||
|
if (what === "quote")
|
||||||
|
return i18n.ts.userSaysSomethingReasonQuote;
|
||||||
|
|
||||||
|
// I don't think here is reachable, but just in case
|
||||||
|
return i18n.ts.userSaysSomething;
|
||||||
|
}
|
||||||
|
|
||||||
const enableEmojiReactions = defaultStore.state.enableEmojiReactions;
|
const enableEmojiReactions = defaultStore.state.enableEmojiReactions;
|
||||||
|
|
||||||
// plugin
|
// plugin
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
<template>
|
<template>
|
||||||
<div
|
<div
|
||||||
|
v-if="!muted.muted || muted.what === 'reply'"
|
||||||
ref="el"
|
ref="el"
|
||||||
v-size="{ max: [450, 500] }"
|
v-size="{ max: [450, 500] }"
|
||||||
class="wrpstxzv"
|
class="wrpstxzv"
|
||||||
@ -161,6 +162,22 @@
|
|||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
</div>
|
</div>
|
||||||
|
<div v-else class="muted" @click="muted.muted = false">
|
||||||
|
<I18n :src="softMuteReasonI18nSrc(muted.what)" tag="small">
|
||||||
|
<template #name>
|
||||||
|
<MkA
|
||||||
|
v-user-preview="appearNote.userId"
|
||||||
|
class="name"
|
||||||
|
:to="userPage(appearNote.user)"
|
||||||
|
>
|
||||||
|
<MkUserName :user="appearNote.user" />
|
||||||
|
</MkA>
|
||||||
|
</template>
|
||||||
|
<template #reason>
|
||||||
|
<b class="_blur_text">{{ muted.matched.join(", ") }}</b>
|
||||||
|
</template>
|
||||||
|
</I18n>
|
||||||
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script lang="ts" setup>
|
<script lang="ts" setup>
|
||||||
@ -176,10 +193,12 @@ import XRenoteButton from "@/components/MkRenoteButton.vue";
|
|||||||
import XQuoteButton from "@/components/MkQuoteButton.vue";
|
import XQuoteButton from "@/components/MkQuoteButton.vue";
|
||||||
import { pleaseLogin } from "@/scripts/please-login";
|
import { pleaseLogin } from "@/scripts/please-login";
|
||||||
import { getNoteMenu } from "@/scripts/get-note-menu";
|
import { getNoteMenu } from "@/scripts/get-note-menu";
|
||||||
|
import { getWordMute } from "@/scripts/check-word-mute";
|
||||||
import { notePage } from "@/filters/note";
|
import { notePage } from "@/filters/note";
|
||||||
import { useRouter } from "@/router";
|
import { useRouter } from "@/router";
|
||||||
import * as os from "@/os";
|
import * as os from "@/os";
|
||||||
import { reactionPicker } from "@/scripts/reaction-picker";
|
import { reactionPicker } from "@/scripts/reaction-picker";
|
||||||
|
import { $i } from "@/account";
|
||||||
import { i18n } from "@/i18n";
|
import { i18n } from "@/i18n";
|
||||||
import { deepClone } from "@/scripts/clone";
|
import { deepClone } from "@/scripts/clone";
|
||||||
import { useNoteCapture } from "@/scripts/use-note-capture";
|
import { useNoteCapture } from "@/scripts/use-note-capture";
|
||||||
@ -206,6 +225,20 @@ const props = withDefaults(
|
|||||||
|
|
||||||
let note = $ref(deepClone(props.note));
|
let note = $ref(deepClone(props.note));
|
||||||
|
|
||||||
|
const softMuteReasonI18nSrc = (what?: string) => {
|
||||||
|
if (what === "note")
|
||||||
|
return i18n.ts.userSaysSomethingReason;
|
||||||
|
if (what === "reply")
|
||||||
|
return i18n.ts.userSaysSomethingReasonReply;
|
||||||
|
if (what === "renote")
|
||||||
|
return i18n.ts.userSaysSomethingReasonRenote;
|
||||||
|
if (what === "quote")
|
||||||
|
return i18n.ts.userSaysSomethingReasonQuote;
|
||||||
|
|
||||||
|
// I don't think here is reachable, but just in case
|
||||||
|
return i18n.ts.userSaysSomething;
|
||||||
|
}
|
||||||
|
|
||||||
const isRenote =
|
const isRenote =
|
||||||
note.renote != null &&
|
note.renote != null &&
|
||||||
note.text == null &&
|
note.text == null &&
|
||||||
@ -222,6 +255,7 @@ let appearNote = $computed(() =>
|
|||||||
isRenote ? (note.renote as misskey.entities.Note) : note
|
isRenote ? (note.renote as misskey.entities.Note) : note
|
||||||
);
|
);
|
||||||
const isDeleted = ref(false);
|
const isDeleted = ref(false);
|
||||||
|
const muted = ref(getWordMute(appearNote, $i, defaultStore.state.mutedWords));
|
||||||
const translation = ref(null);
|
const translation = ref(null);
|
||||||
const translating = ref(false);
|
const translating = ref(false);
|
||||||
const replies: misskey.entities.Note[] =
|
const replies: misskey.entities.Note[] =
|
||||||
@ -617,4 +651,10 @@ function noteClick(e) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.muted {
|
||||||
|
padding: 8px;
|
||||||
|
text-align: center;
|
||||||
|
opacity: 0.7;
|
||||||
|
}
|
||||||
</style>
|
</style>
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
export type Muted = {
|
export type Muted = {
|
||||||
muted: boolean;
|
muted: boolean;
|
||||||
matched: string[];
|
matched: string[];
|
||||||
|
what?: string; // "note" || "reply" || "renote" || "quote"
|
||||||
};
|
};
|
||||||
|
|
||||||
const NotMuted = { muted: false, matched: [] };
|
const NotMuted = { muted: false, matched: [] };
|
||||||
@ -9,29 +10,15 @@ function escapeRegExp(x: string) {
|
|||||||
return x.replace(/[.*+?^${}()|[\]\\]/g, "\\$&"); // $& means the whole matched string
|
return x.replace(/[.*+?^${}()|[\]\\]/g, "\\$&"); // $& means the whole matched string
|
||||||
}
|
}
|
||||||
|
|
||||||
export function getWordMute(
|
function checkWordMute(note: NoteLike): Muted {
|
||||||
note: Record<string, any>,
|
const text = ((note.cw ?? "") + " " + (note.text ?? "")).trim();
|
||||||
me: Record<string, any> | null | undefined,
|
if (text === "") return NotMuted;
|
||||||
mutedWords: Array<string | string[]>,
|
|
||||||
): Muted {
|
|
||||||
// 自分自身
|
|
||||||
if (me && note.userId === me.id) {
|
|
||||||
return NotMuted;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (mutedWords.length > 0) {
|
|
||||||
const text = ((note.cw ?? "") + "\n" + (note.text ?? "")).trim();
|
|
||||||
|
|
||||||
if (text === "") {
|
|
||||||
return NotMuted;
|
|
||||||
}
|
|
||||||
|
|
||||||
for (const mutePattern of mutedWords) {
|
for (const mutePattern of mutedWords) {
|
||||||
let mute: RegExp;
|
let mute: RegExp;
|
||||||
let matched: string[];
|
let matched: string[];
|
||||||
if (Array.isArray(mutePattern)) {
|
if (Array.isArray(mutePattern)) {
|
||||||
matched = mutePattern.filter((keyword) => keyword !== "");
|
matched = mutePattern.filter((keyword) => keyword !== "");
|
||||||
|
|
||||||
if (matched.length === 0) {
|
if (matched.length === 0) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
@ -49,7 +36,6 @@ export function getWordMute(
|
|||||||
mute = new RegExp(regexp[1], regexp[2]);
|
mute = new RegExp(regexp[1], regexp[2]);
|
||||||
matched = [mutePattern];
|
matched = [mutePattern];
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
if (mute.test(text)) {
|
if (mute.test(text)) {
|
||||||
return { muted: true, matched };
|
return { muted: true, matched };
|
||||||
@ -60,5 +46,39 @@ export function getWordMute(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function getWordMute(
|
||||||
|
note: Record<string, any>,
|
||||||
|
me: Record<string, any> | null | undefined,
|
||||||
|
mutedWords: Array<string | string[]>,
|
||||||
|
): Muted {
|
||||||
|
// 自分自身
|
||||||
|
if (me && note.userId === me.id) {
|
||||||
|
return NotMuted;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (mutedWords.length > 0) {
|
||||||
|
let noteMuted = checkWordMute(note);
|
||||||
|
if (noteMuted.muted) {
|
||||||
|
noteMuted.what = "note";
|
||||||
|
return noteMuted;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (note.reply) {
|
||||||
|
let replyMuted = checkWordMute(note.reply);
|
||||||
|
if (replyMuted.muted) {
|
||||||
|
replyMuted.what = "reply";
|
||||||
|
return replyMuted;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (note.renote) {
|
||||||
|
let renoteMuted = checkWordMute(note.renote);
|
||||||
|
if (renoteMuted.muted) {
|
||||||
|
renoteMuted.what = (note.text == null ? "renote" : "quote");
|
||||||
|
return renoteMuted;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return NotMuted;
|
return NotMuted;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user