Macro is a unified workspace for teams: email, chat, docs, tasks, agents, calls, and CRM — @-linked together with shared AI memory.
TypeScript agentaiai-agentsall-in-onecrmcrm-systememaillinearmcpmessagingnotesnotionofficerustslackslack-alternativestartupstartup-toolstypescriptworkspace
feat(channels): add engineers to support channels and group additions (#9033)
Jacob Beckerman4b3e12e33068
diff --git a/apps/web/src/features/channel/Channel/Channel.tsx b/apps/web/src/features/channel/Channel/Channel.tsxindex 375b66f47c..8dd2889b84 100644--- a/apps/web/src/features/channel/Channel/Channel.tsx+++ b/apps/web/src/features/channel/Channel/Channel.tsx@@ -101,7 +101,10 @@ import {} from '../Input';import { ChannelInputContainer } from '../Input/ChannelInputContainer';import { hasSendableInputContent } from '../Input/utils/sendable-content';-import { decodeSystemActivity } from '../queries/system-activity';+import {+ decodeSystemActivityRow,+ mergesSystemActivity,+} from '../queries/system-activity';import { SystemActivity } from '../SystemActivity';import { ChannelThread } from '../Thread';import { ThreadRow } from '../Thread/ThreadRow';@@ -263,10 +266,12 @@ export function Channel(props: ChannelProps) {);// The index reads immediately, before EntityLoadGate's boundary exists.- const messageIndex = createMessageIndex(() =>- queryReadyGate(messagesQuery)- ? (messagesQuery.data as MessageTimelineData)- : undefined+ const messageIndex = createMessageIndex(+ () =>+ queryReadyGate(messagesQuery)+ ? (messagesQuery.data as MessageTimelineData)+ : undefined,+ mergesSystemActivity);const messageById = () => messageIndex.byId;@@ -833,8 +838,10 @@ export function Channel(props: ChannelProps) {listMeta={listMetaByKey()[item.id]}><SystemActivity- event={decodeSystemActivity(- activity()+ event={decodeSystemActivityRow(+ messageIndex.activityGroupByKey.get(+ item.id+ ) ?? [activity()])}/><Show when={isNewestRow()}>diff --git a/apps/web/src/features/channel/SystemActivity.tsx b/apps/web/src/features/channel/SystemActivity.tsxindex cc26d59316..0fddacbd46 100644--- a/apps/web/src/features/channel/SystemActivity.tsx+++ b/apps/web/src/features/channel/SystemActivity.tsx@@ -1,5 +1,6 @@import { getDisplayName, tryMacroId } from '@core/user';import { getBotDisplayName } from '@queries/messages/message-sender';+import { match } from 'ts-pattern';import { SystemActivityRow } from './components/SystemActivityRow';import type { SystemActivity as SystemActivityEvent } from './core/system-activity';@@ -10,9 +11,21 @@ function name(id: string): string {/** App composition uses the same cached principal names as channel messages. */export function SystemActivity(props: { event: SystemActivityEvent }) {const participant = () =>- 'participant' in props.event.action- ? name(props.event.action.participant)- : 'a participant';+ match(props.event.action)+ .with({ kind: 'participant_added' }, ({ participants }) =>+ participants.map(name).join(', ')+ )+ .with({ kind: 'participant_removed' }, ({ participant }) =>+ name(participant)+ )+ .with(+ { kind: 'renamed' },+ { kind: 'picture_changed' },+ { kind: 'call_ended' },+ { kind: 'unknown' },+ () => 'a participant'+ )+ .exhaustive();return (<SystemActivityRowevent={props.event}diff --git a/apps/web/src/features/channel/components/SystemActivityRow.tsx b/apps/web/src/features/channel/components/SystemActivityRow.tsxindex 355fdeb108..4bbc018c94 100644--- a/apps/web/src/features/channel/components/SystemActivityRow.tsx+++ b/apps/web/src/features/channel/components/SystemActivityRow.tsx@@ -45,6 +45,10 @@ export function SystemActivityRow(props: {subject={description().subject}label={`${props.actorName} ${describeSystemActivity(props.event, props.participantName)}`}occurredAt={props.event.occurredAt}+ wrap={+ props.event.action.kind === 'participant_added' &&+ props.event.action.participants.length > 1+ }/>);}@@ -64,10 +68,18 @@ export function SystemActivityLine(props: {/** The whole line, for the tooltip. */label: string;occurredAt: string;+ /**+ * Wrap instead of truncating, for lines listing several names: the tooltip+ * that reveals a truncated line is unavailable on touch devices.+ */+ wrap?: boolean;}) {return (<div- class="h-9 flex items-center gap-2 pl-(--message-padding-x) pr-2 text-sm text-ink-muted"+ class={cn(+ 'flex items-center gap-2 pl-(--message-padding-x) pr-2 text-sm text-ink-muted',+ props.wrap ? 'min-h-9 py-2' : 'h-9'+ )}data-system-activity={props.id}><span@@ -81,10 +93,10 @@ export function SystemActivityLine(props: {</span><Tooltiplabel={props.label}- class="min-w-0 max-w-max flex-1 truncate"+ class={cn('min-w-0 max-w-max flex-1', !props.wrap && 'truncate')}as="span">- <span class="truncate">+ <span class={props.wrap ? undefined : 'truncate'}><Show when={props.actor}>{(actor) => (<>diff --git a/apps/web/src/features/channel/core/system-activity.test.ts b/apps/web/src/features/channel/core/system-activity.test.tsindex 5eaa8c2fca..54de44c260 100644--- a/apps/web/src/features/channel/core/system-activity.test.ts+++ b/apps/web/src/features/channel/core/system-activity.test.ts@@ -1,7 +1,57 @@+import { buildMessageIndex } from '@queries/messages/timeline';+import type {+ MessageTimelineEntry,+ TimelineActivity,+} from '@service-storage/messages';import { expect, it } from 'vitest';-import { decodeSystemActivity } from '../queries/system-activity';+import {+ decodeSystemActivity,+ decodeSystemActivityRow,+ mergesSystemActivity,+} from '../queries/system-activity';import { callDuration, describeSystemActivity } from './system-activity';+const ACTOR = 'macro|[email protected]';++function added(+ id: string,+ participant: string,+ actor = ACTOR+): MessageTimelineEntry {+ return {+ type: 'activity',+ activity: {+ id,+ actor_id: actor,+ action: 'participant_added',+ occurred_at: '2026-09-19T12:00:00Z',+ payload: { participant },+ },+ };+}++/** Index entries given oldest first, as the channel builds them. */+function index(entries: MessageTimelineEntry[]) {+ return buildMessageIndex(+ [+ {+ entries: [...entries].reverse(),+ next_cursor: null,+ previous_cursor: null,+ },+ ],+ mergesSystemActivity+ );+}++function rowActivities(+ built: ReturnType<typeof index>,+ key: string+): TimelineActivity[] {+ const activity = built.activityByKey.get(key);+ return built.activityGroupByKey.get(key) ?? (activity ? [activity] : []);+}+it('describes completed calls, renames, and self membership changes', () => {const event = {id: 'a',@@ -54,3 +104,55 @@ it('formats durations and tolerates malformed future activity', () => {}).action.kind).toBe('unknown');});++it('merges consecutive additions by one actor into a row keyed by the newest', () => {+ const built = index([+ added('a', 'macro|[email protected]'),+ added('b', 'macro|[email protected]'),+ added('c', 'macro|[email protected]'),+ ]);+ expect(built.entryKeys).toEqual(['activity:c']);+ const row = decodeSystemActivityRow(rowActivities(built, 'activity:c'));+ expect(row.id).toBe('c');+ expect(row.action).toEqual({+ kind: 'participant_added',+ participants: [+ 'macro|[email protected]',+ 'macro|[email protected]',+ 'macro|[email protected]',+ ],+ });+ expect(describeSystemActivity(row, 'A, B, C')).toBe('added A, B, C');+});++it('keeps additions apart across other actors, joins, and messages', () => {+ const built = index([+ added('a', 'macro|[email protected]'),+ added('other', 'macro|[email protected]', 'macro|[email protected]'),+ added('join', 'macro|[email protected]', 'macro|[email protected]'),+ added('b', 'macro|[email protected]'),+ {+ type: 'message',+ message: {+ id: 'm',+ created_at: '2026-09-19T12:01:00Z',+ } as Extract<MessageTimelineEntry, { type: 'message' }>['message'],+ },+ added('c', 'macro|[email protected]'),+ ]);+ expect(built.entryKeys).toEqual([+ 'activity:a',+ 'activity:other',+ 'activity:join',+ 'activity:b',+ 'm',+ 'activity:c',+ ]);+ expect(built.activityGroupByKey.size).toBe(0);+ expect(+ describeSystemActivity(+ decodeSystemActivityRow(rowActivities(built, 'activity:join')),+ ''+ )+ ).toBe('joined the channel');+});diff --git a/apps/web/src/features/channel/core/system-activity.ts b/apps/web/src/features/channel/core/system-activity.tsindex 8e60c945d3..064443534f 100644--- a/apps/web/src/features/channel/core/system-activity.ts+++ b/apps/web/src/features/channel/core/system-activity.ts@@ -7,7 +7,8 @@ export type SystemActivity = {action:| { kind: 'renamed'; name?: string }| { kind: 'picture_changed' }- | { kind: 'participant_added'; participant: string }+ /** Several when consecutive additions by one actor share a row. */+ | { kind: 'participant_added'; participants: string[] }| { kind: 'participant_removed'; participant: string }| { kind: 'call_ended'; durationMs: number }| { kind: 'unknown' };@@ -23,6 +24,16 @@ export function callDuration(durationMs: number): string {return `${hours} ${hours === 1 ? 'hour' : 'hours'}${remainder ? ` ${remainder} ${remainder === 1 ? 'minute' : 'minutes'}` : ''}`;}+/** Whether the actor added themselves: joined rather than added someone. */+export function isSelfJoin(event: SystemActivity): boolean {+ return (+ event.action.kind === 'participant_added' &&+ event.action.participants.length === 1 &&+ event.action.participants[0] === event.actorId+ );+}++/** `participantName` names every participant, comma separated. */export function systemActivityDescription(event: SystemActivity,participantName: string@@ -36,8 +47,8 @@ export function systemActivityDescription(.with({ kind: 'picture_changed' }, () => ({verb: 'updated the channel profile picture',}))- .with({ kind: 'participant_added' }, ({ participant }) =>- participant === event.actorId+ .with({ kind: 'participant_added' }, () =>+ isSelfJoin(event)? { verb: 'joined the channel' }: { verb: 'added', subject: participantName })diff --git a/apps/web/src/features/channel/queries/system-activity.ts b/apps/web/src/features/channel/queries/system-activity.tsindex f4bbb0e811..143af19818 100644--- a/apps/web/src/features/channel/queries/system-activity.ts+++ b/apps/web/src/features/channel/queries/system-activity.ts@@ -1,5 +1,5 @@import type { TimelineActivity } from '@service-storage/messages';-import type { SystemActivity } from '../core/system-activity';+import { isSelfJoin, type SystemActivity } from '../core/system-activity';/** Decode the durable vocabulary at the transport boundary, tolerating future actions. */export function decodeSystemActivity(event: TimelineActivity): SystemActivity {@@ -13,13 +13,14 @@ export function decodeSystemActivity(event: TimelineActivity): SystemActivity {name:'to' in fields && typeof fields.to === 'string' ? fields.to : undefined,};- if (- (event.action === 'participant_added' ||- event.action === 'participant_removed') &&- 'participant' in fields &&- typeof fields.participant === 'string'- ) {- action = { kind: event.action, participant: fields.participant };+ if ('participant' in fields && typeof fields.participant === 'string') {+ if (event.action === 'participant_added')+ action = {+ kind: 'participant_added',+ participants: [fields.participant],+ };+ if (event.action === 'participant_removed')+ action = { kind: 'participant_removed', participant: fields.participant };}if (event.action === 'call_ended' &&@@ -36,3 +37,40 @@ export function decodeSystemActivity(event: TimelineActivity): SystemActivity {action,};}++function addedParticipants(event: SystemActivity): string[] | undefined {+ return event.action.kind === 'participant_added' && !isSelfJoin(event)+ ? event.action.participants+ : undefined;+}++/** One actor adding people in succession shares a row; joining keeps its own. */+export function mergesSystemActivity(+ previous: TimelineActivity,+ next: TimelineActivity+): boolean {+ const before = decodeSystemActivity(previous);+ const after = decodeSystemActivity(next);+ return (+ before.actorId === after.actorId &&+ addedParticipants(before) !== undefined &&+ addedParticipants(after) !== undefined+ );+}++/** A row's activities, oldest first, as one event dated by the newest. */+export function decodeSystemActivityRow(+ activities: readonly TimelineActivity[]+): SystemActivity {+ const events = activities.map(decodeSystemActivity);+ const newest = events[events.length - 1];+ if (events.length === 1 || newest.action.kind !== 'participant_added')+ return newest;+ return {+ ...newest,+ action: {+ kind: 'participant_added',+ participants: events.flatMap((event) => addedParticipants(event) ?? []),+ },+ };+}diff --git a/apps/web/src/lib/queries/messages/timeline.ts b/apps/web/src/lib/queries/messages/timeline.tsindex 6d79e0a200..3d76139475 100644--- a/apps/web/src/lib/queries/messages/timeline.ts+++ b/apps/web/src/lib/queries/messages/timeline.ts@@ -733,13 +733,26 @@ export function softInvalidateMessageTimelineByIds(parent: MessageParent) {});}+/** Whether `next` joins the activity row that `previous`, just before it, ends. */+export type ActivityMerge = (+ previous: TimelineActivity,+ next: TimelineActivity+) => boolean;+/*** Build a single oldest-first timeline index for display and lookup.* Pages arrive newest-first, entries within each page are newest-first,* so we reverse both layers in one pass.*/-/** The rows a timeline renders, oldest first, from its cached pages. */-export function buildMessageIndex(pages: MessageTimelinePage[] | undefined) {+/**+ * The rows a timeline renders, oldest first, from its cached pages.+ * Consecutive activity that `mergeActivity` accepts shares one row, keyed and+ * dated by its newest activity.+ */+export function buildMessageIndex(+ pages: MessageTimelinePage[] | undefined,+ mergeActivity?: ActivityMerge+) {/*** New objects carrying their row key as `id`, so `reconcile` pairs each* entry with its own previous copy. Without an `id` it pairs by position@@ -752,9 +765,20 @@ export function buildMessageIndex(pages: MessageTimelinePage[] | undefined) {/** Message ids only: selection and navigation skip activity. */const keys: string[] = [];const byId = new Map<string, MessageListItem>();+ /** Each activity row's newest activity. */const activityByKey = new Map<string, TimelineActivity>();-- if (!pages?.length) return { entries, entryKeys, keys, byId, activityByKey };+ /** Every activity of a row that merged several, oldest first. */+ const activityGroupByKey = new Map<string, TimelineActivity[]>();++ if (!pages?.length)+ return {+ entries,+ entryKeys,+ keys,+ byId,+ activityByKey,+ activityGroupByKey,+ };const seen = new Set<string>();for (let i = pages.length - 1; i >= 0; i--) {@@ -764,26 +788,46 @@ export function buildMessageIndex(pages: MessageTimelinePage[] | undefined) {const key = timelineEntryKey(entry);if (seen.has(key)) continue;seen.add(key);- entries.push({ ...entry, id: key });- entryKeys.push(key);if (entry.type === 'activity') {+ const lastKey = entryKeys.at(-1);+ const previous =+ lastKey === undefined ? undefined : activityByKey.get(lastKey);+ if (+ lastKey !== undefined &&+ previous &&+ mergeActivity?.(previous, entry.activity)+ ) {+ const group = activityGroupByKey.get(lastKey) ?? [previous];+ activityByKey.delete(lastKey);+ activityGroupByKey.delete(lastKey);+ entries[entries.length - 1] = { ...entry, id: key };+ entryKeys[entryKeys.length - 1] = key;+ activityByKey.set(key, entry.activity);+ activityGroupByKey.set(key, [...group, entry.activity]);+ continue;+ }+ entries.push({ ...entry, id: key });+ entryKeys.push(key);activityByKey.set(key, entry.activity);continue;}+ entries.push({ ...entry, id: key });+ entryKeys.push(key);keys.push(key);byId.set(key, entry.message);}}- return { entries, entryKeys, keys, byId, activityByKey };+ return { entries, entryKeys, keys, byId, activityByKey, activityGroupByKey };}/** A reactive index over a timeline query's cached pages. */export function createMessageIndex(- data: Accessor<MessageTimelineData | undefined>+ data: Accessor<MessageTimelineData | undefined>,+ mergeActivity?: ActivityMerge) {const [messageIndex, setMessageIndex] = createStore(- buildMessageIndex(data()?.pages)+ buildMessageIndex(data()?.pages, mergeActivity));createEffect(@@ -792,7 +836,9 @@ export function createMessageIndex(if (!data()) {return;}- setMessageIndex(reconcile(buildMessageIndex(data()?.pages)));+ setMessageIndex(+ reconcile(buildMessageIndex(data()?.pages, mergeActivity))+ );}));diff --git a/services/authentication_service/src/api/webhooks/user/create_user_webhook.rs b/services/authentication_service/src/api/webhooks/user/create_user_webhook.rsindex 8c35eb50d9..3125bc19f6 100644--- a/services/authentication_service/src/api/webhooks/user/create_user_webhook.rs+++ b/services/authentication_service/src/api/webhooks/user/create_user_webhook.rs@@ -40,13 +40,23 @@ use model_entity::EntityType;use teams::domain::team_repo::TeamService;use tracing::Instrument;-/// Macro support team members added to every new user's support channel.-const MACRO_SUPPORT_EMAILS: [&str; 5] = [+/// Macro team members added to every new user's support channel.+const MACRO_SUPPORT_EMAILS: [&str; 15] = [+ "[email protected]",+ "[email protected]",+ "[email protected]",+ "[email protected]",+ "[email protected]",+ "[email protected]",+ "[email protected]",+ "[email protected]",+ "[email protected]",+ "[email protected]",];fn support_channel_name<T: AsRef<str>>(email: &Email<T>) -> String {@@ -538,6 +548,7 @@ async fn create_user_webhook(ctx: &ApiContext, req: FusionAuthUserWebhook) -> an}};+ let participants_count = participants.len();let channel = match channel_service.create_system_channel(owner_id.clone(),@@ -557,7 +568,7 @@ async fn create_user_webhook(ctx: &ApiContext, req: FusionAuthUserWebhook) -> anreturn;}};- tracing::info!(channel_id=%channel.id, "created Macro support channel");+ tracing::info!(channel_id=%channel.id, participant_count=participants_count, "created Macro support channel");let channel_entity = EntityType::Channel.with_entity_str(&channel.id);if let Err(e) = favorites_servicediff --git a/services/authentication_service/src/api/webhooks/user/create_user_webhook/test.rs b/services/authentication_service/src/api/webhooks/user/create_user_webhook/test.rsindex 8d0b83859d..ce46c91626 100644--- a/services/authentication_service/src/api/webhooks/user/create_user_webhook/test.rs+++ b/services/authentication_service/src/api/webhooks/user/create_user_webhook/test.rs@@ -11,11 +11,25 @@ use model::authentication::webhooks::{};use serde_json::Value;+use macro_user_id::user_id::MacroUserIdStr;+use super::{- UserCreateWebhookError, dispatch_user_create_webhook, identity_provider_name,- support_channel_name, user_create_webhook_error_response,+ MACRO_SUPPORT_EMAILS, UserCreateWebhookError, dispatch_user_create_webhook,+ identity_provider_name, support_channel_name, user_create_webhook_error_response,};+/// A bad entry would skip support channel creation for every signup.+#[test]+fn support_emails_are_distinct_user_ids() {+ let participants = MACRO_SUPPORT_EMAILS+ .into_iter()+ .map(MacroUserIdStr::try_from_email)+ .collect::<Result<std::collections::HashSet<_>, _>>()+ .expect("every support email is a valid user id");++ assert_eq!(participants.len(), MACRO_SUPPORT_EMAILS.len());+}+#[test]fn support_channel_name_uses_email_local_part() {let email = Email::parse_from_str("[email protected]").expect("valid email");