From c2426eb40cb60f397b92bb45eeeb7904937d104f Mon Sep 17 00:00:00 2001 From: Tom Moor Date: Mon, 19 Oct 2026 09:21:20 -0400 Subject: [PATCH] fix: Allow every mention notification to be turned off and unsubscribed - The Mentioned and Group mentions settings now control both the document and comment event types. - Mention, share, collection invite, and access request emails now have an unsubscribe link and List-Unsubscribe header. --- app/scenes/Settings/Notifications.tsx | 70 ++++++---- .../templates/CollectionSharedEmail.tsx | 16 ++- .../templates/DocumentAccessRequestEmail.tsx | 16 +++ .../templates/DocumentMentionedEmail.tsx | 16 ++- .../emails/templates/DocumentSharedEmail.tsx | 16 ++- .../templates/GroupDocumentMentionedEmail.tsx | 17 ++- .../templates/NotificationEmails.test.ts | 126 ++++++++++++++++++ server/queues/processors/EmailsProcessor.ts | 2 + 8 files changed, 247 insertions(+), 32 deletions(-) create mode 100644 server/emails/templates/NotificationEmails.test.ts diff --git a/app/scenes/Settings/Notifications.tsx b/app/scenes/Settings/Notifications.tsx index 0ffabbe29f..b55b658207 100644 --- a/app/scenes/Settings/Notifications.tsx +++ b/app/scenes/Settings/Notifications.tsx @@ -36,7 +36,7 @@ function Notifications() { const options = [ { - event: NotificationEventType.PublishDocument, + events: [NotificationEventType.PublishDocument], icon: , title: t("Document published"), description: t( @@ -44,7 +44,7 @@ function Notifications() { ), }, { - event: NotificationEventType.UpdateDocument, + events: [NotificationEventType.UpdateDocument], icon: , title: t("Document updated"), description: t( @@ -52,7 +52,7 @@ function Notifications() { ), }, { - event: NotificationEventType.CreateComment, + events: [NotificationEventType.CreateComment], icon: , title: t("Comment posted"), description: t( @@ -60,7 +60,10 @@ function Notifications() { ), }, { - event: NotificationEventType.MentionedInComment, + events: [ + NotificationEventType.MentionedInComment, + NotificationEventType.MentionedInDocument, + ], icon: , title: t("Mentioned"), description: t( @@ -68,7 +71,10 @@ function Notifications() { ), }, { - event: NotificationEventType.GroupMentionedInDocument, + events: [ + NotificationEventType.GroupMentionedInDocument, + NotificationEventType.GroupMentionedInComment, + ], icon: , title: t("Group mentions"), description: t( @@ -76,7 +82,7 @@ function Notifications() { ), }, { - event: NotificationEventType.ResolveComment, + events: [NotificationEventType.ResolveComment], icon: , title: t("Resolved"), description: t( @@ -84,7 +90,7 @@ function Notifications() { ), }, { - event: NotificationEventType.ReactionsCreate, + events: [NotificationEventType.ReactionsCreate], icon: , title: t("Reaction added"), description: t( @@ -92,7 +98,7 @@ function Notifications() { ), }, { - event: NotificationEventType.CreateCollection, + events: [NotificationEventType.CreateCollection], icon: , title: t("Collection created"), description: t( @@ -100,7 +106,7 @@ function Notifications() { ), }, { - event: NotificationEventType.InviteAccepted, + events: [NotificationEventType.InviteAccepted], icon: , title: t("Invite accepted"), description: t( @@ -108,7 +114,7 @@ function Notifications() { ), }, { - event: NotificationEventType.AddUserToDocument, + events: [NotificationEventType.AddUserToDocument], icon: , title: t("Invited to document"), description: t( @@ -116,7 +122,7 @@ function Notifications() { ), }, { - event: NotificationEventType.AddUserToCollection, + events: [NotificationEventType.AddUserToCollection], icon: , title: t("Invited to collection"), description: t( @@ -124,7 +130,7 @@ function Notifications() { ), }, { - event: NotificationEventType.AddUserToGroup, + events: [NotificationEventType.AddUserToGroup], icon: , title: t("Group membership"), description: t( @@ -132,7 +138,7 @@ function Notifications() { ), }, { - event: NotificationEventType.ExportCompleted, + events: [NotificationEventType.ExportCompleted], icon: , title: t("Export completed"), description: t( @@ -140,7 +146,7 @@ function Notifications() { ), }, { - event: NotificationEventType.RequestDocumentAccess, + events: [NotificationEventType.RequestDocumentAccess], icon: , title: t("Document access requested"), description: t( @@ -150,14 +156,14 @@ function Notifications() { { visible: isCloudHosted, icon: , - event: NotificationEventType.Onboarding, + events: [NotificationEventType.Onboarding], title: t("Getting started"), description: t("Tips on getting started with features and functionality"), }, { visible: isCloudHosted, icon: , - event: NotificationEventType.Features, + events: [NotificationEventType.Features], title: t("New features"), description: t("Receive an email when new features of note are added"), }, @@ -170,8 +176,11 @@ function Notifications() { }, 500); const handleChange = React.useCallback( - (eventType: NotificationEventType) => async (checked: boolean) => { - await user.setNotificationEventType(eventType, checked); + (eventTypes: NotificationEventType[]) => async (checked: boolean) => { + // Sequential, as each request saves the full settings object. + for (const eventType of eventTypes) { + await user.setNotificationEventType(eventType, checked); + } showSuccessMessage(); }, [user, showSuccessMessage] @@ -182,7 +191,9 @@ function Notifications() { runInAction(() => { const updated = { ...user.notificationSettings }; for (const option of visibleOptions) { - updated[option.event] = checked; + for (const eventType of option.events) { + updated[eventType] = checked; + } } user.notificationSettings = updated; }); @@ -197,7 +208,7 @@ function Notifications() { ); const allEnabled = visibleOptions.every((o) => - user.subscribedToEventType(o.event) + o.events.every((eventType) => user.subscribedToEventType(eventType)) ); const showSuccessNotice = window.location.search === "?success"; @@ -231,14 +242,17 @@ function Notifications() { {options.map((option) => { - const setting = user.subscribedToEventType(option.event); + const [name] = option.events; + const checked = option.events.every((eventType) => + user.subscribedToEventType(eventType) + ); return ( {option.description} @@ -247,11 +261,11 @@ function Notifications() { compact > ); diff --git a/server/emails/templates/CollectionSharedEmail.tsx b/server/emails/templates/CollectionSharedEmail.tsx index 22b4e2ad8d..02457190f1 100644 --- a/server/emails/templates/CollectionSharedEmail.tsx +++ b/server/emails/templates/CollectionSharedEmail.tsx @@ -1,11 +1,13 @@ import * as React from "react"; -import { CollectionPermission } from "@shared/types"; +import { CollectionPermission, NotificationEventType } from "@shared/types"; import { Collection, UserMembership } from "@server/models"; +import NotificationSettingsHelper from "@server/models/helpers/NotificationSettingsHelper"; import type { EmailProps } from "./BaseEmail"; import BaseEmail, { EmailMessageCategory } from "./BaseEmail"; import Body from "./components/Body"; import Button from "./components/Button"; import EmailTemplate from "./components/EmailLayout"; +import Footer from "./components/Footer"; import Header from "./components/Header"; import Heading from "./components/Heading"; @@ -53,6 +55,13 @@ export default class CollectionSharedEmail extends BaseEmail< return { collection, membership }; } + protected unsubscribeUrl({ userId }: InputProps) { + return NotificationSettingsHelper.unsubscribeUrl( + userId, + NotificationEventType.AddUserToCollection + ); + } + protected subject({ actorName, collection }: Props) { return this.t( "{{ actorName }} invited you to the “{{ collectionName }}” collection", @@ -111,6 +120,11 @@ ${this.t("View Collection")}: ${teamUrl}${collection.path}

+ +