Skip to content

Commit

Permalink
persist commentStatus onto notification
Browse files Browse the repository at this point in the history
allows us to retain state of comment snapshotted at the time
the notification was created.
  • Loading branch information
nick-funk committed Nov 2, 2023
1 parent c8cf99d commit 1f9b5d0
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,21 @@ import { GQLCOMMENT_STATUS } from "coral-framework/schema";
import HTMLContent from "coral-stream/common/HTMLContent";
import { Timestamp } from "coral-ui/components/v2";

import { NotificationCommentContainer_comment } from "coral-stream/__generated__/NotificationCommentContainer_comment.graphql";
import {
COMMENT_STATUS,
NotificationCommentContainer_comment,
} from "coral-stream/__generated__/NotificationCommentContainer_comment.graphql";

import styles from "./NotificationCommentContainer.css";

interface Props {
comment: NotificationCommentContainer_comment;
status: COMMENT_STATUS;
}

const NotificationCommentContainer: FunctionComponent<Props> = ({
comment,
status,
}) => {
const [isOpen, setIsOpen] = useState<boolean>(false);

Expand All @@ -26,28 +31,28 @@ const NotificationCommentContainer: FunctionComponent<Props> = ({

return (
<>
{comment.status === GQLCOMMENT_STATUS.APPROVED && isOpen && (
{status === GQLCOMMENT_STATUS.APPROVED && isOpen && (
<button className={styles.toggle} onClick={onToggleOpenClosed}>
<Localized id="notification-comment-toggle-approved-open">
Approved comment
</Localized>
</button>
)}
{comment.status === GQLCOMMENT_STATUS.APPROVED && !isOpen && (
{status === GQLCOMMENT_STATUS.APPROVED && !isOpen && (
<button className={styles.toggle} onClick={onToggleOpenClosed}>
<Localized id="notification-comment-toggle-approved-closed">
+ Approved comment
</Localized>
</button>
)}
{comment.status === GQLCOMMENT_STATUS.REJECTED && isOpen && (
{status === GQLCOMMENT_STATUS.REJECTED && isOpen && (
<button className={styles.toggle} onClick={onToggleOpenClosed}>
<Localized id="notification-comment-toggle-rejected-open">
Rejected comment
</Localized>
</button>
)}
{comment.status === GQLCOMMENT_STATUS.REJECTED && !isOpen && (
{status === GQLCOMMENT_STATUS.REJECTED && !isOpen && (
<button className={styles.toggle} onClick={onToggleOpenClosed}>
<Localized id="notification-comment-toggle-rejected-closed">
+ Rejected comment
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ interface Props {
}

const NotificationContainer: FunctionComponent<Props> = ({
notification: { title, body, comment, createdAt },
notification: { title, body, comment, createdAt, commentStatus },
viewer,
}) => {
const seen = useMemo(() => {
Expand Down Expand Up @@ -52,7 +52,10 @@ const NotificationContainer: FunctionComponent<Props> = ({
{body && <div className={cn(styles.body)}>{body}</div>}
{comment && (
<div className={styles.contextItem}>
<NotificationCommentContainer comment={comment} />
<NotificationCommentContainer
comment={comment}
status={commentStatus ? commentStatus : comment.status}
/>
</div>
)}
<div className={styles.footer}>
Expand All @@ -78,7 +81,9 @@ const enhanced = withFragmentContainer<Props>({
body
comment {
...NotificationCommentContainer_comment
status
}
commentStatus
}
`,
})(NotificationContainer);
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 @@ -23,6 +23,7 @@ export const NotificationResolver: Required<

return comment;
},
commentStatus: ({ commentStatus }) => commentStatus,
dsaReport: async ({ reportID }, input, ctx) => {
if (!reportID) {
return null;
Expand Down
8 changes: 8 additions & 0 deletions server/src/core/server/graph/schema/schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -4591,6 +4591,14 @@ type Notification {
"""
comment: Comment

"""
commentStatus is the optional status of the comment when the notification
was created. This allows for the context of the state of the comment to be
persisted even if the comment reference undergoes multiple moderation actions
since the notification was created.
"""
commentStatus: COMMENT_STATUS

"""
dsaReport is the details of the DSA Report related to the notification.
This is usually in reference to the comment that is also related to
Expand Down
4 changes: 4 additions & 0 deletions server/src/core/server/models/notifications/notification.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import { MongoContext } from "coral-server/data/context";

import { GQLCOMMENT_STATUS } from "coral-server/graph/schema/__generated__/types";

import { ConnectionInput, Query, resolveConnection } from "../helpers";
import { TenantResource } from "../tenant";
import { User } from "../user";
Expand All @@ -14,7 +16,9 @@ export interface Notification extends TenantResource {
ownerID: string;

reportID?: string;

commentID?: string;
commentStatus?: GQLCOMMENT_STATUS;

title?: string;
body?: string;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ export class InternalNotificationContext {
}
),
commentID: comment.id,
commentStatus: comment.status,
});
result.attempted = true;
} else if (type === NotificationType.COMMENT_APPROVED && comment) {
Expand All @@ -107,6 +108,7 @@ export class InternalNotificationContext {
}
),
commentID: comment.id,
commentStatus: comment.status,
});
result.attempted = true;
} else if (type === NotificationType.COMMENT_REJECTED && comment) {
Expand All @@ -129,6 +131,7 @@ export class InternalNotificationContext {
}
),
commentID: comment.id,
commentStatus: comment.status,
});
result.attempted = true;
}
Expand Down

0 comments on commit 1f9b5d0

Please sign in to comment.