This commit is contained in:
Philipinho
2026-03-31 01:23:14 +01:00
parent d034fce11b
commit bd42dec6be
5 changed files with 30 additions and 16 deletions
@@ -2,7 +2,7 @@ import { userAtom } from "@/features/user/atoms/current-user-atom.ts";
import { updateUser } from "@/features/user/services/user-service.ts"; import { updateUser } from "@/features/user/services/user-service.ts";
import { IUser, IUserSettings } from "@/features/user/types/user.types.ts"; import { IUser, IUserSettings } from "@/features/user/types/user.types.ts";
import { Switch, Text, Title, Stack } from "@mantine/core"; import { Switch, Text, Title, Stack } from "@mantine/core";
import { useAtom } from "jotai/index"; import { useAtom } from "jotai";
import React, { useState } from "react"; import React, { useState } from "react";
import { useTranslation } from "react-i18next"; import { useTranslation } from "react-i18next";
import { import {
@@ -26,13 +26,13 @@ const notificationItems: {
description: "Get notified when pages you watch are updated.", description: "Get notified when pages you watch are updated.",
}, },
{ {
key: "page.user_mention", key: "page.userMention",
dtoField: "notificationPageUserMention", dtoField: "notificationPageUserMention",
label: "Page mentions", label: "Page mentions",
description: "Get notified when someone mentions you on a page.", description: "Get notified when someone mentions you on a page.",
}, },
{ {
key: "comment.user_mention", key: "comment.userMention",
dtoField: "notificationCommentUserMention", dtoField: "notificationCommentUserMention",
label: "Comment mentions", label: "Comment mentions",
description: "Get notified when someone mentions you in a comment.", description: "Get notified when someone mentions you in a comment.",
@@ -41,7 +41,8 @@ const notificationItems: {
key: "comment.created", key: "comment.created",
dtoField: "notificationCommentCreated", dtoField: "notificationCommentCreated",
label: "New comments", 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", key: "comment.resolved",
@@ -39,11 +39,11 @@ export interface IUserSettings {
pageEditMode: string; pageEditMode: string;
}; };
notifications?: { notifications?: {
'page.updated'?: boolean; "page.updated"?: boolean;
'page.user_mention'?: boolean; "page.userMention"?: boolean;
'comment.user_mention'?: boolean; "comment.userMention"?: boolean;
'comment.created'?: boolean; "comment.created"?: boolean;
'comment.resolved'?: boolean; "comment.resolved"?: boolean;
}; };
} }
@@ -12,7 +12,17 @@ export type NotificationType =
export type NotificationSettingKey = export type NotificationSettingKey =
| 'page.updated' | 'page.updated'
| 'page.user_mention' | 'page.userMention'
| 'comment.user_mention' | 'comment.userMention'
| 'comment.created' | 'comment.created'
| 'comment.resolved'; | 'comment.resolved';
export const NotificationTypeToSettingKey: Partial<
Record<NotificationType, NotificationSettingKey>
> = {
[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',
};
@@ -6,7 +6,7 @@ import { InsertableNotification } from '@docmost/db/types/entity.types';
import { PaginationOptions } from '@docmost/db/pagination/pagination-options'; import { PaginationOptions } from '@docmost/db/pagination/pagination-options';
import { WsGateway } from '../../ws/ws.gateway'; import { WsGateway } from '../../ws/ws.gateway';
import { MailService } from '../../integrations/mail/mail.service'; import { MailService } from '../../integrations/mail/mail.service';
import { NotificationType } from './notification.constants'; import { NotificationType, NotificationTypeToSettingKey } from './notification.constants';
@Injectable() @Injectable()
export class NotificationService { export class NotificationService {
@@ -78,8 +78,11 @@ export class NotificationService {
if (!user?.email) return; if (!user?.email) return;
if (type) { if (type) {
const settings = user.settings as any; const settingKey = NotificationTypeToSettingKey[type];
if (settings?.notifications?.[type] === false) return; if (settingKey) {
const settings = user.settings as any;
if (settings?.notifications?.[settingKey] === false) return;
}
} }
await this.mailService.sendToQueue({ await this.mailService.sendToQueue({
+2 -2
View File
@@ -63,8 +63,8 @@ export class UserService {
const notificationSettings: Record<string, NotificationSettingKey> = { const notificationSettings: Record<string, NotificationSettingKey> = {
notificationPageUpdates: 'page.updated', notificationPageUpdates: 'page.updated',
notificationPageUserMention: 'page.user_mention', notificationPageUserMention: 'page.userMention',
notificationCommentUserMention: 'comment.user_mention', notificationCommentUserMention: 'comment.userMention',
notificationCommentCreated: 'comment.created', notificationCommentCreated: 'comment.created',
notificationCommentResolved: 'comment.resolved', notificationCommentResolved: 'comment.resolved',
}; };