mirror of
https://github.com/Drop-OSS/drop.git
synced 2025-11-10 04:22:09 +10:00
fix: don't send system notifications to all users
This commit is contained in:
@ -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<void>[] = [];
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user