mirror of
https://codeberg.org/yeentown/barkey.git
synced 2025-07-07 20:44:34 +00:00
use targetNotes to reduce duplicate code
This commit is contained in:
parent
5e2cc8eb85
commit
58d2c4af6b
1 changed files with 22 additions and 29 deletions
|
@ -531,6 +531,25 @@ export class NoteEntityService implements OnModuleInit {
|
||||||
) {
|
) {
|
||||||
if (notes.length === 0) return [];
|
if (notes.length === 0) return [];
|
||||||
|
|
||||||
|
const targetNotes: MiNote[] = [];
|
||||||
|
for (const note of notes) {
|
||||||
|
if (isPureRenote(note)) {
|
||||||
|
// we may need to fetch 'my reaction' for renote target.
|
||||||
|
targetNotes.push(note.renote);
|
||||||
|
if (note.renote.reply) {
|
||||||
|
// idem if the renote is also a reply.
|
||||||
|
targetNotes.push(note.renote.reply);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if (note.reply) {
|
||||||
|
// idem for OP of a regular reply.
|
||||||
|
targetNotes.push(note.reply);
|
||||||
|
}
|
||||||
|
|
||||||
|
targetNotes.push(note);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
const bufferedReactions = this.meta.enableReactionsBuffering ? await this.reactionsBufferingService.getMany([...getAppearNoteIds(notes)]) : null;
|
const bufferedReactions = this.meta.enableReactionsBuffering ? await this.reactionsBufferingService.getMany([...getAppearNoteIds(notes)]) : null;
|
||||||
|
|
||||||
const meId = me ? me.id : null;
|
const meId = me ? me.id : null;
|
||||||
|
@ -538,25 +557,6 @@ export class NoteEntityService implements OnModuleInit {
|
||||||
if (meId) {
|
if (meId) {
|
||||||
const idsNeedFetchMyReaction = new Set<MiNote['id']>();
|
const idsNeedFetchMyReaction = new Set<MiNote['id']>();
|
||||||
|
|
||||||
const targetNotes: MiNote[] = [];
|
|
||||||
for (const note of notes) {
|
|
||||||
if (isPureRenote(note)) {
|
|
||||||
// we may need to fetch 'my reaction' for renote target.
|
|
||||||
targetNotes.push(note.renote);
|
|
||||||
if (note.renote.reply) {
|
|
||||||
// idem if the renote is also a reply.
|
|
||||||
targetNotes.push(note.renote.reply);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
if (note.reply) {
|
|
||||||
// idem for OP of a regular reply.
|
|
||||||
targetNotes.push(note.reply);
|
|
||||||
}
|
|
||||||
|
|
||||||
targetNotes.push(note);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
for (const note of targetNotes) {
|
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);
|
const reactionsCount = Object.values(this.reactionsBufferingService.mergeReactions(note.reactions, bufferedReactions?.get(note.id)?.deltas ?? {})).reduce((a, b) => a + b, 0);
|
||||||
if (reactionsCount === 0) {
|
if (reactionsCount === 0) {
|
||||||
|
@ -597,17 +597,10 @@ export class NoteEntityService implements OnModuleInit {
|
||||||
.then(users => new Map(users.map(u => [u.id, u])));
|
.then(users => new Map(users.map(u => [u.id, u])));
|
||||||
|
|
||||||
// Recursively add all mentioned users from all notes + replies + renotes
|
// Recursively add all mentioned users from all notes + replies + renotes
|
||||||
const allMentionedUsers = notes.reduce((users, note) => {
|
const allMentionedUsers = targetNotes.reduce((users, note) => {
|
||||||
function add(n: MiNote) {
|
for (const user of note.mentions) {
|
||||||
for (const user of n.mentions) {
|
users.add(user);
|
||||||
users.add(user);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (n.reply) add(n.reply);
|
|
||||||
if (n.renote) add(n.renote);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
add(note);
|
|
||||||
return users;
|
return users;
|
||||||
}, new Set<string>());
|
}, new Set<string>());
|
||||||
const mentionHandles = await this.getUserHandles(Array.from(allMentionedUsers));
|
const mentionHandles = await this.getUserHandles(Array.from(allMentionedUsers));
|
||||||
|
|
Loading…
Add table
Reference in a new issue