Skip to content

Commit

Permalink
persist notification type on documents
Browse files Browse the repository at this point in the history
useful for filtering and searching in mongo later
  • Loading branch information
nick-funk committed Nov 14, 2023
1 parent fad3f77 commit d0cbc39
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 22 deletions.
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
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
6 changes: 2 additions & 4 deletions server/src/core/server/services/dsaReports/reports.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand All @@ -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 {
Expand Down
24 changes: 16 additions & 8 deletions server/src/core/server/services/notifications/internal/context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand All @@ -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;
Expand Down Expand Up @@ -93,6 +86,7 @@ export class InternalNotificationContext {
result.notification = await this.createFeatureCommentNotification(
lang,
tenantID,
type,
targetUserID,
comment,
now
Expand All @@ -102,6 +96,7 @@ export class InternalNotificationContext {
result.notification = await this.createApproveCommentNotification(
lang,
tenantID,
type,
targetUserID,
comment,
now
Expand All @@ -111,6 +106,7 @@ export class InternalNotificationContext {
result.notification = await this.createRejectCommentNotification(
lang,
tenantID,
type,
targetUserID,
comment,
rejectionReason,
Expand All @@ -121,6 +117,7 @@ export class InternalNotificationContext {
result.notification = await this.createIllegalRejectionNotification(
lang,
tenantID,
type,
targetUserID,
comment,
legal,
Expand All @@ -135,6 +132,7 @@ export class InternalNotificationContext {
result.notification = await this.createDSAReportDecisionMadeNotification(
lang,
tenantID,
type,
targetUserID,
comment,
report,
Expand All @@ -152,6 +150,7 @@ export class InternalNotificationContext {
private async createRejectCommentNotification(
lang: LanguageCode,
tenantID: string,
type: NotificationType,
targetUserID: string,
comment: Readonly<Comment>,
rejectionReason?: RejectionReasonInput | null,
Expand Down Expand Up @@ -218,6 +217,7 @@ export class InternalNotificationContext {
const notification = await createNotification(this.mongo, {
id: uuid(),
tenantID,
type,
createdAt: now,
ownerID: targetUserID,
title: this.translatePhrase(
Expand All @@ -236,13 +236,15 @@ export class InternalNotificationContext {
private async createFeatureCommentNotification(
lang: LanguageCode,
tenantID: string,
type: NotificationType,
targetUserID: string,
comment: Readonly<Comment>,
now: Date
) {
const notification = await createNotification(this.mongo, {
id: uuid(),
tenantID,
type,
createdAt: now,
ownerID: targetUserID,
title: this.translatePhrase(
Expand All @@ -268,13 +270,15 @@ export class InternalNotificationContext {
private async createApproveCommentNotification(
lang: LanguageCode,
tenantID: string,
type: NotificationType,
targetUserID: string,
comment: Readonly<Comment>,
now: Date
) {
const notification = await createNotification(this.mongo, {
id: uuid(),
tenantID,
type,
createdAt: now,
ownerID: targetUserID,
title: this.translatePhrase(
Expand All @@ -300,6 +304,7 @@ export class InternalNotificationContext {
private async createIllegalRejectionNotification(
lang: LanguageCode,
tenantID: string,
type: NotificationType,
targetUserID: string,
comment: Readonly<Comment>,
legal: DSALegality | undefined,
Expand Down Expand Up @@ -339,6 +344,7 @@ export class InternalNotificationContext {
const notification = await createNotification(this.mongo, {
id: uuid(),
tenantID,
type,
createdAt: now,
ownerID: targetUserID,
title: this.translatePhrase(
Expand All @@ -357,6 +363,7 @@ export class InternalNotificationContext {
private async createDSAReportDecisionMadeNotification(
lang: LanguageCode,
tenantID: string,
type: NotificationType,
targetUserID: string,
comment: Readonly<Comment>,
report: Readonly<DSAReport>,
Expand Down Expand Up @@ -432,6 +439,7 @@ export class InternalNotificationContext {
const notification = await createNotification(this.mongo, {
id: uuid(),
tenantID,
type,
createdAt: now,
ownerID: targetUserID,
title: this.translatePhrase(
Expand Down
6 changes: 2 additions & 4 deletions server/src/core/server/stacks/approveComment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down
6 changes: 2 additions & 4 deletions server/src/core/server/stacks/rejectComment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down

0 comments on commit d0cbc39

Please sign in to comment.