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): improve browser notifications + parse out m tags (#285)

teod74fc716814b
diff --git a/js/app/packages/lexical-core/index.ts b/js/app/packages/lexical-core/index.ts
index 9cad98af1c..d70e49b17d 100644
--- a/js/app/packages/lexical-core/index.ts
+++ b/js/app/packages/lexical-core/index.ts
@@ -28,3 +28,4 @@ export * from './plugins/nodeIdPlugin';
export * from './plugins/peerIdPlugin';
export * from './transformers';
+export * from './utils/mentions';
diff --git a/js/app/packages/lexical-core/utils/mentions.ts b/js/app/packages/lexical-core/utils/mentions.ts
index e6fe6051ae..7eebcbeb50 100644
--- a/js/app/packages/lexical-core/utils/mentions.ts
+++ b/js/app/packages/lexical-core/utils/mentions.ts
@@ -74,3 +74,69 @@ export function buildMentionMarkdownString(info: MentionInfo): string {
return wrapXml('m-date-mention', dropKey(info, 'type'));
}
}
+
+/**
+ * Converts markdown text with XML mention tags to plain text.
+ * Extracts the readable text from mention nodes:
+ * - User mentions: email
+ * - Contact mentions: name (fallback to emailOrDomain)
+ * - Date mentions: displayFormat
+ * - Document mentions: documentName
+ */
+export function markdownToPlainText(markdown: string): string {
+ let result = markdown;
+
+ // Replace user mentions with email
+ result = result.replace(
+ /<m-user-mention>(.*?)<\/m-user-mention>/g,
+ (_, json) => {
+ try {
+ const data = JSON.parse(json);
+ return data.email || '';
+ } catch {
+ return '';
+ }
+ }
+ );
+
+ // Replace contact mentions with name or emailOrDomain
+ result = result.replace(
+ /<m-contact-mention>(.*?)<\/m-contact-mention>/g,
+ (_, json) => {
+ try {
+ const data = JSON.parse(json);
+ return data.name || data.emailOrDomain || '';
+ } catch {
+ return '';
+ }
+ }
+ );
+
+ // Replace date mentions with displayFormat
+ result = result.replace(
+ /<m-date-mention>(.*?)<\/m-date-mention>/g,
+ (_, json) => {
+ try {
+ const data = JSON.parse(json);
+ return data.displayFormat || '';
+ } catch {
+ return '';
+ }
+ }
+ );
+
+ // Replace document mentions with documentName
+ result = result.replace(
+ /<m-document-mention>(.*?)<\/m-document-mention>/g,
+ (_, json) => {
+ try {
+ const data = JSON.parse(json);
+ return data.documentName || '';
+ } catch {
+ return '';
+ }
+ }
+ );
+
+ return result;
+}
diff --git a/js/app/packages/notifications/components/Playground.tsx b/js/app/packages/notifications/components/Playground.tsx
index a84e37e3f3..a95d1a3235 100644
--- a/js/app/packages/notifications/components/Playground.tsx
+++ b/js/app/packages/notifications/components/Playground.tsx
@@ -121,7 +121,7 @@ function NotificationItem(props: {
>
<div class="flex items-start gap-3">
<div
- class={`size-2 mt-1 shrink-0 rounded-full ${
+ class={`size-2 mt-1 shrink-0 ${
isUnread() ? 'bg-accent' : 'bg-ink-extra-muted'
}`}
/>
@@ -376,7 +376,7 @@ function NotificationDetail(props: {
<div class="p-4 bg-menu rounded-xl border border-edge-muted">
<div class="flex items-start gap-3">
<div
- class={`size-2 mt-1 shrink-0 rounded-full ${
+ class={`size-2 mt-1 shrink-0 ${
!props.notification.viewedAt
? 'bg-accent'
: 'bg-ink-extra-muted'
@@ -401,7 +401,7 @@ function NotificationDetail(props: {
>
<div class="flex justify-start items-center gap-3 mb-4 font-mono text-ink-muted text-xs uppercase">
<div
- class={`size-2 rounded-full ${
+ class={`size-2 ${
!props.notification.viewedAt
? 'bg-accent'
: 'bg-ink-extra-muted'
diff --git a/js/app/packages/notifications/notification-preview.ts b/js/app/packages/notifications/notification-preview.ts
index 9a45c1fd64..96292c1d42 100644
--- a/js/app/packages/notifications/notification-preview.ts
+++ b/js/app/packages/notifications/notification-preview.ts
@@ -10,10 +10,12 @@ import type {
export type NotificationData = {
actor?: { id: string };
action: string;
+ type: NotificationEventType;
target?: {
type: EntityType;
id?: string;
name?: string | null;
+ show?: boolean;
};
content?: string | null;
meta?: {
@@ -53,6 +55,7 @@ const extractors: {
const m = n.notificationMetadata;
if (!m) return null;
return {
+ type: n.notificationEventType,
actor: m.sharedBy ? { id: m.sharedBy! } : undefined,
action: 'shared',
target: {
@@ -72,6 +75,7 @@ const extractors: {
const m = n.notificationMetadata;
if (!m) return null;
return {
+ type: n.notificationEventType,
actor: m.sharedBy ? { id: m.sharedBy! } : undefined,
action: 'shared',
target: {
@@ -91,9 +95,14 @@ const extractors: {
const m = n.notificationMetadata;
if (!m) return null;
return {
+ type: n.notificationEventType,
actor: n.senderId ? { id: n.senderId! } : undefined,
action: 'mentioned you in',
- target: { type: 'channel', id: n.eventItemId },
+ target: {
+ type: 'channel',
+ id: n.eventItemId,
+ show: n.notificationMetadata.channelType !== 'direct_message',
+ },
content: m.messageContent,
meta: {
messageId: m.messageId,
@@ -104,6 +113,7 @@ const extractors: {
const m = n.notificationMetadata;
if (!m) return null;
return {
+ type: n.notificationEventType,
actor: n.senderId ? { id: n.senderId! } : undefined,
action: 'mentioned you in',
target: { type: 'document', id: n.eventItemId, name: m.documentName },
@@ -117,6 +127,7 @@ const extractors: {
const m = n.notificationMetadata;
if (!m) return null;
return {
+ type: n.notificationEventType,
actor: m.invitedBy ? { id: m.invitedBy! } : undefined,
action: 'invited you to',
target: { type: 'channel', id: n.eventItemId, name: m.channelName },
@@ -127,9 +138,14 @@ const extractors: {
const m = n.notificationMetadata;
if (!m) return null;
return {
+ type: n.notificationEventType,
actor: m.sender ? { id: m.sender! } : undefined,
action: 'sent a message in',
- target: { type: 'channel', id: n.eventItemId },
+ target: {
+ type: 'channel',
+ id: n.eventItemId,
+ show: n.notificationMetadata.channelType !== 'direct_message',
+ },
content: m.messageContent,
meta: {
messageId: m.messageId,
@@ -140,9 +156,14 @@ const extractors: {
const m = n.notificationMetadata;
if (!m) return null;
return {
+ type: n.notificationEventType,
actor: m.userId ? { id: m.userId! } : undefined,
action: 'replied in',
- target: { type: 'channel', id: n.eventItemId },
+ target: {
+ type: 'channel',
+ id: n.eventItemId,
+ show: n.notificationMetadata.channelType !== 'direct_message',
+ },
content: m.messageContent,
meta: {
messageId: m.messageId,
@@ -154,6 +175,7 @@ const extractors: {
const m = n.notificationMetadata;
if (!m) return null;
return {
+ type: n.notificationEventType,
actor: m.owner ? { id: m.owner! } : undefined,
action: 'shared with you',
target: { type: 'document', id: n.eventItemId, name: m.documentName },
@@ -167,9 +189,10 @@ const extractors: {
const m = n.notificationMetadata;
if (!m) return null;
return {
+ type: n.notificationEventType,
actor: m.sender ? { id: m.sender! } : undefined,
action: 'sent a new email',
- target: { type: 'email', id: n.eventItemId },
+ target: { type: 'email', id: n.eventItemId, show: false },
content: m.subject,
meta: {
sender: m.sender,
@@ -182,6 +205,7 @@ const extractors: {
const m = n.notificationMetadata;
if (!m) return null;
return {
+ type: n.notificationEventType,
actor: m.invitedBy ? { id: m.invitedBy! } : undefined,
action: 'invited you to',
target: { type: 'team', id: n.eventItemId, name: m.teamName },
@@ -192,6 +216,7 @@ const extractors: {
const m = n.notificationMetadata;
if (!m) return null;
return {
+ type: n.notificationEventType,
actor: undefined,
action: 'rejected your team invitation',
target: { type: 'team', id: n.eventItemId },
@@ -217,6 +242,7 @@ export interface BrowserNotificationPreview {
}
import { getFaviconUrl } from '@app/util/favicon';
+import { markdownToPlainText } from '@lexical-core';
import { themeReactive } from '../block-theme/signals/themeReactive';
const USER_NAME_FALLBACK = 'Someone';
@@ -238,6 +264,8 @@ export async function toBrowserNotification(
(data.actor ? await resolveUserName(data.actor.id) : undefined) ??
USER_NAME_FALLBACK;
+ const showTarget = data.target?.show ?? false;
+
const targetName =
data.target?.name ??
(data.target?.id
@@ -249,8 +277,8 @@ export async function toBrowserNotification(
const icon = getFaviconUrl(accentColor);
return {
- title: `${actor} ${data.action} ${targetName}`,
- body: data.content ?? `${actor} ${data.action}`,
+ title: `${actor}${showTarget ? ` <${targetName}>` : ''}`,
+ body: data.content ? markdownToPlainText(data.content) : `${data.action}`,
icon,
};
}