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.

fix(notifications): correctly resolve sender name for emails (#932)

teob031388ae3af
diff --git a/js/app/packages/core/component/NotificationRenderer.tsx b/js/app/packages/core/component/NotificationRenderer.tsx
index 3926c7ca63..0dc4359936 100644
--- a/js/app/packages/core/component/NotificationRenderer.tsx
+++ b/js/app/packages/core/component/NotificationRenderer.tsx
@@ -1,6 +1,6 @@
import { InlineItemPreview } from '@core/component/ItemPreview';
import { StaticMarkdown } from '@core/component/LexicalMarkdown/component/core/StaticMarkdown';
-import { tryMacroId, useDisplayName } from '@core/user';
+import { macroIdToEmail, tryMacroId, useDisplayName } from '@core/user';
import { formatDate } from '@core/util/date';
import {
extractNotificationData,
@@ -32,9 +32,12 @@ export function NotificationRenderer(props: NotificationRendererProps) {
<Show when={data()}>
{(d) => {
const actorId = d().actor?.id ?? '';
- const [actorName] = useDisplayName(tryMacroId(actorId));
-
- const displayName = () => actorName() || 'Someone';
+ const macroId = tryMacroId(actorId);
+ const [actorName] = useDisplayName(macroId);
+ const emailFallback = macroId
+ ? macroIdToEmail(macroId)
+ : actorId || undefined;
+ const displayName = () => actorName() || emailFallback || 'Someone';
if (props.mode === 'preview') {
return (
diff --git a/js/app/packages/notifications/notification-preview.ts b/js/app/packages/notifications/notification-preview.ts
index 04559c1cef..a700d18a38 100644
--- a/js/app/packages/notifications/notification-preview.ts
+++ b/js/app/packages/notifications/notification-preview.ts
@@ -185,9 +185,10 @@ const extractors: {
new_email: (n) => {
const m = n.notificationMetadata;
if (!m) return null;
+ const actorId = n.senderId ?? m.sender;
return {
type: n.notificationEventType,
- actor: m.sender ? { id: m.sender! } : undefined,
+ actor: actorId ? { id: actorId } : undefined,
action: 'sent a new email',
target: { type: 'email', id: n.entity_id, show: false },
content: m.subject,
diff --git a/js/app/packages/notifications/notification-resolvers.ts b/js/app/packages/notifications/notification-resolvers.ts
index b41a8e75f8..d8e8bf0eb3 100644
--- a/js/app/packages/notifications/notification-resolvers.ts
+++ b/js/app/packages/notifications/notification-resolvers.ts
@@ -2,7 +2,7 @@ import type { BlockName } from '@core/block';
import { itemToResolvedBlockName } from '@core/constant/allBlocks';
import { isAccessiblePreviewItem, useItemPreview } from '@core/signal/preview';
import type { EntityType } from '@core/types';
-import { tryMacroId, useDisplayName } from '@core/user';
+import { macroIdToEmail, tryMacroId, useDisplayName } from '@core/user';
import type { ItemType } from '@service-storage/client';
import { raceTimeout, until } from '@solid-primitives/promise';
@@ -19,8 +19,15 @@ export type NotificationBlockNameResolver = (
const RESOLVER_TIMEOUT = 1000;
-export const DefaultUserNameResolver: UserNameResolver = async (id: string) =>
- raceTimeout(until(useDisplayName(tryMacroId(id))[0]), RESOLVER_TIMEOUT);
+export const DefaultUserNameResolver: UserNameResolver = async (id: string) => {
+ const macroId = tryMacroId(id);
+ const resolvedName = await raceTimeout(
+ until(useDisplayName(macroId)[0]),
+ RESOLVER_TIMEOUT
+ );
+ if (resolvedName) return resolvedName;
+ return macroId ? macroIdToEmail(macroId) : id || undefined;
+};
const getPreview = async (id: string, type: EntityType) => {
const [preview] = useItemPreview({ id, type: type as ItemType });
diff --git a/js/app/packages/notifications/tests/notification-preview.test.ts b/js/app/packages/notifications/tests/notification-preview.test.ts
new file mode 100644
index 0000000000..f71f252e4e
--- /dev/null
+++ b/js/app/packages/notifications/tests/notification-preview.test.ts
@@ -0,0 +1,54 @@
+import { describe, expect, it } from 'vitest';
+import type { NotificationEventType } from '@service-notification/generated/schemas';
+import { extractNotificationData } from '../notification-preview';
+import { tryToTypedNotification } from '../notification-metadata';
+import type { UnifiedNotification } from '../types';
+
+function createEmailNotification(
+ senderId: string | null | undefined,
+ metadataSender: string | null | undefined
+): UnifiedNotification {
+ return {
+ id: 'notif-1',
+ entity_id: 'thread-1',
+ entity_type: 'email',
+ createdAt: Date.now(),
+ updatedAt: null,
+ viewedAt: null,
+ deletedAt: null,
+ done: false,
+ sent: true,
+ senderId,
+ notificationEventType: 'new_email' as NotificationEventType,
+ notificationMetadata: {
+ sender: metadataSender,
+ subject: 'Test Subject',
+ snippet: 'Test snippet',
+ threadId: 'thread-1',
+ toEmail: '[email protected]',
+ },
+ } as UnifiedNotification;
+}
+
+describe('new_email extractor', () => {
+ it('prefers senderId over metadata sender', () => {
+ const notification = createEmailNotification(
+ );
+
+ const typed = tryToTypedNotification(notification)!;
+ const data = extractNotificationData(typed);
+
+ expect(data).toHaveProperty('actor.id', 'macro|[email protected]');
+ });
+
+ it('falls back to metadata sender when senderId is null', () => {
+ const notification = createEmailNotification(null, '[email protected]');
+
+ const typed = tryToTypedNotification(notification)!;
+ const data = extractNotificationData(typed);
+
+ expect(data).toHaveProperty('actor.id', '[email protected]');
+ });
+});
diff --git a/js/app/vitest.config.ts b/js/app/vitest.config.ts
index 30e535fd8f..b7eb56ad70 100644
--- a/js/app/vitest.config.ts
+++ b/js/app/vitest.config.ts
@@ -58,6 +58,13 @@ export default defineConfig({
name: 'block-channel',
},
},
+ {
+ extends: './packages/notifications/vitest.config.ts',
+ test: {
+ include: ['packages/notifications/**/*.{test,spec}.{ts,tsx}'],
+ name: 'notifications',
+ },
+ },
],
},
});