Remove thread surface refresh callback

This commit is contained in:
murashit 2026-06-15 08:16:55 +09:00
parent 57feea86ea
commit 7ee4c3c354
4 changed files with 30 additions and 27 deletions

View file

@ -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<void> {

View file

@ -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();
},
};
}

View file

@ -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");

View file

@ -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();