Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[CORL-3179]: Create notification on previously rejected comment being approved if DSA is enabled #4671

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading