Skip to content

Commit

Permalink
Merge pull request #4443 from coralproject/feat/CORL-2976-notificatio…
Browse files Browse the repository at this point in the history
…ns-rejection-text-updates

[CORL-2976]: Notifications for comment rejection updates
  • Loading branch information
kabeaty authored Dec 4, 2023
2 parents e0af4e1 + e7438f9 commit 4916033
Show file tree
Hide file tree
Showing 7 changed files with 60 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -54,24 +54,29 @@ const getLegalReason = (

const getGeneralReason = (
bundles: FluentBundle[],
reason: REJECTION_REASON_CODE | null
reason: REJECTION_REASON_CODE | null,
customReason: string | null
) => {
if (reason === GQLREJECTION_REASON_CODE.OFFENSIVE) {
return getMessage(
bundles,
"notifications-rejectionReason-offensive",
"Offensive"
"This comment contains offensive language"
);
}
if (reason === GQLREJECTION_REASON_CODE.ABUSIVE) {
return getMessage(
bundles,
"notifications-rejectionReason-abusive",
"Abusive"
"This comment contains abusive language"
);
}
if (reason === GQLREJECTION_REASON_CODE.SPAM) {
return getMessage(bundles, "notifications-rejectionReason-spam", "Spam");
return getMessage(
bundles,
"notifications-rejectionReason-spam",
"This comment is spam"
);
}
if (reason === GQLREJECTION_REASON_CODE.BANNED_WORD) {
return getMessage(
Expand All @@ -81,47 +86,64 @@ const getGeneralReason = (
);
}
if (reason === GQLREJECTION_REASON_CODE.AD) {
return getMessage(bundles, "notifications-rejectionReason-ad", "Ad");
return getMessage(
bundles,
"notifications-rejectionReason-ad",
"This comment is an advertisement"
);
}
if (reason === GQLREJECTION_REASON_CODE.ILLEGAL_CONTENT) {
return getMessage(
bundles,
"notifications-rejectionReason-illegalContent",
"Illegal content"
"This comment contains illegal content"
);
}

if (reason === GQLREJECTION_REASON_CODE.HARASSMENT_BULLYING) {
return getMessage(
bundles,
"notifications-rejectionReason-harassmentBullying",
"Harassment or bullying"
"This comment contains harassing or bullying language"
);
}
if (reason === GQLREJECTION_REASON_CODE.MISINFORMATION) {
return getMessage(
bundles,
"notifications-rejectionReason-misinformation",
"Misinformation"
"This comment contains misinformation"
);
}
if (reason === GQLREJECTION_REASON_CODE.HATE_SPEECH) {
return getMessage(
bundles,
"notifications-rejectionReason-hateSpeech",
"Hate speech"
"This comment contains hate speech"
);
}
if (reason === GQLREJECTION_REASON_CODE.IRRELEVANT_CONTENT) {
return getMessage(
bundles,
"notifications-rejectionReason-irrelevant",
"Irrelevant content"
"This comment is irrelevant to the discussion"
);
}

if (reason === GQLREJECTION_REASON_CODE.OTHER) {
return getMessage(bundles, "notifications-rejectionReason-other", "Other");
if (customReason) {
return getMessage(
bundles,
"notifications-rejectionReason-other-customReason",
`Other - ${customReason}`,
{ vars: { customReason } }
);
} else {
return getMessage(
bundles,
"notifications-rejectionReason-other",
"Other"
);
}
}

return getMessage(
Expand All @@ -138,7 +160,8 @@ const stringIsNullOrEmpty = (value: string) => {
const RejectedCommentNotificationBody: FunctionComponent<Props> = ({
notification,
}) => {
const { type, decisionDetails, rejectionReason, comment } = notification;
const { type, decisionDetails, rejectionReason, customReason, comment } =
notification;

const { localeBundles } = useCoralContext();

Expand All @@ -165,7 +188,7 @@ const RejectedCommentNotificationBody: FunctionComponent<Props> = ({
<div className={styles.detailLabel}>Reason for removal</div>
</Localized>
<div className={styles.detailItem}>
{getGeneralReason(localeBundles, rejectionReason)}
{getGeneralReason(localeBundles, rejectionReason, customReason)}
</div>
{hasExplanation && (
<>
Expand Down Expand Up @@ -237,6 +260,7 @@ const enhanced = withFragmentContainer<Props>({
fragment RejectedCommentNotificationBody_notification on Notification {
type
rejectionReason
customReason
decisionDetails {
legality
grounds
Expand Down
19 changes: 10 additions & 9 deletions locales/en-US/stream.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -1063,17 +1063,18 @@ notifications-dsaReportLegality-legal = Legal content
notifications-dsaReportLegality-illegal = Illegal content
notifications-dsaReportLegality-unknown = Unknown
notifications-rejectionReason-offensive = Offensive
notifications-rejectionReason-abusive = Abusive
notifications-rejectionReason-spam = Spam
notifications-rejectionReason-offensive = This comment contains offensive language
notifications-rejectionReason-abusive = This comment contains abusive language
notifications-rejectionReason-spam = This comment is spam
notifications-rejectionReason-bannedWord = Banned word
notifications-rejectionReason-ad = Ad
notifications-rejectionReason-illegalContent = Illegal content
notifications-rejectionReason-harassmentBullying = Harassment or bullying
notifications-rejectionReason-misinformation = Misinformation
notifications-rejectionReason-hateSpeech = Hate speech
notifications-rejectionReason-irrelevant = Irrelevant content
notifications-rejectionReason-ad = This comment is an advertisement
notifications-rejectionReason-illegalContent = This comment contains illegal content
notifications-rejectionReason-harassmentBullying = This comment contains harassing or bullying language
notifications-rejectionReason-misinformation = This comment contains misinformation
notifications-rejectionReason-hateSpeech = This comment contains hate speech
notifications-rejectionReason-irrelevant = This comment is irrelevant to the discussion
notifications-rejectionReason-other = Other
notifications-rejectionReason-other-customReason = Other - { $customReason }
notifications-rejectionReason-unknown = Unknown
notifications-reportDecisionMade-legal =
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 @@ -29,4 +29,5 @@ export const NotificationResolver: Required<
},
decisionDetails: ({ decisionDetails }) => decisionDetails,
rejectionReason: ({ rejectionReason }) => rejectionReason,
customReason: ({ customReason }) => customReason,
};
5 changes: 5 additions & 0 deletions server/src/core/server/graph/schema/schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -4820,6 +4820,11 @@ type Notification {
"""
decisionDetails: NotificationDecisionDetails

"""
customReason is a reason provided for rejection when the Other rejection code is selected.
"""
customReason: String

"""
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
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ export interface Notification extends TenantResource {

rejectionReason?: GQLREJECTION_REASON_CODE;
decisionDetails?: GQLNotificationDecisionDetails;
customReason?: string;
}

type BaseConnectionInput = ConnectionInput<Notification>;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ export interface RejectionReasonInput {
code: GQLREJECTION_REASON_CODE;
legalGrounds?: string | undefined;
detailedExplanation?: string | undefined;
customReason?: string | undefined;
}

export interface CreateNotificationInput {
Expand Down Expand Up @@ -164,6 +165,7 @@ export class InternalNotificationContext {
commentID: comment.id,
commentStatus: comment.status,
rejectionReason: rejectionReason?.code ?? undefined,
customReason: rejectionReason?.customReason ?? undefined,
decisionDetails: {
explanation: rejectionReason?.detailedExplanation ?? undefined,
},
Expand Down
5 changes: 4 additions & 1 deletion server/src/core/server/stacks/rejectComment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,10 @@ const rejectComment = async (
});
}

if (sendNotification) {
if (
sendNotification &&
!(reason?.code === GQLREJECTION_REASON_CODE.BANNED_WORD)
) {
await notifications.create(tenant.id, tenant.locale, {
targetUserID: result.after.authorID!,
comment: result.after,
Expand Down

0 comments on commit 4916033

Please sign in to comment.