Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: reject reason on notification #2485

Merged
merged 6 commits into from
Nov 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion __tests__/notifications/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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;
Expand Down
30 changes: 29 additions & 1 deletion src/entity/SourcePostModeration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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, string> = {
[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'])
Expand Down Expand Up @@ -58,7 +86,7 @@ export class SourcePostModeration {
moderatorMessage?: string | null;

@Column({ type: 'text', nullable: true })
rejectionReason?: string | null;
rejectionReason?: PostModerationReason | null;

@CreateDateColumn()
createdAt: Date;
Expand Down
9 changes: 7 additions & 2 deletions src/notifications/generate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -135,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: ${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.`,
};
Expand Down
Loading