mirror of
https://github.com/Drop-OSS/drop.git
synced 2026-07-26 09:44:40 +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);
|
await this.pushNotification(userId, notification);
|
||||||
}
|
}
|
||||||
|
|
||||||
async pushAll(notificationCreateArgs: NotificationCreateArgs) {
|
/**
|
||||||
const users = await prisma.user.findMany({
|
* Internal call to batch push notifications to many users
|
||||||
where: { id: { not: "system" } },
|
* @param notificationCreateArgs
|
||||||
select: {
|
* @param users
|
||||||
id: true,
|
*/
|
||||||
},
|
private async _pushMany(
|
||||||
});
|
notificationCreateArgs: NotificationCreateArgs,
|
||||||
|
users: { id: string }[],
|
||||||
|
) {
|
||||||
const res: Promise<void>[] = [];
|
const res: Promise<void>[] = [];
|
||||||
for (const user of users) {
|
for (const user of users) {
|
||||||
res.push(this.push(user.id, notificationCreateArgs));
|
res.push(this.push(user.id, notificationCreateArgs));
|
||||||
@@ -110,8 +111,39 @@ class NotificationSystem {
|
|||||||
await Promise.all(res);
|
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) {
|
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