Skip to content

Commit

Permalink
Merge pull request #4671 from coralproject/feat/CORL-3179-dsa-rejecte…
Browse files Browse the repository at this point in the history
…d-comments-approved-update

[CORL-3179]: Create notification on previously rejected comment being approved if DSA is enabled
  • Loading branch information
tessalt authored Oct 3, 2024
2 parents 9fcdecc + 4011d81 commit d80f5de
Show file tree
Hide file tree
Showing 5 changed files with 70 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down Expand Up @@ -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 approved."
);
}
if (type === GQLNOTIFICATION_TYPE.COMMENT_FEATURED) {
return getMessage(
bundles,
Expand Down Expand Up @@ -200,7 +210,9 @@ const NotificationContainer: FunctionComponent<Props> = ({
{(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) && (
<CommentNotificationBody
notification={notification}
reply={
Expand Down
2 changes: 2 additions & 0 deletions locales/en-US/stream.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -1082,6 +1082,8 @@ notifications-yourCommentHasBeenRejected =
Your comment has been rejected
notifications-yourCommentHasBeenApproved =
Your comment has been approved
notifications-yourPreviouslyRejectedCommentHasBeenApproved =
Your comment was previously rejected. It has now been approved.
notifications-yourCommentHasBeenFeatured =
Your comment has been featured
notifications-yourCommentHasReceivedAReply =
Expand Down
8 changes: 7 additions & 1 deletion server/src/core/server/graph/schema/schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -4125,7 +4125,12 @@ type ExternalMedia {
"""
CommentMedia is the various media types that can be attached to a Comment.
"""
union CommentMedia = GiphyMedia | TwitterMedia | YouTubeMedia | ExternalMedia | TenorMedia
union CommentMedia =
GiphyMedia
| TwitterMedia
| YouTubeMedia
| ExternalMedia
| TenorMedia

type CommentRevision {
"""
Expand Down Expand Up @@ -5028,6 +5033,7 @@ enum NOTIFICATION_TYPE {
DSA_REPORT_DECISION_MADE
REPLY
REPLY_STAFF
PREVIOUSLY_REJECTED_COMMENT_APPROVED
}

type Notification {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,19 @@ export class InternalNotificationContext {
now
);
result.attempted = true;
} else if (
type === GQLNOTIFICATION_TYPE.PREVIOUSLY_REJECTED_COMMENT_APPROVED &&
comment
) {
result.notification =
await this.createPreviouslyRejectedCommentApprovedNotification(
tenantID,
type,
targetUserID,
comment,
now
);
result.attempted = true;
} else if (type === GQLNOTIFICATION_TYPE.COMMENT_REJECTED && comment) {
result.notification = await this.createRejectCommentNotification(
tenantID,
Expand Down Expand Up @@ -225,7 +238,8 @@ export class InternalNotificationContext {
// Determine whether to increment notificationCount based on user's in-page notification settings
let shouldIncrementCount = true;
if (
type === GQLNOTIFICATION_TYPE.COMMENT_APPROVED &&
(type === GQLNOTIFICATION_TYPE.COMMENT_APPROVED ||
type === GQLNOTIFICATION_TYPE.PREVIOUSLY_REJECTED_COMMENT_APPROVED) &&
!preferences?.onModeration
) {
shouldIncrementCount = false;
Expand Down Expand Up @@ -330,6 +344,26 @@ export class InternalNotificationContext {
return notification;
}

private async createPreviouslyRejectedCommentApprovedNotification(
tenantID: string,
type: GQLNOTIFICATION_TYPE,
targetUserID: string,
comment: Readonly<Comment>,
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,
Expand Down
13 changes: 13 additions & 0 deletions server/src/core/server/stacks/approveComment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,19 @@ 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 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
Expand Down

0 comments on commit d80f5de

Please sign in to comment.