fix: renotes endpoint filters

This commit is contained in:
Namekuji 2023-08-09 06:30:37 -04:00
parent dfcac3750c
commit 746e2fac41
No known key found for this signature in database
GPG key ID: 1D62332C07FBA532

View file

@ -9,9 +9,17 @@ import { generateBlockedUserQuery } from "../../common/generate-block-query.js";
import {
ScyllaNote,
execTimelineQuery,
filterBlockedUser,
filterMutedUser,
filterVisibility,
scyllaClient,
} from "@/db/scylla.js";
import {
InstanceMutingsCache,
LocalFollowingsCache,
UserBlockedCache,
UserMutingsCache,
} from "@/misc/cache.js";
export const meta = {
tags: ["notes"],
@ -60,9 +68,34 @@ export default define(meta, paramDef, async (ps, user) => {
});
if (scyllaClient) {
let [
followingUserIds,
mutedUserIds,
mutedInstances,
blockerIds,
]: string[][] = [];
if (user) {
[followingUserIds, mutedUserIds, mutedInstances, blockerIds] =
await Promise.all([
LocalFollowingsCache.init(user.id).then((cache) => cache.getAll()),
UserMutingsCache.init(user.id).then((cache) => cache.getAll()),
InstanceMutingsCache.init(user.id).then((cache) => cache.getAll()),
UserBlockedCache.init(user.id).then((cache) => cache.getAll()),
]);
}
const filter = async (notes: ScyllaNote[]) => {
let filtered = notes.filter((n) => n.renoteId === note.id);
filtered = await filterVisibility(filtered, user);
if (user) {
filtered = await filterMutedUser(
filtered,
user,
mutedUserIds,
mutedInstances,
);
filtered = await filterBlockedUser(filtered, user, blockerIds);
}
return filtered;
};