From ab645b67ff1e34227db8270c78cf1d2452633d9b Mon Sep 17 00:00:00 2001 From: Pierre HUBERT Date: Sat, 28 Mar 2020 14:25:58 +0100 Subject: [PATCH] Handles comments creation notification --- src/controllers/CommentsController.ts | 3 ++- src/helpers/NotificationsHelper.ts | 15 +++++++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/src/controllers/CommentsController.ts b/src/controllers/CommentsController.ts index a5732be..93ec850 100644 --- a/src/controllers/CommentsController.ts +++ b/src/controllers/CommentsController.ts @@ -48,7 +48,8 @@ export class CommentsController { // Create notifications await NotificationsHelper.CreatePostNotification(h.getUserId(), postID, NotifEventType.COMMENT_CREATED); - // TODO : Delete any notifications targetting this user about the post + // Delete any notifications targetting this user about the post + await NotificationsHelper.DeleteAllPostsNotificationsTargetingUser(h.getUserId(), postID); h.send({success: true, commentID: commentID}); } diff --git a/src/helpers/NotificationsHelper.ts b/src/helpers/NotificationsHelper.ts index c72c6f2..eb4a549 100644 --- a/src/helpers/NotificationsHelper.ts +++ b/src/helpers/NotificationsHelper.ts @@ -370,6 +370,21 @@ export class NotificationsHelper { })); } + /** + * Delete all the notifications about a post targetting a specified + * user + * + * @param userID Target user ID + * @param postID Target post ID + */ + public static async DeleteAllPostsNotificationsTargetingUser(userID: number, postID: number) { + await this.Delete(new Notif({ + destUserID: userID, + onElemType: NotifElemType.POST, + onElemID: postID + })); + } + /** * Delete all the notification related with a post *