From f6d534d754c655d497f264f1217bc707502f08cf Mon Sep 17 00:00:00 2001 From: naskya Date: Mon, 30 Oct 2023 20:07:30 +0900 Subject: [PATCH] fix: following check in check-hit-antenna --- .../backend/src/misc/check-hit-antenna.ts | 19 ++++++++++++------- packages/backend/src/services/note/create.ts | 12 +----------- 2 files changed, 13 insertions(+), 18 deletions(-) diff --git a/packages/backend/src/misc/check-hit-antenna.ts b/packages/backend/src/misc/check-hit-antenna.ts index 941417cff..df6bc9af5 100644 --- a/packages/backend/src/misc/check-hit-antenna.ts +++ b/packages/backend/src/misc/check-hit-antenna.ts @@ -1,7 +1,7 @@ import type { Antenna } from "@/models/entities/antenna.js"; import type { Note } from "@/models/entities/note.js"; import type { User } from "@/models/entities/user.js"; -import { Blockings, UserProfiles } from "@/models/index.js"; +import { Blockings, Followings, UserProfiles } from "@/models/index.js"; import { getFullApAccount } from "./convert-host.js"; import * as Acct from "@/misc/acct.js"; import type { Packed } from "./schema.js"; @@ -10,12 +10,12 @@ import { getWordHardMute } from "./check-word-mute.js"; const blockingCache = new Cache("blocking", 60 * 5); const mutedWordsCache = new Cache("mutedWords", 60 * 5); +const followingCache = new Cache("following", 60 * 5); export async function checkHitAntenna( antenna: Antenna, note: Note | Packed<"Note">, noteUser: { id: User["id"]; username: string; host: string | null }, - antennaUserFollowing: User["id"][], ): Promise { if (note.visibility === "specified") return false; if (antenna.withFile) { @@ -23,11 +23,6 @@ export async function checkHitAntenna( } if (!antenna.withReplies && note.replyId != null) return false; - if (note.visibility === "followers" || note.visibility === "home") { - if (antennaUserFollowing && !antennaUserFollowing.includes(note.userId)) - return false; - } - if (antenna.src === "users") { const accts = antenna.users.map((x) => { const { username, host } = Acct.parse(x); @@ -99,6 +94,16 @@ export async function checkHitAntenna( ); if (blockings.includes(antenna.userId)) return false; + if (note.visibility === "followers" || note.visibility === "home") { + const following = await followingCache.fetch(antenna.userId, () => + Followings.find({ + where: { followerId: antenna.userId }, + select: ["followeeId"], + }).then((relations) => relations.map((relation) => relation.followeeId)), + ); + if (!following.includes(note.userId)) return false; + } + const mutedWords = await mutedWordsCache.fetch(antenna.userId, () => UserProfiles.findOneBy({ userId: antenna.userId }).then( (profile) => profile?.mutedWords, diff --git a/packages/backend/src/services/note/create.ts b/packages/backend/src/services/note/create.ts index 3602192c5..24e645329 100644 --- a/packages/backend/src/services/note/create.ts +++ b/packages/backend/src/services/note/create.ts @@ -386,17 +386,7 @@ export default async ( // Antenna for (const antenna of await getAntennas()) { - checkHitAntenna( - antenna, - note, - user, - ( - await Followings.find({ - where: { followerId: user.id }, - select: ["followeeId"], - }) - ).map((x) => x.followeeId), - ).then((hit) => { + checkHitAntenna(antenna, note, user).then((hit) => { if (hit) { addNoteToAntenna(antenna, note, user); }