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(calls): keep Call tab participants current after leaving (#9055)

Eric Hayes3df1c6dac2d8
diff --git a/apps/web/src/features/channel/Call/ChannelCallTab.tsx b/apps/web/src/features/channel/Call/ChannelCallTab.tsx
index 5546d341eb..ab56afef75 100644
--- a/apps/web/src/features/channel/Call/ChannelCallTab.tsx
+++ b/apps/web/src/features/channel/Call/ChannelCallTab.tsx
@@ -3,7 +3,7 @@ import { UserGroup } from '@core/component/UserGroup';
import { getDisplayName, tryMacroId } from '@core/user';
import PhoneIcon from '@icon/system/regular/phone-call.svg';
import { Telemetry } from '@macro-inc/observability';
-import { useActiveCallQuery, useCallRecordQuery } from '@queries/call/call';
+import { useActiveCallQuery, useLiveCallRecordQuery } from '@queries/call/call';
import { Button } from '@ui';
import { type Accessor, createMemo, Match, Show, Switch } from 'solid-js';
import { ActiveCallLink } from './ActiveCallLink';
@@ -50,7 +50,7 @@ function JoinCallEmptyState(props: {
onJoin: () => void;
}) {
const activeCallQuery = useActiveCallQuery(() => props.channelId);
- const callRecordQuery = useCallRecordQuery(
+ const callRecordQuery = useLiveCallRecordQuery(
() => activeCallQuery.data?.callId ?? ''
);
const participantIds = createMemo(
diff --git a/apps/web/src/lib/queries/call/call.test.ts b/apps/web/src/lib/queries/call/call.test.ts
index dfd9738557..a7eb981b31 100644
--- a/apps/web/src/lib/queries/call/call.test.ts
+++ b/apps/web/src/lib/queries/call/call.test.ts
@@ -36,6 +36,7 @@ import {
buildCallTeamSharePayload,
fetchCallSharePermission,
isCallSharedWithTeam,
+ refetchLeftCallRecord,
setActiveCallEndedCache,
setActiveCallStartedCache,
setCallRecordTeamShareCache,
@@ -349,3 +350,53 @@ describe('call team sharing helpers', () => {
});
});
});
+
+describe('refetchLeftCallRecord', () => {
+ beforeEach(() => {
+ queryClient.clear();
+ callClient.getCallRecord.mockReset();
+ });
+
+ it('refetches the left call record even with no mounted reader', async () => {
+ const participant = {
+ userId: 'macro|[email protected]',
+ joinedAt: '2026-08-21T09:00:00.000Z',
+ };
+ queryClient.setQueryData(
+ callKeys.active('channel-1').queryKey,
+ started({ callId: 'call-1', channelId: 'channel-1' })
+ );
+ const key = callKeys.record('call-1').queryKey;
+ const recordFetch = vi
+ .fn<() => CallRecord>()
+ .mockReturnValueOnce(
+ record({
+ isActive: true,
+ participants: [{ ...participant, leftAt: null }],
+ })
+ )
+ .mockReturnValueOnce(
+ record({
+ isActive: true,
+ participants: [
+ { ...participant, leftAt: '2026-08-21T09:05:00.000Z' },
+ ],
+ })
+ );
+ // Cached by a reader that has since unmounted.
+ await queryClient.fetchQuery({ queryKey: key, queryFn: recordFetch });
+
+ refetchLeftCallRecord('channel-1');
+
+ await vi.waitFor(() =>
+ expect(
+ queryClient.getQueryData<CallRecord>(key)?.participants[0]?.leftAt
+ ).toBe('2026-08-21T09:05:00.000Z')
+ );
+ });
+
+ it('does nothing when the channel has no cached call', () => {
+ refetchLeftCallRecord('channel-1');
+ expect(callClient.getCallRecord).not.toHaveBeenCalled();
+ });
+});
diff --git a/apps/web/src/lib/queries/call/call.ts b/apps/web/src/lib/queries/call/call.ts
index 84b3941352..f78bb33b96 100644
--- a/apps/web/src/lib/queries/call/call.ts
+++ b/apps/web/src/lib/queries/call/call.ts
@@ -150,6 +150,22 @@ function isNotFoundResultError(error: unknown) {
);
}
+/**
+ * Refetches the record of the channel's call after the user leaves it, even
+ * while unmounted, so the Call tab doesn't list them in the call. Runs before
+ * the active-call invalidation, whose refetch may clear the call id.
+ */
+export function refetchLeftCallRecord(channelId: string) {
+ const callId = queryClient.getQueryData<CallActiveResponse | null>(
+ callKeys.active(channelId).queryKey
+ )?.callId;
+ if (!callId) return;
+ queryClient.invalidateQueries({
+ queryKey: callKeys.record(callId).queryKey,
+ refetchType: 'all',
+ });
+}
+
export function useLeaveCallMutation() {
return useMutation(() => ({
gcTime: 0,
@@ -164,7 +180,8 @@ export function useLeaveCallMutation() {
throw error;
}
},
- onSuccess() {
+ onSuccess(_result, channelId) {
+ refetchLeftCallRecord(channelId);
fireAndForget(invalidateActiveCallQueries(), 'call-membership');
},
onError(error: Error) {
@@ -190,6 +207,20 @@ export function useCallRecordQuery(callId: Accessor<string>) {
return useQuery(() => callRecordQueryOptions(callId()));
}
+function liveCallRecordQueryOptions(callId: string) {
+ return queryOptions({
+ ...callRecordQueryOptions(callId),
+ // Participants join and leave without an event; poll like the active call.
+ staleTime: 0,
+ refetchInterval: 15_000,
+ });
+}
+
+/** The call record with current participants, for presence in a live call. */
+export function useLiveCallRecordQuery(callId: Accessor<string>) {
+ return useQuery(() => liveCallRecordQueryOptions(callId()));
+}
+
export function fetchCallRecord(
callId: string,
staleTimeMs: number