diff --git a/server/src/core/server/graph/mutators/Comments.ts b/server/src/core/server/graph/mutators/Comments.ts index 1cec81a7b5..d26957182a 100644 --- a/server/src/core/server/graph/mutators/Comments.ts +++ b/server/src/core/server/graph/mutators/Comments.ts @@ -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, @@ -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, diff --git a/server/src/core/server/models/notifications/notification.ts b/server/src/core/server/models/notifications/notification.ts index f3e40d4f0f..45c546842c 100644 --- a/server/src/core/server/models/notifications/notification.ts +++ b/server/src/core/server/models/notifications/notification.ts @@ -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; diff --git a/server/src/core/server/services/dsaReports/reports.ts b/server/src/core/server/services/dsaReports/reports.ts index 76ccfea773..9b41a48bbe 100644 --- a/server/src/core/server/services/dsaReports/reports.ts +++ b/server/src/core/server/services/dsaReports/reports.ts @@ -12,6 +12,7 @@ import { 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"; @@ -23,10 +24,7 @@ import { } from "coral-server/graph/schema/__generated__/types"; import { I18n } from "../i18n"; -import { - InternalNotificationContext, - NotificationType, -} from "../notifications/internal/context"; +import { InternalNotificationContext } from "../notifications/internal/context"; import { AugmentedRedis } from "../redis"; export interface CreateDSAReportInput { diff --git a/server/src/core/server/services/notifications/internal/context.ts b/server/src/core/server/services/notifications/internal/context.ts index 49f0ef7f51..0497d5a894 100644 --- a/server/src/core/server/services/notifications/internal/context.ts +++ b/server/src/core/server/services/notifications/internal/context.ts @@ -8,6 +8,7 @@ import { DSAReport } from "coral-server/models/dsaReport/report"; import { createNotification, Notification, + NotificationType, } from "coral-server/models/notifications/notification"; import { retrieveUser } from "coral-server/models/user"; import { I18n, translate } from "coral-server/services/i18n"; @@ -17,14 +18,6 @@ import { GQLREJECTION_REASON_CODE, } from "coral-server/graph/schema/__generated__/types"; -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 DSALegality { legality: GQLDSAReportDecisionLegality; grounds?: string; @@ -93,6 +86,7 @@ export class InternalNotificationContext { result.notification = await this.createFeatureCommentNotification( lang, tenantID, + type, targetUserID, comment, now @@ -102,6 +96,7 @@ export class InternalNotificationContext { result.notification = await this.createApproveCommentNotification( lang, tenantID, + type, targetUserID, comment, now @@ -111,6 +106,7 @@ export class InternalNotificationContext { result.notification = await this.createRejectCommentNotification( lang, tenantID, + type, targetUserID, comment, rejectionReason, @@ -121,6 +117,7 @@ export class InternalNotificationContext { result.notification = await this.createIllegalRejectionNotification( lang, tenantID, + type, targetUserID, comment, legal, @@ -135,6 +132,7 @@ export class InternalNotificationContext { result.notification = await this.createDSAReportDecisionMadeNotification( lang, tenantID, + type, targetUserID, comment, report, @@ -152,6 +150,7 @@ export class InternalNotificationContext { private async createRejectCommentNotification( lang: LanguageCode, tenantID: string, + type: NotificationType, targetUserID: string, comment: Readonly, rejectionReason?: RejectionReasonInput | null, @@ -218,6 +217,7 @@ export class InternalNotificationContext { const notification = await createNotification(this.mongo, { id: uuid(), tenantID, + type, createdAt: now, ownerID: targetUserID, title: this.translatePhrase( @@ -236,6 +236,7 @@ export class InternalNotificationContext { private async createFeatureCommentNotification( lang: LanguageCode, tenantID: string, + type: NotificationType, targetUserID: string, comment: Readonly, now: Date @@ -243,6 +244,7 @@ export class InternalNotificationContext { const notification = await createNotification(this.mongo, { id: uuid(), tenantID, + type, createdAt: now, ownerID: targetUserID, title: this.translatePhrase( @@ -268,6 +270,7 @@ export class InternalNotificationContext { private async createApproveCommentNotification( lang: LanguageCode, tenantID: string, + type: NotificationType, targetUserID: string, comment: Readonly, now: Date @@ -275,6 +278,7 @@ export class InternalNotificationContext { const notification = await createNotification(this.mongo, { id: uuid(), tenantID, + type, createdAt: now, ownerID: targetUserID, title: this.translatePhrase( @@ -300,6 +304,7 @@ export class InternalNotificationContext { private async createIllegalRejectionNotification( lang: LanguageCode, tenantID: string, + type: NotificationType, targetUserID: string, comment: Readonly, legal: DSALegality | undefined, @@ -339,6 +344,7 @@ export class InternalNotificationContext { const notification = await createNotification(this.mongo, { id: uuid(), tenantID, + type, createdAt: now, ownerID: targetUserID, title: this.translatePhrase( @@ -357,6 +363,7 @@ export class InternalNotificationContext { private async createDSAReportDecisionMadeNotification( lang: LanguageCode, tenantID: string, + type: NotificationType, targetUserID: string, comment: Readonly, report: Readonly, @@ -432,6 +439,7 @@ export class InternalNotificationContext { const notification = await createNotification(this.mongo, { id: uuid(), tenantID, + type, createdAt: now, ownerID: targetUserID, title: this.translatePhrase( diff --git a/server/src/core/server/stacks/approveComment.ts b/server/src/core/server/stacks/approveComment.ts index f67f78f987..2ddc437dfe 100644 --- a/server/src/core/server/stacks/approveComment.ts +++ b/server/src/core/server/stacks/approveComment.ts @@ -3,13 +3,11 @@ import { DataCache } from "coral-server/data/cache/dataCache"; import { MongoContext } from "coral-server/data/context"; import { CoralEventPublisherBroker } from "coral-server/events/publisher"; import { getLatestRevision } from "coral-server/models/comment"; +import { NotificationType } from "coral-server/models/notifications/notification"; import { Tenant } from "coral-server/models/tenant"; import { moderate } from "coral-server/services/comments/moderation"; import { I18n } from "coral-server/services/i18n"; -import { - InternalNotificationContext, - NotificationType, -} from "coral-server/services/notifications/internal/context"; +import { InternalNotificationContext } from "coral-server/services/notifications/internal/context"; import { AugmentedRedis } from "coral-server/services/redis"; import { submitCommentAsNotSpam } from "coral-server/services/spam"; import { Request } from "coral-server/types/express"; diff --git a/server/src/core/server/stacks/rejectComment.ts b/server/src/core/server/stacks/rejectComment.ts index bfa2abafc3..3f54dad584 100644 --- a/server/src/core/server/stacks/rejectComment.ts +++ b/server/src/core/server/stacks/rejectComment.ts @@ -8,14 +8,12 @@ import { hasTag, UpdateCommentStatus, } from "coral-server/models/comment"; +import { NotificationType } from "coral-server/models/notifications/notification"; import { Tenant } from "coral-server/models/tenant"; import { removeTag } from "coral-server/services/comments"; import { moderate } from "coral-server/services/comments/moderation"; import { I18n } from "coral-server/services/i18n"; -import { - InternalNotificationContext, - NotificationType, -} from "coral-server/services/notifications/internal/context"; +import { InternalNotificationContext } from "coral-server/services/notifications/internal/context"; import { AugmentedRedis } from "coral-server/services/redis"; import { submitCommentAsSpam } from "coral-server/services/spam"; import { Request } from "coral-server/types/express";