mirror of
https://example.com
synced 2024-11-22 12:46:39 +09:00
fix: following check in check-hit-antenna
This commit is contained in:
parent
65817a540f
commit
f6d534d754
2 changed files with 13 additions and 18 deletions
|
@ -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<User["id"][]>("blocking", 60 * 5);
|
||||
const mutedWordsCache = new Cache<string[][] | undefined>("mutedWords", 60 * 5);
|
||||
const followingCache = new Cache<User["id"][]>("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<boolean> {
|
||||
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,
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue