fix: cache muted words

This commit is contained in:
naskya 2023-10-17 07:55:07 +09:00
parent ae637ec85b
commit bdf3311402
No known key found for this signature in database
GPG key ID: 164DFF24E2D40139

View file

@ -9,6 +9,7 @@ import { Cache } from "./cache.js";
import { getWordHardMute } from "./check-word-mute.js";
const blockingCache = new Cache<User["id"][]>("blocking", 60 * 5);
const mutedWordsCache = new Cache<string[][] | undefined>("mutedWords", 60 * 5);
export async function checkHitAntenna(
antenna: Antenna,
@ -22,14 +23,6 @@ export async function checkHitAntenna(
if (note.fileIds && note.fileIds.length === 0) return false;
}
// アンテナ作成者がノート作成者にブロックされていたらスキップ
const blockings = await blockingCache.fetch(noteUser.id, () =>
Blockings.findBy({ blockerId: noteUser.id }).then((res) =>
res.map((x) => x.blockeeId),
),
);
if (blockings.some((blocking) => blocking === antenna.userId)) return false;
if (antenna.src === "users") {
const accts = antenna.users.map((x) => {
const { username, host } = Acct.parse(x);
@ -88,16 +81,20 @@ export async function checkHitAntenna(
if (matched) return false;
}
if (
await getWordHardMute(
note,
antenna.userId,
(
await UserProfiles.findOneBy({ userId: antenna.userId })
)?.mutedWords,
)
)
return false;
// アンテナ作成者がノート作成者にブロックされていたらスキップ
const blockings = await blockingCache.fetch(noteUser.id, () =>
Blockings.findBy({ blockerId: noteUser.id }).then((res) =>
res.map((x) => x.blockeeId),
),
);
if (blockings.includes(antenna.userId)) return false;
const mutedWords = await mutedWordsCache.fetch(antenna.userId, () =>
UserProfiles.findOneBy({ userId: antenna.userId }).then(
(profile) => profile?.mutedWords,
),
);
if (await getWordHardMute(note, antenna.userId, mutedWords)) return false;
// TODO: eval expression