use targetNotes to reduce duplicate code

This commit is contained in:
Hazelnoot 2025-05-08 11:29:42 -04:00
parent 5e2cc8eb85
commit 58d2c4af6b

View file

@ -531,13 +531,6 @@ export class NoteEntityService implements OnModuleInit {
) {
if (notes.length === 0) return [];
const bufferedReactions = this.meta.enableReactionsBuffering ? await this.reactionsBufferingService.getMany([...getAppearNoteIds(notes)]) : null;
const meId = me ? me.id : null;
const myReactionsMap = new Map<MiNote['id'], string | null>();
if (meId) {
const idsNeedFetchMyReaction = new Set<MiNote['id']>();
const targetNotes: MiNote[] = [];
for (const note of notes) {
if (isPureRenote(note)) {
@ -557,6 +550,13 @@ export class NoteEntityService implements OnModuleInit {
}
}
const bufferedReactions = this.meta.enableReactionsBuffering ? await this.reactionsBufferingService.getMany([...getAppearNoteIds(notes)]) : null;
const meId = me ? me.id : null;
const myReactionsMap = new Map<MiNote['id'], string | null>();
if (meId) {
const idsNeedFetchMyReaction = new Set<MiNote['id']>();
for (const note of targetNotes) {
const reactionsCount = Object.values(this.reactionsBufferingService.mergeReactions(note.reactions, bufferedReactions?.get(note.id)?.deltas ?? {})).reduce((a, b) => a + b, 0);
if (reactionsCount === 0) {
@ -597,17 +597,10 @@ export class NoteEntityService implements OnModuleInit {
.then(users => new Map(users.map(u => [u.id, u])));
// Recursively add all mentioned users from all notes + replies + renotes
const allMentionedUsers = notes.reduce((users, note) => {
function add(n: MiNote) {
for (const user of n.mentions) {
const allMentionedUsers = targetNotes.reduce((users, note) => {
for (const user of note.mentions) {
users.add(user);
}
if (n.reply) add(n.reply);
if (n.renote) add(n.renote);
}
add(note);
return users;
}, new Set<string>());
const mentionHandles = await this.getUserHandles(Array.from(allMentionedUsers));