From 3078137596f31ff99a222607efa3601c5eb00d6a Mon Sep 17 00:00:00 2001 From: ThatOneCalculator Date: Sat, 26 Nov 2022 09:31:54 -0800 Subject: [PATCH] temp notification api fix, thank you @supakaity --- .../src/models/repositories/notification.ts | 29 +++++++++++-------- 1 file changed, 17 insertions(+), 12 deletions(-) diff --git a/packages/backend/src/models/repositories/notification.ts b/packages/backend/src/models/repositories/notification.ts index 42b47ab150..efa3e860ba 100644 --- a/packages/backend/src/models/repositories/notification.ts +++ b/packages/backend/src/models/repositories/notification.ts @@ -1,14 +1,14 @@ import { In, Repository } from 'typeorm'; -import { Users, Notes, UserGroupInvitations, AccessTokens, NoteReactions } from '../index.js'; import { Notification } from '@/models/entities/notification.js'; import { awaitAll } from '@/prelude/await-all.js'; -import { Packed } from '@/misc/schema.js'; -import { Note } from '@/models/entities/note.js'; -import { NoteReaction } from '@/models/entities/note-reaction.js'; -import { User } from '@/models/entities/user.js'; +import type { Packed } from '@/misc/schema.js'; +import type { Note } from '@/models/entities/note.js'; +import type { NoteReaction } from '@/models/entities/note-reaction.js'; +import type { User } from '@/models/entities/user.js'; import { aggregateNoteEmojis, prefetchEmojis } from '@/misc/populate-emojis.js'; import { notificationTypes } from '@/types.js'; import { db } from '@/db/postgre.js'; +import { Users, Notes, UserGroupInvitations, AccessTokens, NoteReactions } from '../index.js'; export const NotificationRepository = db.getRepository(Notification).extend({ async pack( @@ -17,7 +17,7 @@ export const NotificationRepository = db.getRepository(Notification).extend({ _hintForEachNotes_?: { myReactions: Map; }; - } + }, ): Promise> { const notification = typeof src === 'object' ? src : await this.findOneByOrFail({ id: src }); const token = notification.appAccessTokenId ? await AccessTokens.findOneByOrFail({ id: notification.appAccessTokenId }) : null; @@ -86,7 +86,7 @@ export const NotificationRepository = db.getRepository(Notification).extend({ async packMany( notifications: Notification[], - meId: User['id'] + meId: User['id'], ) { if (notifications.length === 0) return []; @@ -106,10 +106,15 @@ export const NotificationRepository = db.getRepository(Notification).extend({ await prefetchEmojis(aggregateNoteEmojis(notes)); - return await Promise.all(notifications.map(x => this.pack(x, { - _hintForEachNotes_: { - myReactions: myReactionsMap, - }, - }))); + const results = await Promise.all(notifications + .map(x => + this.pack(x, { + _hintForEachNotes_: { + myReactions: myReactionsMap, + }, + }).catch(e => null), + ), + ); + return results.filter(x => x != null); }, });