Skip to content

armgit / macro

Public Imported from GitHub
0

Macro is a unified workspace for teams: email, chat, docs, tasks, agents, calls, and CRM — @-linked together with shared AI memory.

feat: document mention notification type (#2516)

Peter Chinmane03cc792fc90
diff --git a/js/app/packages/app/component/next-soup/filters/predicates.ts b/js/app/packages/app/component/next-soup/filters/predicates.ts
index d144a3bb94..172ae98ec7 100644
--- a/js/app/packages/app/component/next-soup/filters/predicates.ts
+++ b/js/app/packages/app/component/next-soup/filters/predicates.ts
@@ -39,8 +39,6 @@ export function unreadFilter(notificationSource: NotificationSource) {
export function notDoneFilter(notificationSource: NotificationSource) {
return function (entity: WithNotification<EntityData>) {
if (entity.type === 'email') return !entity.done;
- // Tasks are handled by signalFilter based on assignee/status, not notifications
- if (isTaskEntity(entity)) return true;
const notifications =
notificationSource.notificationsByEntity()[compositeEntity(entity)];
diff --git a/js/app/packages/core/constant/featureFlags.ts b/js/app/packages/core/constant/featureFlags.ts
index 5394f63c8a..6adffff602 100644
--- a/js/app/packages/core/constant/featureFlags.ts
+++ b/js/app/packages/core/constant/featureFlags.ts
@@ -243,6 +243,11 @@ export const ENABLE_EMAIL_SHARING = resolveFeatureFlag(
true
);
+export const ENABLE_DOCUMENT_MENTION_NOTIFICATIONS = resolveFeatureFlag(
+ 'ENABLE_DOCUMENT_MENTION_NOTIFICATIONS',
+ DEV_MODE_ENV
+);
+
// Auto expand stand-alone mentions to richer previews in channels
export const ENABLE_STATIC_DOCUMENT_CARDS = resolveFeatureFlag(
'ENABLE_STATIC_DOCUMENT_CARDS',
diff --git a/js/app/packages/entity/src/extractors-notification/mobile-notification-stacks.tsx b/js/app/packages/entity/src/extractors-notification/mobile-notification-stacks.tsx
index 555081ac1f..7d7c55acd8 100644
--- a/js/app/packages/entity/src/extractors-notification/mobile-notification-stacks.tsx
+++ b/js/app/packages/entity/src/extractors-notification/mobile-notification-stacks.tsx
@@ -1,4 +1,4 @@
-import { Show, useContext, createEffect, type JSX } from 'solid-js';
+import { useContext, createEffect, type JSX } from 'solid-js';
import { reconcile, createStore } from 'solid-js/store';
import {
type NotificationStack,
@@ -8,18 +8,14 @@ import {
import type { WithNotification } from '../types/notification';
import { isChannelEntity, type EntityData } from '../types/entity';
import { CollapsibleList } from '../components/CollapsibleList';
-import {
- extractMessageContent,
- isNotificationUnread,
-} from '../utils/notification';
+import { isNotificationUnread } from '../utils/notification';
import { Entity } from '../entity';
import { UnreadIndicator } from '../components/UnreadIndicator';
import { EntityRow, EntityRowContext } from '@app/component/mobile/EntityRow';
import { useGlobalNotificationSource } from '@app/component/GlobalAppState';
import { toast } from '@core/component/Toast/Toast';
-import { StaticMarkdown } from '@core/component/LexicalMarkdown/component/core/StaticMarkdown';
-import { unifiedListMarkdownTheme } from '@core/component/LexicalMarkdown/theme';
import { cn } from '@ui/utils/classname';
+import { NotificationContent } from './notification-content';
export type EntityRowConfig = {
swipeLeftColor?: string;
@@ -33,9 +29,6 @@ function MobileStackRowLayout(props: {
entity: WithNotification<EntityData>;
unread: boolean;
}) {
- const msgContent = () =>
- extractMessageContent(getMostRecentNotification(props.stack));
-
return (
<Entity.Layout
class="w-full text-sm grid bg-edge/10 border-edge-muted"
@@ -68,17 +61,11 @@ function MobileStackRowLayout(props: {
</Entity.Slot>
<Entity.Slot
placement="body"
- class="text-ink-extra-muted truncate pb-2 min-h-[1lh] pr-4"
+ class={cn('text-ink-extra-muted pb-2 min-h-[1lh] pr-4', {
+ truncate: props.stack.type !== 'document_mention',
+ })}
>
- <Show when={msgContent()}>
- {(content) => (
- <StaticMarkdown
- theme={unifiedListMarkdownTheme}
- markdown={content()}
- singleLine
- />
- )}
- </Show>
+ <NotificationContent stack={props.stack} />
</Entity.Slot>
</Entity.Layout>
);
diff --git a/js/app/packages/entity/src/extractors-notification/notification-content.tsx b/js/app/packages/entity/src/extractors-notification/notification-content.tsx
index fd4138c8b0..a682e0fae0 100644
--- a/js/app/packages/entity/src/extractors-notification/notification-content.tsx
+++ b/js/app/packages/entity/src/extractors-notification/notification-content.tsx
@@ -1,9 +1,20 @@
-import { Show } from 'solid-js';
+import { useGlobalNotificationSource } from '@app/component/GlobalAppState';
+import { globalSplitManager } from '@app/signal/splitLayout';
+import { EntityIcon } from '@core/component/EntityIcon';
import { StaticMarkdown } from '@core/component/LexicalMarkdown/component/core/StaticMarkdown';
import { unifiedListMarkdownTheme } from '@core/component/LexicalMarkdown/theme';
+import { fileTypeToBlockName } from '@core/constant/allBlocks';
+import CheckIcon from '@icon/regular/check.svg';
+import {
+ type NotificationStack,
+ openNotification,
+ type UnifiedNotification,
+} from '@notifications';
+import { Button } from '@ui/components/Button';
+import { createEffect, createSignal, For, onCleanup, Show } from 'solid-js';
import type { Notification } from '../types/notification';
-import type { NotificationStack } from '@notifications';
import { extractMessageContent } from '../utils/notification';
+import { useNotificationActions } from './notification-actions';
interface NotificationContentProps {
notification?: Notification;
@@ -11,10 +22,184 @@ interface NotificationContentProps {
singleLine?: boolean;
}
+function DocumentMentionPill(props: { notification: UnifiedNotification }) {
+ const notificationSource = useGlobalNotificationSource();
+ const { markAsDone } = useNotificationActions({
+ notification: props.notification,
+ });
+
+ const documentMeta = () => {
+ const m = props.notification.notification_metadata;
+ return m.tag === 'document_mention' ? m.content : undefined;
+ };
+ const documentName = () => documentMeta()?.documentName ?? 'Untitled';
+ const targetType = () => {
+ const meta = documentMeta();
+
+ const subTypeStr = meta?.subType?.type;
+ return fileTypeToBlockName(subTypeStr ?? meta?.fileType) ?? 'default';
+ };
+
+ const handleClick = async (e: MouseEvent) => {
+ e.stopPropagation();
+ const splitManager = globalSplitManager();
+ if (!splitManager) return;
+ await openNotification(props.notification, splitManager, e.shiftKey);
+ await notificationSource.markAsRead(props.notification);
+ };
+
+ return (
+ <div
+ class="group relative flex items-center gap-1.5 px-2 py-1 rounded border border-edge-muted bg-panel hover:bg-hover cursor-pointer text-xs min-w-0 max-w-48 flex-shrink-0"
+ onClick={handleClick}
+ role="button"
+ tabIndex={0}
+ >
+ <EntityIcon targetType={targetType()} size="xs" />
+ <span class="truncate min-w-0">{documentName()}</span>
+ <Button
+ class="absolute -top-2 -right-2 size-6 rounded-full bg-panel border border-edge-muted p-0 place-items-center hidden group-hover:grid hover:bg-accent! hover:text-panel!"
+ tooltip="Mark as done"
+ onClick={(e) => {
+ e.stopPropagation();
+ markAsDone();
+ }}
+ >
+ <CheckIcon class="size-2.5" />
+ </Button>
+ </div>
+ );
+}
+
+function DocumentMentionPills(props: { stack: NotificationStack }) {
+ let measureRef: HTMLDivElement | undefined;
+ let badgeRef: HTMLButtonElement | undefined;
+ // null = not yet measured; show all pills until the first measurement completes.
+ const [visibleCount, setVisibleCount] = createSignal<number | null>(null);
+ const [expanded, setExpanded] = createSignal(false);
+ const notifications = () => props.stack.notifications;
+
+ const recalculate = () => {
+ const container = measureRef;
+ if (!container) return;
+ const containerWidth = container.getBoundingClientRect().width;
+ if (containerWidth === 0) return;
+
+ const gap = 6; // gap-1.5 = 6px
+ // Direct children are the pills; the badge button is excluded via data-badge.
+ const pills = Array.from(container.children).filter(
+ (el) => !el.hasAttribute('data-badge')
+ ) as HTMLElement[];
+ if (pills.length === 0) return;
+
+ const pillWidths = pills.map((el) => el.getBoundingClientRect().width);
+ const badgeWidth = badgeRef
+ ? badgeRef.getBoundingClientRect().width + gap
+ : 0;
+
+ // Check whether every pill fits with no badge needed.
+ const totalWidth = pillWidths.reduce(
+ (sum, w, i) => sum + w + (i > 0 ? gap : 0),
+ 0
+ );
+ if (totalWidth <= containerWidth) {
+ setVisibleCount(pills.length);
+ return;
+ }
+
+ // Some pills overflow — fit as many as possible while leaving room for the badge.
+ const availableWidth = containerWidth - badgeWidth;
+ let usedWidth = 0;
+ let count = 0;
+ for (let i = 0; i < pillWidths.length; i++) {
+ const addWidth = (i > 0 ? gap : 0) + pillWidths[i];
+ if (usedWidth + addWidth <= availableWidth) {
+ usedWidth += addWidth;
+ count++;
+ } else {
+ break;
+ }
+ }
+ setVisibleCount(Math.max(1, count));
+ };
+
+ // Re-measure when notifications change or on first mount.
+ createEffect(() => {
+ void notifications();
+ recalculate();
+ });
+
+ // Re-measure whenever the container is resized (window resize, panel resize, etc.).
+ createEffect(() => {
+ const container = measureRef;
+ if (!container) return;
+ const observer = new ResizeObserver(recalculate);
+ observer.observe(container);
+ onCleanup(() => observer.disconnect());
+ });
+
+ const count = () =>
+ expanded()
+ ? notifications().length
+ : (visibleCount() ?? notifications().length);
+ const overflow = () => Math.max(0, notifications().length - count());
+
+ return (
+ <div class="relative pt-1">
+ {/*
+ Invisible measurement layer: absolutely positioned so it takes no layout
+ space, but always contains every pill + the badge so their widths can be
+ measured at any point regardless of what the visible layer shows.
+ */}
+ <div
+ ref={measureRef}
+ class="absolute inset-x-0 top-0 flex flex-nowrap items-center gap-1.5 invisible pointer-events-none"
+ aria-hidden="true"
+ >
+ <For each={notifications()}>
+ {(n) => <DocumentMentionPill notification={n} />}
+ </For>
+ <button
+ ref={badgeRef}
+ data-badge
+ class="text-xs text-ink-muted border border-edge-muted rounded px-2 py-1 flex-shrink-0"
+ tabIndex={-1}
+ >
+ +{notifications().length} more
+ </button>
+ </div>
+ {/* Visible layer: only as many pills as fit, followed by the badge if needed. */}
+ <div
+ class={
+ expanded()
+ ? 'flex flex-wrap items-center gap-1.5'
+ : 'flex flex-nowrap items-center gap-1.5'
+ }
+ >
+ <For each={notifications().slice(0, count())}>
+ {(n) => <DocumentMentionPill notification={n} />}
+ </For>
+ <Show when={overflow() > 0}>
+ <button
+ class="text-xs text-ink-muted border border-edge-muted rounded px-2 py-1 bg-panel hover:bg-edge/10 flex-shrink-0"
+ onClick={(e) => {
+ e.stopPropagation();
+ setExpanded(true);
+ }}
+ >
+ +{overflow()} more
+ </button>
+ </Show>
+ </div>
+ </div>
+ );
+}
+
/**
* Displays the content/preview of a notification
* For single notifications, shows the message content
* For stacks, shows the most recent notification's content
+ * For document_mention stacks, shows pills for each mentioned document
*/
export function NotificationContent(props: NotificationContentProps) {
const content = () => {
@@ -28,23 +213,30 @@ export function NotificationContent(props: NotificationContentProps) {
};
return (
- <Show when={content()}>
- {(text) => (
- <Show
- when={text().trim()}
- fallback={
- <span class="italic text-ink-disabled">Attached items</span>
- }
- >
- {(trimmedContent) => (
- <StaticMarkdown
- markdown={trimmedContent()}
- theme={unifiedListMarkdownTheme}
- singleLine={props.singleLine ?? true}
- />
+ <Show
+ when={props.stack?.type === 'document_mention'}
+ fallback={
+ <Show when={content()}>
+ {(text) => (
+ <Show
+ when={text().trim()}
+ fallback={
+ <span class="italic text-ink-disabled">Attached items</span>
+ }
+ >
+ {(trimmedContent) => (
+ <StaticMarkdown
+ markdown={trimmedContent()}
+ theme={unifiedListMarkdownTheme}
+ singleLine={props.singleLine ?? true}
+ />
+ )}
+ </Show>
)}
</Show>
- )}
+ }
+ >
+ <DocumentMentionPills stack={props.stack!} />
</Show>
);
}
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.ts
index d8e2ce2f91..578d000705 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
@@ -23,7 +23,7 @@ export function getUniqueSenderIds(notifications: Notification[]): string[] {
export function getActionVerb(type: NotificationType): string {
return match(type)
.with('channel_mention', () => 'mentioned you')
- .with('document_mention', () => 'mentioned you')
+ .with('document_mention', () => 'shared with you')
.with('mentioned_in_document_comment', () => 'mentioned you')
.with('replied_to_document_comment_thread', () => 'replied')
.with('commented_on_document', () => 'commented')
@@ -47,7 +47,9 @@ export function getTypeNoun(type: NotificationType, count: number): string {
.with('channel_message_send', () => (count === 1 ? 'message' : 'messages'))
.with('ai_response', () => (count === 1 ? 'response' : 'responses'))
.with('channel_mention', () => (count === 1 ? 'mention' : 'mentions'))
- .with('document_mention', () => (count === 1 ? 'mention' : 'mentions'))
+ .with('document_mention', () =>
+ count === 1 ? 'document shared' : 'documents shared'
+ )
.with('mentioned_in_document_comment', () =>
count === 1 ? 'mention' : 'mentions'
)
@@ -61,3 +63,9 @@ export function getTypeNoun(type: NotificationType, count: number): string {
.with('task_assigned', () => (count === 1 ? 'task' : 'tasks'))
.exhaustive();
}
+
+export function getTypePreposition(type: NotificationType): string {
+ return match(type)
+ .with('document_mention', () => 'by')
+ .otherwise(() => 'from');
+}
diff --git a/js/app/packages/entity/src/extractors-notification/notification-description.tsx b/js/app/packages/entity/src/extractors-notification/notification-description.tsx
index 2208f53641..8aab92d199 100644
--- a/js/app/packages/entity/src/extractors-notification/notification-description.tsx
+++ b/js/app/packages/entity/src/extractors-notification/notification-description.tsx
@@ -1,15 +1,16 @@
-import type { Notification } from '../types/notification';
-import type { NotificationStack } from '@notifications';
import type { NotificationType } from '@core/types';
import { tryMacroId, useDisplayNameParts } from '@core/user';
+import type { NotificationStack } from '@notifications';
+import type { Notification } from '../types/notification';
import {
- getUniqueSenderIds,
getActionVerb,
getTypeNoun,
+ getTypePreposition,
+ getUniqueSenderIds,
} from './notification-description-helpers';
// Re-export helpers for backward compatibility and testing
-export { getUniqueSenderIds, getActionVerb, getTypeNoun };
+export { getActionVerb, getTypeNoun, getTypePreposition, getUniqueSenderIds };
interface NotificationDescriptionProps {
notification?: Notification;
@@ -101,10 +102,10 @@ export function NotificationDescription(props: NotificationDescriptionProps) {
if (senderId) {
const senderCount = senderIds().length;
if (senderCount === 2) {
- return `${count()} ${getTypeNoun(type, count())} from ${primarySenderFirstName()} and ${secondarySenderFirstName()}`;
+ return `${count()} ${getTypeNoun(type, count())} ${getTypePreposition(type)} ${primarySenderFirstName()} and ${secondarySenderFirstName()}`;
}
// Three or more senders: "13 messages from Peter and 5 others"
- return `${count()} ${getTypeNoun(type, count())} from ${primarySenderFirstName()} and ${additionalSenderCount()} ${additionalSenderCount() === 1 ? 'other' : 'others'}`;
+ return `${count()} ${getTypeNoun(type, count())} ${getTypePreposition(type)} ${primarySenderFirstName()} and ${additionalSenderCount()} ${additionalSenderCount() === 1 ? 'other' : 'others'}`;
}
return `${count()} ${getTypeNoun(type, count())}`;
}
diff --git a/js/app/packages/entity/src/extractors-notification/notification-icon.tsx b/js/app/packages/entity/src/extractors-notification/notification-icon.tsx
index 13a7dbd3fd..d75071a80f 100644
--- a/js/app/packages/entity/src/extractors-notification/notification-icon.tsx
+++ b/js/app/packages/entity/src/extractors-notification/notification-icon.tsx
@@ -7,6 +7,7 @@ import type { NotificationType } from '@core/types';
import ChatIcon from '@icon/regular/chat.svg';
import ArrowBendUpLeftIcon from '@icon/regular/arrow-bend-up-left.svg';
import AtIcon from '@icon/regular/at.svg';
+import FilesIcon from '@icon/regular/files.svg';
import EnvelopeIcon from '@icon/regular/envelope.svg';
import UserPlusIcon from '@icon/regular/user-plus.svg';
import CheckIcon from '@icon/regular/check.svg';
@@ -26,7 +27,7 @@ function getNotificationIcon(
): (props: { class?: string }) => JSX.Element {
return match(type)
.with('channel_mention', () => AtIcon)
- .with('document_mention', () => AtIcon)
+ .with('document_mention', () => FilesIcon)
.with('mentioned_in_document_comment', () => AtIcon)
.with('replied_to_document_comment_thread', () => ArrowBendUpLeftIcon)
.with('commented_on_document', () => ChatIcon)
diff --git a/js/app/packages/entity/src/extractors-notification/notification-stacks.tsx b/js/app/packages/entity/src/extractors-notification/notification-stacks.tsx
index 1d6c90d490..113aae48bc 100644
--- a/js/app/packages/entity/src/extractors-notification/notification-stacks.tsx
+++ b/js/app/packages/entity/src/extractors-notification/notification-stacks.tsx
@@ -1,31 +1,31 @@
-import { Show, createEffect } from 'solid-js';
-import { reconcile, createStore } from 'solid-js/store';
+import { useGlobalNotificationSource } from '@app/component/GlobalAppState';
+import { globalSplitManager } from '@app/signal/splitLayout';
+import CheckIcon from '@icon/regular/check.svg';
import {
- stackNotifications,
- type NotificationStack,
getMostRecentNotification,
+ type NotificationStack,
openNotification,
+ stackNotifications,
} from '@notifications';
-import type { WithNotification } from '../types/notification';
-import type { EntityData } from '../types/entity';
+import { Button } from '@ui/components/Button';
+import { cn } from '@ui/utils/classname';
+import { createEffect, type JSX, Show } from 'solid-js';
+import { createStore, reconcile } from 'solid-js/store';
import { CollapsibleList } from '../components/CollapsibleList';
+import { UnreadIndicator } from '../components/UnreadIndicator';
+import type { EntityData } from '../types/entity';
+import type { WithNotification } from '../types/notification';
import {
- filterValidNotifications,
filterNotDoneNotifications,
+ filterValidNotifications,
isNotificationUnread,
} from '../utils/notification';
+import { useNotificationStackActions } from './notification-actions';
import { NotificationContent } from './notification-content';
-import { NotificationIcon } from './notification-icon';
import { NotificationDescription } from './notification-description';
+import { NotificationIcon } from './notification-icon';
import { NotificationSenderIcon } from './notification-sender-icon';
import { NotificationTimestamp } from './notification-timestamp';
-import { UnreadIndicator } from '../components/UnreadIndicator';
-import { useGlobalNotificationSource } from '@app/component/GlobalAppState';
-import { globalSplitManager } from '@app/signal/splitLayout';
-import { cn } from '@ui/utils/classname';
-import { useNotificationStackActions } from './notification-actions';
-import { Button } from '@ui/components/Button';
-import CheckIcon from '@icon/regular/check.svg';
const DEFAULT_VISIBLE_COUNT = 3;
@@ -38,6 +38,7 @@ interface NotificationStacksProps {
function NotificationStackRow(props: {
stack: NotificationStack;
onClick?: (e: PointerEvent | MouseEvent) => void;
+ content?: JSX.Element;
}) {
const notificationSource = useGlobalNotificationSource();
const unread = () => isNotificationUnread(props.stack);
@@ -112,8 +113,13 @@ function NotificationStackRow(props: {
</Button>
</div>
</div>
- <div class="ph-no-capture mt-1 truncate min-w-0 overflow-hidden">
- <NotificationContent stack={props.stack} />
+ <div
+ class={cn('ph-no-capture mt-1 min-w-0', {
+ 'truncate overflow-hidden':
+ props.stack.type !== 'document_mention' && !props.content,
+ })}
+ >
+ {props.content ?? <NotificationContent stack={props.stack} />}
</div>
</div>
</div>
diff --git a/js/app/packages/entity/src/utils/notification.ts b/js/app/packages/entity/src/utils/notification.ts
index d38c7ffeaf..0d1db0e245 100644
--- a/js/app/packages/entity/src/utils/notification.ts
+++ b/js/app/packages/entity/src/utils/notification.ts
@@ -1,7 +1,8 @@
-import type { NotificationStack } from '@notifications/notification-stacking';
-import type { Notification } from '../types/notification';
+import { ENABLE_DOCUMENT_MENTION_NOTIFICATIONS } from '@core/constant/featureFlags';
import { notificationIsRead, type UnifiedNotification } from '@notifications';
+import type { NotificationStack } from '@notifications/notification-stacking';
import { match } from 'ts-pattern';
+import type { Notification } from '../types/notification';
/**
* Filters out invalid notification types that shouldn't be displayed
@@ -12,7 +13,11 @@ export function filterValidNotifications(
if (!notifications) return [];
return notifications.filter((n) => {
- return n.notification_event_type !== undefined;
+ return (
+ n.notification_event_type !== undefined &&
+ (ENABLE_DOCUMENT_MENTION_NOTIFICATIONS ||
+ n.notification_event_type !== 'document_mention')
+ );
});
}
diff --git a/js/app/packages/notifications/notification-stacking.ts b/js/app/packages/notifications/notification-stacking.ts
index 2f20b6761b..12d4279126 100644
--- a/js/app/packages/notifications/notification-stacking.ts
+++ b/js/app/packages/notifications/notification-stacking.ts
@@ -76,12 +76,16 @@ export function stackNotifications(
const replies = filteredNotifications
.filter(byTag('channel_message_reply'))
.filter((n) => !isShadowed(n));
- const others = notifications.filter((n) => !isChannelNotification(n));
+ const docMentions = notifications.filter(byTag('document_mention'));
+ const others = notifications.filter(
+ (n) => !isChannelNotification(n) && !byTag('document_mention')(n)
+ );
const groups: NotificationStack[] = [
...mentions.flatMap((n) => makeStack('channel_mention', [n])),
...makeStack('channel_message_send', newMsgs),
...makeReplyStacks(replies),
+ ...makeStack('document_mention', docMentions),
...others.flatMap((n) => makeStack(n.notification_metadata.tag, [n])),
];
diff --git a/js/app/packages/service-clients/service-notification/generated/schemas/documentMentionMetadata.ts b/js/app/packages/service-clients/service-notification/generated/schemas/documentMentionMetadata.ts
index 0846d39af7..55dbf7948e 100644
--- a/js/app/packages/service-clients/service-notification/generated/schemas/documentMentionMetadata.ts
+++ b/js/app/packages/service-clients/service-notification/generated/schemas/documentMentionMetadata.ts
@@ -6,6 +6,7 @@
*/
import type { DocumentMentionMetadataFileType } from './documentMentionMetadataFileType';
import type { DocumentMentionMetadataSenderProfilePictureUrl } from './documentMentionMetadataSenderProfilePictureUrl';
+import type { DocumentMentionMetadataSubType } from './documentMentionMetadataSubType';
/**
* Someone mentioned a document in a channel
@@ -18,4 +19,5 @@ export interface DocumentMentionMetadata {
/** The owner of the document */
owner: string;
senderProfilePictureUrl?: DocumentMentionMetadataSenderProfilePictureUrl;
+ subType?: DocumentMentionMetadataSubType;
}
diff --git a/js/app/packages/service-clients/service-notification/generated/schemas/documentMentionMetadataSubType.ts b/js/app/packages/service-clients/service-notification/generated/schemas/documentMentionMetadataSubType.ts
new file mode 100644
index 0000000000..07fe2e5416
--- /dev/null
+++ b/js/app/packages/service-clients/service-notification/generated/schemas/documentMentionMetadataSubType.ts
@@ -0,0 +1,9 @@
+/**
+ * Generated by orval v7.13.0 🍺
+ * Do not edit manually.
+ * notification_service
+ * OpenAPI spec version: 0.1.0
+ */
+import type { NotificationDocumentSubType } from './notificationDocumentSubType';
+
+export type DocumentMentionMetadataSubType = null | NotificationDocumentSubType;
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.ts
index b0719df2e2..0e3bfdb5da 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
@@ -44,6 +44,7 @@ export * from './deviceType';
export * from './documentMentionMetadata';
export * from './documentMentionMetadataFileType';
export * from './documentMentionMetadataSenderProfilePictureUrl';
+export * from './documentMentionMetadataSubType';
export * from './emptyResponse';
export * from './entity';
export * from './entityType';
@@ -91,6 +92,9 @@ export * from './notifEventOneOfTwooneTag';
export * from './notifEventOneOfTwothree';
export * from './notifEventOneOfTwothreeTag';
export * from './notificationBulkRequest';
+export * from './notificationDocumentSubType';
+export * from './notificationDocumentSubTypeOneOf';
+export * from './notificationDocumentSubTypeOneOfType';
export * from './notificationServiceApiVersion';
export * from './notificationTypeName';
export * from './pushNotificationData';
diff --git a/js/app/packages/service-clients/service-notification/generated/schemas/notificationDocumentSubType.ts b/js/app/packages/service-clients/service-notification/generated/schemas/notificationDocumentSubType.ts
new file mode 100644
index 0000000000..e75d8d106e
--- /dev/null
+++ b/js/app/packages/service-clients/service-notification/generated/schemas/notificationDocumentSubType.ts
@@ -0,0 +1,13 @@
+/**
+ * Generated by orval v7.13.0 🍺
+ * Do not edit manually.
+ * notification_service
+ * OpenAPI spec version: 0.1.0
+ */
+import type { NotificationDocumentSubTypeOneOf } from './notificationDocumentSubTypeOneOf';
+
+/**
+ * The sub type of a document in a notification.
+Serializes as `{ "type": "task" }` matching the storage service pattern.
+ */
+export type NotificationDocumentSubType = NotificationDocumentSubTypeOneOf;
diff --git a/js/app/packages/service-clients/service-notification/generated/schemas/notificationDocumentSubTypeOneOf.ts b/js/app/packages/service-clients/service-notification/generated/schemas/notificationDocumentSubTypeOneOf.ts
new file mode 100644
index 0000000000..4059afb365
--- /dev/null
+++ b/js/app/packages/service-clients/service-notification/generated/schemas/notificationDocumentSubTypeOneOf.ts
@@ -0,0 +1,11 @@
+/**
+ * Generated by orval v7.13.0 🍺
+ * Do not edit manually.
+ * notification_service
+ * OpenAPI spec version: 0.1.0
+ */
+import type { NotificationDocumentSubTypeOneOfType } from './notificationDocumentSubTypeOneOfType';
+
+export type NotificationDocumentSubTypeOneOf = {
+ type: NotificationDocumentSubTypeOneOfType;
+};
diff --git a/js/app/packages/service-clients/service-notification/generated/schemas/notificationDocumentSubTypeOneOfType.ts b/js/app/packages/service-clients/service-notification/generated/schemas/notificationDocumentSubTypeOneOfType.ts
new file mode 100644
index 0000000000..7086a1b542
--- /dev/null
+++ b/js/app/packages/service-clients/service-notification/generated/schemas/notificationDocumentSubTypeOneOfType.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 NotificationDocumentSubTypeOneOfType =
+ (typeof NotificationDocumentSubTypeOneOfType)[keyof typeof NotificationDocumentSubTypeOneOfType];
+
+// eslint-disable-next-line @typescript-eslint/no-redeclare
+export const NotificationDocumentSubTypeOneOfType = {
+ task: 'task',
+} as const;
diff --git a/js/app/packages/service-clients/service-notification/generated/zod.ts b/js/app/packages/service-clients/service-notification/generated/zod.ts
index d2efa9de29..f62a704cea 100644
--- a/js/app/packages/service-clients/service-notification/generated/zod.ts
+++ b/js/app/packages/service-clients/service-notification/generated/zod.ts
@@ -192,6 +192,18 @@ export const listTypedNotificationsResponse = zod
.string()
.describe('The owner of the document'),
senderProfilePictureUrl: zod.string().nullish(),
+ subType: zod
+ .union([
+ zod.null(),
+ zod
+ .object({
+ type: zod.enum(['task']),
+ })
+ .describe(
+ 'The sub type of a document in a notification.\nSerializes as `{ \"type\": \"task\" }` matching the storage service pattern.'
+ ),
+ ])
+ .optional(),
})
.describe('Someone mentioned a document in a channel'),
tag: zod.enum(['document_mention']),
@@ -611,6 +623,18 @@ export const bulkGetTypedNotificationsByEventItemIdsResponse = zod
.string()
.describe('The owner of the document'),
senderProfilePictureUrl: zod.string().nullish(),
+ subType: zod
+ .union([
+ zod.null(),
+ zod
+ .object({
+ type: zod.enum(['task']),
+ })
+ .describe(
+ 'The sub type of a document in a notification.\nSerializes as `{ \"type\": \"task\" }` matching the storage service pattern.'
+ ),
+ ])
+ .optional(),
})
.describe('Someone mentioned a document in a channel'),
tag: zod.enum(['document_mention']),
@@ -1024,6 +1048,18 @@ export const getTypedNotificationsByEventItemIdResponse = zod
.string()
.describe('The owner of the document'),
senderProfilePictureUrl: zod.string().nullish(),
+ subType: zod
+ .union([
+ zod.null(),
+ zod
+ .object({
+ type: zod.enum(['task']),
+ })
+ .describe(
+ 'The sub type of a document in a notification.\nSerializes as `{ \"type\": \"task\" }` matching the storage service pattern.'
+ ),
+ ])
+ .optional(),
})
.describe('Someone mentioned a document in a channel'),
tag: zod.enum(['document_mention']),
@@ -1444,6 +1480,18 @@ export const getTypedNotificationByIdResponse = zod
.describe('The file type of the document'),
owner: zod.string().describe('The owner of the document'),
senderProfilePictureUrl: zod.string().nullish(),
+ subType: zod
+ .union([
+ zod.null(),
+ zod
+ .object({
+ type: zod.enum(['task']),
+ })
+ .describe(
+ 'The sub type of a document in a notification.\nSerializes as `{ \"type\": \"task\" }` matching the storage service pattern.'
+ ),
+ ])
+ .optional(),
})
.describe('Someone mentioned a document in a channel'),
tag: zod.enum(['document_mention']),
diff --git a/js/app/packages/service-clients/service-notification/openapi.json b/js/app/packages/service-clients/service-notification/openapi.json
index 5da647e664..2784bc55d7 100644
--- a/js/app/packages/service-clients/service-notification/openapi.json
+++ b/js/app/packages/service-clients/service-notification/openapi.json
@@ -1409,6 +1409,17 @@
},
"senderProfilePictureUrl": {
"type": ["string", "null"]
+ },
+ "subType": {
+ "oneOf": [
+ {
+ "type": "null"
+ },
+ {
+ "$ref": "#/components/schemas/NotificationDocumentSubType",
+ "description": "The sub type of the document (e.g. task)"
+ }
+ ]
}
}
},
@@ -1819,6 +1830,21 @@
}
}
},
+ "NotificationDocumentSubType": {
+ "oneOf": [
+ {
+ "type": "object",
+ "required": ["type"],
+ "properties": {
+ "type": {
+ "type": "string",
+ "enum": ["task"]
+ }
+ }
+ }
+ ],
+ "description": "The sub type of a document in a notification.\nSerializes as `{ \"type\": \"task\" }` matching the storage service pattern."
+ },
"NotificationServiceApiVersion": {
"type": "string",
"enum": ["v1"]
diff --git a/rust/cloud-storage/comms_service/src/notification.rs b/rust/cloud-storage/comms_service/src/notification.rs
index 53fa8e87af..5d48a548c3 100644
--- a/rust/cloud-storage/comms_service/src/notification.rs
+++ b/rust/cloud-storage/comms_service/src/notification.rs
@@ -12,6 +12,7 @@ use model_entity::EntityType;
use model_notifications::{
ChannelInviteMetadata, ChannelMentionMetadata, ChannelMessageSendMetadata,
ChannelReplyMetadata, CommonChannelMetadata, DocumentMentionMetadata,
+ NotificationDocumentSubType,
};
use notification_hex::domain::models::SendNotificationRequestBuilder;
use notification_hex::domain::service::NotificationIngress;
@@ -99,6 +100,10 @@ impl ChannelMessageEvent<'_> {
document_name: mention.item_name.clone(),
owner: mention.item_owner.clone(),
file_type: mention.file_type.clone(),
+ sub_type: match mention.sub_type.as_deref() {
+ Some("task") => Some(NotificationDocumentSubType::Task),
+ _ => None,
+ },
sender_profile_picture_url: self.sender_profile_picture_url.clone(),
},
sender_id: sender(),
diff --git a/rust/cloud-storage/macro_db_client/.sqlx/query-2d1112d21440f0dfdf8fcbec264389f7abdcc74544558d60d817f56ff0c14524.json b/rust/cloud-storage/macro_db_client/.sqlx/query-2d1112d21440f0dfdf8fcbec264389f7abdcc74544558d60d817f56ff0c14524.json
new file mode 100644
index 0000000000..61b064aaf0
--- /dev/null
+++ b/rust/cloud-storage/macro_db_client/.sqlx/query-2d1112d21440f0dfdf8fcbec264389f7abdcc74544558d60d817f56ff0c14524.json
@@ -0,0 +1,55 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n SELECT\n d.id as \"document_id\",\n d.owner,\n d.name as \"document_name\",\n d.\"fileType\" as \"file_type\",\n dst.sub_type as \"sub_type?: DocumentSubType\"\n FROM\n \"Document\" d\n LEFT JOIN document_sub_type dst ON dst.document_id = d.id\n WHERE d.id = ANY($1)\n ",
+ "describe": {
+ "columns": [
+ {
+ "ordinal": 0,
+ "name": "document_id",
+ "type_info": "Text"
+ },
+ {
+ "ordinal": 1,
+ "name": "owner",
+ "type_info": "Text"
+ },
+ {
+ "ordinal": 2,
+ "name": "document_name",
+ "type_info": "Text"
+ },
+ {
+ "ordinal": 3,
+ "name": "file_type",
+ "type_info": "Text"
+ },
+ {
+ "ordinal": 4,
+ "name": "sub_type?: DocumentSubType",
+ "type_info": {
+ "Custom": {
+ "name": "document_sub_type_value",
+ "kind": {
+ "Enum": [
+ "task"
+ ]
+ }
+ }
+ }
+ }
+ ],
+ "parameters": {
+ "Left": [
+ "TextArray"
+ ]
+ },
+ "nullable": [
+ false,
+ false,
+ false,
+ true,
+ true
+ ]
+ },
+ "hash": "2d1112d21440f0dfdf8fcbec264389f7abdcc74544558d60d817f56ff0c14524"
+}
diff --git a/rust/cloud-storage/macro_db_client/.sqlx/query-63ca13cc79c27b5267ebbf53491b657ca7671e1ab9d1a4691372693a9f9a4ff8.json b/rust/cloud-storage/macro_db_client/.sqlx/query-63ca13cc79c27b5267ebbf53491b657ca7671e1ab9d1a4691372693a9f9a4ff8.json
new file mode 100644
index 0000000000..a110bb67c6
--- /dev/null
+++ b/rust/cloud-storage/macro_db_client/.sqlx/query-63ca13cc79c27b5267ebbf53491b657ca7671e1ab9d1a4691372693a9f9a4ff8.json
@@ -0,0 +1,22 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n SELECT DISTINCT cp.user_id\n FROM comms_channel_participants cp\n WHERE cp.channel_id = $1 AND cp.left_at IS NULL\n ",
+ "describe": {
+ "columns": [
+ {
+ "ordinal": 0,
+ "name": "user_id",
+ "type_info": "Text"
+ }
+ ],
+ "parameters": {
+ "Left": [
+ "Uuid"
+ ]
+ },
+ "nullable": [
+ false
+ ]
+ },
+ "hash": "63ca13cc79c27b5267ebbf53491b657ca7671e1ab9d1a4691372693a9f9a4ff8"
+}
diff --git a/rust/cloud-storage/macro_db_client/.sqlx/query-6ea5fe0c08693b233361460d1a1b46168b4bf9848d252242a06569301144a4f6.json b/rust/cloud-storage/macro_db_client/.sqlx/query-6ea5fe0c08693b233361460d1a1b46168b4bf9848d252242a06569301144a4f6.json
new file mode 100644
index 0000000000..5d785a97ee
--- /dev/null
+++ b/rust/cloud-storage/macro_db_client/.sqlx/query-6ea5fe0c08693b233361460d1a1b46168b4bf9848d252242a06569301144a4f6.json
@@ -0,0 +1,55 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n SELECT\n d.id as \"document_id\",\n d.owner,\n d.name as \"document_name\",\n d.\"fileType\" as \"file_type\",\n dst.sub_type as \"sub_type?: DocumentSubType\"\n FROM\n \"Document\" d\n LEFT JOIN document_sub_type dst ON dst.document_id = d.id\n WHERE d.id = $1\n LIMIT 1\n ",
+ "describe": {
+ "columns": [
+ {
+ "ordinal": 0,
+ "name": "document_id",
+ "type_info": "Text"
+ },
+ {
+ "ordinal": 1,
+ "name": "owner",
+ "type_info": "Text"
+ },
+ {
+ "ordinal": 2,
+ "name": "document_name",
+ "type_info": "Text"
+ },
+ {
+ "ordinal": 3,
+ "name": "file_type",
+ "type_info": "Text"
+ },
+ {
+ "ordinal": 4,
+ "name": "sub_type?: DocumentSubType",
+ "type_info": {
+ "Custom": {
+ "name": "document_sub_type_value",
+ "kind": {
+ "Enum": [
+ "task"
+ ]
+ }
+ }
+ }
+ }
+ ],
+ "parameters": {
+ "Left": [
+ "Text"
+ ]
+ },
+ "nullable": [
+ false,
+ false,
+ false,
+ true,
+ false
+ ]
+ },
+ "hash": "6ea5fe0c08693b233361460d1a1b46168b4bf9848d252242a06569301144a4f6"
+}
diff --git a/rust/cloud-storage/macro_db_client/src/notification/mod.rs b/rust/cloud-storage/macro_db_client/src/notification/mod.rs
index c742181708..a7cdf26927 100644
--- a/rust/cloud-storage/macro_db_client/src/notification/mod.rs
+++ b/rust/cloud-storage/macro_db_client/src/notification/mod.rs
@@ -1,11 +1,8 @@
use anyhow::Context;
-use macro_user_id::user_id::MacroUserIdStr;
+use document_sub_type::DocumentSubType;
+use macro_user_id::{cowlike::CowLike, user_id::MacroUserIdStr};
-use crate::document::get_basic_documents;
-use crate::{
- chat::get_basic_chat, document::get_basic_document,
- projects::get_project::get_basic_project::get_basic_project,
-};
+use crate::{chat::get_basic_chat, projects::get_project::get_basic_project::get_basic_project};
pub mod document;
pub mod project;
@@ -17,6 +14,8 @@ pub struct BasicCloudStorageItemMetadata {
pub item_name: String,
pub item_owner: MacroUserIdStr<'static>,
pub file_type: Option<String>,
+ /// Raw sub_type string from DB (e.g. "task"). None for non-task documents.
+ pub sub_type: Option<String>,
}
/// Gets the basic cloud storage item metadata for a given item
@@ -29,15 +28,36 @@ pub async fn get_basic_cloud_storage_item_metadata(
match item_type {
"document" => {
tracing::trace!("getting document metadata");
- let basic_document_metadata = get_basic_document(db, item_id)
- .await
- .context("unable to get document metadata")?;
+ let row = sqlx::query!(
+ r#"
+ SELECT
+ d.id as "document_id",
+ d.owner,
+ d.name as "document_name",
+ d."fileType" as "file_type",
+ dst.sub_type as "sub_type?: DocumentSubType"
+ FROM
+ "Document" d
+ LEFT JOIN document_sub_type dst ON dst.document_id = d.id
+ WHERE d.id = $1
+ LIMIT 1
+ "#,
+ item_id,
+ )
+ .fetch_one(db)
+ .await
+ .context("unable to get document metadata")?;
+
+ let owner = MacroUserIdStr::parse_from_str(&row.owner)
+ .map_err(|e| anyhow::anyhow!("invalid owner id: {e}"))?
+ .into_owned();
Ok(BasicCloudStorageItemMetadata {
- item_id: basic_document_metadata.document_id,
- item_name: basic_document_metadata.document_name,
- item_owner: basic_document_metadata.owner,
- file_type: basic_document_metadata.file_type,
+ item_id: row.document_id,
+ item_name: row.document_name,
+ item_owner: owner,
+ file_type: row.file_type,
+ sub_type: row.sub_type.map(|st| st.to_string()),
})
}
"chat" => {
@@ -51,6 +71,7 @@ pub async fn get_basic_cloud_storage_item_metadata(
item_name: basic_chat_metadata.name,
item_owner: basic_chat_metadata.user_id,
file_type: None,
+ sub_type: None,
})
}
"project" => {
@@ -63,6 +84,7 @@ pub async fn get_basic_cloud_storage_item_metadata(
item_name: project_metadata.name,
item_owner: project_metadata.user_id,
file_type: None,
+ sub_type: None,
})
}
_ => Err(anyhow::anyhow!("invalid item type")),
@@ -81,20 +103,39 @@ pub async fn get_basic_cloud_storage_documents_metadata(
tracing::trace!("getting metadata for {} documents", document_ids.len());
- let basic_documents = get_basic_documents(db, document_ids)
- .await
- .context("unable to get documents metadata")?;
+ let rows = sqlx::query!(
+ r#"
+ SELECT
+ d.id as "document_id",
+ d.owner,
+ d.name as "document_name",
+ d."fileType" as "file_type",
+ dst.sub_type as "sub_type?: DocumentSubType"
+ FROM
+ "Document" d
+ LEFT JOIN document_sub_type dst ON dst.document_id = d.id
+ WHERE d.id = ANY($1)
+ "#,
+ document_ids,
+ )
+ .fetch_all(db)
+ .await
+ .context("unable to get documents metadata")?;
- // Transform documents into BasicCloudStorageItemMetadata with their IDs
- let result = basic_documents
+ let result = rows
.into_iter()
- .map(|doc| BasicCloudStorageItemMetadata {
- item_id: doc.document_id,
- item_name: doc.document_name,
- item_owner: doc.owner,
- file_type: doc.file_type,
+ .map(|row| {
+ MacroUserIdStr::parse_from_str(&row.owner)
+ .map_err(|e| anyhow::anyhow!("invalid owner id: {e}"))
+ .map(|owner| BasicCloudStorageItemMetadata {
+ item_id: row.document_id,
+ item_name: row.document_name,
+ item_owner: owner.into_owned(),
+ file_type: row.file_type,
+ sub_type: row.sub_type.map(|st| st.to_string()),
+ })
})
- .collect();
+ .collect::<anyhow::Result<Vec<_>>>()?;
Ok(result)
}
diff --git a/rust/cloud-storage/model_notifications/src/metadata.rs b/rust/cloud-storage/model_notifications/src/metadata.rs
index ad37dfb2c0..5fc964fd42 100644
--- a/rust/cloud-storage/model_notifications/src/metadata.rs
+++ b/rust/cloud-storage/model_notifications/src/metadata.rs
@@ -155,6 +155,14 @@ pub struct ChannelReplyMetadata {
pub sender_profile_picture_url: Option<String>,
}
+/// The sub type of a document in a notification.
+/// Serializes as `{ "type": "task" }` matching the storage service pattern.
+#[derive(Serialize, Deserialize, Debug, Clone, ToSchema, PartialEq, Eq)]
+#[serde(tag = "type", rename_all = "snake_case")]
+pub enum NotificationDocumentSubType {
+ Task,
+}
+
/// Someone mentioned a document in a channel
#[derive(Serialize, Deserialize, Debug, Clone, ToSchema)]
#[serde(rename_all = "camelCase")]
@@ -168,6 +176,10 @@ pub struct DocumentMentionMetadata {
/// The file type of the document
#[serde(alias = "file_type")]
pub file_type: Option<String>,
+ /// The sub type of the document (e.g. task)
+ #[serde(alias = "sub_type")]
+ #[serde(default)]
+ pub sub_type: Option<NotificationDocumentSubType>,
#[serde(default)]
pub sender_profile_picture_url: Option<String>,
}