From 72bb7abe98cd908d70cbb3f57ab6cc6a98d20ac1 Mon Sep 17 00:00:00 2001 From: Kathryn Beaty Date: Mon, 30 Sep 2024 14:15:15 -0400 Subject: [PATCH 1/4] initial send notification on previously rejected comment being approved --- .../Notifications/NotificationContainer.tsx | 14 +++++++- locales/en-US/stream.ftl | 2 ++ .../core/server/graph/schema/schema.graphql | 8 ++++- .../notifications/internal/context.ts | 36 ++++++++++++++++++- .../src/core/server/stacks/approveComment.ts | 12 +++++++ 5 files changed, 69 insertions(+), 3 deletions(-) diff --git a/client/src/core/client/stream/tabs/Notifications/NotificationContainer.tsx b/client/src/core/client/stream/tabs/Notifications/NotificationContainer.tsx index 917ea18bb0..bbb47aa48c 100644 --- a/client/src/core/client/stream/tabs/Notifications/NotificationContainer.tsx +++ b/client/src/core/client/stream/tabs/Notifications/NotificationContainer.tsx @@ -48,6 +48,9 @@ const getIcon = (type: NOTIFICATION_TYPE | null): ComponentType => { if (type === GQLNOTIFICATION_TYPE.COMMENT_APPROVED) { return CheckCircleIcon; } + if (type === GQLNOTIFICATION_TYPE.PREVIOUSLY_REJECTED_COMMENT_APPROVED) { + return CheckCircleIcon; + } if (type === GQLNOTIFICATION_TYPE.COMMENT_FEATURED) { return RatingStarRibbonIcon; } @@ -83,6 +86,13 @@ const getTitle = ( "Your comment has been published" ); } + if (type === GQLNOTIFICATION_TYPE.PREVIOUSLY_REJECTED_COMMENT_APPROVED) { + return getMessage( + bundles, + "notifications-yourPreviouslyRejectedCommentHasBeenApproved", + "Your comment was previously rejected. It has now been restored to the page." + ); + } if (type === GQLNOTIFICATION_TYPE.COMMENT_FEATURED) { return getMessage( bundles, @@ -200,7 +210,9 @@ const NotificationContainer: FunctionComponent = ({ {(type === GQLNOTIFICATION_TYPE.REPLY || type === GQLNOTIFICATION_TYPE.REPLY_STAFF || type === GQLNOTIFICATION_TYPE.COMMENT_FEATURED || - type === GQLNOTIFICATION_TYPE.COMMENT_APPROVED) && ( + type === GQLNOTIFICATION_TYPE.COMMENT_APPROVED || + type === + GQLNOTIFICATION_TYPE.PREVIOUSLY_REJECTED_COMMENT_APPROVED) && ( , + now = new Date() + ) { + const notification = await createNotification(this.mongo, { + id: uuid(), + tenantID, + type, + createdAt: now, + ownerID: targetUserID, + commentID: comment.id, + commentStatus: comment.status, + }); + + return notification; + } + private async createRejectCommentNotification( tenantID: string, type: GQLNOTIFICATION_TYPE, diff --git a/server/src/core/server/stacks/approveComment.ts b/server/src/core/server/stacks/approveComment.ts index 150d9a35cf..3ff583b0f2 100644 --- a/server/src/core/server/stacks/approveComment.ts +++ b/server/src/core/server/stacks/approveComment.ts @@ -106,6 +106,18 @@ const approveComment = async ( }); } + // create notification if dsa enabled upon approval of previously rejected comment + if (tenant.dsa?.enabled) { + if (previousComment?.status === GQLCOMMENT_STATUS.REJECTED) { + await notifications.create(tenant.id, tenant.locale, { + targetUserID: result.after.authorID!, + comment: result.after, + previousStatus: result.before.status, + type: GQLNOTIFICATION_TYPE.PREVIOUSLY_REJECTED_COMMENT_APPROVED, + }); + } + } + // if comment was previously rejected, system withheld, or in pre-mod, // and there is a reply notification for it, increment the notificationCount // for that notification's owner since it was decremented upon original From b44bf19d030bc351222a37ea4a566eaecd0f39e9 Mon Sep 17 00:00:00 2001 From: Kathryn Beaty Date: Wed, 2 Oct 2024 14:17:39 -0400 Subject: [PATCH 2/4] simplify if --- server/src/core/server/stacks/approveComment.ts | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/server/src/core/server/stacks/approveComment.ts b/server/src/core/server/stacks/approveComment.ts index 3ff583b0f2..54040b2b68 100644 --- a/server/src/core/server/stacks/approveComment.ts +++ b/server/src/core/server/stacks/approveComment.ts @@ -107,8 +107,7 @@ const approveComment = async ( } // create notification if dsa enabled upon approval of previously rejected comment - if (tenant.dsa?.enabled) { - if (previousComment?.status === GQLCOMMENT_STATUS.REJECTED) { + if (tenant.dsa?.enabled && previousComment?.status === GQLCOMMENT_STATUS.REJECTED) { await notifications.create(tenant.id, tenant.locale, { targetUserID: result.after.authorID!, comment: result.after, From f08318fd55a728a8ea76e3429ba71825cb7732e0 Mon Sep 17 00:00:00 2001 From: Kathryn Beaty Date: Wed, 2 Oct 2024 14:27:28 -0400 Subject: [PATCH 3/4] copy update --- .../client/stream/tabs/Notifications/NotificationContainer.tsx | 2 +- locales/en-US/stream.ftl | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/client/src/core/client/stream/tabs/Notifications/NotificationContainer.tsx b/client/src/core/client/stream/tabs/Notifications/NotificationContainer.tsx index bbb47aa48c..a715701db3 100644 --- a/client/src/core/client/stream/tabs/Notifications/NotificationContainer.tsx +++ b/client/src/core/client/stream/tabs/Notifications/NotificationContainer.tsx @@ -90,7 +90,7 @@ const getTitle = ( return getMessage( bundles, "notifications-yourPreviouslyRejectedCommentHasBeenApproved", - "Your comment was previously rejected. It has now been restored to the page." + "Your comment was previously rejected. It has now been approved." ); } if (type === GQLNOTIFICATION_TYPE.COMMENT_FEATURED) { diff --git a/locales/en-US/stream.ftl b/locales/en-US/stream.ftl index 4e8c44801c..dcaa5b8557 100644 --- a/locales/en-US/stream.ftl +++ b/locales/en-US/stream.ftl @@ -1083,7 +1083,7 @@ notifications-yourCommentHasBeenRejected = notifications-yourCommentHasBeenApproved = Your comment has been approved notifications-yourPreviouslyRejectedCommentHasBeenApproved = - Your comment was previously rejected. It has now been restored to the page. + Your comment was previously rejected. It has now been approved. notifications-yourCommentHasBeenFeatured = Your comment has been featured notifications-yourCommentHasReceivedAReply = From 4011d8175ca3184ea4b6d2b1ce8ce656c799465e Mon Sep 17 00:00:00 2001 From: Kathryn Beaty Date: Wed, 2 Oct 2024 14:32:36 -0400 Subject: [PATCH 4/4] fix if check update --- .../src/core/server/stacks/approveComment.ts | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/server/src/core/server/stacks/approveComment.ts b/server/src/core/server/stacks/approveComment.ts index 54040b2b68..51e4dc9a09 100644 --- a/server/src/core/server/stacks/approveComment.ts +++ b/server/src/core/server/stacks/approveComment.ts @@ -107,14 +107,16 @@ const approveComment = async ( } // create notification if dsa enabled upon approval of previously rejected comment - if (tenant.dsa?.enabled && previousComment?.status === GQLCOMMENT_STATUS.REJECTED) { - await notifications.create(tenant.id, tenant.locale, { - targetUserID: result.after.authorID!, - comment: result.after, - previousStatus: result.before.status, - type: GQLNOTIFICATION_TYPE.PREVIOUSLY_REJECTED_COMMENT_APPROVED, - }); - } + if ( + tenant.dsa?.enabled && + previousComment?.status === GQLCOMMENT_STATUS.REJECTED + ) { + await notifications.create(tenant.id, tenant.locale, { + targetUserID: result.after.authorID!, + comment: result.after, + previousStatus: result.before.status, + type: GQLNOTIFICATION_TYPE.PREVIOUSLY_REJECTED_COMMENT_APPROVED, + }); } // if comment was previously rejected, system withheld, or in pre-mod,