Macro is a unified workspace for teams: email, chat, docs, tasks, agents, calls, and CRM — @-linked together with shared AI memory.
TypeScript agentaiai-agentsall-in-onecrmcrm-systememaillinearmcpmessagingnotesnotionofficerustslackslack-alternativestartupstartup-toolstypescriptworkspace
feat(dss): add more comment notification types (#2170)
Sean Aye6b3dc7a72ff5
diff --git a/flake.lock b/flake.lockindex 2fde8b0494..71e321b4e1 100644--- a/flake.lock+++ b/flake.lock@@ -8,11 +8,11 @@"rust-analyzer-src": "rust-analyzer-src"},"locked": {- "lastModified": 1769670296,- "narHash": "sha256-0OzQzsufPwHUTJMAgVf+TXPFG+8x5xrYwz1/M/kI+7o=",+ "lastModified": 1774423251,+ "narHash": "sha256-g/PP8G9WcP4vtZVOBNYwfGxLnwLQoTERHnef8irAMeQ=","owner": "nix-community","repo": "fenix",- "rev": "b00052920f71c43987b44c804196c083eb0fa1bf",+ "rev": "b70d7535088cd8a9e4322c372a475f66ffa18adf","type": "github"},"original": {@@ -41,11 +41,11 @@},"nixpkgs": {"locked": {- "lastModified": 1769461804,- "narHash": "sha256-msG8SU5WsBUfVVa/9RPLaymvi5bI8edTavbIq3vRlhI=",+ "lastModified": 1774106199,+ "narHash": "sha256-US5Tda2sKmjrg2lNHQL3jRQ6p96cgfWh3J1QBliQ8Ws=","owner": "NixOS","repo": "nixpkgs",- "rev": "bfc1b8a4574108ceef22f02bafcf6611380c100d",+ "rev": "6c9a78c09ff4d6c21d0319114873508a6ec01655","type": "github"},"original": {@@ -65,11 +65,11 @@"rust-analyzer-src": {"flake": false,"locked": {- "lastModified": 1769526882,- "narHash": "sha256-64CZX2vKsfSLKnTCZ0pbc1jPvixWWwuT382g3QHBz5c=",+ "lastModified": 1774376228,+ "narHash": "sha256-7oA0u4aghFjjIcIDKZ26NUpXH7hVXGPC0sI1OfK7NUk=","owner": "rust-lang","repo": "rust-analyzer",- "rev": "40cda2f4bd585c1cb99ae4eb025968b8dc2eec42",+ "rev": "eabb84b771420b8396ab4bb4747694302d9be277","type": "github"},"original": {diff --git a/js/app/packages/core/component/LexicalMarkdown/component/core/LinkWithPreview.tsx b/js/app/packages/core/component/LexicalMarkdown/component/core/LinkWithPreview.tsxindex 7b3c9b9fa6..09dfde93d6 100644--- a/js/app/packages/core/component/LexicalMarkdown/component/core/LinkWithPreview.tsx+++ b/js/app/packages/core/component/LexicalMarkdown/component/core/LinkWithPreview.tsx@@ -40,6 +40,7 @@ export function LinkWithPreview(props: UnfurlLinkProps) {debouncedSetPreviewOpen(false);}}draggable={false}+ rel="noopener">{props.children}</a>diff --git a/js/app/packages/entity/src/extractors-notification/notification-description-helpers.ts b/js/app/packages/entity/src/extractors-notification/notification-description-helpers.tsindex 06b9d80140..d8e2ce2f91 100644--- a/js/app/packages/entity/src/extractors-notification/notification-description-helpers.ts+++ b/js/app/packages/entity/src/extractors-notification/notification-description-helpers.ts@@ -25,6 +25,8 @@ export function getActionVerb(type: NotificationType): string {.with('channel_mention', () => 'mentioned you').with('document_mention', () => 'mentioned you').with('mentioned_in_document_comment', () => 'mentioned you')+ .with('replied_to_document_comment_thread', () => 'replied')+ .with('commented_on_document', () => 'commented').with('channel_message_reply', () => 'replied').with('channel_message_send', () => 'sent a message').with('ai_response', () => 'AI responded')@@ -49,6 +51,10 @@ export function getTypeNoun(type: NotificationType, count: number): string {.with('mentioned_in_document_comment', () =>count === 1 ? 'mention' : 'mentions')+ .with('replied_to_document_comment_thread', () =>+ count === 1 ? 'reply' : 'replies'+ )+ .with('commented_on_document', () => (count === 1 ? 'comment' : 'comments')).with('new_email', () => (count === 1 ? 'email' : 'emails')).with('channel_invite', () => (count === 1 ? 'invite' : 'invites')).with('invite_to_team', () => (count === 1 ? 'invite' : 'invites'))diff --git a/js/app/packages/entity/src/extractors-notification/notification-icon.tsx b/js/app/packages/entity/src/extractors-notification/notification-icon.tsxindex 1b729a74e7..13a7dbd3fd 100644--- a/js/app/packages/entity/src/extractors-notification/notification-icon.tsx+++ b/js/app/packages/entity/src/extractors-notification/notification-icon.tsx@@ -28,6 +28,8 @@ function getNotificationIcon(.with('channel_mention', () => AtIcon).with('document_mention', () => AtIcon).with('mentioned_in_document_comment', () => AtIcon)+ .with('replied_to_document_comment_thread', () => ArrowBendUpLeftIcon)+ .with('commented_on_document', () => ChatIcon).with('channel_message_reply', () => ArrowBendUpLeftIcon).with('channel_message_send', () => ChatIcon).with('new_email', () => EnvelopeIcon)diff --git a/js/app/packages/entity/src/utils/notification.ts b/js/app/packages/entity/src/utils/notification.tsindex a2f91a8560..fc92808f14 100644--- a/js/app/packages/entity/src/utils/notification.ts+++ b/js/app/packages/entity/src/utils/notification.ts@@ -56,6 +56,8 @@ export function getNotificationActionText(n: Notification): string {.with('channel_message_reply', () => 'replied').with('document_mention', () => 'mentioned').with('mentioned_in_document_comment', () => 'mentioned')+ .with('replied_to_document_comment_thread', () => 'replied')+ .with('commented_on_document', () => 'commented').with('channel_invite', () => 'invited').with('new_email', () => 'emailed').with('invite_to_team', () => 'invited')@@ -80,6 +82,11 @@ export function extractMessageContent(notification: Notification): string {).with({ tag: 'document_mention' }, (m) => m.content.documentName || '').with({ tag: 'mentioned_in_document_comment' }, (m) => m.content.text || '')+ .with(+ { tag: 'replied_to_document_comment_thread' },+ (m) => m.content.text || ''+ )+ .with({ tag: 'commented_on_document' }, (m) => m.content.text || '').with({ tag: 'new_email' }, (m) => m.content.subject || '').with({ tag: 'task_assigned' }, (m) => m.content.taskName ?? '').with({ tag: 'ai_response' }, (m) => m.content.summary || '')diff --git a/js/app/packages/notifications/notification-metadata.ts b/js/app/packages/notifications/notification-metadata.tsindex dc7aa11223..c44a7c3912 100644--- a/js/app/packages/notifications/notification-metadata.ts+++ b/js/app/packages/notifications/notification-metadata.ts@@ -8,6 +8,8 @@ export function getNotificationAction(n: UnifiedNotification): string {.with('channel_mention', () => 'mentioned you in').with('document_mention', () => 'sent a document').with('mentioned_in_document_comment', () => 'mentioned you in')+ .with('replied_to_document_comment_thread', () => 'replied in')+ .with('commented_on_document', () => 'commented on').with('channel_message_send', () => 'sent a message in').with('ai_response', () => 'AI responded').with('channel_message_reply', () => 'replied in')@@ -29,6 +31,11 @@ export function getNotificationTargetName({ tag: 'mentioned_in_document_comment' },(m) => m.content.documentName)+ .with(+ { tag: 'replied_to_document_comment_thread' },+ (m) => m.content.documentName+ )+ .with({ tag: 'commented_on_document' }, (m) => m.content.documentName).with({ tag: 'invite_to_team' }, (m) => m.content.teamName).with({ tag: 'task_assigned' }, (m) => m.content.taskName ?? undefined).with({ tag: 'channel_mention' }, () => undefined)@@ -50,6 +57,8 @@ export function getNotificationContent(.with({ tag: 'channel_message_reply' }, (m) => m.content.messageContent).with({ tag: 'document_mention' }, (m) => m.content.documentName).with({ tag: 'mentioned_in_document_comment' }, (m) => m.content.text)+ .with({ tag: 'replied_to_document_comment_thread' }, (m) => m.content.text)+ .with({ tag: 'commented_on_document' }, (m) => m.content.text).with({ tag: 'new_email' }, (m) => m.content.subject).with({ tag: 'task_assigned' }, (m) => m.content.taskName ?? undefined).with({ tag: 'channel_invite' }, () => undefined)@@ -77,6 +86,8 @@ export function shouldShowNotificationTarget(n: UnifiedNotification): boolean {.with({ tag: 'task_assigned' }, () => true).with({ tag: 'document_mention' }, () => true).with({ tag: 'mentioned_in_document_comment' }, () => true)+ .with({ tag: 'replied_to_document_comment_thread' }, () => true)+ .with({ tag: 'commented_on_document' }, () => true).with({ tag: 'channel_invite' }, () => true).with({ tag: 'invite_to_team' }, () => true).exhaustive();diff --git a/js/app/packages/notifications/notification-navigation.ts b/js/app/packages/notifications/notification-navigation.tsindex 06ddce9206..2b5a228221 100644--- a/js/app/packages/notifications/notification-navigation.ts+++ b/js/app/packages/notifications/notification-navigation.ts@@ -150,6 +150,28 @@ function getSupportedHandler(newSplit);})+ .with('replied_to_document_comment_thread', () => {+ const meta = notification.notification_metadata;+ if (meta.tag !== 'replied_to_document_comment_thread') return null;+ return async (lm: SplitManager, newSplit: boolean = false) =>+ openSplitIfNotOpen(+ lm,+ safeFileTypeToBlockName(meta.content.fileType),+ notification.entity_id,+ newSplit+ );+ })+ .with('commented_on_document', () => {+ const meta = notification.notification_metadata;+ if (meta.tag !== 'commented_on_document') return null;+ return async (lm: SplitManager, newSplit: boolean = false) =>+ openSplitIfNotOpen(+ lm,+ safeFileTypeToBlockName(meta.content.fileType),+ notification.entity_id,+ newSplit+ );+ }).exhaustive();}diff --git a/js/app/packages/notifications/notification-preview.ts b/js/app/packages/notifications/notification-preview.tsindex f488d16a3f..75c4ea18dd 100644--- a/js/app/packages/notifications/notification-preview.ts+++ b/js/app/packages/notifications/notification-preview.ts@@ -6,6 +6,8 @@ export const NOTIFICATION_LABEL_BY_TYPE: Record<NotificationType, string> = {channel_message_reply: 'REPLY',document_mention: 'MENTION',mentioned_in_document_comment: 'MENTION',+ replied_to_document_comment_thread: 'REPLY',+ commented_on_document: 'COMMENT',channel_invite: 'INVITE',new_email: 'EMAIL',invite_to_team: 'INVITE',diff --git a/js/app/packages/service-clients/service-notification/generated/schemas/commentedOnDocumentMetadata.ts b/js/app/packages/service-clients/service-notification/generated/schemas/commentedOnDocumentMetadata.tsnew file mode 100644index 0000000000..de8996140d--- /dev/null+++ b/js/app/packages/service-clients/service-notification/generated/schemas/commentedOnDocumentMetadata.ts@@ -0,0 +1,27 @@+/**+ * Generated by orval v7.13.0 🍺+ * Do not edit manually.+ * notification_service+ * OpenAPI spec version: 0.1.0+ */+import type { CommentedOnDocumentMetadataFileType } from './commentedOnDocumentMetadataFileType';+import type { CommentedOnDocumentMetadataSenderProfilePictureUrl } from './commentedOnDocumentMetadataSenderProfilePictureUrl';++/**+ * Notification sent when someone comments on a document the user owns.+ */+export interface CommentedOnDocumentMetadata {+ /** the comment id */+ commentId: number;+ /** The name of the document. */+ documentName: string;+ /** The file type of the document. */+ fileType?: CommentedOnDocumentMetadataFileType;+ /** The owner of the document. */+ owner: string;+ senderProfilePictureUrl?: CommentedOnDocumentMetadataSenderProfilePictureUrl;+ /** the text of the comment */+ text: string;+ /** the thread id */+ threadId: number;+}diff --git a/js/app/packages/service-clients/service-notification/generated/schemas/commentedOnDocumentMetadataFileType.ts b/js/app/packages/service-clients/service-notification/generated/schemas/commentedOnDocumentMetadataFileType.tsnew file mode 100644index 0000000000..f651c865eb--- /dev/null+++ b/js/app/packages/service-clients/service-notification/generated/schemas/commentedOnDocumentMetadataFileType.ts@@ -0,0 +1,11 @@+/**+ * Generated by orval v7.13.0 🍺+ * Do not edit manually.+ * notification_service+ * OpenAPI spec version: 0.1.0+ */++/**+ * The file type of the document.+ */+export type CommentedOnDocumentMetadataFileType = string | null;diff --git a/js/app/packages/service-clients/service-notification/generated/schemas/commentedOnDocumentMetadataSenderProfilePictureUrl.ts b/js/app/packages/service-clients/service-notification/generated/schemas/commentedOnDocumentMetadataSenderProfilePictureUrl.tsnew file mode 100644index 0000000000..55044ddadc--- /dev/null+++ b/js/app/packages/service-clients/service-notification/generated/schemas/commentedOnDocumentMetadataSenderProfilePictureUrl.ts@@ -0,0 +1,8 @@+/**+ * Generated by orval v7.13.0 🍺+ * Do not edit manually.+ * notification_service+ * OpenAPI spec version: 0.1.0+ */++export type CommentedOnDocumentMetadataSenderProfilePictureUrl = string | null;diff --git a/js/app/packages/service-clients/service-notification/generated/schemas/index.ts b/js/app/packages/service-clients/service-notification/generated/schemas/index.tsindex 4145b0d127..deb99c540e 100644--- a/js/app/packages/service-clients/service-notification/generated/schemas/index.ts+++ b/js/app/packages/service-clients/service-notification/generated/schemas/index.ts@@ -30,6 +30,9 @@ export * from './channelReplyMetadataAllOf';export * from './channelReplyMetadataAllOfSenderProfilePictureUrl';export * from './channelReplyMetadataAllOfThreadParentSenderId';export * from './channelType';+export * from './commentedOnDocumentMetadata';+export * from './commentedOnDocumentMetadataFileType';+export * from './commentedOnDocumentMetadataSenderProfilePictureUrl';export * from './commonChannelMetadata';export * from './createNotification';export * from './createNotificationAllOf';@@ -77,10 +80,17 @@ export * from './notifEventOneOfSevenTag';export * from './notifEventOneOfTag';export * from './notifEventOneOfThree';export * from './notifEventOneOfThreeTag';+export * from './notifEventOneOfTwoone';+export * from './notifEventOneOfTwooneTag';+export * from './notifEventOneOfTwothree';+export * from './notifEventOneOfTwothreeTag';export * from './notificationBulkRequest';export * from './notificationServiceApiVersion';export * from './pushNotificationData';export * from './pushNotificationDataSenderProfilePictureUrl';+export * from './repliedToDocumentCommentThreadMetadata';+export * from './repliedToDocumentCommentThreadMetadataFileType';+export * from './repliedToDocumentCommentThreadMetadataSenderProfilePictureUrl';export * from './taskAssignedMetadata';export * from './taskAssignedMetadataSenderProfilePictureUrl';export * from './taskAssignedMetadataTaskName';diff --git a/js/app/packages/service-clients/service-notification/generated/schemas/notifEvent.ts b/js/app/packages/service-clients/service-notification/generated/schemas/notifEvent.tsindex 9cab5ffd8c..6cc23aa052 100644--- a/js/app/packages/service-clients/service-notification/generated/schemas/notifEvent.ts+++ b/js/app/packages/service-clients/service-notification/generated/schemas/notifEvent.ts@@ -14,6 +14,8 @@ import type { NotifEventOneOfOneseven } from './notifEventOneOfOneseven';import type { NotifEventOneOfOnethree } from './notifEventOneOfOnethree';import type { NotifEventOneOfSeven } from './notifEventOneOfSeven';import type { NotifEventOneOfThree } from './notifEventOneOfThree';+import type { NotifEventOneOfTwoone } from './notifEventOneOfTwoone';+import type { NotifEventOneOfTwothree } from './notifEventOneOfTwothree';/*** Mirrors [`model_notifications::NotificationEvent`] but uses `tag` / `content`@@ -33,4 +35,6 @@ export type NotifEvent =| NotifEventOneOfOnethree| NotifEventOneOfOnefive| NotifEventOneOfOneseven- | NotifEventOneOfOnenine;+ | NotifEventOneOfOnenine+ | NotifEventOneOfTwoone+ | NotifEventOneOfTwothree;diff --git a/js/app/packages/service-clients/service-notification/generated/schemas/notifEventOneOfNine.ts b/js/app/packages/service-clients/service-notification/generated/schemas/notifEventOneOfNine.tsindex 15bcb0404c..9d9d84878d 100644--- a/js/app/packages/service-clients/service-notification/generated/schemas/notifEventOneOfNine.ts+++ b/js/app/packages/service-clients/service-notification/generated/schemas/notifEventOneOfNine.ts@@ -4,14 +4,14 @@* notification_service* OpenAPI spec version: 0.1.0*/-import type { ChannelMessageSendMetadata } from './channelMessageSendMetadata';+import type { CommentedOnDocumentMetadata } from './commentedOnDocumentMetadata';import type { NotifEventOneOfNineTag } from './notifEventOneOfNineTag';/**- * A user sent a message in a channel.+ * Someone commented on a document the user owns.*/export type NotifEventOneOfNine = {- /** A user sent a message in a channel. */- content: ChannelMessageSendMetadata;+ /** Someone commented on a document the user owns. */+ content: CommentedOnDocumentMetadata;tag: NotifEventOneOfNineTag;};diff --git a/js/app/packages/service-clients/service-notification/generated/schemas/notifEventOneOfNineTag.ts b/js/app/packages/service-clients/service-notification/generated/schemas/notifEventOneOfNineTag.tsindex cea73469c5..ed2141eac5 100644--- a/js/app/packages/service-clients/service-notification/generated/schemas/notifEventOneOfNineTag.ts+++ b/js/app/packages/service-clients/service-notification/generated/schemas/notifEventOneOfNineTag.ts@@ -10,5 +10,5 @@ export type NotifEventOneOfNineTag =// eslint-disable-next-line @typescript-eslint/no-redeclareexport const NotifEventOneOfNineTag = {- channel_message_send: 'channel_message_send',+ commented_on_document: 'commented_on_document',} as const;diff --git a/js/app/packages/service-clients/service-notification/generated/schemas/notifEventOneOfOnefive.ts b/js/app/packages/service-clients/service-notification/generated/schemas/notifEventOneOfOnefive.tsindex 4e86c892a4..093672ac5f 100644--- a/js/app/packages/service-clients/service-notification/generated/schemas/notifEventOneOfOnefive.ts+++ b/js/app/packages/service-clients/service-notification/generated/schemas/notifEventOneOfOnefive.ts@@ -4,14 +4,14 @@* notification_service* OpenAPI spec version: 0.1.0*/-import type { InviteToTeamMetadata } from './inviteToTeamMetadata';+import type { ChannelReplyMetadata } from './channelReplyMetadata';import type { NotifEventOneOfOnefiveTag } from './notifEventOneOfOnefiveTag';/**- * A user was invited to a team.+ * Someone replied to a thread in a channel that the user is part of.*/export type NotifEventOneOfOnefive = {- /** A user was invited to a team. */- content: InviteToTeamMetadata;+ /** Someone replied to a thread in a channel that the user is part of. */+ content: ChannelReplyMetadata;tag: NotifEventOneOfOnefiveTag;};diff --git a/js/app/packages/service-clients/service-notification/generated/schemas/notifEventOneOfOnefiveTag.ts b/js/app/packages/service-clients/service-notification/generated/schemas/notifEventOneOfOnefiveTag.tsindex 29fcdc3276..71d33fb48d 100644--- a/js/app/packages/service-clients/service-notification/generated/schemas/notifEventOneOfOnefiveTag.ts+++ b/js/app/packages/service-clients/service-notification/generated/schemas/notifEventOneOfOnefiveTag.ts@@ -10,5 +10,5 @@ export type NotifEventOneOfOnefiveTag =// eslint-disable-next-line @typescript-eslint/no-redeclareexport const NotifEventOneOfOnefiveTag = {- invite_to_team: 'invite_to_team',+ channel_message_reply: 'channel_message_reply',} as const;diff --git a/js/app/packages/service-clients/service-notification/generated/schemas/notifEventOneOfOnenine.ts b/js/app/packages/service-clients/service-notification/generated/schemas/notifEventOneOfOnenine.tsindex fda6faf71e..7e36de4e22 100644--- a/js/app/packages/service-clients/service-notification/generated/schemas/notifEventOneOfOnenine.ts+++ b/js/app/packages/service-clients/service-notification/generated/schemas/notifEventOneOfOnenine.ts@@ -4,14 +4,14 @@* notification_service* OpenAPI spec version: 0.1.0*/-import type { AiResponseMetadata } from './aiResponseMetadata';+import type { InviteToTeamMetadata } from './inviteToTeamMetadata';import type { NotifEventOneOfOnenineTag } from './notifEventOneOfOnenineTag';/**- * An AI assistant responded to a chat.+ * A user was invited to a team.*/export type NotifEventOneOfOnenine = {- /** An AI assistant responded to a chat. */- content: AiResponseMetadata;+ /** A user was invited to a team. */+ content: InviteToTeamMetadata;tag: NotifEventOneOfOnenineTag;};diff --git a/js/app/packages/service-clients/service-notification/generated/schemas/notifEventOneOfOnenineTag.ts b/js/app/packages/service-clients/service-notification/generated/schemas/notifEventOneOfOnenineTag.tsindex dfad5c8e07..73aac334cd 100644--- a/js/app/packages/service-clients/service-notification/generated/schemas/notifEventOneOfOnenineTag.ts+++ b/js/app/packages/service-clients/service-notification/generated/schemas/notifEventOneOfOnenineTag.ts@@ -10,5 +10,5 @@ export type NotifEventOneOfOnenineTag =// eslint-disable-next-line @typescript-eslint/no-redeclareexport const NotifEventOneOfOnenineTag = {- ai_response: 'ai_response',+ invite_to_team: 'invite_to_team',} as const;diff --git a/js/app/packages/service-clients/service-notification/generated/schemas/notifEventOneOfOneone.ts b/js/app/packages/service-clients/service-notification/generated/schemas/notifEventOneOfOneone.tsindex c16800c192..c6f6850442 100644--- a/js/app/packages/service-clients/service-notification/generated/schemas/notifEventOneOfOneone.ts+++ b/js/app/packages/service-clients/service-notification/generated/schemas/notifEventOneOfOneone.ts@@ -4,14 +4,14 @@* notification_service* OpenAPI spec version: 0.1.0*/-import type { ChannelReplyMetadata } from './channelReplyMetadata';+import type { ChannelInviteMetadata } from './channelInviteMetadata';import type { NotifEventOneOfOneoneTag } from './notifEventOneOfOneoneTag';/**- * Someone replied to a thread in a channel that the user is part of.+ * The user was invited to a channel.*/export type NotifEventOneOfOneone = {- /** Someone replied to a thread in a channel that the user is part of. */- content: ChannelReplyMetadata;+ /** The user was invited to a channel. */+ content: ChannelInviteMetadata;tag: NotifEventOneOfOneoneTag;};diff --git a/js/app/packages/service-clients/service-notification/generated/schemas/notifEventOneOfOneoneTag.ts b/js/app/packages/service-clients/service-notification/generated/schemas/notifEventOneOfOneoneTag.tsindex 8cbb2c4e6a..3941aa1e81 100644--- a/js/app/packages/service-clients/service-notification/generated/schemas/notifEventOneOfOneoneTag.ts+++ b/js/app/packages/service-clients/service-notification/generated/schemas/notifEventOneOfOneoneTag.ts@@ -10,5 +10,5 @@ export type NotifEventOneOfOneoneTag =// eslint-disable-next-line @typescript-eslint/no-redeclareexport const NotifEventOneOfOneoneTag = {- channel_message_reply: 'channel_message_reply',+ channel_invite: 'channel_invite',} as const;diff --git a/js/app/packages/service-clients/service-notification/generated/schemas/notifEventOneOfOneseven.ts b/js/app/packages/service-clients/service-notification/generated/schemas/notifEventOneOfOneseven.tsindex 421cb8131c..fe5b3d9d2a 100644--- a/js/app/packages/service-clients/service-notification/generated/schemas/notifEventOneOfOneseven.ts+++ b/js/app/packages/service-clients/service-notification/generated/schemas/notifEventOneOfOneseven.ts@@ -4,15 +4,14 @@* notification_service* OpenAPI spec version: 0.1.0*/-+import type { NewEmailMetadata } from './newEmailMetadata';import type { NotifEventOneOfOnesevenTag } from './notifEventOneOfOnesevenTag';-import type { TaskAssignedMetadata } from './taskAssignedMetadata';/**- * A user was assigned to a task.+ * A new email has been sent to the user.*/export type NotifEventOneOfOneseven = {- /** A user was assigned to a task. */- content: TaskAssignedMetadata;+ /** A new email has been sent to the user. */+ content: NewEmailMetadata;tag: NotifEventOneOfOnesevenTag;};diff --git a/js/app/packages/service-clients/service-notification/generated/schemas/notifEventOneOfOnesevenTag.ts b/js/app/packages/service-clients/service-notification/generated/schemas/notifEventOneOfOnesevenTag.tsindex 4799ebfbce..c3cad6091a 100644--- a/js/app/packages/service-clients/service-notification/generated/schemas/notifEventOneOfOnesevenTag.ts+++ b/js/app/packages/service-clients/service-notification/generated/schemas/notifEventOneOfOnesevenTag.ts@@ -10,5 +10,5 @@ export type NotifEventOneOfOnesevenTag =// eslint-disable-next-line @typescript-eslint/no-redeclareexport const NotifEventOneOfOnesevenTag = {- task_assigned: 'task_assigned',+ new_email: 'new_email',} as const;diff --git a/js/app/packages/service-clients/service-notification/generated/schemas/notifEventOneOfOnethree.ts b/js/app/packages/service-clients/service-notification/generated/schemas/notifEventOneOfOnethree.tsindex 45022594c0..8cf9b3235f 100644--- a/js/app/packages/service-clients/service-notification/generated/schemas/notifEventOneOfOnethree.ts+++ b/js/app/packages/service-clients/service-notification/generated/schemas/notifEventOneOfOnethree.ts@@ -4,14 +4,14 @@* notification_service* OpenAPI spec version: 0.1.0*/-import type { NewEmailMetadata } from './newEmailMetadata';+import type { ChannelMessageSendMetadata } from './channelMessageSendMetadata';import type { NotifEventOneOfOnethreeTag } from './notifEventOneOfOnethreeTag';/**- * A new email has been sent to the user.+ * A user sent a message in a channel.*/export type NotifEventOneOfOnethree = {- /** A new email has been sent to the user. */- content: NewEmailMetadata;+ /** A user sent a message in a channel. */+ content: ChannelMessageSendMetadata;tag: NotifEventOneOfOnethreeTag;};diff --git a/js/app/packages/service-clients/service-notification/generated/schemas/notifEventOneOfOnethreeTag.ts b/js/app/packages/service-clients/service-notification/generated/schemas/notifEventOneOfOnethreeTag.tsindex 84cacd8992..57cb8d2f60 100644--- a/js/app/packages/service-clients/service-notification/generated/schemas/notifEventOneOfOnethreeTag.ts+++ b/js/app/packages/service-clients/service-notification/generated/schemas/notifEventOneOfOnethreeTag.ts@@ -10,5 +10,5 @@ export type NotifEventOneOfOnethreeTag =// eslint-disable-next-line @typescript-eslint/no-redeclareexport const NotifEventOneOfOnethreeTag = {- new_email: 'new_email',+ channel_message_send: 'channel_message_send',} as const;diff --git a/js/app/packages/service-clients/service-notification/generated/schemas/notifEventOneOfSeven.ts b/js/app/packages/service-clients/service-notification/generated/schemas/notifEventOneOfSeven.tsindex 0eccae5d53..f3e4921f1e 100644--- a/js/app/packages/service-clients/service-notification/generated/schemas/notifEventOneOfSeven.ts+++ b/js/app/packages/service-clients/service-notification/generated/schemas/notifEventOneOfSeven.ts@@ -4,14 +4,15 @@* notification_service* OpenAPI spec version: 0.1.0*/-import type { ChannelInviteMetadata } from './channelInviteMetadata';+import type { NotifEventOneOfSevenTag } from './notifEventOneOfSevenTag';+import type { RepliedToDocumentCommentThreadMetadata } from './repliedToDocumentCommentThreadMetadata';/**- * The user was invited to a channel.+ * Someone replied to a document comment thread the user participated in.*/export type NotifEventOneOfSeven = {- /** The user was invited to a channel. */- content: ChannelInviteMetadata;+ /** Someone replied to a document comment thread the user participated in. */+ content: RepliedToDocumentCommentThreadMetadata;tag: NotifEventOneOfSevenTag;};diff --git a/js/app/packages/service-clients/service-notification/generated/schemas/notifEventOneOfSevenTag.ts b/js/app/packages/service-clients/service-notification/generated/schemas/notifEventOneOfSevenTag.tsindex 0354aa14c0..44940a7d72 100644--- a/js/app/packages/service-clients/service-notification/generated/schemas/notifEventOneOfSevenTag.ts+++ b/js/app/packages/service-clients/service-notification/generated/schemas/notifEventOneOfSevenTag.ts@@ -10,5 +10,5 @@ export type NotifEventOneOfSevenTag =// eslint-disable-next-line @typescript-eslint/no-redeclareexport const NotifEventOneOfSevenTag = {- channel_invite: 'channel_invite',+ replied_to_document_comment_thread: 'replied_to_document_comment_thread',} as const;diff --git a/js/app/packages/service-clients/service-notification/generated/schemas/notifEventOneOfTwoone.ts b/js/app/packages/service-clients/service-notification/generated/schemas/notifEventOneOfTwoone.tsnew file mode 100644index 0000000000..2d7d8b97d0--- /dev/null+++ b/js/app/packages/service-clients/service-notification/generated/schemas/notifEventOneOfTwoone.ts@@ -0,0 +1,18 @@+/**+ * Generated by orval v7.13.0 🍺+ * Do not edit manually.+ * notification_service+ * OpenAPI spec version: 0.1.0+ */++import type { NotifEventOneOfTwooneTag } from './notifEventOneOfTwooneTag';+import type { TaskAssignedMetadata } from './taskAssignedMetadata';++/**+ * A user was assigned to a task.+ */+export type NotifEventOneOfTwoone = {+ /** A user was assigned to a task. */+ content: TaskAssignedMetadata;+ tag: NotifEventOneOfTwooneTag;+};diff --git a/js/app/packages/service-clients/service-notification/generated/schemas/notifEventOneOfTwooneTag.ts b/js/app/packages/service-clients/service-notification/generated/schemas/notifEventOneOfTwooneTag.tsnew file mode 100644index 0000000000..01eee0c9be--- /dev/null+++ b/js/app/packages/service-clients/service-notification/generated/schemas/notifEventOneOfTwooneTag.ts@@ -0,0 +1,14 @@+/**+ * Generated by orval v7.13.0 🍺+ * Do not edit manually.+ * notification_service+ * OpenAPI spec version: 0.1.0+ */++export type NotifEventOneOfTwooneTag =+ (typeof NotifEventOneOfTwooneTag)[keyof typeof NotifEventOneOfTwooneTag];++// eslint-disable-next-line @typescript-eslint/no-redeclare+export const NotifEventOneOfTwooneTag = {+ task_assigned: 'task_assigned',+} as const;diff --git a/js/app/packages/service-clients/service-notification/generated/schemas/notifEventOneOfTwothree.ts b/js/app/packages/service-clients/service-notification/generated/schemas/notifEventOneOfTwothree.tsnew file mode 100644index 0000000000..f0922ef89b--- /dev/null+++ b/js/app/packages/service-clients/service-notification/generated/schemas/notifEventOneOfTwothree.ts@@ -0,0 +1,17 @@+/**+ * Generated by orval v7.13.0 🍺+ * Do not edit manually.+ * notification_service+ * OpenAPI spec version: 0.1.0+ */+import type { AiResponseMetadata } from './aiResponseMetadata';+import type { NotifEventOneOfTwothreeTag } from './notifEventOneOfTwothreeTag';++/**+ * An AI assistant responded to a chat.+ */+export type NotifEventOneOfTwothree = {+ /** An AI assistant responded to a chat. */+ content: AiResponseMetadata;+ tag: NotifEventOneOfTwothreeTag;+};diff --git a/js/app/packages/service-clients/service-notification/generated/schemas/notifEventOneOfTwothreeTag.ts b/js/app/packages/service-clients/service-notification/generated/schemas/notifEventOneOfTwothreeTag.tsnew file mode 100644index 0000000000..e4b9751797--- /dev/null+++ b/js/app/packages/service-clients/service-notification/generated/schemas/notifEventOneOfTwothreeTag.ts@@ -0,0 +1,14 @@+/**+ * Generated by orval v7.13.0 🍺+ * Do not edit manually.+ * notification_service+ * OpenAPI spec version: 0.1.0+ */++export type NotifEventOneOfTwothreeTag =+ (typeof NotifEventOneOfTwothreeTag)[keyof typeof NotifEventOneOfTwothreeTag];++// eslint-disable-next-line @typescript-eslint/no-redeclare+export const NotifEventOneOfTwothreeTag = {+ ai_response: 'ai_response',+} as const;diff --git a/js/app/packages/service-clients/service-notification/generated/schemas/repliedToDocumentCommentThreadMetadata.ts b/js/app/packages/service-clients/service-notification/generated/schemas/repliedToDocumentCommentThreadMetadata.tsnew file mode 100644index 0000000000..b67a344aca--- /dev/null+++ b/js/app/packages/service-clients/service-notification/generated/schemas/repliedToDocumentCommentThreadMetadata.ts@@ -0,0 +1,27 @@+/**+ * Generated by orval v7.13.0 🍺+ * Do not edit manually.+ * notification_service+ * OpenAPI spec version: 0.1.0+ */+import type { RepliedToDocumentCommentThreadMetadataFileType } from './repliedToDocumentCommentThreadMetadataFileType';+import type { RepliedToDocumentCommentThreadMetadataSenderProfilePictureUrl } from './repliedToDocumentCommentThreadMetadataSenderProfilePictureUrl';++/**+ * Notification sent when someone replies to a document comment thread.+ */+export interface RepliedToDocumentCommentThreadMetadata {+ /** the comment id */+ commentId: number;+ /** The name of the document. */+ documentName: string;+ /** The file type of the document. */+ fileType?: RepliedToDocumentCommentThreadMetadataFileType;+ /** The owner of the document. */+ owner: string;+ senderProfilePictureUrl?: RepliedToDocumentCommentThreadMetadataSenderProfilePictureUrl;+ /** the text of the comment */+ text: string;+ /** the thread id */+ threadId: number;+}diff --git a/js/app/packages/service-clients/service-notification/generated/schemas/repliedToDocumentCommentThreadMetadataFileType.ts b/js/app/packages/service-clients/service-notification/generated/schemas/repliedToDocumentCommentThreadMetadataFileType.tsnew file mode 100644index 0000000000..b58291f45c--- /dev/null+++ b/js/app/packages/service-clients/service-notification/generated/schemas/repliedToDocumentCommentThreadMetadataFileType.ts@@ -0,0 +1,11 @@+/**+ * Generated by orval v7.13.0 🍺+ * Do not edit manually.+ * notification_service+ * OpenAPI spec version: 0.1.0+ */++/**+ * The file type of the document.+ */+export type RepliedToDocumentCommentThreadMetadataFileType = string | null;diff --git a/js/app/packages/service-clients/service-notification/generated/schemas/repliedToDocumentCommentThreadMetadataSenderProfilePictureUrl.ts b/js/app/packages/service-clients/service-notification/generated/schemas/repliedToDocumentCommentThreadMetadataSenderProfilePictureUrl.tsnew file mode 100644index 0000000000..5069f928d5--- /dev/null+++ b/js/app/packages/service-clients/service-notification/generated/schemas/repliedToDocumentCommentThreadMetadataSenderProfilePictureUrl.ts@@ -0,0 +1,10 @@+/**+ * Generated by orval v7.13.0 🍺+ * Do not edit manually.+ * notification_service+ * OpenAPI spec version: 0.1.0+ */++export type RepliedToDocumentCommentThreadMetadataSenderProfilePictureUrl =+ | string+ | null;diff --git a/js/app/packages/service-clients/service-notification/openapi.json b/js/app/packages/service-clients/service-notification/openapi.jsonindex fbfc54f4aa..18e87c950e 100644--- a/js/app/packages/service-clients/service-notification/openapi.json+++ b/js/app/packages/service-clients/service-notification/openapi.json@@ -1082,6 +1082,42 @@"type": "string","enum": ["public", "organization", "private", "directMessage", "team"]},+ "CommentedOnDocumentMetadata": {+ "type": "object",+ "description": "Notification sent when someone comments on a document the user owns.",+ "required": ["documentName", "owner", "commentId", "threadId", "text"],+ "properties": {+ "commentId": {+ "type": "integer",+ "format": "int64",+ "description": "the comment id"+ },+ "documentName": {+ "type": "string",+ "description": "The name of the document."+ },+ "fileType": {+ "type": ["string", "null"],+ "description": "The file type of the document."+ },+ "owner": {+ "type": "string",+ "description": "The owner of the document."+ },+ "senderProfilePictureUrl": {+ "type": ["string", "null"]+ },+ "text": {+ "type": "string",+ "description": "the text of the comment"+ },+ "threadId": {+ "type": "integer",+ "format": "int64",+ "description": "the thread id"+ }+ }+ },"CommonChannelMetadata": {"type": "object","description": "Common metadata for notifications on channels",@@ -1392,6 +1428,36 @@}}},+ {+ "type": "object",+ "description": "Someone replied to a document comment thread the user participated in.",+ "required": ["content", "tag"],+ "properties": {+ "content": {+ "$ref": "#/components/schemas/RepliedToDocumentCommentThreadMetadata",+ "description": "Someone replied to a document comment thread the user participated in."+ },+ "tag": {+ "type": "string",+ "enum": ["replied_to_document_comment_thread"]+ }+ }+ },+ {+ "type": "object",+ "description": "Someone commented on a document the user owns.",+ "required": ["content", "tag"],+ "properties": {+ "content": {+ "$ref": "#/components/schemas/CommentedOnDocumentMetadata",+ "description": "Someone commented on a document the user owns."+ },+ "tag": {+ "type": "string",+ "enum": ["commented_on_document"]+ }+ }+ },{"type": "object","description": "The user was invited to a channel.",@@ -1534,6 +1600,42 @@}}},+ "RepliedToDocumentCommentThreadMetadata": {+ "type": "object",+ "description": "Notification sent when someone replies to a document comment thread.",+ "required": ["documentName", "owner", "commentId", "threadId", "text"],+ "properties": {+ "commentId": {+ "type": "integer",+ "format": "int64",+ "description": "the comment id"+ },+ "documentName": {+ "type": "string",+ "description": "The name of the document."+ },+ "fileType": {+ "type": ["string", "null"],+ "description": "The file type of the document."+ },+ "owner": {+ "type": "string",+ "description": "The owner of the document."+ },+ "senderProfilePictureUrl": {+ "type": ["string", "null"]+ },+ "text": {+ "type": "string",+ "description": "the text of the comment"+ },+ "threadId": {+ "type": "integer",+ "format": "int64",+ "description": "the thread id"+ }+ }+ },"TaskAssignedMetadata": {"type": "object","description": "Metadata for when a user is assigned to a task",diff --git a/rust/cloud-storage/comms_service/src/notification.rs b/rust/cloud-storage/comms_service/src/notification.rsindex 28a87cd94b..bbc6fb2f66 100644--- a/rust/cloud-storage/comms_service/src/notification.rs+++ b/rust/cloud-storage/comms_service/src/notification.rs@@ -435,6 +435,9 @@ fn set_sender_profile_picture(event: &mut NotifEvent, url: Option<String>) {NotifEvent::ChannelMention(m) => m.sender_profile_picture_url = url,NotifEvent::ChannelMessageReply(m) => m.sender_profile_picture_url = url,NotifEvent::DocumentMention(m) => m.sender_profile_picture_url = url,+ NotifEvent::MentionedInDocumentComment(m) => m.sender_profile_picture_url = url,+ NotifEvent::RepliedToDocumentCommentThread(m) => m.sender_profile_picture_url = url,+ NotifEvent::CommentedOnDocument(m) => m.sender_profile_picture_url = url,_ => {}}}diff --git a/rust/cloud-storage/document_storage_service/src/api/annotations/create_comment.rs b/rust/cloud-storage/document_storage_service/src/api/annotations/create_comment.rsindex 5581a1c8d5..1c3aea766b 100644--- a/rust/cloud-storage/document_storage_service/src/api/annotations/create_comment.rs+++ b/rust/cloud-storage/document_storage_service/src/api/annotations/create_comment.rs@@ -1,7 +1,10 @@use std::sync::Arc;use crate::{- api::{annotations::build_mention_notif, context::ApiContext},+ api::{+ annotations::{CommentNotifContext, compute_notification_recipients},+ context::ApiContext,+ },service::conn_gateway::update_live_comment_state,};use axum::{@@ -12,6 +15,7 @@ use axum::{};use connection_gateway_client::ConnectionGatewayClient;use macro_db_client::annotations::create_comment::create_document_comment;+use macro_user_id::user_id::MacroUserIdStr;use model::{annotations::{AnnotationIncrementalUpdate, Mentions,@@ -68,9 +72,8 @@ pub async fn create_comment_handler(}match create_document_comment(&db, &document_id, &user_id, &req).await {Ok(res) => {- if let Some(Mentions { users, mention_id }) = &req.mentions- && let Some(comment) = res.comment_thread.comments.first()- {+ if let Some(comment) = res.comment_thread.comments.last() {+ let sender_id: Option<MacroUserIdStr<'static>> = user_id.clone().try_into().ok();let sender_profile_picture_url =macro_db_client::user::update_profile_picture::get_profile_pictures(&db,@@ -80,27 +83,83 @@ pub async fn create_comment_handler(.ok().and_then(|pics| pics.pictures.into_iter().next().map(|p| p.url));- let request = build_mention_notif(- req.text,- comment,- res.comment_thread.thread.thread_id,- users,- document_context.document_name.clone(),- document_context.owner.clone(),- document_context.file_type.clone(),- user_id.clone().try_into().ok(),- document_id.to_string(),- mention_id,+ let thread_id = res.comment_thread.thread.thread_id;+ let is_reply = res.comment_thread.comments.len() > 1;+ let mentioned_user_ids = req+ .mentions+ .as_ref()+ .map(|m| m.users.as_slice())+ .unwrap_or_default();+ let thread_comment_owners: Vec<String> = res+ .comment_thread+ .comments+ .iter()+ .map(|c| c.owner.clone())+ .collect();++ let recipients = compute_notification_recipients(+ sender_id.as_ref(),+ mentioned_user_ids,+ &thread_comment_owners,+ &document_context.owner,+ is_reply,+ );++ let notif_ctx = CommentNotifContext {+ text: req.text.clone(),+ comment_id: comment.comment_id,+ thread_id,+ document_name: document_context.document_name.clone(),+ document_id: document_id.to_string(),+ owner: document_context.owner.clone(),+ file_type: document_context.file_type.clone(),+ sender_id: sender_id.clone(),sender_profile_picture_url,- )- .into_request()- .with_apns()- .with_conn_gateway();+ };- _ = notification_ingress_service- .send_notification(request)- .await- .inspect_err(|e| tracing::error!(error =? e, "couldn't send document mention notification"));+ // 1. Mention notifications (highest priority)+ if let Some(Mentions { mention_id, .. }) = &req.mentions+ && !recipients.mention_recipients.is_empty()+ {+ let request = notif_ctx+ .build_mention_notif(recipients.mention_recipients, mention_id)+ .into_request()+ .with_apns()+ .with_conn_gateway();++ _ = notification_ingress_service+ .send_notification(request)+ .await+ .inspect_err(|e| tracing::error!(error =? e, "couldn't send document mention notification"));+ }++ // 2. Thread reply notifications+ if !recipients.thread_reply_recipients.is_empty() {+ let request = notif_ctx+ .build_thread_reply_notif(recipients.thread_reply_recipients)+ .into_request()+ .with_apns()+ .with_conn_gateway();++ _ = notification_ingress_service+ .send_notification(request)+ .await+ .inspect_err(|e| tracing::error!(error =? e, "couldn't send thread reply notification"));+ }++ // 3. Document owner notification (lowest priority)+ if recipients.doc_owner_recipient.is_some() {+ let request = notif_ctx+ .build_document_comment_notif()+ .into_request()+ .with_apns()+ .with_conn_gateway();++ _ = notification_ingress_service+ .send_notification(request)+ .await+ .inspect_err(|e| tracing::error!(error =? e, "couldn't send document comment notification"));+ }}update_live_comment_state(&conn_gateway_client,diff --git a/rust/cloud-storage/document_storage_service/src/api/annotations/edit_comment.rs b/rust/cloud-storage/document_storage_service/src/api/annotations/edit_comment.rsindex 91b9bd7af0..8fbbc644e1 100644--- a/rust/cloud-storage/document_storage_service/src/api/annotations/edit_comment.rs+++ b/rust/cloud-storage/document_storage_service/src/api/annotations/edit_comment.rs@@ -1,7 +1,7 @@use std::sync::Arc;use crate::{- api::annotations::build_mention_notif, service::conn_gateway::update_live_comment_state,+ api::annotations::CommentNotifContext, service::conn_gateway::update_live_comment_state,};use axum::{Json,@@ -11,6 +11,7 @@ use axum::{};use connection_gateway_client::ConnectionGatewayClient;use macro_db_client::annotations::edit_comment::edit_document_comment;+use macro_user_id::user_id::MacroUserIdStr;use model::{annotations::{AnnotationIncrementalUpdate, Mentions,@@ -65,22 +66,30 @@ pub async fn edit_comment_handler(.ok().and_then(|pics| pics.pictures.into_iter().next().map(|p| p.url));- let request = build_mention_notif(- req.text.clone().unwrap_or_else(|| "".to_string()),- &res.comment,- req.thread_id,- &users,- res.document_name.clone(),- res.document_owner.clone(),- res.file_type.clone(),- user_id.clone().try_into().ok(),- res.document_id.to_string(),- &mention_id,+ // Only mention notifications on edit — no thread-reply or document-owner+ // notifications, since edits shouldn't re-notify participants.+ let notif_ctx = CommentNotifContext {+ text: req.text.clone().unwrap_or_default(),+ comment_id: res.comment.comment_id,+ thread_id: req.thread_id,+ document_name: res.document_name.clone(),+ document_id: res.document_id.to_string(),+ owner: res.document_owner.clone(),+ file_type: res.file_type.clone(),+ sender_id: user_id.clone().try_into().ok(),sender_profile_picture_url,- )- .into_request()- .with_apns()- .with_conn_gateway();+ };++ let recipient_ids = users+ .iter()+ .filter_map(|id| MacroUserIdStr::try_from(id.clone()).ok())+ .collect();++ let request = notif_ctx+ .build_mention_notif(recipient_ids, &mention_id)+ .into_request()+ .with_apns()+ .with_conn_gateway();_ = notification_ingress_service.send_notification(request)diff --git a/rust/cloud-storage/document_storage_service/src/api/annotations/mod.rs b/rust/cloud-storage/document_storage_service/src/api/annotations/mod.rsindex 9cbac1ddfe..32c4a3b0e1 100644--- a/rust/cloud-storage/document_storage_service/src/api/annotations/mod.rs+++ b/rust/cloud-storage/document_storage_service/src/api/annotations/mod.rs@@ -17,9 +17,12 @@ use axum::{};use macro_db_client::annotations::CommentError;use macro_user_id::user_id::MacroUserIdStr;-use model::{annotations::Comment, response::ErrorResponse};+use model::response::ErrorResponse;use model_entity::EntityType;-use model_notifications::MentionedInDocumentCommentMetadata;+use model_notifications::{+ CommentedOnDocumentMetadata, MentionedInDocumentCommentMetadata,+ RepliedToDocumentCommentThreadMetadata,+};use notification::domain::models::SendNotificationRequestBuilder;use tower::ServiceBuilder;@@ -122,64 +125,175 @@ pub fn comment_error_response(e: anyhow::Error, default_msg: &str) -> Result<Res}}-#[expect(clippy::too_many_arguments)]-fn build_mention_notif<'a>(- text: String,- comment: &Comment,- thread_id: i64,- mentions: &'a [String],- document_name: String,- owner: MacroUserIdStr<'static>,- file_type: Option<String>,- sender_id: Option<MacroUserIdStr<'static>>,- document_id: String,- mention_id: &str,- sender_profile_picture_url: Option<String>,-) -> SendNotificationRequestBuilder<'a, MentionedInDocumentCommentMetadata> {- let notification = MentionedInDocumentCommentMetadata {- document_name,- owner,- file_type,- mention_id: mention_id.to_string(),- comment_id: comment.comment_id,- thread_id,- text,- sender_profile_picture_url,- };+/// Computes the recipient sets for each notification type, ensuring no user+/// receives more than one notification per comment.+///+/// Priority: mention > thread reply > document owner.+pub(crate) fn compute_notification_recipients(+ sender_id: Option<&MacroUserIdStr<'_>>,+ mentioned_user_ids: &[String],+ thread_comment_owners: &[String],+ document_owner: &MacroUserIdStr<'_>,+ is_reply: bool,+) -> NotificationRecipients {+ let mut notified: HashSet<String> = HashSet::new();- let recipient_ids: HashSet<MacroUserIdStr<'a>> = mentions+ // 1. Mention recipients — normalize to MacroUserIdStr format for consistent comparison+ let mention_recipients: HashSet<MacroUserIdStr<'static>> = mentioned_user_ids.iter()- .filter_map(|id| MacroUserIdStr::parse_from_str(id).ok())+ .filter_map(|id| MacroUserIdStr::try_from(id.clone()).ok()).collect();+ notified.extend(mention_recipients.iter().map(|id| id.as_ref().to_string()));- SendNotificationRequestBuilder {- notification_entity: EntityType::Document.with_entity_string(document_id),- notification,- sender_id,- recipient_ids,+ // 2. Thread reply recipients — only if this is a reply (>1 comments in thread)+ let mut thread_reply_recipients: HashSet<MacroUserIdStr<'static>> = HashSet::new();+ if is_reply {+ for owner_str in thread_comment_owners {+ if let Ok(parsed) = MacroUserIdStr::try_from(owner_str.clone()) {+ let normalized = parsed.as_ref().to_string();+ let is_sender = sender_id.is_some_and(|s| s.as_ref() == normalized);+ if !is_sender && !notified.contains(&normalized) {+ notified.insert(normalized);+ thread_reply_recipients.insert(parsed);+ }+ }+ }+ }++ // 3. Document owner — only if not sender and not already notified+ let owner_normalized = document_owner.as_ref().to_string();+ let owner_is_sender = sender_id.is_some_and(|s| s.as_ref() == owner_normalized);+ let doc_owner_recipient = if !owner_is_sender && !notified.contains(&owner_normalized) {+ Some(owner_normalized)+ } else {+ None+ };++ NotificationRecipients {+ mention_recipients,+ thread_reply_recipients,+ doc_owner_recipient,}}-#[cfg(test)]-mod tests {- use super::*;-- #[test]- fn check_ser_meta() -> Result<(), Box<dyn std::error::Error>> {- let m = MentionedInDocumentCommentMetadata {- document_name: "test".to_string(),- owner: MacroUserIdStr::parse_from_str("macro|[email protected]").unwrap(),- file_type: None,- mention_id: "xxx".to_string(),- thread_id: 42,- comment_id: 99,- text: "yy".to_string(),- sender_profile_picture_url: None,+pub(crate) struct NotificationRecipients {+ /// Users who should get a mention notification (already parsed and owned).+ pub mention_recipients: HashSet<MacroUserIdStr<'static>>,+ /// Users who should get a thread reply notification (already parsed and owned).+ pub thread_reply_recipients: HashSet<MacroUserIdStr<'static>>,+ /// The document owner, if they should get a "commented on your document" notification.+ pub doc_owner_recipient: Option<String>,+}++impl NotificationRecipients {+ /// Returns all recipient IDs across all notification types.+ #[cfg(test)]+ pub fn all_recipients(&self) -> HashSet<String> {+ let mut all = HashSet::new();+ for r in &self.mention_recipients {+ all.insert(r.as_ref().to_string());+ }+ for r in &self.thread_reply_recipients {+ all.insert(r.as_ref().to_string());+ }+ if let Some(r) = &self.doc_owner_recipient {+ all.insert(r.clone());+ }+ all+ }++ /// Total number of recipients across all notification types.+ #[cfg(test)]+ pub fn total_count(&self) -> usize {+ self.mention_recipients.len()+ + self.thread_reply_recipients.len()+ + self.doc_owner_recipient.iter().count()+ }+}++pub(crate) struct CommentNotifContext {+ pub text: String,+ pub comment_id: i64,+ pub thread_id: i64,+ pub document_name: String,+ pub document_id: String,+ pub owner: MacroUserIdStr<'static>,+ pub file_type: Option<String>,+ pub sender_id: Option<MacroUserIdStr<'static>>,+ pub sender_profile_picture_url: Option<String>,+}++impl CommentNotifContext {+ pub fn build_mention_notif(+ &self,+ recipient_ids: HashSet<MacroUserIdStr<'static>>,+ mention_id: &str,+ ) -> SendNotificationRequestBuilder<'static, MentionedInDocumentCommentMetadata> {+ let notification = MentionedInDocumentCommentMetadata {+ document_name: self.document_name.clone(),+ owner: self.owner.clone(),+ file_type: self.file_type.clone(),+ mention_id: mention_id.to_string(),+ comment_id: self.comment_id,+ thread_id: self.thread_id,+ text: self.text.clone(),+ sender_profile_picture_url: self.sender_profile_picture_url.clone(),};- let res = serde_json::to_string(&m).unwrap();- assert!(res.contains(r#"mentionId":"xxx""#));- assert!(res.contains(r#"threadId":42"#));- assert!(res.contains(r#"commentId":99"#));- Ok(())++ SendNotificationRequestBuilder {+ notification_entity: EntityType::Document.with_entity_string(self.document_id.clone()),+ notification,+ sender_id: self.sender_id.clone(),+ recipient_ids,+ }+ }++ pub fn build_thread_reply_notif(+ &self,+ participant_ids: HashSet<MacroUserIdStr<'static>>,+ ) -> SendNotificationRequestBuilder<'static, RepliedToDocumentCommentThreadMetadata> {+ let notification = RepliedToDocumentCommentThreadMetadata {+ document_name: self.document_name.clone(),+ owner: self.owner.clone(),+ file_type: self.file_type.clone(),+ comment_id: self.comment_id,+ thread_id: self.thread_id,+ text: self.text.clone(),+ sender_profile_picture_url: self.sender_profile_picture_url.clone(),+ };++ SendNotificationRequestBuilder {+ notification_entity: EntityType::Document.with_entity_string(self.document_id.clone()),+ notification,+ sender_id: self.sender_id.clone(),+ recipient_ids: participant_ids,+ }+ }++ pub fn build_document_comment_notif(+ &self,+ ) -> SendNotificationRequestBuilder<'static, CommentedOnDocumentMetadata> {+ let notification = CommentedOnDocumentMetadata {+ document_name: self.document_name.clone(),+ owner: self.owner.clone(),+ file_type: self.file_type.clone(),+ comment_id: self.comment_id,+ thread_id: self.thread_id,+ text: self.text.clone(),+ sender_profile_picture_url: self.sender_profile_picture_url.clone(),+ };++ let mut recipient_ids = HashSet::new();+ recipient_ids.insert(self.owner.clone());++ SendNotificationRequestBuilder {+ notification_entity: EntityType::Document.with_entity_string(self.document_id.clone()),+ notification,+ sender_id: self.sender_id.clone(),+ recipient_ids,+ }}}++#[cfg(test)]+mod test;diff --git a/rust/cloud-storage/document_storage_service/src/api/annotations/test.rs b/rust/cloud-storage/document_storage_service/src/api/annotations/test.rsnew file mode 100644index 0000000000..029fe9e1b2--- /dev/null+++ b/rust/cloud-storage/document_storage_service/src/api/annotations/test.rs@@ -0,0 +1,255 @@+use super::*;++#[test]+fn check_ser_meta() -> Result<(), Box<dyn std::error::Error>> {+ let m = MentionedInDocumentCommentMetadata {+ document_name: "test".to_string(),+ owner: MacroUserIdStr::parse_from_str("macro|[email protected]").unwrap(),+ file_type: None,+ mention_id: "xxx".to_string(),+ thread_id: 42,+ comment_id: 99,+ text: "yy".to_string(),+ sender_profile_picture_url: None,+ };+ let res = serde_json::to_string(&m).unwrap();+ assert!(res.contains(r#"mentionId":"xxx""#));+ assert!(res.contains(r#"threadId":42"#));+ assert!(res.contains(r#"commentId":99"#));+ Ok(())+}++fn user_id(s: &str) -> MacroUserIdStr<'static> {+ MacroUserIdStr::try_from(s.to_string()).unwrap()+}++// ---------------------------------------------------------------------------+// No duplicate notifications+// ---------------------------------------------------------------------------++#[test]+fn mentioned_user_who_is_also_thread_participant_gets_only_mention() {+ let sender = user_id("macro|[email protected]");+ let bob = "macro|[email protected]";++ let result = compute_notification_recipients(+ Some(&sender),+ &[bob.to_string()], // bob is mentioned+ &[bob.to_string(), sender.as_ref().to_string()], // bob is also a thread participant+ &user_id("macro|[email protected]"),+ true, // is_reply+ );++ assert!(+ result.mention_recipients.contains(&user_id(bob)),+ "bob should be in mention recipients"+ );+ assert!(+ !result.thread_reply_recipients.contains(&user_id(bob)),+ "bob should NOT be in thread reply recipients"+ );+ assert_eq!(+ result.all_recipients().len(),+ result.total_count(),+ "no user should appear in more than one recipient set"+ );+}++#[test]+fn mentioned_user_who_is_also_doc_owner_gets_only_mention() {+ let sender = user_id("macro|[email protected]");+ let owner = user_id("macro|[email protected]");++ let result = compute_notification_recipients(+ Some(&sender),+ &[owner.as_ref().to_string()], // owner is mentioned+ &[sender.as_ref().to_string()],+ &owner,+ false,+ );++ assert!(+ result.mention_recipients.contains(&owner),+ "owner should be in mention recipients"+ );+ assert!(+ result.doc_owner_recipient.is_none(),+ "owner should NOT get a separate doc owner notification"+ );+}++#[test]+fn thread_participant_who_is_also_doc_owner_gets_only_thread_reply() {+ let sender = user_id("macro|[email protected]");+ let owner = user_id("macro|[email protected]");++ let result = compute_notification_recipients(+ Some(&sender),+ &[], // no mentions+ &[owner.as_ref().to_string(), sender.as_ref().to_string()], // owner is thread participant+ &owner,+ true,+ );++ assert!(+ result.thread_reply_recipients.contains(&owner),+ "owner should be in thread reply recipients"+ );+ assert!(+ result.doc_owner_recipient.is_none(),+ "owner should NOT also get a doc owner notification"+ );+}++#[test]+fn user_who_is_mentioned_and_thread_participant_and_doc_owner_gets_only_mention() {+ let sender = user_id("macro|[email protected]");+ let owner = user_id("macro|[email protected]");++ let result = compute_notification_recipients(+ Some(&sender),+ &[owner.as_ref().to_string()], // owner is mentioned+ &[owner.as_ref().to_string(), sender.as_ref().to_string()], // owner is thread participant+ &owner, // and doc owner+ true,+ );++ assert!(result.mention_recipients.contains(&owner),);+ assert!(!result.thread_reply_recipients.contains(&owner));+ assert!(result.doc_owner_recipient.is_none());+ assert_eq!(result.all_recipients().len(), result.total_count());+}++// ---------------------------------------------------------------------------+// Case-insensitive dedup: mention IDs may have different casing than owner IDs+// ---------------------------------------------------------------------------++#[test]+fn dedup_works_across_different_casing() {+ let sender = user_id("macro|[email protected]");+ let owner = user_id("macro|[email protected]");++ // Mention comes in with mixed case, comment owner stored lowercase+ let result = compute_notification_recipients(+ Some(&sender),+ &["macro|[email protected]".to_string()], // mixed case mention+ &[+ "macro|[email protected]".to_string(),+ sender.as_ref().to_string(),+ ], // lowercase owner+ &owner,+ true,+ );++ // Bob should appear exactly once across all recipient sets+ let all = result.all_recipients();+ let bob_count = all.iter().filter(|r| r.contains("bob")).count();+ assert_eq!(+ bob_count, 1,+ "bob should receive exactly one notification, got {bob_count}"+ );+ assert_eq!(result.all_recipients().len(), result.total_count());+}++#[test]+fn dedup_works_for_doc_owner_with_different_casing() {+ let sender = user_id("macro|[email protected]");+ let owner = user_id("macro|[email protected]");++ // Mention uses mixed case for the owner+ let result = compute_notification_recipients(+ Some(&sender),+ &["macro|[email protected]".to_string()], // mixed case+ &[sender.as_ref().to_string()],+ &owner,+ false,+ );++ assert!(+ result.mention_recipients.len() == 1,+ "owner should get mention"+ );+ assert!(+ result.doc_owner_recipient.is_none(),+ "owner should NOT also get doc owner notification"+ );+}++// ---------------------------------------------------------------------------+// Sender exclusion+// ---------------------------------------------------------------------------++#[test]+fn sender_never_receives_notification() {+ let sender = user_id("macro|[email protected]");++ let result = compute_notification_recipients(+ Some(&sender),+ &[],+ &[sender.as_ref().to_string()], // sender is only thread participant+ &sender, // sender is also doc owner+ true,+ );++ assert!(result.mention_recipients.is_empty());+ assert!(result.thread_reply_recipients.is_empty());+ assert!(result.doc_owner_recipient.is_none());+ assert_eq!(result.total_count(), 0);+}++// ---------------------------------------------------------------------------+// Basic happy paths+// ---------------------------------------------------------------------------++#[test]+fn new_thread_comment_notifies_doc_owner() {+ let sender = user_id("macro|[email protected]");+ let owner = user_id("macro|[email protected]");++ let result = compute_notification_recipients(+ Some(&sender),+ &[],+ &[sender.as_ref().to_string()], // only one comment (the new one)+ &owner,+ false, // not a reply+ );++ assert!(result.mention_recipients.is_empty());+ assert!(result.thread_reply_recipients.is_empty());+ assert_eq!(result.doc_owner_recipient.as_deref(), Some(owner.as_ref()),);+}++#[test]+fn reply_notifies_thread_participants_and_doc_owner() {+ let sender = user_id("macro|[email protected]");+ let owner = user_id("macro|[email protected]");+ let alice = "macro|[email protected]";++ let result = compute_notification_recipients(+ Some(&sender),+ &[],+ &[alice.to_string(), sender.as_ref().to_string()],+ &owner,+ true,+ );++ assert!(result.mention_recipients.is_empty());+ assert!(result.thread_reply_recipients.contains(&user_id(alice)));+ assert_eq!(result.doc_owner_recipient.as_deref(), Some(owner.as_ref()));+}++#[test]+fn no_thread_reply_notifications_for_first_comment() {+ let sender = user_id("macro|[email protected]");+ let owner = user_id("macro|[email protected]");++ let result = compute_notification_recipients(+ Some(&sender),+ &[],+ &[sender.as_ref().to_string()],+ &owner,+ false, // first comment, not a reply+ );++ assert!(result.thread_reply_recipients.is_empty());+}diff --git a/rust/cloud-storage/model_notifications/src/lib.rs b/rust/cloud-storage/model_notifications/src/lib.rsindex 67b493eb32..1212fe085b 100644--- a/rust/cloud-storage/model_notifications/src/lib.rs+++ b/rust/cloud-storage/model_notifications/src/lib.rs@@ -168,6 +168,12 @@ define_notif_event!(/// User was mentioned in a comment in a documentMentionedInDocumentComment(MentionedInDocumentCommentMetadata),+ /// Someone replied to a document comment thread the user participated in.+ RepliedToDocumentCommentThread(RepliedToDocumentCommentThreadMetadata),++ /// Someone commented on a document the user owns.+ CommentedOnDocument(CommentedOnDocumentMetadata),+/// The user was invited to a channel.ChannelInvite(ChannelInviteMetadata),@@ -206,6 +212,8 @@ impl NotificationTitle for NotifEvent {NotifEvent::MentionedInDocumentComment(mentioned_in_document_comment_metadata) => {mentioned_in_document_comment_metadata.format_title(sender_id)}+ NotifEvent::RepliedToDocumentCommentThread(m) => m.format_title(sender_id),+ NotifEvent::CommentedOnDocument(m) => m.format_title(sender_id),NotifEvent::ChannelInvite(channel_invite_metadata) => {channel_invite_metadata.format_title(sender_id)}@@ -242,6 +250,8 @@ impl NotificationTitle for NotifEvent {NotifEvent::MentionedInDocumentComment(mentioned_in_document_comment_metadata) => {mentioned_in_document_comment_metadata.format_body(sender_id)}+ NotifEvent::RepliedToDocumentCommentThread(m) => m.format_body(sender_id),+ NotifEvent::CommentedOnDocument(m) => m.format_body(sender_id),NotifEvent::ChannelInvite(channel_invite_metadata) => {channel_invite_metadata.format_body(sender_id)}diff --git a/rust/cloud-storage/model_notifications/src/metadata.rs b/rust/cloud-storage/model_notifications/src/metadata.rsindex 24e2bcd496..8bf00f2674 100644--- a/rust/cloud-storage/model_notifications/src/metadata.rs+++ b/rust/cloud-storage/model_notifications/src/metadata.rs@@ -358,16 +358,12 @@ impl NotificationTitle for MentionedInDocumentCommentMetadata {) -> Result<String, rootcause::Report> {let sender =sender_id.ok_or_else(|| report!("Expected sender id to exist for {:?}", &self))?;- let file_type_str = self- .file_type- .as_ref()- .ok_or_else(|| report!("Expected the file type to exist"))?;let email = sender.0.email_part();let sender = email.email_str();- let title = format!(- "{sender} mentioned you in {}.{}",- self.document_name, file_type_str- );+ let title = match &self.file_type {+ Some(ft) => format!("{sender} mentioned you in {}.{ft}", self.document_name),+ None => format!("{sender} mentioned you in {}", self.document_name),+ };Ok(title)}@@ -760,3 +756,139 @@ impl NotificationExtIos for MentionedInDocumentCommentMetadata {alert_apns(self, sender_id, notification_id, profile_pic).ok()}}++/// Notification sent when someone replies to a document comment thread.+#[derive(Debug, Clone, Serialize, Deserialize, ToSchema)]+#[serde(rename_all = "camelCase")]+pub struct RepliedToDocumentCommentThreadMetadata {+ /// The name of the document.+ pub document_name: String,+ /// The owner of the document.+ #[schema(value_type = String)]+ pub owner: MacroUserIdStr<'static>,+ /// The file type of the document.+ pub file_type: Option<String>,+ /// the comment id+ pub comment_id: i64,+ /// the thread id+ pub thread_id: i64,+ /// the text of the comment+ pub text: String,+ #[serde(default)]+ pub sender_profile_picture_url: Option<String>,+}++impl Notification for RepliedToDocumentCommentThreadMetadata {+ const TYPE_NAME: &'static str = "replied_to_document_comment_thread";+}++impl NotificationTitle for RepliedToDocumentCommentThreadMetadata {+ fn format_title(+ &self,+ sender_id: Option<MacroUserIdStr<'_>>,+ ) -> Result<String, rootcause::Report> {+ let sender =+ sender_id.ok_or_else(|| report!("Expected sender id to exist for {:?}", &self))?;+ let email = sender.0.email_part();+ let sender = email.email_str();+ let title = match &self.file_type {+ Some(ft) => format!("{sender} replied in {}.{ft}", self.document_name),+ None => format!("{sender} replied in {}", self.document_name),+ };+ Ok(title)+ }++ fn format_body(+ &self,+ _sender_id: Option<MacroUserIdStr<'_>>,+ ) -> Result<String, rootcause::Report> {+ parse_message_plain_text(&self.text)+ }+}++impl NotificationExtIos for RepliedToDocumentCommentThreadMetadata {+ type NotifData = ::notification::domain::models::apple::PushNotificationData;++ fn collapse_key(&self, entity: &Entity<'_>) -> NotifCollapseKey {+ let entity_type: &'static str = entity.entity_type.into();+ NotifCollapseKey::new(entity_type).append(&entity.entity_id)+ }++ fn as_apns<'a>(+ &self,+ sender_id: Option<MacroUserIdStr<'a>>,+ _entity: &Entity<'_>,+ notification_id: Uuid,+ ) -> Option<APNSPushNotification<Self::NotifData>> {+ let profile_pic = self.sender_profile_picture_url.clone();+ alert_apns(self, sender_id, notification_id, profile_pic).ok()+ }+}++/// Notification sent when someone comments on a document the user owns.+#[derive(Debug, Clone, Serialize, Deserialize, ToSchema)]+#[serde(rename_all = "camelCase")]+pub struct CommentedOnDocumentMetadata {+ /// The name of the document.+ pub document_name: String,+ /// The owner of the document.+ #[schema(value_type = String)]+ pub owner: MacroUserIdStr<'static>,+ /// The file type of the document.+ pub file_type: Option<String>,+ /// the comment id+ pub comment_id: i64,+ /// the thread id+ pub thread_id: i64,+ /// the text of the comment+ pub text: String,+ #[serde(default)]+ pub sender_profile_picture_url: Option<String>,+}++impl Notification for CommentedOnDocumentMetadata {+ const TYPE_NAME: &'static str = "commented_on_document";+}++impl NotificationTitle for CommentedOnDocumentMetadata {+ fn format_title(+ &self,+ sender_id: Option<MacroUserIdStr<'_>>,+ ) -> Result<String, rootcause::Report> {+ let sender =+ sender_id.ok_or_else(|| report!("Expected sender id to exist for {:?}", &self))?;+ let email = sender.0.email_part();+ let sender = email.email_str();+ let title = match &self.file_type {+ Some(ft) => format!("{sender} commented on {}.{ft}", self.document_name),+ None => format!("{sender} commented on {}", self.document_name),+ };+ Ok(title)+ }++ fn format_body(+ &self,+ _sender_id: Option<MacroUserIdStr<'_>>,+ ) -> Result<String, rootcause::Report> {+ parse_message_plain_text(&self.text)+ }+}++impl NotificationExtIos for CommentedOnDocumentMetadata {+ type NotifData = ::notification::domain::models::apple::PushNotificationData;++ fn collapse_key(&self, entity: &Entity<'_>) -> NotifCollapseKey {+ let entity_type: &'static str = entity.entity_type.into();+ NotifCollapseKey::new(entity_type).append(&entity.entity_id)+ }++ fn as_apns<'a>(+ &self,+ sender_id: Option<MacroUserIdStr<'a>>,+ _entity: &Entity<'_>,+ notification_id: Uuid,+ ) -> Option<APNSPushNotification<Self::NotifData>> {+ let profile_pic = self.sender_profile_picture_url.clone();+ alert_apns(self, sender_id, notification_id, profile_pic).ok()+ }+}diff --git a/rust/cloud-storage/notification_service/src/api/swagger.rs b/rust/cloud-storage/notification_service/src/api/swagger.rsindex 2715dd78ef..8689dd7b21 100644--- a/rust/cloud-storage/notification_service/src/api/swagger.rs+++ b/rust/cloud-storage/notification_service/src/api/swagger.rs@@ -7,8 +7,9 @@ use model::{};use model_notifications::{ChannelInviteMetadata, ChannelMentionMetadata, ChannelMessageSendMetadata,- ChannelReplyMetadata, CommonChannelMetadata, DeviceType, DocumentMentionMetadata,- InviteToTeamMetadata, ItemSharedMetadata, NewEmailMetadata, UserUnsubscribe,+ ChannelReplyMetadata, CommentedOnDocumentMetadata, CommonChannelMetadata, DeviceType,+ DocumentMentionMetadata, InviteToTeamMetadata, ItemSharedMetadata, NewEmailMetadata,+ RepliedToDocumentCommentThreadMetadata, UserUnsubscribe,};use utoipa::OpenApi;@@ -73,6 +74,8 @@ use crate::{ChannelMentionMetadata,ChannelReplyMetadata,DocumentMentionMetadata,+ RepliedToDocumentCommentThreadMetadata,+ CommentedOnDocumentMetadata,// v2 typed notificationsmodel_notifications::NotifEvent,