add filter notification is not null

This commit is contained in:
taichan 2024-02-20 15:03:10 +09:00
parent 239a6952f7
commit d53b837994
No known key found for this signature in database
GPG Key ID: CCE28623AFA24E9C
1 changed files with 6 additions and 6 deletions

View File

@ -114,7 +114,7 @@ export class NotificationEntityService implements OnModuleInit {
public async packMany( public async packMany(
notifications: MiNotification[], notifications: MiNotification[],
meId: MiUser['id'], meId: MiUser['id'],
) { ): Promise<MiNotification[]> {
if (notifications.length === 0) return []; if (notifications.length === 0) return [];
let validNotifications = notifications; let validNotifications = notifications;
@ -147,10 +147,10 @@ export class NotificationEntityService implements OnModuleInit {
validNotifications = validNotifications.filter(x => (x.type !== 'receiveFollowRequest') || reqs.some(r => r.followerId === x.notifierId)); validNotifications = validNotifications.filter(x => (x.type !== 'receiveFollowRequest') || reqs.some(r => r.followerId === x.notifierId));
} }
return await Promise.all(validNotifications.map(x => this.pack(x, meId, {}, { return (await Promise.all(validNotifications.map(x => this.pack(x, meId, {}, {
packedNotes, packedNotes,
packedUsers, packedUsers,
}))); })))).filter(isNotNull);
} }
@bindThis @bindThis
@ -248,7 +248,7 @@ export class NotificationEntityService implements OnModuleInit {
public async packGroupedMany( public async packGroupedMany(
notifications: MiGroupedNotification[], notifications: MiGroupedNotification[],
meId: MiUser['id'], meId: MiUser['id'],
) { ) : Promise<MiGroupedNotification[]> {
if (notifications.length === 0) return []; if (notifications.length === 0) return [];
let validNotifications = notifications; let validNotifications = notifications;
@ -286,10 +286,10 @@ export class NotificationEntityService implements OnModuleInit {
validNotifications = validNotifications.filter(x => (x.type !== 'receiveFollowRequest') || reqs.some(r => r.followerId === x.notifierId)); validNotifications = validNotifications.filter(x => (x.type !== 'receiveFollowRequest') || reqs.some(r => r.followerId === x.notifierId));
} }
return await Promise.all(validNotifications.map(x => this.packGrouped(x, meId, {}, { return (await Promise.all(validNotifications.map(x => this.packGrouped(x, meId, {}, {
packedNotes, packedNotes,
packedUsers, packedUsers,
}))); })))).filter(isNotNull);
} }
/** /**