fix: visibility

This commit is contained in:
Namekuji 2023-09-19 16:24:38 -04:00
parent 8fd4773260
commit f6980ca040
No known key found for this signature in database
GPG key ID: 1D62332C07FBA532
2 changed files with 51 additions and 31 deletions

View file

@ -163,8 +163,8 @@ export default define(meta, paramDef, async (ps, user) => {
user.id, user.id,
30, 30,
)) as ScyllaNotification[] )) as ScyllaNotification[]
).slice(0, ps.limit); );
return await Notifications.packMany(foundNotifications, user.id); return (await Notifications.packMany(foundNotifications, user.id)).slice(0, ps.limit);
} }
const followingQuery = Followings.createQueryBuilder("following") const followingQuery = Followings.createQueryBuilder("following")

View file

@ -17,8 +17,10 @@ import {
scyllaClient, scyllaClient,
} from "@/db/scylla.js"; } from "@/db/scylla.js";
import { import {
ChannelFollowingsCache,
InstanceMutingsCache, InstanceMutingsCache,
LocalFollowingsCache, LocalFollowingsCache,
RenoteMutingsCache,
UserBlockedCache, UserBlockedCache,
UserBlockingCache, UserBlockingCache,
UserMutingsCache, UserMutingsCache,
@ -84,28 +86,44 @@ export default define(meta, paramDef, async (ps, me) => {
}); });
if (scyllaClient) { if (scyllaClient) {
const [ let [
followingChannelIds,
followingUserIds, followingUserIds,
mutedUserIds, mutedUserIds,
mutedInstances, mutedInstances,
mutedWords,
blockerIds, blockerIds,
blockingIds, blockingIds,
] = await Promise.all([ renoteMutedIds,
LocalFollowingsCache.init(user.id).then((cache) => cache.getAll()), ]: string[][] = [];
UserMutingsCache.init(user.id).then((cache) => cache.getAll()), let mutedWords: string[][];
InstanceMutingsCache.init(user.id).then((cache) => cache.getAll()), if (me) {
userWordMuteCache [
.fetchMaybe(user.id, () => followingChannelIds,
UserProfiles.findOne({ followingUserIds,
select: ["mutedWords"], mutedUserIds,
where: { userId: user.id }, mutedInstances,
}).then((profile) => profile?.mutedWords), mutedWords,
) blockerIds,
.then((words) => words ?? []), blockingIds,
UserBlockedCache.init(user.id).then((cache) => cache.getAll()), renoteMutedIds,
UserBlockingCache.init(user.id).then((cache) => cache.getAll()), ] = await Promise.all([
]); ChannelFollowingsCache.init(me.id).then((cache) => cache.getAll()),
LocalFollowingsCache.init(me.id).then((cache) => cache.getAll()),
UserMutingsCache.init(me.id).then((cache) => cache.getAll()),
InstanceMutingsCache.init(me.id).then((cache) => cache.getAll()),
userWordMuteCache
.fetchMaybe(me.id, () =>
UserProfiles.findOne({
select: ["mutedWords"],
where: { userId: user.id },
}).then((profile) => profile?.mutedWords),
)
.then((words) => words ?? []),
UserBlockedCache.init(me.id).then((cache) => cache.getAll()),
UserBlockingCache.init(me.id).then((cache) => cache.getAll()),
RenoteMutingsCache.init(me.id).then((cache) => cache.getAll()),
]);
}
if ( if (
mutedUserIds.includes(user.id) || mutedUserIds.includes(user.id) ||
@ -117,18 +135,20 @@ export default define(meta, paramDef, async (ps, me) => {
const filter = async (notes: ScyllaNote[]) => { const filter = async (notes: ScyllaNote[]) => {
let filtered = notes.filter((n) => n.userId === ps.userId); let filtered = notes.filter((n) => n.userId === ps.userId);
filtered = await filterVisibility(filtered, user, followingUserIds); filtered = await filterVisibility(filtered, me, followingUserIds);
filtered = await filterMutedUser( if (me) {
filtered, filtered = await filterMutedUser(
user, filtered,
mutedUserIds, me,
mutedInstances, mutedUserIds,
); mutedInstances,
filtered = await filterMutedNote(filtered, user, mutedWords); );
filtered = await filterBlockUser(filtered, user, [ filtered = await filterMutedNote(filtered, me, mutedWords);
...blockerIds, filtered = await filterBlockUser(filtered, me, [
...blockingIds, ...blockerIds,
]); ...blockingIds,
]);
}
if (ps.withFiles) { if (ps.withFiles) {
filtered = filtered.filter((n) => n.files.length > 0); filtered = filtered.filter((n) => n.files.length > 0);
} }