mirror of
https://example.com
synced 2024-11-22 12:06:39 +09:00
fix: properly check post language in checkLangMute()
This commit is contained in:
parent
bf045daaed
commit
da624d23ad
1 changed files with 9 additions and 5 deletions
|
@ -12,11 +12,15 @@ function checkLangMute(
|
|||
note: firefish.entities.Note,
|
||||
mutedLangs: Array<string | string[]>,
|
||||
): Muted {
|
||||
const mutedLangList = new Set(
|
||||
mutedLangs.reduce((arr, x) => [...arr, ...(Array.isArray(x) ? x : [x])]),
|
||||
);
|
||||
if (mutedLangList.has((note.lang?.[0]?.lang || "").split("-")[0])) {
|
||||
return { muted: true, matched: [note.lang?.[0]?.lang] };
|
||||
const mutedLangList = new Set(mutedLangs.flatMap((e) => e));
|
||||
// handle subtags
|
||||
// e.g. if lang = "zh-hant-tw", check ["zh", "zh-hant", "zh-hant-tw"]
|
||||
const langChunks: string[] = (note.lang || "").split("-");
|
||||
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;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue