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(calendar): show event descriptions in mention preview cards (#6888)

gbirmand4110708fd03
diff --git a/.sqlx/query-27eb7fa656e642da28f0937f7c9cf5cb27097157ed86b5cfb29caf98b679c55b.json b/.sqlx/query-27eb7fa656e642da28f0937f7c9cf5cb27097157ed86b5cfb29caf98b679c55b.json
deleted file mode 100644
index cdedca8129..0000000000
--- a/.sqlx/query-27eb7fa656e642da28f0937f7c9cf5cb27097157ed86b5cfb29caf98b679c55b.json
+++ /dev/null
@@ -1,139 +0,0 @@
-{
- "db_name": "PostgreSQL",
- "query": "\n SELECT\n (mentioned.id IS NOT NULL) AS \"mention_exists!\",\n viewer_event.id AS \"resolved_event_id?\",\n viewer_event.is_channel_shared AS \"is_channel_shared?\",\n viewer_event.title AS \"title?\",\n viewer_event.location AS \"location?\",\n viewer_event.organizer_email AS \"organizer_email?\",\n viewer_event.organizer_name AS \"organizer_name?\",\n viewer_event.recurrence_lines AS \"recurrence_lines?\",\n viewer_event.starts_at AS \"event_starts_at?\",\n viewer_event.ends_at AS \"event_ends_at?\",\n viewer_event.start_date AS \"event_start_date?\",\n viewer_event.end_date AS \"event_end_date?\",\n viewer_event.time_zone AS \"time_zone?\",\n viewer_event.updated_at AS \"updated_at?\",\n occurrence.occurrence_key AS \"occurrence_key?\",\n occurrence.starts_at AS \"occurrence_starts_at?\",\n occurrence.ends_at AS \"occurrence_ends_at?\",\n occurrence.start_date AS \"occurrence_start_date?\",\n occurrence.end_date AS \"occurrence_end_date?\",\n attendees.attendee_count AS \"attendee_count?\"\n FROM unnest($2::uuid[], $3::text[])\n WITH ORDINALITY AS requested(event_id, occurrence_key, ord)\n LEFT JOIN calendar_events mentioned\n ON mentioned.id = requested.event_id\n AND mentioned.status <> 'cancelled'\n LEFT JOIN LATERAL (\n SELECT resolved.*\n FROM (\n SELECT\n candidate.id,\n false AS is_channel_shared,\n (candidate.owner_id = $1) AS is_owned,\n (candidate.id = mentioned.id) AS is_mentioned,\n candidate.title,\n candidate.location,\n candidate.organizer_email,\n candidate.organizer_name,\n candidate.recurrence_lines,\n candidate.starts_at,\n candidate.ends_at,\n candidate.start_date,\n candidate.end_date,\n candidate.time_zone,\n candidate.updated_at\n FROM calendar_events candidate\n WHERE candidate.ical_uid = mentioned.ical_uid\n AND candidate.status <> 'cancelled'\n AND (\n candidate.owner_id = $1\n OR EXISTS (\n SELECT 1\n FROM macro_user_links link\n WHERE link.link_id = candidate.source_link_id\n AND link.primary_macro_id = $1\n )\n )\n UNION ALL\n SELECT\n mentioned.id,\n true,\n false,\n true,\n mentioned.title,\n mentioned.location,\n mentioned.organizer_email,\n mentioned.organizer_name,\n mentioned.recurrence_lines,\n mentioned.starts_at,\n mentioned.ends_at,\n mentioned.start_date,\n mentioned.end_date,\n mentioned.time_zone,\n mentioned.updated_at\n WHERE mentioned.visibility IN ('default', 'public')\n AND EXISTS (\n SELECT 1\n FROM entity_access grant_row\n JOIN comms_channel_participants participant\n ON participant.channel_id::text = grant_row.source_id\n AND participant.user_id = $1\n AND participant.left_at IS NULL\n WHERE grant_row.entity_id = mentioned.id\n AND grant_row.entity_type = 'calendar_event'\n AND grant_row.source_type = 'channel'\n )\n ) resolved\n ORDER BY\n resolved.is_channel_shared,\n resolved.is_owned DESC,\n resolved.is_mentioned DESC,\n resolved.updated_at DESC,\n resolved.id\n LIMIT 1\n ) viewer_event ON true\n LEFT JOIN LATERAL (\n SELECT\n instance.occurrence_key,\n instance.starts_at,\n instance.ends_at,\n instance.start_date,\n instance.end_date\n FROM calendar_event_occurrences instance\n CROSS JOIN LATERAL (\n SELECT COALESCE(\n instance.starts_at,\n instance.start_date::timestamp AT TIME ZONE 'UTC'\n ) AS at\n ) instance_start\n WHERE instance.event_id = viewer_event.id\n AND NOT instance.is_cancelled\n ORDER BY\n (instance.occurrence_key\n IS NOT DISTINCT FROM requested.occurrence_key) DESC,\n (instance_start.at >= $4) DESC,\n CASE WHEN instance_start.at >= $4 THEN instance_start.at END ASC,\n instance_start.at DESC,\n instance.occurrence_key\n LIMIT 1\n ) occurrence ON true\n LEFT JOIN LATERAL (\n SELECT count(*) AS attendee_count\n FROM calendar_event_attendees attendee\n WHERE attendee.event_id = viewer_event.id\n ) attendees ON true\n ORDER BY requested.ord\n ",
- "describe": {
- "columns": [
- {
- "ordinal": 0,
- "name": "mention_exists!",
- "type_info": "Bool"
- },
- {
- "ordinal": 1,
- "name": "resolved_event_id?",
- "type_info": "Uuid"
- },
- {
- "ordinal": 2,
- "name": "is_channel_shared?",
- "type_info": "Bool"
- },
- {
- "ordinal": 3,
- "name": "title?",
- "type_info": "Text"
- },
- {
- "ordinal": 4,
- "name": "location?",
- "type_info": "Text"
- },
- {
- "ordinal": 5,
- "name": "organizer_email?",
- "type_info": "Text"
- },
- {
- "ordinal": 6,
- "name": "organizer_name?",
- "type_info": "Text"
- },
- {
- "ordinal": 7,
- "name": "recurrence_lines?",
- "type_info": "TextArray"
- },
- {
- "ordinal": 8,
- "name": "event_starts_at?",
- "type_info": "Timestamptz"
- },
- {
- "ordinal": 9,
- "name": "event_ends_at?",
- "type_info": "Timestamptz"
- },
- {
- "ordinal": 10,
- "name": "event_start_date?",
- "type_info": "Date"
- },
- {
- "ordinal": 11,
- "name": "event_end_date?",
- "type_info": "Date"
- },
- {
- "ordinal": 12,
- "name": "time_zone?",
- "type_info": "Text"
- },
- {
- "ordinal": 13,
- "name": "updated_at?",
- "type_info": "Timestamptz"
- },
- {
- "ordinal": 14,
- "name": "occurrence_key?",
- "type_info": "Text"
- },
- {
- "ordinal": 15,
- "name": "occurrence_starts_at?",
- "type_info": "Timestamptz"
- },
- {
- "ordinal": 16,
- "name": "occurrence_ends_at?",
- "type_info": "Timestamptz"
- },
- {
- "ordinal": 17,
- "name": "occurrence_start_date?",
- "type_info": "Date"
- },
- {
- "ordinal": 18,
- "name": "occurrence_end_date?",
- "type_info": "Date"
- },
- {
- "ordinal": 19,
- "name": "attendee_count?",
- "type_info": "Int8"
- }
- ],
- "parameters": {
- "Left": [
- "Text",
- "UuidArray",
- "TextArray",
- "Timestamptz"
- ]
- },
- "nullable": [
- null,
- true,
- true,
- true,
- true,
- true,
- true,
- true,
- true,
- true,
- true,
- true,
- true,
- true,
- true,
- true,
- true,
- true,
- true,
- null
- ]
- },
- "hash": "27eb7fa656e642da28f0937f7c9cf5cb27097157ed86b5cfb29caf98b679c55b"
-}
diff --git a/.sqlx/query-2e3790c0a14f6980f2126ace81782647896ab07b3524d9db00016293433a0aba.json b/.sqlx/query-2e3790c0a14f6980f2126ace81782647896ab07b3524d9db00016293433a0aba.json
new file mode 100644
index 0000000000..c4e14f20d2
--- /dev/null
+++ b/.sqlx/query-2e3790c0a14f6980f2126ace81782647896ab07b3524d9db00016293433a0aba.json
@@ -0,0 +1,146 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n SELECT\n (mentioned.id IS NOT NULL) AS \"mention_exists!\",\n viewer_event.id AS \"resolved_event_id?\",\n viewer_event.is_channel_shared AS \"is_channel_shared?\",\n COALESCE(occurrence_override.title, viewer_event.title) AS \"title?\",\n left(\n COALESCE(occurrence_override.description, viewer_event.description),\n $5\n ) AS \"description?\",\n COALESCE(occurrence_override.location, viewer_event.location) AS \"location?\",\n viewer_event.organizer_email AS \"organizer_email?\",\n viewer_event.organizer_name AS \"organizer_name?\",\n viewer_event.recurrence_lines AS \"recurrence_lines?\",\n viewer_event.starts_at AS \"event_starts_at?\",\n viewer_event.ends_at AS \"event_ends_at?\",\n viewer_event.start_date AS \"event_start_date?\",\n viewer_event.end_date AS \"event_end_date?\",\n viewer_event.time_zone AS \"time_zone?\",\n viewer_event.updated_at AS \"updated_at?\",\n occurrence.occurrence_key AS \"occurrence_key?\",\n occurrence.starts_at AS \"occurrence_starts_at?\",\n occurrence.ends_at AS \"occurrence_ends_at?\",\n occurrence.start_date AS \"occurrence_start_date?\",\n occurrence.end_date AS \"occurrence_end_date?\",\n attendees.attendee_count AS \"attendee_count?\"\n FROM unnest($2::uuid[], $3::text[])\n WITH ORDINALITY AS requested(event_id, occurrence_key, ord)\n LEFT JOIN calendar_events mentioned\n ON mentioned.id = requested.event_id\n AND mentioned.status <> 'cancelled'\n LEFT JOIN LATERAL (\n SELECT resolved.*\n FROM (\n SELECT\n candidate.id,\n false AS is_channel_shared,\n (candidate.owner_id = $1) AS is_owned,\n (candidate.id = mentioned.id) AS is_mentioned,\n candidate.title,\n candidate.description,\n candidate.location,\n candidate.organizer_email,\n candidate.organizer_name,\n candidate.recurrence_lines,\n candidate.starts_at,\n candidate.ends_at,\n candidate.start_date,\n candidate.end_date,\n candidate.time_zone,\n candidate.updated_at\n FROM calendar_events candidate\n WHERE candidate.ical_uid = mentioned.ical_uid\n AND candidate.status <> 'cancelled'\n AND (\n candidate.owner_id = $1\n OR EXISTS (\n SELECT 1\n FROM macro_user_links link\n WHERE link.link_id = candidate.source_link_id\n AND link.primary_macro_id = $1\n )\n )\n UNION ALL\n SELECT\n mentioned.id,\n true,\n false,\n true,\n mentioned.title,\n mentioned.description,\n mentioned.location,\n mentioned.organizer_email,\n mentioned.organizer_name,\n mentioned.recurrence_lines,\n mentioned.starts_at,\n mentioned.ends_at,\n mentioned.start_date,\n mentioned.end_date,\n mentioned.time_zone,\n mentioned.updated_at\n WHERE mentioned.visibility IN ('default', 'public')\n AND EXISTS (\n SELECT 1\n FROM entity_access grant_row\n JOIN comms_channel_participants participant\n ON participant.channel_id::text = grant_row.source_id\n AND participant.user_id = $1\n AND participant.left_at IS NULL\n WHERE grant_row.entity_id = mentioned.id\n AND grant_row.entity_type = 'calendar_event'\n AND grant_row.source_type = 'channel'\n )\n ) resolved\n ORDER BY\n resolved.is_channel_shared,\n resolved.is_owned DESC,\n resolved.is_mentioned DESC,\n resolved.updated_at DESC,\n resolved.id\n LIMIT 1\n ) viewer_event ON true\n LEFT JOIN LATERAL (\n SELECT\n instance.occurrence_key,\n instance.recurrence_id,\n instance.starts_at,\n instance.ends_at,\n instance.start_date,\n instance.end_date\n FROM calendar_event_occurrences instance\n CROSS JOIN LATERAL (\n SELECT COALESCE(\n instance.starts_at,\n instance.start_date::timestamp AT TIME ZONE 'UTC'\n ) AS at\n ) instance_start\n WHERE instance.event_id = viewer_event.id\n AND NOT instance.is_cancelled\n ORDER BY\n (instance.occurrence_key\n IS NOT DISTINCT FROM requested.occurrence_key) DESC,\n (instance_start.at >= $4) DESC,\n CASE WHEN instance_start.at >= $4 THEN instance_start.at END ASC,\n instance_start.at DESC,\n instance.occurrence_key\n LIMIT 1\n ) occurrence ON true\n -- An exception's content replaces the series content for the\n -- previewed occurrence alone, as it does in the event view.\n LEFT JOIN calendar_event_overrides occurrence_override\n ON occurrence_override.event_id = viewer_event.id\n AND occurrence_override.recurrence_id = occurrence.recurrence_id\n LEFT JOIN LATERAL (\n SELECT count(*) AS attendee_count\n FROM calendar_event_attendees attendee\n WHERE attendee.event_id = viewer_event.id\n ) attendees ON true\n ORDER BY requested.ord\n ",
+ "describe": {
+ "columns": [
+ {
+ "ordinal": 0,
+ "name": "mention_exists!",
+ "type_info": "Bool"
+ },
+ {
+ "ordinal": 1,
+ "name": "resolved_event_id?",
+ "type_info": "Uuid"
+ },
+ {
+ "ordinal": 2,
+ "name": "is_channel_shared?",
+ "type_info": "Bool"
+ },
+ {
+ "ordinal": 3,
+ "name": "title?",
+ "type_info": "Text"
+ },
+ {
+ "ordinal": 4,
+ "name": "description?",
+ "type_info": "Text"
+ },
+ {
+ "ordinal": 5,
+ "name": "location?",
+ "type_info": "Text"
+ },
+ {
+ "ordinal": 6,
+ "name": "organizer_email?",
+ "type_info": "Text"
+ },
+ {
+ "ordinal": 7,
+ "name": "organizer_name?",
+ "type_info": "Text"
+ },
+ {
+ "ordinal": 8,
+ "name": "recurrence_lines?",
+ "type_info": "TextArray"
+ },
+ {
+ "ordinal": 9,
+ "name": "event_starts_at?",
+ "type_info": "Timestamptz"
+ },
+ {
+ "ordinal": 10,
+ "name": "event_ends_at?",
+ "type_info": "Timestamptz"
+ },
+ {
+ "ordinal": 11,
+ "name": "event_start_date?",
+ "type_info": "Date"
+ },
+ {
+ "ordinal": 12,
+ "name": "event_end_date?",
+ "type_info": "Date"
+ },
+ {
+ "ordinal": 13,
+ "name": "time_zone?",
+ "type_info": "Text"
+ },
+ {
+ "ordinal": 14,
+ "name": "updated_at?",
+ "type_info": "Timestamptz"
+ },
+ {
+ "ordinal": 15,
+ "name": "occurrence_key?",
+ "type_info": "Text"
+ },
+ {
+ "ordinal": 16,
+ "name": "occurrence_starts_at?",
+ "type_info": "Timestamptz"
+ },
+ {
+ "ordinal": 17,
+ "name": "occurrence_ends_at?",
+ "type_info": "Timestamptz"
+ },
+ {
+ "ordinal": 18,
+ "name": "occurrence_start_date?",
+ "type_info": "Date"
+ },
+ {
+ "ordinal": 19,
+ "name": "occurrence_end_date?",
+ "type_info": "Date"
+ },
+ {
+ "ordinal": 20,
+ "name": "attendee_count?",
+ "type_info": "Int8"
+ }
+ ],
+ "parameters": {
+ "Left": [
+ "Text",
+ "UuidArray",
+ "TextArray",
+ "Timestamptz",
+ "Int4"
+ ]
+ },
+ "nullable": [
+ null,
+ true,
+ true,
+ null,
+ true,
+ null,
+ true,
+ true,
+ true,
+ true,
+ true,
+ true,
+ true,
+ true,
+ true,
+ true,
+ true,
+ true,
+ true,
+ true,
+ null
+ ]
+ },
+ "hash": "2e3790c0a14f6980f2126ace81782647896ab07b3524d9db00016293433a0aba"
+}
diff --git a/apps/web/src/lib/core/component/DocumentPreview.test.tsx b/apps/web/src/lib/core/component/DocumentPreview.test.tsx
new file mode 100644
index 0000000000..6a0ff48689
--- /dev/null
+++ b/apps/web/src/lib/core/component/DocumentPreview.test.tsx
@@ -0,0 +1,159 @@
+import type { PreviewItem } from '@queries/preview/types';
+import type { CalendarMentionEvent } from '@service-storage/generated/schemas/calendarMentionEvent';
+import { fireEvent, render, screen } from '@solidjs/testing-library';
+import { beforeEach, describe, expect, it, vi } from 'vitest';
+
+const mocks = vi.hoisted(() => ({
+ item: undefined as unknown,
+ openDocument: vi.fn(),
+ openExternalUrl: vi.fn(),
+}));
+vi.mock(
+ '@core/component/LexicalMarkdown/component/core/BlockLink',
+ async (importOriginal) => ({
+ ...(await importOriginal<object>()),
+ openDocument: mocks.openDocument,
+ })
+);
+vi.mock('@core/util/url', async (importOriginal) => ({
+ ...(await importOriginal<object>()),
+ openExternalUrl: mocks.openExternalUrl,
+}));
+vi.mock('./ItemPreview', () => ({
+ useItemPreviewData: () => ({
+ item: () => mocks.item,
+ ItemEntityIcon: () => null,
+ documentProperties: () => undefined,
+ }),
+}));
+// The preview's import graph opens the storage and connection-gateway sockets.
+vi.mock('@service-storage/websocket', () => ({
+ storageWS: { reconnectIfDisconnected: vi.fn() },
+ createWebSocketJob: vi.fn(),
+}));
+vi.mock('@service-connection/websocket', () => ({
+ ws: { addEventListener: vi.fn(), send: vi.fn() },
+ state: () => 'closed',
+ createConnectionBlockWebsocketEffect: vi.fn(),
+ createConnectionWebsocketEffect: vi.fn(),
+}));
+vi.mock('@solidjs/router', () => ({ useNavigate: () => vi.fn() }));
+vi.mock('./AccessErrorViews/Unauthorized', () => ({
+ default: () => <p>You don't have access to this file</p>,
+}));
+vi.mock('./AccessErrorViews/NotFound', () => ({
+ default: () => <p>Not found</p>,
+}));
+
+import { DocumentPreviewContent } from './DocumentPreview';
+
+function calendarItem(event: Partial<CalendarMentionEvent>): PreviewItem {
+ return {
+ id: 'mentioned-event',
+ type: 'calendar_event',
+ access: 'access',
+ loading: false,
+ rawName: 'Pilates',
+ name: 'Pilates',
+ updatedAt: '2026-09-23T17:04:00Z',
+ event: {
+ title: 'Pilates',
+ description: 'Bring a <b>mat</b> <script>alert(1)</script>',
+ time: {
+ kind: 'timed',
+ startsAt: '2026-09-23T23:00:00Z',
+ endsAt: '2026-09-23T23:30:00Z',
+ },
+ occurrenceKey: '2026-09-23T23:00:00+00:00',
+ isRecurring: false,
+ attendeeCount: 1,
+ organizerEmail: '[email protected]',
+ updatedAt: '2026-09-23T17:04:00Z',
+ viewerEventId: 'viewer-copy',
+ ...event,
+ },
+ };
+}
+
+function renderCard() {
+ return render(() => (
+ <DocumentPreviewContent
+ documentInfo={{
+ id: 'mentioned-event',
+ type: 'calendar',
+ params: {},
+ isOpenable: true,
+ }}
+ />
+ ));
+}
+
+beforeEach(() => {
+ vi.clearAllMocks();
+ mocks.item = calendarItem({});
+});
+
+describe('calendar mention preview card', () => {
+ it("opens the viewer's own copy and shows its description", () => {
+ const view = renderCard();
+
+ expect(screen.getByRole('button', { name: 'Pilates' })).toBeTruthy();
+ expect(screen.queryByText(/not on your calendar/)).toBeNull();
+ expect(view.container.textContent).toContain('Bring a mat');
+ expect(view.container.querySelector('b')?.textContent).toBe('mat');
+ expect(view.container.querySelector('script')).toBeNull();
+ });
+
+ // The byline's last-updated time reads as the meeting time on a calendar
+ // card, which already shows the event's own schedule.
+ it('omits the last-updated byline', () => {
+ const view = renderCard();
+
+ expect(view.container.textContent).not.toContain('5:04');
+ expect(view.container.textContent).not.toMatch(/Sep 23, 2026/);
+ });
+
+ it('is read-only for a channel-shared meeting', () => {
+ mocks.item = calendarItem({ viewerEventId: null });
+ const view = renderCard();
+
+ expect(
+ screen.getByText(/Shared with you · not on your calendar/)
+ ).toBeTruthy();
+ expect(screen.queryByRole('button', { name: 'Pilates' })).toBeNull();
+ expect(view.container.textContent).toContain('Pilates');
+ expect(view.container.textContent).toContain('Bring a mat');
+ });
+
+ it('shows no event details without access', () => {
+ mocks.item = {
+ id: 'mentioned-event',
+ type: 'calendar_event',
+ access: 'no_access',
+ loading: false,
+ } satisfies PreviewItem;
+ const view = renderCard();
+
+ expect(screen.getByText("You don't have access to this file")).toBeTruthy();
+ expect(view.container.textContent).not.toContain('Pilates');
+ });
+
+ it('opens description links like the event view does', () => {
+ mocks.item = calendarItem({
+ description:
+ 'See <a href="https://macro.com/app/md/doc-1?line=3">notes</a> and <a href="https://zoom.us/j/1">Zoom</a>',
+ });
+ renderCard();
+
+ fireEvent.click(screen.getByText('notes'));
+ expect(mocks.openDocument).toHaveBeenCalledWith(
+ 'md',
+ 'doc-1',
+ { line: '3' },
+ false
+ );
+
+ fireEvent.click(screen.getByText('Zoom'));
+ expect(mocks.openExternalUrl).toHaveBeenCalledWith('https://zoom.us/j/1');
+ });
+});
diff --git a/apps/web/src/lib/core/component/DocumentPreview.tsx b/apps/web/src/lib/core/component/DocumentPreview.tsx
index 39d0eaee27..a276b26423 100644
--- a/apps/web/src/lib/core/component/DocumentPreview.tsx
+++ b/apps/web/src/lib/core/component/DocumentPreview.tsx
@@ -1,4 +1,8 @@
import { parseLocalDate } from '@app/features/calendar/utils/calendar-date';
+import {
+ parseMacroAppLink,
+ sanitizeCalendarDescription,
+} from '@app/features/calendar/utils/calendar-description';
import {
type CalendarMentionTarget,
copyCalendarEventMentionTarget,
@@ -19,7 +23,10 @@ import {
} from '@core/block';
import { EntityIcon } from '@core/component/EntityIcon';
import { useHoldParentHoverCardOpen } from '@core/component/HoverCard';
-import { isBlockNameWithLocation } from '@core/component/LexicalMarkdown/component/core/BlockLink';
+import {
+ isBlockNameWithLocation,
+ openDocument as openBlockDocument,
+} from '@core/component/LexicalMarkdown/component/core/BlockLink';
import { StaticMarkdown } from '@core/component/LexicalMarkdown/component/core/StaticMarkdown';
import { channelTheme } from '@core/component/LexicalMarkdown/theme';
import { toast } from '@core/component/Toast/Toast';
@@ -27,6 +34,7 @@ import { itemToBlockName, resolveBlockAlias } from '@core/constant/allBlocks';
import { getDisplayName, tryMacroId } from '@core/user';
import { copyBranchNameToClipboard } from '@core/util/branchName';
import { matches } from '@core/util/match';
+import { openExternalUrl } from '@core/util/url';
import MacroEmbed from '@icon/macro-embed.svg';
import CollapseInlinePreview from '@phosphor/arrows-in-line-horizontal.svg';
import ExpandInlinePreview from '@phosphor/arrows-out-line-horizontal.svg';
@@ -42,6 +50,7 @@ import Link from '@phosphor/link.svg';
import MapPinIcon from '@phosphor/map-pin-simple.svg';
import SparkleIcon from '@phosphor/sparkle.svg';
import LoadingSpinner from '@phosphor/spinner.svg';
+import TextAlignLeftIcon from '@phosphor/text-align-left.svg';
import TrashSimple from '@phosphor/trash-simple.svg';
import UsersIcon from '@phosphor/users.svg';
import {
@@ -372,6 +381,27 @@ function CalendarEventPreviewDetails(props: {
}) {
const organizer = () =>
props.event.organizerName ?? props.event.organizerEmail;
+ const descriptionHtml = () =>
+ sanitizeCalendarDescription(props.event.description ?? '');
+ // Opening a Macro link reads the split layout from context, so the handler
+ // keeps this component's owner.
+ const openDescriptionLink = createCallback((event: MouseEvent) => {
+ const anchor = (event.target as Element | null)?.closest('a[href]');
+ if (!(anchor instanceof HTMLAnchorElement)) return;
+ event.preventDefault();
+ event.stopPropagation();
+ const target = parseMacroAppLink(anchor.href);
+ if (target) {
+ openBlockDocument(
+ target.blockName,
+ target.documentId,
+ Object.fromEntries(new URL(anchor.href).searchParams),
+ event.shiftKey
+ );
+ return;
+ }
+ openExternalUrl(anchor.href);
+ });
return (
<div class="px-2 pb-2 flex flex-col gap-1 text-sm text-ink-muted">
<Show when={!props.event.viewerEventId}>
@@ -394,6 +424,18 @@ function CalendarEventPreviewDetails(props: {
</MetadataInfo>
)}
</Show>
+ <Show when={descriptionHtml()}>
+ {(html) => (
+ <div class="mt-2 flex items-start text-[0.8em] text-ink-muted">
+ <TextAlignLeftIcon class="relative mx-1 mt-0.5 size-3 shrink-0" />
+ <div
+ class="line-clamp-4 min-w-0 wrap-anywhere [&_a]:text-accent [&_a]:underline [&_ol]:list-decimal [&_ol]:pl-4 [&_p+p]:mt-1 [&_ul]:list-disc [&_ul]:pl-4"
+ innerHTML={html()}
+ onClick={openDescriptionLink}
+ />
+ </div>
+ )}
+ </Show>
<Show when={organizer() || props.event.attendeeCount > 0}>
<MetadataInfo icon={UsersIcon}>
<span class="truncate">
@@ -844,12 +886,15 @@ export function DocumentPreviewContent(props: DocumentPreviewContentProps) {
<PreviewTitle
name={props.documentInfo.name || accessibleItem().name}
/>
+ {/* A calendar card shows the event's own schedule; its
+ last-updated time would read as the meeting time. */}
<Show
when={
- messageContext()?.sender_id ||
- accessibleItem().owner ||
- messageContext()?.created_at ||
- accessibleItem().updatedAt
+ !isCalendarEventPreviewItem(accessibleItem()) &&
+ (messageContext()?.sender_id ||
+ accessibleItem().owner ||
+ messageContext()?.created_at ||
+ accessibleItem().updatedAt)
}
>
<Item.Description class="text-left wrap-anywhere">
diff --git a/apps/web/src/lib/service-clients/service-storage/generated/schemas/calendarMentionEvent.ts b/apps/web/src/lib/service-clients/service-storage/generated/schemas/calendarMentionEvent.ts
index 513d340ae4..f3bc4300fb 100644
--- a/apps/web/src/lib/service-clients/service-storage/generated/schemas/calendarMentionEvent.ts
+++ b/apps/web/src/lib/service-clients/service-storage/generated/schemas/calendarMentionEvent.ts
@@ -4,6 +4,7 @@
* document_storage_service
* OpenAPI spec version: 0.1.0
*/
+import type { CalendarMentionEventDescription } from './calendarMentionEventDescription';
import type { CalendarMentionEventLocation } from './calendarMentionEventLocation';
import type { CalendarMentionEventOccurrenceKey } from './calendarMentionEventOccurrenceKey';
import type { CalendarMentionEventOrganizerEmail } from './calendarMentionEventOrganizerEmail';
@@ -22,6 +23,9 @@ export interface CalendarMentionEvent {
* @minimum 0
*/
attendeeCount: number;
+ /** Provider description, plain text or HTML, truncated for the preview.
+Clients must sanitize it before rendering. */
+ description?: CalendarMentionEventDescription;
/** Whether the event repeats. */
isRecurring: boolean;
/** Location label, when set. */
diff --git a/apps/web/src/lib/service-clients/service-storage/generated/schemas/calendarMentionEventDescription.ts b/apps/web/src/lib/service-clients/service-storage/generated/schemas/calendarMentionEventDescription.ts
new file mode 100644
index 0000000000..332eba27b2
--- /dev/null
+++ b/apps/web/src/lib/service-clients/service-storage/generated/schemas/calendarMentionEventDescription.ts
@@ -0,0 +1,12 @@
+/**
+ * Generated by orval v7.21.0 🍺
+ * Do not edit manually.
+ * document_storage_service
+ * OpenAPI spec version: 0.1.0
+ */
+
+/**
+ * Provider description, plain text or HTML, truncated for the preview.
+Clients must sanitize it before rendering.
+ */
+export type CalendarMentionEventDescription = string | null;
diff --git a/apps/web/src/lib/service-clients/service-storage/generated/schemas/index.ts b/apps/web/src/lib/service-clients/service-storage/generated/schemas/index.ts
index d2cadaa4a9..36eb5c34d3 100644
--- a/apps/web/src/lib/service-clients/service-storage/generated/schemas/index.ts
+++ b/apps/web/src/lib/service-clients/service-storage/generated/schemas/index.ts
@@ -238,6 +238,7 @@ export * from './calendarEventSourceContentCreatorName';
export * from './calendarEventSourceContentDescription';
export * from './calendarEventSourceContentLocation';
export * from './calendarMentionEvent';
+export * from './calendarMentionEventDescription';
export * from './calendarMentionEventLocation';
export * from './calendarMentionEventOccurrenceKey';
export * from './calendarMentionEventOrganizerEmail';
diff --git a/apps/web/src/lib/service-clients/service-storage/generated/zod.ts b/apps/web/src/lib/service-clients/service-storage/generated/zod.ts
index b758183135..64cb68b7bf 100644
--- a/apps/web/src/lib/service-clients/service-storage/generated/zod.ts
+++ b/apps/web/src/lib/service-clients/service-storage/generated/zod.ts
@@ -1603,6 +1603,12 @@ export const mentionPreviewsResponse = zod
.number()
.min(mentionPreviewsResponseItemsItemEventAttendeeCountMin)
.describe('Number of attendees on the previewed copy.'),
+ description: zod
+ .string()
+ .nullish()
+ .describe(
+ 'Provider description, plain text or HTML, truncated for the preview.\nClients must sanitize it before rendering.'
+ ),
isRecurring: zod
.boolean()
.describe('Whether the event repeats.'),
diff --git a/apps/web/src/lib/service-clients/service-storage/openapi.json b/apps/web/src/lib/service-clients/service-storage/openapi.json
index bb8918277b..01fb32759d 100644
--- a/apps/web/src/lib/service-clients/service-storage/openapi.json
+++ b/apps/web/src/lib/service-clients/service-storage/openapi.json
@@ -17212,6 +17212,10 @@
"description": "Number of attendees on the previewed copy.",
"minimum": 0
},
+ "description": {
+ "type": ["string", "null"],
+ "description": "Provider description, plain text or HTML, truncated for the preview.\nClients must sanitize it before rendering."
+ },
"isRecurring": {
"type": "boolean",
"description": "Whether the event repeats."
diff --git a/crates/calendar_events/src/domain/models.rs b/crates/calendar_events/src/domain/models.rs
index 9a717fe012..f17ab407c8 100644
--- a/crates/calendar_events/src/domain/models.rs
+++ b/crates/calendar_events/src/domain/models.rs
@@ -864,6 +864,9 @@ pub struct CalendarMentionEvent {
pub viewer_event_id: Option<Uuid>,
/// Display title.
pub title: String,
+ /// Provider description, plain text or HTML, truncated for the preview.
+ /// Clients must sanitize it before rendering.
+ pub description: Option<String>,
/// Time of the previewed instance: the requested occurrence when it
/// exists, else the next upcoming one, else the latest past one, else the
/// series start.
diff --git a/crates/calendar_events/src/inbound/axum_router/test.rs b/crates/calendar_events/src/inbound/axum_router/test.rs
index 1c2e0edcc3..c61330eca4 100644
--- a/crates/calendar_events/src/inbound/axum_router/test.rs
+++ b/crates/calendar_events/src/inbound/axum_router/test.rs
@@ -50,6 +50,7 @@ fn mention_preview_items_serialize_the_preview_contract() {
event: Some(CalendarMentionEvent {
viewer_event_id: Some(event_id),
title: "Smart Macro Discussion".to_string(),
+ description: Some("Agenda: <b>roadmap</b>".to_string()),
time: crate::domain::models::EventTime::Timed {
starts_at,
ends_at: starts_at + chrono::Duration::minutes(90),
@@ -70,6 +71,7 @@ fn mention_preview_items_serialize_the_preview_contract() {
assert_eq!(json["event"]["viewerEventId"], event_id.to_string());
assert_eq!(json["event"]["time"]["kind"], "timed");
assert_eq!(json["event"]["attendeeCount"], 3);
+ assert_eq!(json["event"]["description"], "Agenda: <b>roadmap</b>");
// A channel-shared preview carries no event of the viewer's to open.
let mut shared = accessible;
diff --git a/crates/calendar_events/src/outbound/pg.rs b/crates/calendar_events/src/outbound/pg.rs
index 9c4a62ae9d..a20d4661c6 100644
--- a/crates/calendar_events/src/outbound/pg.rs
+++ b/crates/calendar_events/src/outbound/pg.rs
@@ -319,11 +319,16 @@ struct OccurrenceJoinRow {
updated_at: DateTime<Utc>,
}
+/// A preview batch carries up to 100 events, so each description is capped
+/// well above what the hover card shows; clients sanitize what arrives.
+const MENTION_PREVIEW_DESCRIPTION_MAX_CHARS: i32 = 4000;
+
struct MentionPreviewRow {
mention_exists: bool,
resolved_event_id: Option<Uuid>,
is_channel_shared: Option<bool>,
title: Option<String>,
+ description: Option<String>,
location: Option<String>,
organizer_email: Option<String>,
organizer_name: Option<String>,
@@ -1144,8 +1149,12 @@ impl CalendarRepository for PgCalendarRepository {
(mentioned.id IS NOT NULL) AS "mention_exists!",
viewer_event.id AS "resolved_event_id?",
viewer_event.is_channel_shared AS "is_channel_shared?",
- viewer_event.title AS "title?",
- viewer_event.location AS "location?",
+ COALESCE(occurrence_override.title, viewer_event.title) AS "title?",
+ left(
+ COALESCE(occurrence_override.description, viewer_event.description),
+ $5
+ ) AS "description?",
+ COALESCE(occurrence_override.location, viewer_event.location) AS "location?",
viewer_event.organizer_email AS "organizer_email?",
viewer_event.organizer_name AS "organizer_name?",
viewer_event.recurrence_lines AS "recurrence_lines?",
@@ -1175,6 +1184,7 @@ impl CalendarRepository for PgCalendarRepository {
(candidate.owner_id = $1) AS is_owned,
(candidate.id = mentioned.id) AS is_mentioned,
candidate.title,
+ candidate.description,
candidate.location,
candidate.organizer_email,
candidate.organizer_name,
@@ -1204,6 +1214,7 @@ impl CalendarRepository for PgCalendarRepository {
false,
true,
mentioned.title,
+ mentioned.description,
mentioned.location,
mentioned.organizer_email,
mentioned.organizer_name,
@@ -1238,6 +1249,7 @@ impl CalendarRepository for PgCalendarRepository {
LEFT JOIN LATERAL (
SELECT
instance.occurrence_key,
+ instance.recurrence_id,
instance.starts_at,
instance.ends_at,
instance.start_date,
@@ -1260,6 +1272,11 @@ impl CalendarRepository for PgCalendarRepository {
instance.occurrence_key
LIMIT 1
) occurrence ON true
+ -- An exception's content replaces the series content for the
+ -- previewed occurrence alone, as it does in the event view.
+ LEFT JOIN calendar_event_overrides occurrence_override
+ ON occurrence_override.event_id = viewer_event.id
+ AND occurrence_override.recurrence_id = occurrence.recurrence_id
LEFT JOIN LATERAL (
SELECT count(*) AS attendee_count
FROM calendar_event_attendees attendee
@@ -1271,6 +1288,7 @@ impl CalendarRepository for PgCalendarRepository {
&event_ids,
&occurrence_keys as &[Option<String>],
now,
+ MENTION_PREVIEW_DESCRIPTION_MAX_CHARS,
)
.fetch_all(&self.pool)
.await
@@ -4033,6 +4051,9 @@ fn mention_preview_from_row(row: MentionPreviewRow) -> Result<CalendarMentionPre
CalendarMentionEvent {
viewer_event_id: (!is_channel_shared).then_some(resolved_event_id),
title: row.title.unwrap_or_default(),
+ description: row
+ .description
+ .filter(|description| !description.trim().is_empty()),
time,
occurrence_key: row.occurrence_key,
is_recurring: !row.recurrence_lines.unwrap_or_default().is_empty(),
diff --git a/crates/calendar_events/src/outbound/pg/test.rs b/crates/calendar_events/src/outbound/pg/test.rs
index 06bdb5e4ac..a6f95d018b 100644
--- a/crates/calendar_events/src/outbound/pg/test.rs
+++ b/crates/calendar_events/src/outbound/pg/test.rs
@@ -1606,6 +1606,88 @@ async fn occurrence_content_override_shadows_the_series_content(pool: PgPool) {
);
}
+#[sqlx::test(migrator = "MACRO_DB_MIGRATIONS")]
+async fn mention_preview_shows_the_previewed_occurrences_content(pool: PgPool) {
+ let owner_id = "macro|[email protected]";
+ let link_id = insert_link(&pool, owner_id).await;
+ let repo = PgCalendarRepository::new(pool);
+ let provider = provider_ids(&repo, link_id).await;
+ let mut upsert = timed_upsert(
+ owner_id,
+ link_id,
+ provider,
+ "Series title",
+ 1,
+ );
+ upsert.event.description = Some("Series description".to_string());
+ upsert.event.location = Some("Series room".to_string());
+ let event_id = upsert.event.id;
+ let edited_start = Utc.with_ymd_and_hms(2026, 7, 25, 14, 0, 0).unwrap();
+ let recurrence_id = edited_start.to_rfc3339();
+ upsert.occurrences[1].recurrence_id = Some(recurrence_id.clone());
+ upsert.overrides = vec![CalendarEventOverride {
+ recurrence_id: recurrence_id.clone(),
+ original_time: EventStart::Timed(edited_start),
+ time: EventTime::Timed {
+ starts_at: edited_start,
+ ends_at: edited_start + Duration::hours(1),
+ time_zone: Some("UTC".to_string()),
+ },
+ title: Some("Edited title".to_string()),
+ description: Some("Only this occurrence changed".to_string()),
+ location: None,
+ status: None,
+ attendees: None,
+ }];
+ repo.upsert_event_fixture(upsert).await.unwrap();
+
+ let now = Utc.with_ymd_and_hms(2026, 7, 23, 0, 0, 0).unwrap();
+ let series_key = Utc
+ .with_ymd_and_hms(2026, 7, 24, 14, 0, 0)
+ .unwrap()
+ .to_rfc3339();
+ let previews = repo
+ .mention_previews(
+ owner_id,
+ [recurrence_id.clone(), series_key]
+ .map(|key| CalendarMentionRequestItem {
+ event_id,
+ occurrence_key: Some(key),
+ })
+ .to_vec(),
+ now,
+ )
+ .await
+ .unwrap();
+ let content = |preview: &CalendarMentionPreview| match preview {
+ CalendarMentionPreview::Accessible(event) => (
+ event.title.clone(),
+ event.description.clone(),
+ event.location.clone(),
+ ),
+ other => panic!("expected an accessible preview: {other:?}"),
+ };
+
+ assert_eq!(
+ content(&previews[0]),
+ (
+ "Edited title".to_string(),
+ Some("Only this occurrence changed".to_string()),
+ Some("Series room".to_string()),
+ ),
+ "the exception's content replaces the series content, and an unset field inherits it"
+ );
+ assert_eq!(
+ content(&previews[1]),
+ (
+ "Series title".to_string(),
+ Some("Series description".to_string()),
+ Some("Series room".to_string()),
+ ),
+ );
+}
+
/// An exception that explicitly replaces the attendee list with an empty one
/// must project no attendees for that occurrence — not fall back to the
/// series list, which only an exception without an attendee list inherits.
@@ -4188,7 +4270,7 @@ async fn mention_previews_fall_back_to_a_channel_shared_projection(pool: PgPool)
let author_provider = provider_ids(&repo, author_link).await;
let attendee_provider = provider_ids(&repo, attendee_link).await;
- let author_copy = timed_upsert(
+ let mut author_copy = timed_upsert(
author_id,
author_link,
author_provider,
@@ -4196,6 +4278,7 @@ async fn mention_previews_fall_back_to_a_channel_shared_projection(pool: PgPool)
"Pilates",
1,
);
+ author_copy.event.description = Some("Bring a mat".to_string());
let shared_event_id = author_copy.event.id;
repo.upsert_event_fixture(author_copy).await.unwrap();
let attendee_copy = timed_upsert(
@@ -4271,6 +4354,7 @@ async fn mention_previews_fall_back_to_a_channel_shared_projection(pool: PgPool)
};
assert_eq!(shared.viewer_event_id, None);
assert_eq!(shared.title, "Pilates");
+ assert_eq!(shared.description.as_deref(), Some("Bring a mat"));
assert!(shared.occurrence_key.is_some());
// Private events stay hidden despite the grant, and a grant covers only
// the event it names.
diff --git a/docs/AGENT_GUIDE/surfaces.md b/docs/AGENT_GUIDE/surfaces.md
index 84f38348ce..70946aa0ed 100644
--- a/docs/AGENT_GUIDE/surfaces.md
+++ b/docs/AGENT_GUIDE/surfaces.md
@@ -669,6 +669,9 @@ also shares it read-only with the channel's current members: a member without a
own sees the mention's title and time, and its hover card adds a `Shared with you · not on
your calendar` line with no open action. Clicking such a mention shows that hover card
instead of opening the calendar. Private and confidential events are never shared this way.
+Every calendar mention's hover card shows the schedule, location, organizer and attendee
+count, plus the first lines of the event description (its links open), and no last-updated
+byline.
## Calls — `/app/component/calls`
diff --git a/packages/sdk/generated/storage/types.gen.ts b/packages/sdk/generated/storage/types.gen.ts
index 934e136e72..26e6ea9176 100644
--- a/packages/sdk/generated/storage/types.gen.ts
+++ b/packages/sdk/generated/storage/types.gen.ts
@@ -1748,6 +1748,11 @@ export type CalendarMentionEvent = {
* Number of attendees on the previewed copy.
*/
attendeeCount: number;
+ /**
+ * Provider description, plain text or HTML, truncated for the preview.
+ * Clients must sanitize it before rendering.
+ */
+ description?: string | null;
/**
* Whether the event repeats.
*/
diff --git a/packages/sdk/specs/storage.json b/packages/sdk/specs/storage.json
index bb8918277b..01fb32759d 100644
--- a/packages/sdk/specs/storage.json
+++ b/packages/sdk/specs/storage.json
@@ -17212,6 +17212,10 @@
"description": "Number of attendees on the previewed copy.",
"minimum": 0
},
+ "description": {
+ "type": ["string", "null"],
+ "description": "Provider description, plain text or HTML, truncated for the preview.\nClients must sanitize it before rendering."
+ },
"isRecurring": {
"type": "boolean",
"description": "Whether the event repeats."