diff --git a/backend/src/db/migrations/20250405030454-email-notification-settings.ts b/backend/src/db/migrations/20250405030454-email-notification-settings.ts index ad4865240..865d2f5ed 100644 --- a/backend/src/db/migrations/20250405030454-email-notification-settings.ts +++ b/backend/src/db/migrations/20250405030454-email-notification-settings.ts @@ -1,4 +1,4 @@ -import { getDriver } from '../../db/neo4j' +import { getDriver } from '../neo4j' export const description = 'Transforms the `sendNotificationEmails` property on User to a multi value system' @@ -14,6 +14,7 @@ export async function up(next) { MATCH (user:User) SET user.emailNotificationsCommentOnObservedPost = user.sendNotificationEmails SET user.emailNotificationsMention = user.sendNotificationEmails + SET user.emailNotificationsChatMessage = user.sendNotificationEmails SET user.emailNotificationsGroupMemberJoined = user.sendNotificationEmails SET user.emailNotificationsGroupMemberLeft = user.sendNotificationEmails SET user.emailNotificationsGroupMemberRemoved = user.sendNotificationEmails @@ -46,6 +47,7 @@ export async function down(next) { SET user.sendNotificationEmails = true REMOVE user.emailNotificationsCommentOnObservedPost REMOVE user.emailNotificationsMention + REMOVE user.emailNotificationsChatMessage REMOVE user.emailNotificationsGroupMemberJoined REMOVE user.emailNotificationsGroupMemberLeft REMOVE user.emailNotificationsGroupMemberRemoved diff --git a/backend/src/middleware/notifications/notificationsMiddleware.ts b/backend/src/middleware/notifications/notificationsMiddleware.ts index deca37bf7..10b26c3c3 100644 --- a/backend/src/middleware/notifications/notificationsMiddleware.ts +++ b/backend/src/middleware/notifications/notificationsMiddleware.ts @@ -44,7 +44,6 @@ const publishNotifications = async (context, promises, emailNotificationSetting: notifications.forEach((notificationAdded, index) => { pubsub.publish(NOTIFICATION_ADDED, { notificationAdded }) if (notificationAdded.to[emailNotificationSetting] ?? true) { - // Default to true sendMail( notificationTemplate({ email: notificationsEmailAddresses[index].email, @@ -356,7 +355,7 @@ const handleCreateMessage = async (resolve, root, args, context, resolveInfo) => MATCH (room)<-[:CHATS_IN]-(recipientUser:User)-[:PRIMARY_EMAIL]->(emailAddress:EmailAddress) WHERE NOT recipientUser.id = $currentUserId AND NOT (recipientUser)-[:BLOCKED]-(currentUser) - AND recipientUser.sendNotificationEmails = true + AND NOT recipientUser.emailNotificationsChatMessage = false RETURN recipientUser, emailAddress {.email} ` const txResponse = await transaction.run(messageRecipientCypher, { diff --git a/backend/src/models/User.ts b/backend/src/models/User.ts index b1da09f0d..e3f2797ec 100644 --- a/backend/src/models/User.ts +++ b/backend/src/models/User.ts @@ -165,6 +165,10 @@ export default { type: 'boolean', default: true, }, + emailNotificationsChatMessage: { + type: 'boolean', + default: true, + }, emailNotificationsGroupMemberJoined: { type: 'boolean', default: true, diff --git a/backend/src/schema/resolvers/users.spec.ts b/backend/src/schema/resolvers/users.spec.ts index fed78016a..b746283b7 100644 --- a/backend/src/schema/resolvers/users.spec.ts +++ b/backend/src/schema/resolvers/users.spec.ts @@ -676,6 +676,15 @@ describe('emailNotificationSettings', () => { }, ], }, + { + type: 'chat', + settings: [ + { + name: 'chatMessage', + value: true, + }, + ], + }, { type: 'group', settings: [ diff --git a/backend/src/schema/resolvers/users.ts b/backend/src/schema/resolvers/users.ts index 31d79c43f..8ad00b5ce 100644 --- a/backend/src/schema/resolvers/users.ts +++ b/backend/src/schema/resolvers/users.ts @@ -160,8 +160,7 @@ export default { const allowedSettingNames = [ 'commentOnObservedPost', 'mention', - 'postByFollowedUser', - 'postInGroup', + 'chatMessage', 'groupMemberJoined', 'groupMemberLeft', 'groupMemberRemoved', @@ -396,6 +395,15 @@ export default { }, ], }, + { + type: 'chat', + settings: [ + { + name: 'chatMessage', + value: parent.emailNotificationsChatMessage ?? true, + }, + ], + }, { type: 'group', settings: [