summaryrefslogtreecommitdiff
path: root/packages/backend/src/core/entities
diff options
context:
space:
mode:
authorHazelnoot <acomputerdog@gmail.com>2025-05-08 11:29:42 -0400
committerHazelnoot <acomputerdog@gmail.com>2025-05-08 16:20:29 -0400
commit58d2c4af6b110458c6912b2ca07d4c2e31f41c64 (patch)
tree55dd12901028491cf775ee7d2a3acf369559f90a /packages/backend/src/core/entities
parentavoid error when editing notes without any mentions (diff)
downloadsharkey-58d2c4af6b110458c6912b2ca07d4c2e31f41c64.tar.gz
sharkey-58d2c4af6b110458c6912b2ca07d4c2e31f41c64.tar.bz2
sharkey-58d2c4af6b110458c6912b2ca07d4c2e31f41c64.zip
use targetNotes to reduce duplicate code
Diffstat (limited to 'packages/backend/src/core/entities')
-rw-r--r--packages/backend/src/core/entities/NoteEntityService.ts51
1 files changed, 22 insertions, 29 deletions
diff --git a/packages/backend/src/core/entities/NoteEntityService.ts b/packages/backend/src/core/entities/NoteEntityService.ts
index 45d9491e36..6ada5463a3 100644
--- a/packages/backend/src/core/entities/NoteEntityService.ts
+++ b/packages/backend/src/core/entities/NoteEntityService.ts
@@ -531,6 +531,25 @@ export class NoteEntityService implements OnModuleInit {
) {
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 meId = me ? me.id : null;
@@ -538,25 +557,6 @@ export class NoteEntityService implements OnModuleInit {
if (meId) {
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) {
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) {
- users.add(user);
- }
-
- if (n.reply) add(n.reply);
- if (n.renote) add(n.renote);
+ const allMentionedUsers = targetNotes.reduce((users, note) => {
+ for (const user of note.mentions) {
+ users.add(user);
}
-
- add(note);
return users;
}, new Set<string>());
const mentionHandles = await this.getUserHandles(Array.from(allMentionedUsers));