diff --git a/src/main.ts b/src/main.ts index 588449b2..8dae0881 100644 --- a/src/main.ts +++ b/src/main.ts @@ -31,9 +31,6 @@ export default class CodexPanelPlugin extends Plugin { private readonly threadSurfaces = createThreadSurfaceActions({ app: this.app, panels: this.panels, - refreshThreadSurfaces: () => { - this.threadSurfaces.refreshSharedThreadListFromOpenSurface(); - }, }); override async onload(): Promise { diff --git a/src/workspace/thread-surface-actions.ts b/src/workspace/thread-surface-actions.ts index 42b0a1fc..1ecf94f6 100644 --- a/src/workspace/thread-surface-actions.ts +++ b/src/workspace/thread-surface-actions.ts @@ -10,7 +10,6 @@ import type { WorkspacePanelCoordinator } from "./panel-coordinator"; export interface ThreadSurfaceActionsOptions { app: App; panels: WorkspacePanelCoordinator; - refreshThreadSurfaces: () => void; } export interface ThreadSurfaceActions { @@ -30,6 +29,17 @@ export function createThreadSurfaceActions(options: ThreadSurfaceActionsOptions) .getLeavesOfType(VIEW_TYPE_CODEX_THREADS) .flatMap((leaf) => (leaf.view instanceof CodexThreadsView ? [leaf.view] : [])); + const refreshSharedThreadListFromOpenSurface = (): void => { + const chatView = options.panels.panelViews().find((view) => view.openPanelSnapshot().connected); + if (chatView) { + void chatView.refreshSharedThreadList(); + return; + } + + const threadsView = threadsViews().at(0); + if (threadsView) void threadsView.refresh(); + }; + return { refreshOpenViews(): void { for (const view of options.panels.panelViews()) { @@ -37,16 +47,7 @@ export function createThreadSurfaceActions(options: ThreadSurfaceActionsOptions) } }, - refreshSharedThreadListFromOpenSurface(): void { - const chatView = options.panels.panelViews().find((view) => view.openPanelSnapshot().connected); - if (chatView) { - void chatView.refreshSharedThreadList(); - return; - } - - const threadsView = threadsViews().at(0); - if (threadsView) void threadsView.refresh(); - }, + refreshSharedThreadListFromOpenSurface, applyThreadListSnapshot(threads: readonly Thread[]): void { for (const view of options.panels.panelViews()) { @@ -83,14 +84,14 @@ export function createThreadSurfaceActions(options: ThreadSurfaceActionsOptions) for (const leaf of leavesToClose) { leaf.detach(); } - options.refreshThreadSurfaces(); + refreshSharedThreadListFromOpenSurface(); }, notifyThreadRenamed(threadId: string, name: string | null): void { for (const view of options.panels.panelViews()) { view.notifyThreadRenamed(threadId, name); } - options.refreshThreadSurfaces(); + refreshSharedThreadListFromOpenSurface(); }, }; } diff --git a/tests/main.test.ts b/tests/main.test.ts index e304d454..cc4354fb 100644 --- a/tests/main.test.ts +++ b/tests/main.test.ts @@ -377,10 +377,13 @@ describe("CodexPanelPlugin boot restored panel loading", () => { }); it("refreshes shared thread lists after archive lifecycle notifications", async () => { - const plugin = await pluginWithLeaves([]); - const refreshSharedThreadList = vi - .spyOn(threadSurfaces(plugin), "refreshSharedThreadListFromOpenSurface") - .mockImplementation(() => undefined); + const { CodexChatView } = await import("../src/features/chat/host/view"); + const connectedLeaf = leaf(); + connectedLeaf.view = chatView(CodexChatView, connectedLeaf); + const connectedView = connectedLeaf.view as CodexChatView; + vi.spyOn(connectedView, "openPanelSnapshot").mockReturnValue(panelSnapshot({ viewId: "connected", connected: true })); + const refreshSharedThreadList = vi.spyOn(connectedView, "refreshSharedThreadList").mockResolvedValue(undefined); + const plugin = await pluginWithLeaves([connectedLeaf]); threadSurfaces(plugin).notifyThreadArchived("thread-1"); @@ -393,11 +396,12 @@ describe("CodexPanelPlugin boot restored panel loading", () => { const matchingLeaf = leaf(); matchingLeaf.view = chatView(CodexChatView, matchingLeaf); vi.spyOn(matchingLeaf.view as CodexChatView, "openPanelSnapshot").mockReturnValue(panelSnapshot({ threadId: "thread-1" })); + vi.spyOn(matchingLeaf.view as CodexChatView, "refreshSharedThreadList").mockResolvedValue(undefined); const otherLeaf = leaf(); otherLeaf.view = chatView(CodexChatView, otherLeaf); vi.spyOn(otherLeaf.view as CodexChatView, "openPanelSnapshot").mockReturnValue(panelSnapshot({ threadId: "thread-2" })); + vi.spyOn(otherLeaf.view as CodexChatView, "refreshSharedThreadList").mockResolvedValue(undefined); const plugin = await pluginWithLeaves([restoredMatchingLeaf, matchingLeaf, otherLeaf]); - vi.spyOn(threadSurfaces(plugin), "refreshSharedThreadListFromOpenSurface").mockImplementation(() => undefined); threadSurfaces(plugin).notifyThreadArchived("thread-1"); @@ -413,10 +417,13 @@ describe("CodexPanelPlugin boot restored panel loading", () => { }); it("refreshes shared thread lists after rename lifecycle notifications", async () => { - const plugin = await pluginWithLeaves([]); - const refreshSharedThreadList = vi - .spyOn(threadSurfaces(plugin), "refreshSharedThreadListFromOpenSurface") - .mockImplementation(() => undefined); + const { CodexChatView } = await import("../src/features/chat/host/view"); + const connectedLeaf = leaf(); + connectedLeaf.view = chatView(CodexChatView, connectedLeaf); + const connectedView = connectedLeaf.view as CodexChatView; + vi.spyOn(connectedView, "openPanelSnapshot").mockReturnValue(panelSnapshot({ viewId: "connected", connected: true })); + const refreshSharedThreadList = vi.spyOn(connectedView, "refreshSharedThreadList").mockResolvedValue(undefined); + const plugin = await pluginWithLeaves([connectedLeaf]); threadSurfaces(plugin).notifyThreadRenamed("thread-1", "Renamed thread"); diff --git a/tests/workspace/thread-surface-actions.test.ts b/tests/workspace/thread-surface-actions.test.ts index 734f6b15..717b7def 100644 --- a/tests/workspace/thread-surface-actions.test.ts +++ b/tests/workspace/thread-surface-actions.test.ts @@ -25,7 +25,6 @@ describe("createThreadSurfaceActions", () => { }, ], } as never, - refreshThreadSurfaces: vi.fn(), }); threadSurfaces.refreshSharedThreadListFromOpenSurface(); @@ -58,7 +57,6 @@ describe("createThreadSurfaceActions", () => { }, ], } as never, - refreshThreadSurfaces: vi.fn(), }); threadSurfaces.refreshSharedThreadListFromOpenSurface();