diff --git a/apps/client/src/features/user/components/notification-pref.tsx b/apps/client/src/features/user/components/notification-pref.tsx index ce2e8291..e8a983ed 100644 --- a/apps/client/src/features/user/components/notification-pref.tsx +++ b/apps/client/src/features/user/components/notification-pref.tsx @@ -2,7 +2,7 @@ import { userAtom } from "@/features/user/atoms/current-user-atom.ts"; import { updateUser } from "@/features/user/services/user-service.ts"; import { IUser, IUserSettings } from "@/features/user/types/user.types.ts"; import { Switch, Text, Title, Stack } from "@mantine/core"; -import { useAtom } from "jotai/index"; +import { useAtom } from "jotai"; import React, { useState } from "react"; import { useTranslation } from "react-i18next"; import { @@ -26,13 +26,13 @@ const notificationItems: { description: "Get notified when pages you watch are updated.", }, { - key: "page.user_mention", + key: "page.userMention", dtoField: "notificationPageUserMention", label: "Page mentions", description: "Get notified when someone mentions you on a page.", }, { - key: "comment.user_mention", + key: "comment.userMention", dtoField: "notificationCommentUserMention", label: "Comment mentions", description: "Get notified when someone mentions you in a comment.", @@ -41,7 +41,8 @@ const notificationItems: { key: "comment.created", dtoField: "notificationCommentCreated", label: "New comments", - description: "Get notified about new comments on threads you participate in.", + description: + "Get notified about new comments on threads you participate in.", }, { key: "comment.resolved", diff --git a/apps/client/src/features/user/types/user.types.ts b/apps/client/src/features/user/types/user.types.ts index 076ed3d0..75d45bfd 100644 --- a/apps/client/src/features/user/types/user.types.ts +++ b/apps/client/src/features/user/types/user.types.ts @@ -39,11 +39,11 @@ export interface IUserSettings { pageEditMode: string; }; notifications?: { - 'page.updated'?: boolean; - 'page.user_mention'?: boolean; - 'comment.user_mention'?: boolean; - 'comment.created'?: boolean; - 'comment.resolved'?: boolean; + "page.updated"?: boolean; + "page.userMention"?: boolean; + "comment.userMention"?: boolean; + "comment.created"?: boolean; + "comment.resolved"?: boolean; }; } diff --git a/apps/server/src/core/notification/notification.constants.ts b/apps/server/src/core/notification/notification.constants.ts index 96393e47..b619d52f 100644 --- a/apps/server/src/core/notification/notification.constants.ts +++ b/apps/server/src/core/notification/notification.constants.ts @@ -12,7 +12,17 @@ export type NotificationType = export type NotificationSettingKey = | 'page.updated' - | 'page.user_mention' - | 'comment.user_mention' + | 'page.userMention' + | 'comment.userMention' | 'comment.created' | 'comment.resolved'; + +export const NotificationTypeToSettingKey: Partial< + Record +> = { + [NotificationType.PAGE_UPDATED]: 'page.updated', + [NotificationType.PAGE_USER_MENTION]: 'page.userMention', + [NotificationType.COMMENT_USER_MENTION]: 'comment.userMention', + [NotificationType.COMMENT_CREATED]: 'comment.created', + [NotificationType.COMMENT_RESOLVED]: 'comment.resolved', +}; diff --git a/apps/server/src/core/notification/notification.service.ts b/apps/server/src/core/notification/notification.service.ts index 8aa7d4d3..6ea1cbda 100644 --- a/apps/server/src/core/notification/notification.service.ts +++ b/apps/server/src/core/notification/notification.service.ts @@ -6,7 +6,7 @@ import { InsertableNotification } from '@docmost/db/types/entity.types'; import { PaginationOptions } from '@docmost/db/pagination/pagination-options'; import { WsGateway } from '../../ws/ws.gateway'; import { MailService } from '../../integrations/mail/mail.service'; -import { NotificationType } from './notification.constants'; +import { NotificationType, NotificationTypeToSettingKey } from './notification.constants'; @Injectable() export class NotificationService { @@ -78,8 +78,11 @@ export class NotificationService { if (!user?.email) return; if (type) { - const settings = user.settings as any; - if (settings?.notifications?.[type] === false) return; + const settingKey = NotificationTypeToSettingKey[type]; + if (settingKey) { + const settings = user.settings as any; + if (settings?.notifications?.[settingKey] === false) return; + } } await this.mailService.sendToQueue({ diff --git a/apps/server/src/core/user/user.service.ts b/apps/server/src/core/user/user.service.ts index 771c48d6..fa229827 100644 --- a/apps/server/src/core/user/user.service.ts +++ b/apps/server/src/core/user/user.service.ts @@ -63,8 +63,8 @@ export class UserService { const notificationSettings: Record = { notificationPageUpdates: 'page.updated', - notificationPageUserMention: 'page.user_mention', - notificationCommentUserMention: 'comment.user_mention', + notificationPageUserMention: 'page.userMention', + notificationCommentUserMention: 'comment.userMention', notificationCommentCreated: 'comment.created', notificationCommentResolved: 'comment.resolved', };