From d78e34c770a2d2a17b5bb7eeda6b6cfeaa96307c Mon Sep 17 00:00:00 2001 From: Lee Hansel Solevilla Date: Mon, 25 Nov 2024 14:14:54 +0800 Subject: [PATCH 1/3] fix: reject reason on notification --- src/entity/SourcePostModeration.ts | 30 +++++++++++++++++++++++++++++- src/notifications/generate.ts | 3 ++- 2 files changed, 31 insertions(+), 2 deletions(-) diff --git a/src/entity/SourcePostModeration.ts b/src/entity/SourcePostModeration.ts index 1f66b789f..c6cb7554a 100644 --- a/src/entity/SourcePostModeration.ts +++ b/src/entity/SourcePostModeration.ts @@ -17,6 +17,34 @@ export enum SourcePostModerationStatus { Pending = 'pending', } +export enum PostModerationReason { + OffTopic = 'OFF_TOPIC', + Violation = 'VIOLATION', + Promotional = 'PROMOTIONAL', + Duplicate = 'DUPLICATE', + LowQuality = 'LOW_QUALITY', + NSFW = 'NSFW', + Spam = 'SPAM', + Misinformation = 'MISINFORMATION', + Copyright = 'COPYRIGHT', + Other = 'OTHER', +} + +export const rejectReason: Record = { + [PostModerationReason.OffTopic]: 'Off-topic post unrelated to the Squad', + [PostModerationReason.Violation]: 'Violates the Squad’s code of conduct', + [PostModerationReason.Promotional]: 'Too promotional without adding value', + [PostModerationReason.Duplicate]: + 'Duplicate or similar content already posted', + [PostModerationReason.LowQuality]: 'Lacks quality or clarity', + [PostModerationReason.NSFW]: 'Inappropriate, NSFW or offensive post', + [PostModerationReason.Spam]: 'Post is spam or scam', + [PostModerationReason.Misinformation]: + 'Contains misleading or false information', + [PostModerationReason.Copyright]: 'Copyright or privacy violation', + [PostModerationReason.Other]: 'Other', +}; + @Entity() @Index(['sourceId']) @Index(['sourceId', 'createdById']) @@ -58,7 +86,7 @@ export class SourcePostModeration { moderatorMessage?: string | null; @Column({ type: 'text', nullable: true }) - rejectionReason?: string | null; + rejectionReason?: PostModerationReason | null; @CreateDateColumn() createdAt: Date; diff --git a/src/notifications/generate.ts b/src/notifications/generate.ts index 43b9cf874..82dd774f2 100644 --- a/src/notifications/generate.ts +++ b/src/notifications/generate.ts @@ -31,6 +31,7 @@ import { UPVOTE_TITLES } from '../workers/notifications/utils'; import { checkHasMention } from '../common/markdown'; import { NotificationType } from './common'; import { format } from 'date-fns'; +import { rejectReason } from '../entity/SourcePostModeration'; const systemTitle = () => undefined; @@ -136,7 +137,7 @@ export const notificationTitleMap: Record< source_post_approved: (ctx: NotificationPostContext) => `Woohoo! Your post has been approved and is now live in ${ctx.source.name}. Check it out!`, source_post_rejected: (ctx: NotificationPostModerationContext) => - `Your post in ${ctx.source.name} was not approved for the following reason: ${ctx.post.rejectionReason}. Please review the feedback and consider making changes before resubmitting.`, + `Your post in ${ctx.source.name} was not approved for the following reason: ${rejectReason[ctx.post.rejectionReason!]}. Please review the feedback and consider making changes before resubmitting.`, source_post_submitted: (ctx: NotificationPostModerationContext) => `${ctx.user.name} just posted in ${ctx.source.name}. This post is waiting for your review before it gets published on the squad.`, }; From cb9d9c085d832bd8d6ae609d5931cfbba5f1a3e8 Mon Sep 17 00:00:00 2001 From: Lee Hansel Solevilla Date: Mon, 25 Nov 2024 14:27:09 +0800 Subject: [PATCH 2/3] test: notification for rejection reason mapping --- __tests__/notifications/index.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/__tests__/notifications/index.ts b/__tests__/notifications/index.ts index 5b48fc7c0..0bd6b2bbc 100644 --- a/__tests__/notifications/index.ts +++ b/__tests__/notifications/index.ts @@ -59,6 +59,7 @@ import { NotificationType } from '../../src/notifications/common'; import { format } from 'date-fns'; import { saveFixtures } from '../helpers'; import { + PostModerationReason, SourcePostModeration, SourcePostModerationStatus, } from '../../src/entity/SourcePostModeration'; @@ -1324,7 +1325,7 @@ describe('storeNotificationBundle', () => { sourceId: 'a', createdById: '2', status: SourcePostModerationStatus.Rejected, - rejectionReason: 'Other', + rejectionReason: PostModerationReason.Other, moderatorMessage: 'Lacks value.', }); const type = NotificationType.SourcePostRejected; From f782e8692708d2ce56f58117cf66cefe910163f3 Mon Sep 17 00:00:00 2001 From: Lee Hansel Solevilla Date: Mon, 25 Nov 2024 17:46:30 +0800 Subject: [PATCH 3/3] fix: fallback value --- src/notifications/generate.ts | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/notifications/generate.ts b/src/notifications/generate.ts index 82dd774f2..1faa50444 100644 --- a/src/notifications/generate.ts +++ b/src/notifications/generate.ts @@ -136,8 +136,12 @@ export const notificationTitleMap: Record< }, source_post_approved: (ctx: NotificationPostContext) => `Woohoo! Your post has been approved and is now live in ${ctx.source.name}. Check it out!`, - source_post_rejected: (ctx: NotificationPostModerationContext) => - `Your post in ${ctx.source.name} was not approved for the following reason: ${rejectReason[ctx.post.rejectionReason!]}. Please review the feedback and consider making changes before resubmitting.`, + source_post_rejected: (ctx: NotificationPostModerationContext) => { + const reason = ctx.post.rejectionReason + ? rejectReason[ctx.post.rejectionReason] + : rejectReason.OTHER; + return `Your post in ${ctx.source.name} was not approved for the following reason: ${reason}. Please review the feedback and consider making changes before resubmitting.`; + }, source_post_submitted: (ctx: NotificationPostModerationContext) => `${ctx.user.name} just posted in ${ctx.source.name}. This post is waiting for your review before it gets published on the squad.`, };