From 890e49a4ae4ad133f904449b784e63219b0fc607 Mon Sep 17 00:00:00 2001 From: Pierre HUBERT Date: Tue, 24 Mar 2020 19:05:41 +0100 Subject: [PATCH] Can delete group membership notifications --- src/utils/NotificationsUtils.ts | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/src/utils/NotificationsUtils.ts b/src/utils/NotificationsUtils.ts index 6bc0feb..5810c2c 100644 --- a/src/utils/NotificationsUtils.ts +++ b/src/utils/NotificationsUtils.ts @@ -80,7 +80,7 @@ export class NotificationsUtils { * @param kind The kind of notification to create */ public static async CreateGroupMembershipNotification(userID: number, moderatorID: number, groupID: number, kind: NotifEventType) { - // TODO : Delete all previous notifications + await this.DeleteNotificationsGroupsMembership(userID, groupID); const n = new Notif({ onElemID: groupID, @@ -104,4 +104,27 @@ export class NotificationsUtils { await NotificationsHelper.Push(n); } + + /** + * Delete all the notifications related to a specific group membership + * + * @param userID Target user + * @param groupID The ID of the target group + */ + public static async DeleteNotificationsGroupsMembership(userID: number, groupID: number) { + + const n = new Notif({ + onElemType: NotifElemType.GROUP_MEMBERSHIP, + onElemID: groupID + }); + + n.destUserID = userID; + n.fromUserID = -1; + await NotificationsHelper.Delete(n); + + n.destUserID = -1; + n.fromUserID = userID; + await NotificationsHelper.Delete(n); + + } } \ No newline at end of file