Skip to content

Commit

Permalink
Merge pull request #4391 from coralproject/feat/hookup-more-dsa-notif…
Browse files Browse the repository at this point in the history
…ications

Hook up remaining DSA notifications
  • Loading branch information
kabeaty authored Nov 14, 2023
2 parents 0a73efc + d0cbc39 commit 81a9a0d
Show file tree
Hide file tree
Showing 10 changed files with 552 additions and 109 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,35 +29,61 @@ const NotificationCommentContainer: FunctionComponent<Props> = ({
setIsOpen(!isOpen);
}, [setIsOpen, isOpen]);

const hasBeenModerated =
status === GQLCOMMENT_STATUS.APPROVED ||
status === GQLCOMMENT_STATUS.REJECTED;

return (
<>
{status === GQLCOMMENT_STATUS.APPROVED && isOpen && (
<button className={styles.toggle} onClick={onToggleOpenClosed}>
<Localized id="notification-comment-toggle-approved-open">
Approved comment
</Localized>
</button>
)}
{status === GQLCOMMENT_STATUS.APPROVED && !isOpen && (
<button className={styles.toggle} onClick={onToggleOpenClosed}>
<Localized id="notification-comment-toggle-approved-closed">
+ Approved comment
</Localized>
</button>
)}
{status === GQLCOMMENT_STATUS.REJECTED && isOpen && (
<button className={styles.toggle} onClick={onToggleOpenClosed}>
<Localized id="notification-comment-toggle-rejected-open">
Rejected comment
</Localized>
</button>
{hasBeenModerated && (
<>
{status === GQLCOMMENT_STATUS.APPROVED && isOpen && (
<button className={styles.toggle} onClick={onToggleOpenClosed}>
<Localized id="notification-comment-toggle-approved-open">
Approved comment
</Localized>
</button>
)}
{status === GQLCOMMENT_STATUS.APPROVED && !isOpen && (
<button className={styles.toggle} onClick={onToggleOpenClosed}>
<Localized id="notification-comment-toggle-approved-closed">
+ Approved comment
</Localized>
</button>
)}
{status === GQLCOMMENT_STATUS.REJECTED && isOpen && (
<button className={styles.toggle} onClick={onToggleOpenClosed}>
<Localized id="notification-comment-toggle-rejected-open">
Rejected comment
</Localized>
</button>
)}
{status === GQLCOMMENT_STATUS.REJECTED && !isOpen && (
<button className={styles.toggle} onClick={onToggleOpenClosed}>
<Localized id="notification-comment-toggle-rejected-closed">
+ Rejected comment
</Localized>
</button>
)}
</>
)}
{status === GQLCOMMENT_STATUS.REJECTED && !isOpen && (
<button className={styles.toggle} onClick={onToggleOpenClosed}>
<Localized id="notification-comment-toggle-rejected-closed">
+ Rejected comment
</Localized>
</button>
{!hasBeenModerated && (
<>
{isOpen && (
<button className={styles.toggle} onClick={onToggleOpenClosed}>
<Localized id="notification-comment-toggle-default-open">
Comment
</Localized>
</button>
)}
{!isOpen && (
<button className={styles.toggle} onClick={onToggleOpenClosed}>
<Localized id="notification-comment-toggle-default-closed">
+ Comment
</Localized>
</button>
)}
</>
)}

{isOpen && (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import React, { FunctionComponent, useMemo } from "react";
import { graphql } from "react-relay";

import { withFragmentContainer } from "coral-framework/lib/relay";
import HTMLContent from "coral-stream/common/HTMLContent";
import { CheckCircleIcon, SvgIcon } from "coral-ui/components/icons";
import { Timestamp } from "coral-ui/components/v2";

Expand Down Expand Up @@ -49,7 +50,11 @@ const NotificationContainer: FunctionComponent<Props> = ({
<div className={styles.titleText}>{title}</div>
</div>
)}
{body && <div className={cn(styles.body)}>{body}</div>}
{body && (
<div className={cn(styles.body)}>
<HTMLContent>{body || ""}</HTMLContent>
</div>
)}
{comment && (
<div className={styles.contextItem}>
<NotificationCommentContainer
Expand Down
2 changes: 1 addition & 1 deletion server/src/core/server/graph/mutators/Comments.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { ADDITIONAL_DETAILS_MAX_LENGTH } from "coral-common/common/lib/helpers/v
import GraphContext from "coral-server/graph/context";
import { mapFieldsetToErrorCodes } from "coral-server/graph/errors";
import { hasTag } from "coral-server/models/comment";
import { NotificationType } from "coral-server/models/notifications/notification";
import { addTag, removeTag } from "coral-server/services/comments";
import {
createDontAgree,
Expand All @@ -14,7 +15,6 @@ import {
} from "coral-server/services/comments/actions";
import { CreateCommentMediaInput } from "coral-server/services/comments/media";
import { publishCommentFeatured } from "coral-server/services/events";
import { NotificationType } from "coral-server/services/notifications/internal/context";
import { markSeen } from "coral-server/services/seenComments";
import {
approveComment,
Expand Down
6 changes: 4 additions & 2 deletions server/src/core/server/graph/mutators/DSAReports.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ export const DSAReports = (ctx: GraphContext) => ({
reportID,
}: GQLChangeDSAReportStatusInput) =>
changeDSAReportStatus(ctx.mongo, ctx.tenant, { userID, status, reportID }),
makeDSAReportDecision: ({
makeDSAReportDecision: async ({
userID,
legality,
legalGrounds,
Expand All @@ -80,6 +80,7 @@ export const DSAReports = (ctx: GraphContext) => ({
ctx.broker,
ctx.notifications,
ctx.tenant,
await ctx.loaders.Comments.comment.load(commentID),
{
userID,
legality,
Expand All @@ -88,6 +89,7 @@ export const DSAReports = (ctx: GraphContext) => ({
reportID,
commentID,
commentRevisionID,
}
},
ctx.req
),
});
50 changes: 50 additions & 0 deletions server/src/core/server/locales/en-US/common.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -44,5 +44,55 @@ notifications-commentWasFeatured-title = Comment was featured
notifications-commentWasFeatured-body = The comment { $commentID } was featured.
notifications-commentWasApproved-title = Comment was approved
notifications-commentWasApproved-body = The comment { $commentID } was approved.
notifications-commentWasRejected-title = Comment was rejected
notifications-commentWasRejected-body = The comment { $commentID } was rejected.
notifications-commentWasRejectedWithReason-code =
<br/>
{ $code }
notifications-commentWasRejectedWithReason-grounds =
<br/>
{ $grounds }
notifications-commentWasRejectedWithReason-explanation =
<br/>
{ $explanation }
notifications-commentWasRejectedWithReason-body =
The comment { $commentID } was rejected.
The reasons of which were:
{ $code }
{ $grounds }
{ $explanation }
notifications-commentWasRejectedAndIllegal-title = Comment was deemed to contain illegal content and was rejected
notifications-commentWasRejectedAndIllegal-body =
The comment { $commentID } was rejected for containing illegal content.
The reason of which was:
<br/>
{ $reason }
notifications-dsaIllegalRejectedReason-information =
Grounds:
<br/>
{ $grounds }
<br/>
Explanation:
<br/>
{ $explanation }
notifications-dsaIllegalRejectedReason-informationNotFound = The reasoning for this decision cannot be found.
notifications-dsaReportDecisionMade-title = A decision was made on your DSA report
notifications-dsaReportDecision-legal = The report { $reportID } was determined to be legal.
notifications-dsaReportDecision-illegal = The report { $reportID } was determined to be illegal.
notifications-dsaReportDecision-legalInformation =
Grounds:
<br/>
{ $grounds }
<br/>
Explanation:
<br/>
{ $explanation }
notifications-dsaReportDecisionMade-body-withoutInfo = { $decision }
notifications-dsaReportDecisionMade-body-withInfo =
{ $decision }
<br/>
{ $information }
10 changes: 9 additions & 1 deletion server/src/core/server/models/notifications/notification.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,17 @@ import { ConnectionInput, Query, resolveConnection } from "../helpers";
import { TenantResource } from "../tenant";
import { User } from "../user";

export enum NotificationType {
COMMENT_FEATURED = "COMMENT_FEATURED",
COMMENT_APPROVED = "COMMENT_APPROVED",
COMMENT_REJECTED = "COMMENT_REJECTED",
ILLEGAL_REJECTED = "ILLEGAL_REJECTED",
DSA_REPORT_DECISION_MADE = "DSA_REPORT_DECISION_MADE",
}

export interface Notification extends TenantResource {
readonly id: string;

readonly type: NotificationType;
readonly tenantID: string;

createdAt: Date;
Expand Down
41 changes: 39 additions & 2 deletions server/src/core/server/services/dsaReports/reports.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,20 @@ import { Config } from "coral-server/config";
import { DataCache } from "coral-server/data/cache/dataCache";
import { MongoContext } from "coral-server/data/context";
import { CoralEventPublisherBroker } from "coral-server/events/publisher";
import { Comment } from "coral-server/models/comment";
import {
changeDSAReportStatus as changeReportStatus,
createDSAReport as createReport,
createDSAReportNote as createReportNote,
createDSAReportShare as createReportShare,
deleteDSAReportNote as deleteReportNote,
makeDSAReportDecision as makeReportDecision,
retrieveDSAReport,
} from "coral-server/models/dsaReport/report";
import { NotificationType } from "coral-server/models/notifications/notification";
import { Tenant } from "coral-server/models/tenant";
import { rejectComment } from "coral-server/stacks";
import { Request } from "coral-server/types/express";

import {
GQLDSAReportDecisionLegality,
Expand Down Expand Up @@ -180,7 +184,9 @@ export async function makeDSAReportDecision(
broker: CoralEventPublisherBroker,
notifications: InternalNotificationContext,
tenant: Tenant,
comment: Readonly<Comment> | null,
input: MakeDSAReportDecisionInput,
req: Request | undefined,
now = new Date()
) {
const {
Expand All @@ -189,11 +195,12 @@ export async function makeDSAReportDecision(
userID,
legalGrounds,
detailedExplanation,
reportID,
} = input;

// REJECT if ILLEGAL
if (input.legality === GQLDSAReportDecisionLegality.ILLEGAL) {
await rejectComment(
const rejectedComment = await rejectComment(
mongo,
redis,
cache,
Expand All @@ -210,8 +217,38 @@ export async function makeDSAReportDecision(
code: GQLREJECTION_REASON_CODE.ILLEGAL_CONTENT,
legalGrounds,
detailedExplanation,
}
},
req,
true
);

if (rejectedComment.authorID) {
await notifications.create(tenant.id, tenant.locale, {
targetUserID: rejectedComment.authorID,
type: NotificationType.ILLEGAL_REJECTED,
comment: rejectedComment,
legal: {
legality: input.legality,
grounds: legalGrounds,
explanation: detailedExplanation,
},
});
}
}

const report = await retrieveDSAReport(mongo, tenant.id, reportID);
if (report) {
await notifications.create(tenant.id, tenant.locale, {
targetUserID: report.userID,
type: NotificationType.DSA_REPORT_DECISION_MADE,
comment,
report,
legal: {
legality: input.legality,
grounds: legalGrounds,
explanation: detailedExplanation,
},
});
}

const result = await makeReportDecision(mongo, tenant.id, input, now);
Expand Down
Loading

0 comments on commit 81a9a0d

Please sign in to comment.