fix(backend): fix pack of notification behaviour

This commit is contained in:
syuilo 2023-04-06 15:09:21 +09:00
parent bc5be83e29
commit b38811af7c

View file

@ -108,7 +108,9 @@ export class NotificationEntityService implements OnModuleInit {
) {
if (notifications.length === 0) return [];
const noteIds = notifications.map(x => x.noteId).filter(isNotNull);
let validNotifications = notifications;
const noteIds = validNotifications.map(x => x.noteId).filter(isNotNull);
const notes = noteIds.length > 0 ? await this.notesRepository.find({
where: { id: In(noteIds) },
relations: ['user', 'user.avatar', 'user.banner', 'reply', 'reply.user', 'reply.user.avatar', 'reply.user.banner', 'renote', 'renote.user', 'renote.user.avatar', 'renote.user.banner'],
@ -118,7 +120,9 @@ export class NotificationEntityService implements OnModuleInit {
});
const packedNotes = new Map(packedNotesArray.map(p => [p.id, p]));
const userIds = notifications.map(x => x.notifierId).filter(isNotNull);
validNotifications = validNotifications.filter(x => x.noteId == null || packedNotes.has(x.noteId));
const userIds = validNotifications.map(x => x.notifierId).filter(isNotNull);
const users = userIds.length > 0 ? await this.usersRepository.find({
where: { id: In(userIds) },
relations: ['avatar', 'banner'],
@ -128,7 +132,7 @@ export class NotificationEntityService implements OnModuleInit {
});
const packedUsers = new Map(packedUsersArray.map(p => [p.id, p]));
return await Promise.all(notifications.map(x => this.pack(x, meId, {}, {
return await Promise.all(validNotifications.map(x => this.pack(x, meId, {}, {
packedNotes,
packedUsers,
})));