fix: consider hard mutes in antennas
This commit is contained in:
parent
93769b79b1
commit
ae637ec85b
@ -1,11 +1,12 @@
|
|||||||
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 } from "@/models/index.js";
|
import { Blockings, 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";
|
||||||
import { Cache } from "./cache.js";
|
import { Cache } from "./cache.js";
|
||||||
|
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);
|
||||||
|
|
||||||
@ -16,6 +17,10 @@ export async function checkHitAntenna(
|
|||||||
): Promise<boolean> {
|
): Promise<boolean> {
|
||||||
if (note.visibility === "specified") return false;
|
if (note.visibility === "specified") return false;
|
||||||
if (note.visibility === "home") return false;
|
if (note.visibility === "home") return false;
|
||||||
|
if (!antenna.withReplies && note.replyId != null) return false;
|
||||||
|
if (antenna.withFile) {
|
||||||
|
if (note.fileIds && note.fileIds.length === 0) return false;
|
||||||
|
}
|
||||||
|
|
||||||
// アンテナ作成者がノート作成者にブロックされていたらスキップ
|
// アンテナ作成者がノート作成者にブロックされていたらスキップ
|
||||||
const blockings = await blockingCache.fetch(noteUser.id, () =>
|
const blockings = await blockingCache.fetch(noteUser.id, () =>
|
||||||
@ -25,8 +30,6 @@ export async function checkHitAntenna(
|
|||||||
);
|
);
|
||||||
if (blockings.some((blocking) => blocking === antenna.userId)) return false;
|
if (blockings.some((blocking) => blocking === antenna.userId)) return false;
|
||||||
|
|
||||||
if (!antenna.withReplies && note.replyId != null) 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);
|
||||||
@ -85,9 +88,16 @@ export async function checkHitAntenna(
|
|||||||
if (matched) return false;
|
if (matched) return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (antenna.withFile) {
|
if (
|
||||||
if (note.fileIds && note.fileIds.length === 0) return false;
|
await getWordHardMute(
|
||||||
}
|
note,
|
||||||
|
antenna.userId,
|
||||||
|
(
|
||||||
|
await UserProfiles.findOneBy({ userId: antenna.userId })
|
||||||
|
)?.mutedWords,
|
||||||
|
)
|
||||||
|
)
|
||||||
|
return false;
|
||||||
|
|
||||||
// TODO: eval expression
|
// TODO: eval expression
|
||||||
|
|
||||||
|
@ -57,9 +57,9 @@ function checkWordMute(
|
|||||||
export async function getWordHardMute(
|
export async function getWordHardMute(
|
||||||
note: NoteLike,
|
note: NoteLike,
|
||||||
meId: string | null | undefined,
|
meId: string | null | undefined,
|
||||||
mutedWords: Array<string | string[]>,
|
mutedWords?: Array<string | string[]>,
|
||||||
): Promise<boolean> {
|
): Promise<boolean> {
|
||||||
if (note.userId === meId) return false;
|
if (note.userId === meId || mutedWords == null) return false;
|
||||||
|
|
||||||
if (mutedWords.length > 0) {
|
if (mutedWords.length > 0) {
|
||||||
return (
|
return (
|
||||||
|
Loading…
Reference in New Issue
Block a user