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