add reply filter
This commit is contained in:
parent
66309cc793
commit
6a79d82568
2 changed files with 31 additions and 5 deletions
|
@ -231,3 +231,27 @@ export async function filterChannel(
|
|||
|
||||
return foundNotes;
|
||||
}
|
||||
|
||||
export async function filterReply(
|
||||
notes: ScyllaNote[],
|
||||
withReplies: boolean,
|
||||
user: { id: User["id"] } | null,
|
||||
): Promise<ScyllaNote[]> {
|
||||
let foundNotes = notes;
|
||||
|
||||
if (!user) {
|
||||
foundNotes = foundNotes.filter(
|
||||
(note) => !note.replyId || note.replyUserId === note.userId,
|
||||
);
|
||||
} else if (!withReplies) {
|
||||
foundNotes = foundNotes.filter(
|
||||
(note) =>
|
||||
!note.replyId ||
|
||||
note.replyUserId === user.id ||
|
||||
note.userId === user.id ||
|
||||
note.replyUserId === note.userId,
|
||||
);
|
||||
}
|
||||
|
||||
return foundNotes;
|
||||
}
|
||||
|
|
|
@ -17,6 +17,7 @@ import {
|
|||
prepared,
|
||||
scyllaClient,
|
||||
filterChannel,
|
||||
filterReply,
|
||||
} from "@/db/scylla.js";
|
||||
import { LocalFollowingsCache } from "@/misc/cache.js";
|
||||
|
||||
|
@ -76,7 +77,7 @@ export default define(meta, paramDef, async (ps, user) => {
|
|||
|
||||
if (scyllaClient) {
|
||||
let untilDate = new Date();
|
||||
let foundNotes: ScyllaNote[] = [];
|
||||
const foundNotes: ScyllaNote[] = [];
|
||||
const validIds = [user.id].concat(await followingsCache.getAll());
|
||||
|
||||
while (foundNotes.length < ps.limit) {
|
||||
|
@ -97,15 +98,16 @@ export default define(meta, paramDef, async (ps, user) => {
|
|||
}
|
||||
|
||||
const notes = result.rows.map(parseScyllaNote);
|
||||
const filtered = notes.filter((note) => validIds.includes(note.userId));
|
||||
let filtered = notes.filter((note) => validIds.includes(note.userId));
|
||||
|
||||
filtered = await filterChannel(filtered, user);
|
||||
filtered = await filterReply(filtered, ps.withReplies, user);
|
||||
|
||||
foundNotes.push(...filtered);
|
||||
|
||||
untilDate = notes[notes.length - 1].createdAt;
|
||||
}
|
||||
|
||||
// Filter channels
|
||||
foundNotes = await filterChannel(foundNotes, user);
|
||||
|
||||
return Notes.packMany(foundNotes, user);
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue