MCPcopy
hub / github.com/21st-dev/1code / claimChat

Method claimChat

src/main/windows/window-manager.ts:144–165  ·  view source on GitHub ↗

* Attempt to claim a chat for a window. * Returns { ok: true } if claimed, or { ok: false, ownerStableId } if already owned by another window.

(chatId: string, electronId: number)

Source from the content-addressed store, hash-verified

142 * Returns { ok: true } if claimed, or { ok: false, ownerStableId } if already owned by another window.
143 */
144 claimChat(chatId: string, electronId: number): { ok: true } | { ok: false; ownerStableId: string } {
145 const existingOwner = this.chatOwnership.get(chatId)
146
147 // Already owned by this same window — idempotent success
148 if (existingOwner === electronId) {
149 return { ok: true }
150 }
151
152 // Owned by another window — check it still exists
153 if (existingOwner !== undefined) {
154 const ownerWindow = this.windows.get(existingOwner)
155 if (ownerWindow && !ownerWindow.isDestroyed()) {
156 const ownerStableId = this.windowIdMap.get(existingOwner) ?? "unknown"
157 return { ok: false, ownerStableId }
158 }
159 // Owner window is gone — stale entry, clean it up
160 this.chatOwnership.delete(chatId)
161 }
162
163 this.chatOwnership.set(chatId, electronId)
164 return { ok: true }
165 }
166
167 /**
168 * Release a chat owned by a specific window.

Callers 3

AppContentFunction · 0.80
AgentsSidebarFunction · 0.80
registerIpcHandlersFunction · 0.80

Calls 3

getMethod · 0.45
deleteMethod · 0.45
setMethod · 0.45

Tested by

no test coverage detected