From 0fbc9d90686bfd5f5590814059dfba5252857641 Mon Sep 17 00:00:00 2001 From: Pierre HUBERT Date: Mon, 30 Mar 2020 15:42:41 +0200 Subject: [PATCH] Notify websockets when the number of unread notifications decrease --- src/helpers/NotificationsHelper.ts | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/helpers/NotificationsHelper.ts b/src/helpers/NotificationsHelper.ts index d6cded1..fdd7ad6 100644 --- a/src/helpers/NotificationsHelper.ts +++ b/src/helpers/NotificationsHelper.ts @@ -323,8 +323,19 @@ export class NotificationsHelper { // Delete a specific notification const cond = n.hasId ? {id: n.id} : this.NotifToDB(n, false); + // Check for affected users + const users = new Set(); + (await DatabaseHelper.Query({ + table: NOTIFICATIONS_TABLE, + where: cond, + fields: ["dest_user_id"] + })).forEach((row) => users.add(row.dest_user_id)) + // Delete notifications await DatabaseHelper.DeleteRows(NOTIFICATIONS_TABLE, cond); + + // Trigger notifications system + await EventsHelper.Emit("updated_number_notifications", {usersID: [...users]}); } /**