fix: properly check post language in checkLangMute() #3

Manually merged
sup39 merged 1 commit from fix/check-lang-mute into main 2023-12-29 10:42:09 +09:00
Showing only changes of commit 5eaa29057f - Show all commits

View file

@ -12,11 +12,15 @@ function checkLangMute(
note: firefish.entities.Note, note: firefish.entities.Note,
mutedLangs: Array<string | string[]>, mutedLangs: Array<string | string[]>,
): Muted { ): Muted {
const mutedLangList = new Set( const mutedLangList = new Set(mutedLangs.flatMap((e) => e));
mutedLangs.reduce((arr, x) => [...arr, ...(Array.isArray(x) ? x : [x])]), // handle subtags
); // e.g. if lang = "zh-hant-tw", check ["zh", "zh-hant", "zh-hant-tw"]
if (mutedLangList.has((note.lang?.[0]?.lang || "").split("-")[0])) { const langChunks: string[] = (note.lang || "").split("-");
return { muted: true, matched: [note.lang?.[0]?.lang] }; for (let i = 0; i < langChunks.length; i++) {
const lang = langChunks.slice(0, i + 1).join("-");
if (mutedLangList.has(lang)) {
return { muted: true, matched: [lang] };
}
} }
return NotMuted; return NotMuted;
} }