refactor: Refactor NoteReadService.read (#13429)
* refactor: Refactor NoteReadService.read * clean up * Update packages/backend/src/core/NoteReadService.ts --------- Co-authored-by: syuilo <4439005+syuilo@users.noreply.github.com>
This commit is contained in:
parent
2bd9f05a92
commit
4d6fab06de
2 changed files with 32 additions and 33 deletions
|
@ -88,22 +88,24 @@ export class NoteReadService implements OnApplicationShutdown {
|
||||||
userId: MiUser['id'],
|
userId: MiUser['id'],
|
||||||
notes: (MiNote | Packed<'Note'>)[],
|
notes: (MiNote | Packed<'Note'>)[],
|
||||||
): Promise<void> {
|
): Promise<void> {
|
||||||
const readMentions: (MiNote | Packed<'Note'>)[] = [];
|
if (notes.length === 0) return;
|
||||||
const readSpecifiedNotes: (MiNote | Packed<'Note'>)[] = [];
|
|
||||||
|
const noteIds = new Set<MiNote['id']>();
|
||||||
|
|
||||||
for (const note of notes) {
|
for (const note of notes) {
|
||||||
if (note.mentions && note.mentions.includes(userId)) {
|
if (note.mentions && note.mentions.includes(userId)) {
|
||||||
readMentions.push(note);
|
noteIds.add(note.id);
|
||||||
} else if (note.visibleUserIds && note.visibleUserIds.includes(userId)) {
|
} else if (note.visibleUserIds && note.visibleUserIds.includes(userId)) {
|
||||||
readSpecifiedNotes.push(note);
|
noteIds.add(note.id);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((readMentions.length > 0) || (readSpecifiedNotes.length > 0)) {
|
if (noteIds.size === 0) return;
|
||||||
|
|
||||||
// Remove the record
|
// Remove the record
|
||||||
await this.noteUnreadsRepository.delete({
|
await this.noteUnreadsRepository.delete({
|
||||||
userId: userId,
|
userId: userId,
|
||||||
noteId: In([...readMentions.map(n => n.id), ...readSpecifiedNotes.map(n => n.id)]),
|
noteId: In(Array.from(noteIds)),
|
||||||
});
|
});
|
||||||
|
|
||||||
// TODO: ↓まとめてクエリしたい
|
// TODO: ↓まとめてクエリしたい
|
||||||
|
@ -128,7 +130,6 @@ export class NoteReadService implements OnApplicationShutdown {
|
||||||
}
|
}
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
@bindThis
|
@bindThis
|
||||||
public dispose(): void {
|
public dispose(): void {
|
||||||
|
|
|
@ -124,9 +124,7 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
|
||||||
notes.sort((a, b) => a.id > b.id ? -1 : 1);
|
notes.sort((a, b) => a.id > b.id ? -1 : 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (notes.length > 0) {
|
|
||||||
this.noteReadService.read(me.id, notes);
|
this.noteReadService.read(me.id, notes);
|
||||||
}
|
|
||||||
|
|
||||||
return await this.noteEntityService.packMany(notes, me);
|
return await this.noteEntityService.packMany(notes, me);
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in a new issue