Skip to content

Commit 010fd08

Browse files
committed
fix(desktop): preserve huddle companion ownership
Signed-off-by: kenny lopez <[email protected]>
1 parent 277c3ba commit 010fd08

4 files changed

Lines changed: 117 additions & 4 deletions

File tree

‎desktop/src/app/AppShell.tsx‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -643,14 +643,13 @@ export function AppShell() {
643643
unreadChannelIds,
644644
unreadChannelNotificationCount,
645645
});
646-
// Dispatch `buzz://message` deep links into the router.
647646
useMessageDeepLinks();
648647
const handleOpenCreateChannel = React.useCallback(
649648
() => setIsCreateChannelOpen(true),
650649
[],
651650
);
652651
React.useLayoutEffect(() => {
653-
if (settingsOpen) {
652+
if (settingsOpen || isHuddleRoom) {
654653
return;
655654
}
656655

@@ -710,12 +709,13 @@ export function AppShell() {
710709
handleOpenSearch,
711710
goNewMessage,
712711
goHome,
712+
isHuddleRoom,
713713
settingsOpen,
714714
]);
715715
useSettingsShortcuts({
716716
onClose: handleCloseSettings,
717717
onOpenSettings: handleOpenSettings,
718-
open: settingsOpen,
718+
open: isHuddleRoom ? undefined : settingsOpen,
719719
});
720720
useMarkAsReadShortcuts({
721721
activeChannelId: activeChannel?.id ?? null,

‎desktop/src/app/useHuddlePresentation.ts‎

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,9 @@ export function useHuddlePresentation() {
3838
>(() => new Set());
3939
const activeHuddleChannelIdRef = React.useRef<string | null>(null);
4040
const huddleCompanionChannelIdRef = React.useRef<string | null>(null);
41+
const huddleCompanionDismissedChannelIdRef = React.useRef<string | null>(
42+
null,
43+
);
4144
const huddleCompanionOpenPromiseRef = React.useRef<Promise<void> | null>(
4245
null,
4346
);
@@ -196,6 +199,7 @@ export function useHuddlePresentation() {
196199
);
197200
const handleHuddleCompanionOpen = React.useCallback(() => {
198201
const ephemeralChannelId = activeHuddleChannelIdRef.current;
202+
huddleCompanionDismissedChannelIdRef.current = null;
199203
hideHuddleChannel(ephemeralChannelId);
200204
setIsHuddleDrawerOpen(false);
201205
setIsHuddleCompanionOpen(true);
@@ -225,6 +229,12 @@ export function useHuddlePresentation() {
225229
(ephemeralChannelId: string) => {
226230
activeHuddleChannelIdRef.current = ephemeralChannelId;
227231
trackHuddleBackingChannel(ephemeralChannelId);
232+
233+
if (huddleCompanionDismissedChannelIdRef.current === ephemeralChannelId) {
234+
return Promise.resolve();
235+
}
236+
237+
huddleCompanionDismissedChannelIdRef.current = null;
228238
hideHuddleChannel(ephemeralChannelId);
229239
setIsHuddleDrawerOpen(false);
230240
setIsHuddleCompanionOpen(true);
@@ -303,6 +313,7 @@ export function useHuddlePresentation() {
303313
hideHuddleChannel(endedChannelId);
304314
activeHuddleChannelIdRef.current = null;
305315
huddleCompanionChannelIdRef.current = null;
316+
huddleCompanionDismissedChannelIdRef.current = null;
306317
huddleCompanionOpenPromiseRef.current = null;
307318
setIsHuddleCompanionOpen(false);
308319
void queryClient.invalidateQueries({ queryKey: channelsQueryKey });
@@ -317,6 +328,10 @@ export function useHuddlePresentation() {
317328
let unlisten: (() => void) | null = null;
318329
void listen("huddle-companion-returned", () => {
319330
if (cancelled) return;
331+
huddleCompanionDismissedChannelIdRef.current =
332+
activeHuddleChannelIdRef.current;
333+
huddleCompanionChannelIdRef.current = null;
334+
huddleCompanionOpenPromiseRef.current = null;
320335
setIsHuddleCompanionOpen(false);
321336
setIsHuddleDrawerOpen(true);
322337
void invoke<HuddleTranscriptRouteState>("get_huddle_state")
@@ -381,6 +396,7 @@ export function useHuddlePresentation() {
381396
activeHuddleChannelIdRef.current = null;
382397
activeHuddleParentChannelIdRef.current = null;
383398
huddleCompanionChannelIdRef.current = null;
399+
huddleCompanionDismissedChannelIdRef.current = null;
384400
huddleCompanionOpenPromiseRef.current = null;
385401
setIsHuddleDrawerOpen(false);
386402
setIsHuddleCompanionOpen(false);

‎desktop/src/app/useSettingsShortcuts.ts‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { hasPrimaryShortcutModifier } from "@/shared/lib/platform";
55
type UseSettingsShortcutsOptions = {
66
onClose: () => void;
77
onOpenSettings: () => void;
8-
open: boolean;
8+
open?: boolean;
99
};
1010

1111
export function useSettingsShortcuts({
@@ -14,6 +14,8 @@ export function useSettingsShortcuts({
1414
open,
1515
}: UseSettingsShortcutsOptions) {
1616
React.useLayoutEffect(() => {
17+
if (open === undefined) return;
18+
1719
function handleKeyDown(event: KeyboardEvent) {
1820
const isSettingsShortcut =
1921
hasPrimaryShortcutModifier(event) &&

‎desktop/tests/e2e/huddle-transcription.spec.ts‎

Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -296,6 +296,32 @@ test("shows speaker identity on every huddle chat message", async ({
296296
await expect(page.getByTestId("message-thread-panel")).toHaveCount(0);
297297
});
298298

299+
test("keeps main-app shortcuts from navigating the huddle room", async ({
300+
page,
301+
}) => {
302+
await installMockBridge(page, {
303+
windowLabel: `huddle-${HUDDLE_CHANNEL_ID}`,
304+
huddle: {
305+
parentChannelId: HUDDLE_PARENT_ID,
306+
ephemeralChannelId: HUDDLE_CHANNEL_ID,
307+
members: [{ pubkey: TEST_IDENTITIES.tyler.pubkey, role: "member" }],
308+
},
309+
});
310+
await page.goto("/");
311+
312+
await expect(page).toHaveURL(
313+
new RegExp(`/channels/${HUDDLE_CHANNEL_ID.replaceAll("-", "\\-")}`),
314+
);
315+
const huddleUrl = page.url();
316+
const primaryModifier = process.platform === "darwin" ? "Meta" : "Control";
317+
318+
for (const shortcut of ["Shift+K", "Shift+A", "Comma"]) {
319+
await page.keyboard.press(`${primaryModifier}+${shortcut}`);
320+
await expect.poll(() => page.url()).toBe(huddleUrl);
321+
await expect(page.getByTestId("settings-view")).toHaveCount(0);
322+
}
323+
});
324+
299325
test("speaks the first eligible agent reply with its participant identity", async ({
300326
page,
301327
}) => {
@@ -753,6 +779,75 @@ test("keeps a newer huddle event over a delayed hydration snapshot", async ({
753779
).toHaveCount(1);
754780
});
755781

782+
test("keeps a starting huddle in the drawer after its companion closes", async ({
783+
page,
784+
}) => {
785+
await installFakeHuddleMicrophone(page);
786+
await installMockBridge(page, {
787+
openHuddleWindowDelayMs: 500,
788+
startHuddleReturnDelayMs: 1_500,
789+
});
790+
await page.goto("/");
791+
await page.getByTestId("channel-alice-tyler").click();
792+
await page.getByTestId("channel-start-huddle-trigger").click();
793+
794+
await expect
795+
.poll(() =>
796+
page.evaluate(
797+
() =>
798+
(window.__BUZZ_E2E_COMMAND_LOG__ ?? []).filter(
799+
(entry) => entry.command === "open_huddle_window",
800+
).length,
801+
),
802+
)
803+
.toBe(1);
804+
const ephemeralChannelId = await page.evaluate(async () => {
805+
const state = (await window.__BUZZ_E2E_INVOKE_MOCK_COMMAND__?.(
806+
"get_huddle_state",
807+
)) as { ephemeral_channel_id: string };
808+
return state.ephemeral_channel_id;
809+
});
810+
await page.evaluate(async () => {
811+
await window.__BUZZ_E2E_INVOKE_MOCK_COMMAND__?.("close_huddle_companion");
812+
});
813+
814+
await expect(page.locator(".buzz-huddle-shell")).toHaveAttribute(
815+
"data-huddle-open",
816+
"true",
817+
);
818+
await expect(page).toHaveURL(
819+
new RegExp(`/channels/${ephemeralChannelId.replaceAll("-", "\\-")}`),
820+
);
821+
await expect
822+
.poll(() =>
823+
page.evaluate(async () => {
824+
const state = (await window.__BUZZ_E2E_INVOKE_MOCK_COMMAND__?.(
825+
"get_huddle_state",
826+
)) as { phase: string };
827+
return state.phase;
828+
}),
829+
)
830+
.toBe("active");
831+
await expect
832+
.poll(() =>
833+
page.evaluate(
834+
() =>
835+
(window.__BUZZ_E2E_COMMAND_LOG__ ?? []).filter(
836+
(entry) => entry.command === "open_huddle_window",
837+
).length,
838+
),
839+
)
840+
.toBe(1);
841+
await expect(page.locator(".buzz-huddle-shell")).toHaveAttribute(
842+
"data-huddle-open",
843+
"true",
844+
);
845+
await expect(page.getByTestId("profile-huddle-control")).toHaveCount(0);
846+
await expect(
847+
page.locator(`[data-channel-id="${ephemeralChannelId}"]`),
848+
).toBeVisible();
849+
});
850+
756851
test("starts an agent DM huddle and hides its backing channel after it ends", async ({
757852
page,
758853
}) => {

0 commit comments

Comments
 (0)