Skip to content

Commit

Permalink
show different rejected notifications for rejected pre-mod comments
Browse files Browse the repository at this point in the history
  • Loading branch information
nick-funk committed Mar 7, 2024
1 parent c7a4c19 commit e806e5a
Show file tree
Hide file tree
Showing 7 changed files with 48 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { useCoralContext } from "coral-framework/lib/bootstrap";
import { getMessage } from "coral-framework/lib/i18n";
import { withFragmentContainer } from "coral-framework/lib/relay";
import {
GQLCOMMENT_STATUS,
GQLDSAReportDecisionLegality,
GQLNOTIFICATION_TYPE,
GQLREJECTION_REASON_CODE,
Expand Down Expand Up @@ -160,8 +161,14 @@ const stringIsNullOrEmpty = (value: string) => {
const RejectedCommentNotificationBody: FunctionComponent<Props> = ({
notification,
}) => {
const { type, decisionDetails, rejectionReason, customReason, comment } =
notification;
const {
type,
decisionDetails,
rejectionReason,
customReason,
comment,
previousStatus,
} = notification;

const { localeBundles } = useCoralContext();

Expand All @@ -174,12 +181,20 @@ const RejectedCommentNotificationBody: FunctionComponent<Props> = ({

return (
<div className={styles.body}>
<Localized id="notifications-rejectedComment-body">
<p>
The content of your comment was against our community guidelines. The
comment has been removed.
</p>
</Localized>
{previousStatus === GQLCOMMENT_STATUS.PREMOD ? (
<Localized id="notifications-rejectedComment-wasPending-body">
<p>
The content of your comment was against our community guidelines.
</p>
</Localized>
) : (
<Localized id="notifications-rejectedComment-body">
<p>
The content of your comment was against our community guidelines.
The comment has been removed.
</p>
</Localized>
)}
{type === GQLNOTIFICATION_TYPE.COMMENT_REJECTED &&
rejectionReason &&
decisionDetails && (
Expand Down Expand Up @@ -264,6 +279,7 @@ const enhanced = withFragmentContainer<Props>({
type
rejectionReason
customReason
previousStatus
decisionDetails {
legality
grounds
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 @@ -1083,6 +1083,8 @@ notifications-defaultTitle = Notification
notifications-rejectedComment-body =
The content of your comment was against our community guidelines. The comment has been removed.
notifications-rejectedComment-wasPending-body =
The content of your comment was against our community guidelines.
notifications-reasonForRemoval = Reason for removal
notifications-legalGrounds = Legal grounds
notifications-additionalExplanation = Additional explanation
Expand Down
1 change: 1 addition & 0 deletions server/src/core/server/graph/resolvers/Notification.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ export const NotificationResolver: Required<
return await ctx.loaders.Comments.comment.load(replyID);
},
commentStatus: ({ commentStatus }) => commentStatus,
previousStatus: ({ previousStatus }) => previousStatus,
dsaReport: async ({ reportID }, input, ctx) => {
if (!reportID) {
return null;
Expand Down
7 changes: 7 additions & 0 deletions server/src/core/server/graph/schema/schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -5003,6 +5003,13 @@ type Notification {
"""
commentStatus: COMMENT_STATUS

"""
previousStatus is the optional prior status of the comment when the notification
was created. This allows us to determine if a comment was previously pending
review, or reported to compare against the current status (rejected, approved, etc).
"""
previousStatus: COMMENT_STATUS

"""
rejectionReason is an optional field that defines why a comment was rejected.
"""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ export interface Notification extends TenantResource {

commentID?: string;
commentStatus?: GQLCOMMENT_STATUS;
previousStatus?: GQLCOMMENT_STATUS;

replyID?: string;

Expand Down
16 changes: 12 additions & 4 deletions server/src/core/server/services/notifications/internal/context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ export interface CreateNotificationInput {

comment?: Readonly<Comment> | null;
reply?: Readonly<Comment> | null;
previousStatus?: GQLCOMMENT_STATUS;

rejectionReason?: RejectionReasonInput | null;
report?: Readonly<DSAReport> | null;
Expand Down Expand Up @@ -102,6 +103,7 @@ export class InternalNotificationContext {
rejectionReason,
report,
legal,
previousStatus,
} = input;

const targetUser = await retrieveUser(this.mongo, tenantID, targetUserID);
Expand Down Expand Up @@ -145,7 +147,8 @@ export class InternalNotificationContext {
targetUserID,
comment,
rejectionReason,
now
now,
previousStatus
);
result.attempted = true;
} else if (type === GQLNOTIFICATION_TYPE.ILLEGAL_REJECTED && comment) {
Expand Down Expand Up @@ -187,7 +190,8 @@ export class InternalNotificationContext {
targetUserID,
comment,
reply,
now
now,
previousStatus
);
result.attempted = true;
} else if (type === GQLNOTIFICATION_TYPE.REPLY_STAFF && comment && reply) {
Expand Down Expand Up @@ -322,7 +326,8 @@ export class InternalNotificationContext {
targetUserID: string,
comment: Readonly<Comment>,
rejectionReason?: RejectionReasonInput | null,
now = new Date()
now = new Date(),
previousStatus?: GQLCOMMENT_STATUS
) {
const notification = await createNotification(this.mongo, {
id: uuid(),
Expand All @@ -332,6 +337,7 @@ export class InternalNotificationContext {
ownerID: targetUserID,
commentID: comment.id,
commentStatus: comment.status,
previousStatus,
rejectionReason: rejectionReason?.code ?? undefined,
customReason: rejectionReason?.customReason ?? undefined,
decisionDetails: {
Expand Down Expand Up @@ -390,7 +396,8 @@ export class InternalNotificationContext {
targetUserID: string,
comment: Readonly<Comment>,
reply: Readonly<Comment>,
now: Date
now: Date,
previousStatus?: GQLCOMMENT_STATUS
) {
const notification = await createNotification(this.mongo, {
id: uuid(),
Expand All @@ -401,6 +408,7 @@ export class InternalNotificationContext {
commentID: comment.id,
replyID: reply.id,
commentStatus: comment.status,
previousStatus,
});

return notification;
Expand Down
1 change: 1 addition & 0 deletions server/src/core/server/stacks/rejectComment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,7 @@ const rejectComment = async (
comment: result.after,
rejectionReason: reason,
type: GQLNOTIFICATION_TYPE.COMMENT_REJECTED,
previousStatus: result.before.status,
});
}

Expand Down

0 comments on commit e806e5a

Please sign in to comment.