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 { Antenna } from "@/models/entities/antenna.js";
|
||||||
import type { Note } from "@/models/entities/note.js";
|
import type { Note } from "@/models/entities/note.js";
|
||||||
import type { User } from "@/models/entities/user.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 { getFullApAccount } from "./convert-host.js";
|
||||||
import * as Acct from "@/misc/acct.js";
|
import * as Acct from "@/misc/acct.js";
|
||||||
import type { Packed } from "./schema.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 blockingCache = new Cache<User["id"][]>("blocking", 60 * 5);
|
||||||
const mutedWordsCache = new Cache<string[][] | undefined>("mutedWords", 60 * 5);
|
const mutedWordsCache = new Cache<string[][] | undefined>("mutedWords", 60 * 5);
|
||||||
|
const followingCache = new Cache<User["id"][]>("following", 60 * 5);
|
||||||
|
|
||||||
export async function checkHitAntenna(
|
export async function checkHitAntenna(
|
||||||
antenna: Antenna,
|
antenna: Antenna,
|
||||||
note: Note | Packed<"Note">,
|
note: Note | Packed<"Note">,
|
||||||
noteUser: { id: User["id"]; username: string; host: string | null },
|
noteUser: { id: User["id"]; username: string; host: string | null },
|
||||||
antennaUserFollowing: User["id"][],
|
|
||||||
): Promise<boolean> {
|
): Promise<boolean> {
|
||||||
if (note.visibility === "specified") return false;
|
if (note.visibility === "specified") return false;
|
||||||
if (antenna.withFile) {
|
if (antenna.withFile) {
|
||||||
|
@ -23,11 +23,6 @@ export async function checkHitAntenna(
|
||||||
}
|
}
|
||||||
if (!antenna.withReplies && note.replyId != null) return false;
|
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") {
|
if (antenna.src === "users") {
|
||||||
const accts = antenna.users.map((x) => {
|
const accts = antenna.users.map((x) => {
|
||||||
const { username, host } = Acct.parse(x);
|
const { username, host } = Acct.parse(x);
|
||||||
|
@ -99,6 +94,16 @@ export async function checkHitAntenna(
|
||||||
);
|
);
|
||||||
if (blockings.includes(antenna.userId)) return false;
|
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, () =>
|
const mutedWords = await mutedWordsCache.fetch(antenna.userId, () =>
|
||||||
UserProfiles.findOneBy({ userId: antenna.userId }).then(
|
UserProfiles.findOneBy({ userId: antenna.userId }).then(
|
||||||
(profile) => profile?.mutedWords,
|
(profile) => profile?.mutedWords,
|
||||||
|
|
|
@ -386,17 +386,7 @@ export default async (
|
||||||
|
|
||||||
// Antenna
|
// Antenna
|
||||||
for (const antenna of await getAntennas()) {
|
for (const antenna of await getAntennas()) {
|
||||||
checkHitAntenna(
|
checkHitAntenna(antenna, note, user).then((hit) => {
|
||||||
antenna,
|
|
||||||
note,
|
|
||||||
user,
|
|
||||||
(
|
|
||||||
await Followings.find({
|
|
||||||
where: { followerId: user.id },
|
|
||||||
select: ["followeeId"],
|
|
||||||
})
|
|
||||||
).map((x) => x.followeeId),
|
|
||||||
).then((hit) => {
|
|
||||||
if (hit) {
|
if (hit) {
|
||||||
addNoteToAntenna(antenna, note, user);
|
addNoteToAntenna(antenna, note, user);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue