don't recursively check mute text and improve grouping

This commit is contained in:
Hazelnoot 2025-07-06 19:40:22 -04:00
parent 179c7e18bd
commit ba433d8914
23 changed files with 122 additions and 51 deletions

View file

@ -84,19 +84,18 @@ function provideMuteOverrides(overrides: Reactive<MuteOverrides> | null) {
provide(muteOverridesSymbol, overrides);
}
export function checkMute(note: Misskey.entities.Note | ComputedRef<Misskey.entities.Note>, withHardMute?: boolean | ComputedRef<boolean>, dive?: boolean | ComputedRef<boolean>): ComputedRef<Mute> {
export function checkMute(note: Misskey.entities.Note | ComputedRef<Misskey.entities.Note>, withHardMute?: boolean | ComputedRef<boolean>): ComputedRef<Mute> {
// inject() can only be used inside script setup, so it MUST be outside the computed block!
const overrides = injectMuteOverrides();
return computed(() => {
const _note = unref(note);
const _withHardMute = unref(withHardMute) ?? true;
const _dive = unref(dive) ?? false;
return getMutes(_note, _withHardMute, _dive, overrides);
return getMutes(_note, _withHardMute, overrides);
});
}
function getMutes(note: Misskey.entities.Note, withHardMute: boolean, dive: boolean, overrides: MuteOverrides | null): Mute {
function getMutes(note: Misskey.entities.Note, withHardMute: boolean, overrides: MuteOverrides | null): Mute {
const override: Partial<Mute> = overrides ? deepAssign(
{},
note.user.host ? overrides.instance[note.user.host] : undefined,
@ -108,8 +107,8 @@ function getMutes(note: Misskey.entities.Note, withHardMute: boolean, dive: bool
const isMe = $i != null && $i.id === note.userId;
const hardMuted = override.hardMuted ?? (!isMe && withHardMute && isHardMuted(note, dive));
const softMutedWords = override.softMutedWords ?? (isMe ? [] : isSoftMuted(note, dive));
const hardMuted = override.hardMuted ?? (!isMe && withHardMute && isHardMuted(note));
const softMutedWords = override.softMutedWords ?? (isMe ? [] : isSoftMuted(note));
const sensitiveMuted = override.sensitiveMuted ?? isSensitiveMuted(note);
const threadMuted = override.threadMuted ?? (!isMe && note.isMutingThread);
const noteMuted = override.noteMuted ?? (!isMe && note.isMutingNote);
@ -130,17 +129,17 @@ function getMutes(note: Misskey.entities.Note, withHardMute: boolean, dive: bool
return { hasMute, hardMuted, softMutedWords, sensitiveMuted, threadMuted, noteMuted, noteMandatoryCW, userMandatoryCW, instanceMandatoryCW };
}
function isHardMuted(note: Misskey.entities.Note, dive: boolean): boolean {
function isHardMuted(note: Misskey.entities.Note): boolean {
if (!$i?.hardMutedWords.length) return false;
const inputs = expandNote(note, dive);
const inputs = expandNote(note);
return containsMutedWord($i.hardMutedWords, inputs);
}
function isSoftMuted(note: Misskey.entities.Note, dive: boolean): string[] {
function isSoftMuted(note: Misskey.entities.Note): string[] {
if (!$i?.mutedWords.length) return [];
const inputs = expandNote(note, dive);
const inputs = expandNote(note);
return getMutedWords($i.mutedWords, inputs);
}
@ -215,7 +214,7 @@ export function containsMutedWord(mutedWords: (string | string[])[], inputs: Ite
return false;
}
export function *expandNote(note: Misskey.entities.Note, dive: boolean): Generator<string> {
export function *expandNote(note: Misskey.entities.Note): Generator<string> {
if (note.cw) yield note.cw;
if (note.text) yield note.text;
if (note.files) {
@ -228,15 +227,6 @@ export function *expandNote(note: Misskey.entities.Note, dive: boolean): Generat
if (choice.text) yield choice.text;
}
}
if (dive) {
if (note.reply) {
yield* expandNote(note.reply, true);
}
if (note.renote) {
yield* expandNote(note.renote, true);
}
}
}
function parseMutes(mutedWords: (string | string[])[]) {