fix: filter blocking ids out

This commit is contained in:
Namekuji 2023-08-17 02:23:28 -04:00
parent ef0d842298
commit ea94e5001e
No known key found for this signature in database
GPG key ID: 1D62332C07FBA532
14 changed files with 180 additions and 79 deletions

View file

@ -11,6 +11,7 @@ import {
LocalFollowingsCache, LocalFollowingsCache,
RenoteMutingsCache, RenoteMutingsCache,
UserBlockedCache, UserBlockedCache,
UserBlockingCache,
UserMutingsCache, UserMutingsCache,
userWordMuteCache, userWordMuteCache,
} from "@/misc/cache.js"; } from "@/misc/cache.js";
@ -499,17 +500,23 @@ export async function filterMutedNote(
return notes; return notes;
} }
export async function filterBlockedUser( export async function filterBlockUser(
notes: ScyllaNote[], notes: ScyllaNote[],
user: { id: User["id"] }, user: { id: User["id"] },
blockerIds?: User["id"][], blockIds?: User["id"][],
): Promise<ScyllaNote[]> { ): Promise<ScyllaNote[]> {
let ids: User["id"][]; let ids: User["id"][];
if (blockerIds) { if (blockIds) {
ids = blockerIds; ids = blockIds;
} else { } else {
ids = await UserBlockedCache.init(user.id).then((cache) => cache.getAll()); const blocked = await UserBlockedCache.init(user.id).then((cache) =>
cache.getAll(),
);
const blocking = await UserBlockingCache.init(user.id).then((cache) =>
cache.getAll(),
);
ids = [...blocked, ...blocking];
} }
return notes.filter( return notes.filter(

View file

@ -414,6 +414,25 @@ export class InstanceMutingsCache extends SetCache {
} }
} }
export class UserBlockingCache extends SetCache {
private constructor(userId: string) {
const fetcher = () =>
Blockings.find({
select: ["blockeeId"],
where: { blockerId: userId },
}).then((blocks) => blocks.map(({ blockeeId }) => blockeeId));
super("blocking", userId, fetcher);
}
public static async init(userId: string): Promise<UserBlockingCache> {
const cache = new UserBlockingCache(userId);
await cache.fetch();
return cache;
}
}
export class UserBlockedCache extends SetCache { export class UserBlockedCache extends SetCache {
private constructor(userId: string) { private constructor(userId: string) {
const fetcher = () => const fetcher = () =>

View file

@ -4,7 +4,7 @@ import { ApiError } from "../../error.js";
import { getUser } from "../../common/getters.js"; import { getUser } from "../../common/getters.js";
import { NoteWatchings, Users } from "@/models/index.js"; import { NoteWatchings, Users } from "@/models/index.js";
import { HOUR } from "@/const.js"; import { HOUR } from "@/const.js";
import { UserBlockedCache } from "@/misc/cache.js"; import { UserBlockingCache } from "@/misc/cache.js";
export const meta = { export const meta = {
tags: ["account"], tags: ["account"],
@ -70,8 +70,9 @@ export default define(meta, paramDef, async (ps, user) => {
}); });
// Check if already blocking // Check if already blocking
const cache = await UserBlockedCache.init(blockee.id); const exist = await UserBlockingCache.init(blocker.id).then((cache) =>
const exist = await cache.has(blocker.id); cache.has(blockee.id),
);
if (exist) { if (exist) {
throw new ApiError(meta.errors.alreadyBlocking); throw new ApiError(meta.errors.alreadyBlocking);

View file

@ -4,7 +4,7 @@ import { ApiError } from "../../error.js";
import { getUser } from "../../common/getters.js"; import { getUser } from "../../common/getters.js";
import { Blockings, Users } from "@/models/index.js"; import { Blockings, Users } from "@/models/index.js";
import { HOUR } from "@/const.js"; import { HOUR } from "@/const.js";
import { UserBlockedCache } from "@/misc/cache.js"; import { UserBlockedCache, UserBlockingCache } from "@/misc/cache.js";
export const meta = { export const meta = {
tags: ["account"], tags: ["account"],
@ -70,8 +70,9 @@ export default define(meta, paramDef, async (ps, user) => {
}); });
// Check not blocking // Check not blocking
const cache = await UserBlockedCache.init(blockee.id); const exist = await UserBlockingCache.init(blocker.id).then((cache) =>
const exist = await cache.has(blocker.id); cache.has(blockee.id),
);
if (!exist) { if (!exist) {
throw new ApiError(meta.errors.notBlocking); throw new ApiError(meta.errors.notBlocking);

View file

@ -6,7 +6,7 @@ import { generateMutedUserQuery } from "../../common/generate-muted-user-query.j
import { generateBlockedUserQuery } from "../../common/generate-block-query.js"; import { generateBlockedUserQuery } from "../../common/generate-block-query.js";
import { import {
ScyllaNote, ScyllaNote,
filterBlockedUser, filterBlockUser,
filterMutedNote, filterMutedNote,
filterMutedUser, filterMutedUser,
filterVisibility, filterVisibility,
@ -20,6 +20,7 @@ import {
InstanceMutingsCache, InstanceMutingsCache,
LocalFollowingsCache, LocalFollowingsCache,
UserBlockedCache, UserBlockedCache,
UserBlockingCache,
UserMutingsCache, UserMutingsCache,
userWordMuteCache, userWordMuteCache,
} from "@/misc/cache.js"; } from "@/misc/cache.js";
@ -63,11 +64,18 @@ export default define(meta, paramDef, async (ps, user) => {
mutedUserIds, mutedUserIds,
mutedInstances, mutedInstances,
blockerIds, blockerIds,
blockingIds,
]: string[][] = []; ]: string[][] = [];
let mutedWords: string[][] = []; let mutedWords: string[][] = [];
if (user) { if (user) {
[followingUserIds, mutedUserIds, mutedInstances, mutedWords, blockerIds] = [
await Promise.all([ followingUserIds,
mutedUserIds,
mutedInstances,
mutedWords,
blockerIds,
blockingIds,
] = await Promise.all([
LocalFollowingsCache.init(user.id).then((cache) => cache.getAll()), LocalFollowingsCache.init(user.id).then((cache) => cache.getAll()),
UserMutingsCache.init(user.id).then((cache) => cache.getAll()), UserMutingsCache.init(user.id).then((cache) => cache.getAll()),
InstanceMutingsCache.init(user.id).then((cache) => cache.getAll()), InstanceMutingsCache.init(user.id).then((cache) => cache.getAll()),
@ -80,6 +88,7 @@ export default define(meta, paramDef, async (ps, user) => {
) )
.then((words) => words ?? []), .then((words) => words ?? []),
UserBlockedCache.init(user.id).then((cache) => cache.getAll()), UserBlockedCache.init(user.id).then((cache) => cache.getAll()),
UserBlockingCache.init(user.id).then((cache) => cache.getAll()),
]); ]);
} }
@ -100,7 +109,10 @@ export default define(meta, paramDef, async (ps, user) => {
mutedInstances, mutedInstances,
); );
filtered = await filterMutedNote(filtered, user, mutedWords); filtered = await filterMutedNote(filtered, user, mutedWords);
filtered = await filterBlockedUser(filtered, user, blockerIds); filtered = await filterBlockUser(filtered, user, [
...blockerIds,
...blockingIds,
]);
} }
return filtered; return filtered;
}; };

View file

@ -12,7 +12,7 @@ import { generateMutedUserRenotesQueryForNotes } from "../../common/generated-mu
import { import {
ScyllaNote, ScyllaNote,
execNotePaginationQuery, execNotePaginationQuery,
filterBlockedUser, filterBlockUser,
filterMutedNote, filterMutedNote,
filterMutedRenotes, filterMutedRenotes,
filterMutedUser, filterMutedUser,
@ -23,6 +23,7 @@ import {
InstanceMutingsCache, InstanceMutingsCache,
RenoteMutingsCache, RenoteMutingsCache,
UserBlockedCache, UserBlockedCache,
UserBlockingCache,
UserMutingsCache, UserMutingsCache,
userWordMuteCache, userWordMuteCache,
} from "@/misc/cache.js"; } from "@/misc/cache.js";
@ -94,12 +95,23 @@ export default define(meta, paramDef, async (ps, user) => {
}); });
if (scyllaClient) { if (scyllaClient) {
let [mutedUserIds, mutedInstances, blockerIds, renoteMutedIds]: string[][] = let [
[]; mutedUserIds,
mutedInstances,
blockerIds,
blockingIds,
renoteMutedIds,
]: string[][] = [];
let mutedWords: string[][]; let mutedWords: string[][];
if (user) { if (user) {
[mutedUserIds, mutedInstances, mutedWords, blockerIds, renoteMutedIds] = [
await Promise.all([ mutedUserIds,
mutedInstances,
mutedWords,
blockerIds,
blockingIds,
renoteMutedIds,
] = await Promise.all([
UserMutingsCache.init(user.id).then((cache) => cache.getAll()), UserMutingsCache.init(user.id).then((cache) => cache.getAll()),
InstanceMutingsCache.init(user.id).then((cache) => cache.getAll()), InstanceMutingsCache.init(user.id).then((cache) => cache.getAll()),
userWordMuteCache userWordMuteCache
@ -111,6 +123,7 @@ export default define(meta, paramDef, async (ps, user) => {
) )
.then((words) => words ?? []), .then((words) => words ?? []),
UserBlockedCache.init(user.id).then((cache) => cache.getAll()), UserBlockedCache.init(user.id).then((cache) => cache.getAll()),
UserBlockingCache.init(user.id).then((cache) => cache.getAll()),
RenoteMutingsCache.init(user.id).then((cache) => cache.getAll()), RenoteMutingsCache.init(user.id).then((cache) => cache.getAll()),
]); ]);
} }
@ -128,7 +141,10 @@ export default define(meta, paramDef, async (ps, user) => {
mutedInstances, mutedInstances,
); );
filtered = await filterMutedNote(filtered, user, mutedWords); filtered = await filterMutedNote(filtered, user, mutedWords);
filtered = await filterBlockedUser(filtered, user, blockerIds); filtered = await filterBlockUser(filtered, user, [
...blockerIds,
...blockingIds,
]);
filtered = await filterMutedRenotes(filtered, user, renoteMutedIds); filtered = await filterMutedRenotes(filtered, user, renoteMutedIds);
} }
if (ps.withFiles) { if (ps.withFiles) {
@ -140,10 +156,9 @@ export default define(meta, paramDef, async (ps, user) => {
const foundPacked = []; const foundPacked = [];
while (foundPacked.length < ps.limit) { while (foundPacked.length < ps.limit) {
const foundNotes = (await execNotePaginationQuery("global", ps, filter)).slice( const foundNotes = (
0, await execNotePaginationQuery("global", ps, filter)
ps.limit * 1.5, ).slice(0, ps.limit * 1.5); // Some may filtered out by Notes.packMany, thus we take more than ps.limit.
); // Some may filtered out by Notes.packMany, thus we take more than ps.limit.
foundPacked.push( foundPacked.push(
...(await Notes.packMany(foundNotes, user, { scyllaNote: true })), ...(await Notes.packMany(foundNotes, user, { scyllaNote: true })),
); );

View file

@ -15,7 +15,7 @@ import { generateMutedUserRenotesQueryForNotes } from "../../common/generated-mu
import { import {
ScyllaNote, ScyllaNote,
execNotePaginationQuery, execNotePaginationQuery,
filterBlockedUser, filterBlockUser,
filterChannel, filterChannel,
filterMutedNote, filterMutedNote,
filterMutedRenotes, filterMutedRenotes,
@ -30,6 +30,7 @@ import {
LocalFollowingsCache, LocalFollowingsCache,
RenoteMutingsCache, RenoteMutingsCache,
UserBlockedCache, UserBlockedCache,
UserBlockingCache,
UserMutingsCache, UserMutingsCache,
userWordMuteCache, userWordMuteCache,
} from "@/misc/cache.js"; } from "@/misc/cache.js";
@ -108,6 +109,7 @@ export default define(meta, paramDef, async (ps, user) => {
mutedInstances, mutedInstances,
mutedWords, mutedWords,
blockerIds, blockerIds,
blockingIds,
renoteMutedIds, renoteMutedIds,
] = await Promise.all([ ] = await Promise.all([
ChannelFollowingsCache.init(user.id).then((cache) => cache.getAll()), ChannelFollowingsCache.init(user.id).then((cache) => cache.getAll()),
@ -123,6 +125,7 @@ export default define(meta, paramDef, async (ps, user) => {
) )
.then((words) => words ?? []), .then((words) => words ?? []),
UserBlockedCache.init(user.id).then((cache) => cache.getAll()), UserBlockedCache.init(user.id).then((cache) => cache.getAll()),
UserBlockingCache.init(user.id).then((cache) => cache.getAll()),
RenoteMutingsCache.init(user.id).then((cache) => cache.getAll()), RenoteMutingsCache.init(user.id).then((cache) => cache.getAll()),
]); ]);
const homeUserIds = [user.id, ...followingUserIds]; const homeUserIds = [user.id, ...followingUserIds];
@ -145,7 +148,10 @@ export default define(meta, paramDef, async (ps, user) => {
mutedInstances, mutedInstances,
); );
filtered = await filterMutedNote(filtered, user, mutedWords); filtered = await filterMutedNote(filtered, user, mutedWords);
filtered = await filterBlockedUser(filtered, user, blockerIds); filtered = await filterBlockUser(filtered, user, [
...blockerIds,
...blockingIds,
]);
filtered = await filterMutedRenotes(filtered, user, renoteMutedIds); filtered = await filterMutedRenotes(filtered, user, renoteMutedIds);
if (!ps.includeMyRenotes) { if (!ps.includeMyRenotes) {
filtered = filtered.filter((n) => n.userId !== user.id || optFilter(n)); filtered = filtered.filter((n) => n.userId !== user.id || optFilter(n));

View file

@ -15,7 +15,7 @@ import { generateMutedUserRenotesQueryForNotes } from "../../common/generated-mu
import { import {
ScyllaNote, ScyllaNote,
execNotePaginationQuery, execNotePaginationQuery,
filterBlockedUser, filterBlockUser,
filterChannel, filterChannel,
filterMutedNote, filterMutedNote,
filterMutedRenotes, filterMutedRenotes,
@ -30,6 +30,7 @@ import {
LocalFollowingsCache, LocalFollowingsCache,
RenoteMutingsCache, RenoteMutingsCache,
UserBlockedCache, UserBlockedCache,
UserBlockingCache,
UserMutingsCache, UserMutingsCache,
userWordMuteCache, userWordMuteCache,
} from "@/misc/cache.js"; } from "@/misc/cache.js";
@ -115,6 +116,7 @@ export default define(meta, paramDef, async (ps, user) => {
mutedUserIds, mutedUserIds,
mutedInstances, mutedInstances,
blockerIds, blockerIds,
blockingIds,
renoteMutedIds, renoteMutedIds,
]: string[][] = []; ]: string[][] = [];
let mutedWords: string[][]; let mutedWords: string[][];
@ -126,6 +128,7 @@ export default define(meta, paramDef, async (ps, user) => {
mutedInstances, mutedInstances,
mutedWords, mutedWords,
blockerIds, blockerIds,
blockingIds,
renoteMutedIds, renoteMutedIds,
] = await Promise.all([ ] = await Promise.all([
ChannelFollowingsCache.init(user.id).then((cache) => cache.getAll()), ChannelFollowingsCache.init(user.id).then((cache) => cache.getAll()),
@ -141,6 +144,7 @@ export default define(meta, paramDef, async (ps, user) => {
) )
.then((words) => words ?? []), .then((words) => words ?? []),
UserBlockedCache.init(user.id).then((cache) => cache.getAll()), UserBlockedCache.init(user.id).then((cache) => cache.getAll()),
UserBlockingCache.init(user.id).then((cache) => cache.getAll()),
RenoteMutingsCache.init(user.id).then((cache) => cache.getAll()), RenoteMutingsCache.init(user.id).then((cache) => cache.getAll()),
]); ]);
} }
@ -157,7 +161,10 @@ export default define(meta, paramDef, async (ps, user) => {
mutedInstances, mutedInstances,
); );
filtered = await filterMutedNote(filtered, user, mutedWords); filtered = await filterMutedNote(filtered, user, mutedWords);
filtered = await filterBlockedUser(filtered, user, blockerIds); filtered = await filterBlockUser(filtered, user, [
...blockerIds,
...blockingIds,
]);
filtered = await filterMutedRenotes(filtered, user, renoteMutedIds); filtered = await filterMutedRenotes(filtered, user, renoteMutedIds);
} }
if (ps.withFiles) { if (ps.withFiles) {
@ -179,10 +186,9 @@ export default define(meta, paramDef, async (ps, user) => {
const foundPacked = []; const foundPacked = [];
while (foundPacked.length < ps.limit) { while (foundPacked.length < ps.limit) {
const foundNotes = (await execNotePaginationQuery("local", ps, filter)).slice( const foundNotes = (
0, await execNotePaginationQuery("local", ps, filter)
ps.limit * 1.5, ).slice(0, ps.limit * 1.5); // Some may filtered out by Notes.packMany, thus we take more than ps.limit.
); // Some may filtered out by Notes.packMany, thus we take more than ps.limit.
foundPacked.push( foundPacked.push(
...(await Notes.packMany(foundNotes, user, { scyllaNote: true })), ...(await Notes.packMany(foundNotes, user, { scyllaNote: true })),
); );

View file

@ -15,7 +15,7 @@ import { generateMutedUserRenotesQueryForNotes } from "../../common/generated-mu
import { import {
ScyllaNote, ScyllaNote,
execNotePaginationQuery, execNotePaginationQuery,
filterBlockedUser, filterBlockUser,
filterMutedNote, filterMutedNote,
filterMutedRenotes, filterMutedRenotes,
filterMutedUser, filterMutedUser,
@ -28,6 +28,7 @@ import {
LocalFollowingsCache, LocalFollowingsCache,
RenoteMutingsCache, RenoteMutingsCache,
UserBlockedCache, UserBlockedCache,
UserBlockingCache,
UserMutingsCache, UserMutingsCache,
userWordMuteCache, userWordMuteCache,
} from "@/misc/cache.js"; } from "@/misc/cache.js";
@ -111,6 +112,7 @@ export default define(meta, paramDef, async (ps, user) => {
mutedUserIds, mutedUserIds,
mutedInstances, mutedInstances,
blockerIds, blockerIds,
blockingIds,
renoteMutedIds, renoteMutedIds,
]: string[][] = []; ]: string[][] = [];
let mutedWords: string[][]; let mutedWords: string[][];
@ -121,6 +123,7 @@ export default define(meta, paramDef, async (ps, user) => {
mutedInstances, mutedInstances,
mutedWords, mutedWords,
blockerIds, blockerIds,
blockingIds,
renoteMutedIds, renoteMutedIds,
] = await Promise.all([ ] = await Promise.all([
LocalFollowingsCache.init(user.id).then((cache) => cache.getAll()), LocalFollowingsCache.init(user.id).then((cache) => cache.getAll()),
@ -135,6 +138,7 @@ export default define(meta, paramDef, async (ps, user) => {
) )
.then((words) => words ?? []), .then((words) => words ?? []),
UserBlockedCache.init(user.id).then((cache) => cache.getAll()), UserBlockedCache.init(user.id).then((cache) => cache.getAll()),
UserBlockingCache.init(user.id).then((cache) => cache.getAll()),
RenoteMutingsCache.init(user.id).then((cache) => cache.getAll()), RenoteMutingsCache.init(user.id).then((cache) => cache.getAll()),
]); ]);
} }
@ -157,7 +161,10 @@ export default define(meta, paramDef, async (ps, user) => {
mutedInstances, mutedInstances,
); );
filtered = await filterMutedNote(filtered, user, mutedWords); filtered = await filterMutedNote(filtered, user, mutedWords);
filtered = await filterBlockedUser(filtered, user, blockerIds); filtered = await filterBlockUser(filtered, user, [
...blockerIds,
...blockingIds,
]);
filtered = await filterMutedRenotes(filtered, user, renoteMutedIds); filtered = await filterMutedRenotes(filtered, user, renoteMutedIds);
} }
if (ps.withFiles) { if (ps.withFiles) {

View file

@ -9,7 +9,7 @@ import { generateBlockedUserQuery } from "../../common/generate-block-query.js";
import { import {
ScyllaNote, ScyllaNote,
execNotePaginationQuery, execNotePaginationQuery,
filterBlockedUser, filterBlockUser,
filterMutedUser, filterMutedUser,
filterVisibility, filterVisibility,
scyllaClient, scyllaClient,
@ -18,6 +18,7 @@ import {
InstanceMutingsCache, InstanceMutingsCache,
LocalFollowingsCache, LocalFollowingsCache,
UserBlockedCache, UserBlockedCache,
UserBlockingCache,
UserMutingsCache, UserMutingsCache,
} from "@/misc/cache.js"; } from "@/misc/cache.js";
@ -75,12 +76,15 @@ export default define(meta, paramDef, async (ps, user) => {
}); });
if (scyllaClient) { if (scyllaClient) {
let [mutedUserIds, mutedInstances, blockerIds]: string[][] = []; let [mutedUserIds, mutedInstances, blockerIds, blockingIds]: string[][] =
[];
if (user) { if (user) {
[mutedUserIds, mutedInstances, blockerIds] = await Promise.all([ [mutedUserIds, mutedInstances, blockerIds, blockingIds] =
await Promise.all([
UserMutingsCache.init(user.id).then((cache) => cache.getAll()), UserMutingsCache.init(user.id).then((cache) => cache.getAll()),
InstanceMutingsCache.init(user.id).then((cache) => cache.getAll()), InstanceMutingsCache.init(user.id).then((cache) => cache.getAll()),
UserBlockedCache.init(user.id).then((cache) => cache.getAll()), UserBlockedCache.init(user.id).then((cache) => cache.getAll()),
UserBlockingCache.init(user.id).then((cache) => cache.getAll()),
]); ]);
} }
@ -97,7 +101,10 @@ export default define(meta, paramDef, async (ps, user) => {
mutedUserIds, mutedUserIds,
mutedInstances, mutedInstances,
); );
filtered = await filterBlockedUser(filtered, user, blockerIds); filtered = await filterBlockUser(filtered, user, [
...blockerIds,
...blockingIds,
]);
} }
return filtered; return filtered;
}; };

View file

@ -20,7 +20,7 @@ import {
execNotePaginationQuery, execNotePaginationQuery,
filterMutedUser, filterMutedUser,
filterMutedNote, filterMutedNote,
filterBlockedUser, filterBlockUser,
filterMutedRenotes, filterMutedRenotes,
} from "@/db/scylla.js"; } from "@/db/scylla.js";
import { import {
@ -29,6 +29,7 @@ import {
LocalFollowingsCache, LocalFollowingsCache,
RenoteMutingsCache, RenoteMutingsCache,
UserBlockedCache, UserBlockedCache,
UserBlockingCache,
UserMutingsCache, UserMutingsCache,
userWordMuteCache, userWordMuteCache,
} from "@/misc/cache.js"; } from "@/misc/cache.js";
@ -99,6 +100,7 @@ export default define(meta, paramDef, async (ps, user) => {
mutedInstances, mutedInstances,
mutedWords, mutedWords,
blockerIds, blockerIds,
blockingIds,
renoteMutedIds, renoteMutedIds,
] = await Promise.all([ ] = await Promise.all([
ChannelFollowingsCache.init(user.id).then((cache) => cache.getAll()), ChannelFollowingsCache.init(user.id).then((cache) => cache.getAll()),
@ -114,6 +116,7 @@ export default define(meta, paramDef, async (ps, user) => {
) )
.then((words) => words ?? []), .then((words) => words ?? []),
UserBlockedCache.init(user.id).then((cache) => cache.getAll()), UserBlockedCache.init(user.id).then((cache) => cache.getAll()),
UserBlockingCache.init(user.id).then((cache) => cache.getAll()),
RenoteMutingsCache.init(user.id).then((cache) => cache.getAll()), RenoteMutingsCache.init(user.id).then((cache) => cache.getAll()),
]); ]);
const validUserIds = [user.id, ...followingUserIds]; const validUserIds = [user.id, ...followingUserIds];
@ -132,7 +135,10 @@ export default define(meta, paramDef, async (ps, user) => {
mutedInstances, mutedInstances,
); );
filtered = await filterMutedNote(filtered, user, mutedWords); filtered = await filterMutedNote(filtered, user, mutedWords);
filtered = await filterBlockedUser(filtered, user, blockerIds); filtered = await filterBlockUser(filtered, user, [
...blockerIds,
...blockingIds,
]);
filtered = await filterMutedRenotes(filtered, user, renoteMutedIds); filtered = await filterMutedRenotes(filtered, user, renoteMutedIds);
if (!ps.includeMyRenotes) { if (!ps.includeMyRenotes) {
filtered = filtered.filter((n) => n.userId !== user.id || optFilter(n)); filtered = filtered.filter((n) => n.userId !== user.id || optFilter(n));

View file

@ -10,7 +10,7 @@ import { generateBlockedUserQuery } from "../../common/generate-block-query.js";
import { import {
ScyllaNote, ScyllaNote,
execNotePaginationQuery, execNotePaginationQuery,
filterBlockedUser, filterBlockUser,
filterMutedNote, filterMutedNote,
filterMutedUser, filterMutedUser,
filterVisibility, filterVisibility,
@ -20,6 +20,7 @@ import {
InstanceMutingsCache, InstanceMutingsCache,
LocalFollowingsCache, LocalFollowingsCache,
UserBlockedCache, UserBlockedCache,
UserBlockingCache,
UserMutingsCache, UserMutingsCache,
userWordMuteCache, userWordMuteCache,
} from "@/misc/cache.js"; } from "@/misc/cache.js";
@ -89,6 +90,7 @@ export default define(meta, paramDef, async (ps, me) => {
mutedInstances, mutedInstances,
mutedWords, mutedWords,
blockerIds, blockerIds,
blockingIds,
] = await Promise.all([ ] = await Promise.all([
LocalFollowingsCache.init(user.id).then((cache) => cache.getAll()), LocalFollowingsCache.init(user.id).then((cache) => cache.getAll()),
UserMutingsCache.init(user.id).then((cache) => cache.getAll()), UserMutingsCache.init(user.id).then((cache) => cache.getAll()),
@ -102,6 +104,7 @@ export default define(meta, paramDef, async (ps, me) => {
) )
.then((words) => words ?? []), .then((words) => words ?? []),
UserBlockedCache.init(user.id).then((cache) => cache.getAll()), UserBlockedCache.init(user.id).then((cache) => cache.getAll()),
UserBlockingCache.init(user.id).then((cache) => cache.getAll()),
]); ]);
if ( if (
@ -122,7 +125,10 @@ export default define(meta, paramDef, async (ps, me) => {
mutedInstances, mutedInstances,
); );
filtered = await filterMutedNote(filtered, user, mutedWords); filtered = await filterMutedNote(filtered, user, mutedWords);
filtered = await filterBlockedUser(filtered, user, blockerIds); filtered = await filterBlockUser(filtered, user, [
...blockerIds,
...blockingIds,
]);
if (ps.withFiles) { if (ps.withFiles) {
filtered = filtered.filter((n) => n.files.length > 0); filtered = filtered.filter((n) => n.files.length > 0);
} }

View file

@ -19,7 +19,7 @@ import { perUserFollowingChart } from "@/services/chart/index.js";
import { genId } from "@/misc/gen-id.js"; import { genId } from "@/misc/gen-id.js";
import { getActiveWebhooks } from "@/misc/webhook-cache.js"; import { getActiveWebhooks } from "@/misc/webhook-cache.js";
import { webhookDeliver } from "@/queue/index.js"; import { webhookDeliver } from "@/queue/index.js";
import { UserBlockedCache } from "@/misc/cache.js"; import { UserBlockedCache, UserBlockingCache } from "@/misc/cache.js";
export default async function (blocker: User, blockee: User) { export default async function (blocker: User, blockee: User) {
await Promise.all([ await Promise.all([
@ -41,8 +41,12 @@ export default async function (blocker: User, blockee: User) {
await Blockings.insert(blocking); await Blockings.insert(blocking);
const cache = await UserBlockedCache.init(blockee.id); await UserBlockedCache.init(blockee.id).then((cache) =>
await cache.add(blocker.id); cache.add(blocker.id),
);
await UserBlockingCache.init(blocker.id).then((cache) =>
cache.add(blockee.id),
);
if (Users.isLocalUser(blocker) && Users.isRemoteUser(blockee)) { if (Users.isLocalUser(blocker) && Users.isRemoteUser(blockee)) {
const content = renderActivity(renderBlock(blocking)); const content = renderActivity(renderBlock(blocking));

View file

@ -5,7 +5,7 @@ import { deliver } from "@/queue/index.js";
import Logger from "../logger.js"; import Logger from "../logger.js";
import type { CacheableUser } from "@/models/entities/user.js"; import type { CacheableUser } from "@/models/entities/user.js";
import { Blockings, Users } from "@/models/index.js"; import { Blockings, Users } from "@/models/index.js";
import { UserBlockedCache } from "@/misc/cache.js"; import { UserBlockedCache, UserBlockingCache } from "@/misc/cache.js";
const logger = new Logger("blocking/delete"); const logger = new Logger("blocking/delete");
@ -15,8 +15,12 @@ export default async function (blocker: CacheableUser, blockee: CacheableUser) {
blockeeId: blockee.id, blockeeId: blockee.id,
}); });
const cache = await UserBlockedCache.init(blockee.id); await UserBlockedCache.init(blockee.id).then((cache) =>
await cache.delete(blocker.id); cache.delete(blocker.id),
);
await UserBlockingCache.init(blocker.id).then((cache) =>
cache.delete(blockee.id),
);
if (blocking == null) { if (blocking == null) {
logger.warn( logger.warn(