From 5dbe6a54dbbb4bada1b99429e44cc78c5c7222d7 Mon Sep 17 00:00:00 2001 From: Huskydog9988 <39809509+Huskydog9988@users.noreply.github.com> Date: Thu, 15 May 2025 13:53:05 -0400 Subject: [PATCH] fix: don't send system notifications to all users --- server/server/internal/notifications/index.ts | 50 +++++++++++++++---- 1 file changed, 41 insertions(+), 9 deletions(-) diff --git a/server/server/internal/notifications/index.ts b/server/server/internal/notifications/index.ts index b4a60ba4..5780b8f3 100644 --- a/server/server/internal/notifications/index.ts +++ b/server/server/internal/notifications/index.ts @@ -94,14 +94,15 @@ class NotificationSystem { await this.pushNotification(userId, notification); } - async pushAll(notificationCreateArgs: NotificationCreateArgs) { - const users = await prisma.user.findMany({ - where: { id: { not: "system" } }, - select: { - id: true, - }, - }); - + /** + * Internal call to batch push notifications to many users + * @param notificationCreateArgs + * @param users + */ + private async _pushMany( + notificationCreateArgs: NotificationCreateArgs, + users: { id: string }[], + ) { const res: Promise[] = []; for (const user of users) { res.push(this.push(user.id, notificationCreateArgs)); @@ -110,8 +111,39 @@ class NotificationSystem { await Promise.all(res); } + /** + * Send a notification to all users + * @param notificationCreateArgs + */ + async pushAll(notificationCreateArgs: NotificationCreateArgs) { + const users = await prisma.user.findMany({ + where: { id: { not: "system" } }, + select: { + id: true, + }, + }); + + await this._pushMany(notificationCreateArgs, users); + } + + /** + * Send a notification to all system level users + * @param notificationCreateArgs + * @returns + */ async systemPush(notificationCreateArgs: NotificationCreateArgs) { - return await this.pushAll(notificationCreateArgs); + const users = await prisma.user.findMany({ + where: { + id: { not: "system" }, + // no reason to send to any users other then admins rn + admin: true, + }, + select: { + id: true, + }, + }); + + await this._pushMany(notificationCreateArgs, users); } }