MCPcopy Index your code
hub / github.com/codeaashu/claude-code / markMessageAsReadByIndex

Function markMessageAsReadByIndex

src/utils/teammateMailbox.ts:201–271  ·  view source on GitHub ↗
(
  agentName: string,
  teamName: string | undefined,
  messageIndex: number,
)

Source from the content-addressed store, hash-verified

199 * @param messageIndex - Index of the message to mark as read
200 */
201export async function markMessageAsReadByIndex(
202 agentName: string,
203 teamName: string | undefined,
204 messageIndex: number,
205): Promise<void> {
206 const inboxPath = getInboxPath(agentName, teamName)
207 logForDebugging(
208 `[TeammateMailbox] markMessageAsReadByIndex called: agentName=${agentName}, teamName=${teamName}, index=${messageIndex}, path=${inboxPath}`,
209 )
210
211 const lockFilePath = `${inboxPath}.lock`
212
213 let release: (() => Promise<void>) | undefined
214 try {
215 logForDebugging(
216 `[TeammateMailbox] markMessageAsReadByIndex: acquiring lock...`,
217 )
218 release = await lockfile.lock(inboxPath, {
219 lockfilePath: lockFilePath,
220 ...LOCK_OPTIONS,
221 })
222 logForDebugging(`[TeammateMailbox] markMessageAsReadByIndex: lock acquired`)
223
224 // Re-read messages after acquiring lock to get the latest state
225 const messages = await readMailbox(agentName, teamName)
226 logForDebugging(
227 `[TeammateMailbox] markMessageAsReadByIndex: read ${messages.length} messages after lock`,
228 )
229
230 if (messageIndex < 0 || messageIndex >= messages.length) {
231 logForDebugging(
232 `[TeammateMailbox] markMessageAsReadByIndex: index ${messageIndex} out of bounds (${messages.length} messages)`,
233 )
234 return
235 }
236
237 const message = messages[messageIndex]
238 if (!message || message.read) {
239 logForDebugging(
240 `[TeammateMailbox] markMessageAsReadByIndex: message already read or missing`,
241 )
242 return
243 }
244
245 messages[messageIndex] = { ...message, read: true }
246
247 await writeFile(inboxPath, jsonStringify(messages, null, 2), 'utf-8')
248 logForDebugging(
249 `[TeammateMailbox] markMessageAsReadByIndex: marked message at index ${messageIndex} as read`,
250 )
251 } catch (error) {
252 const code = getErrnoCode(error)
253 if (code === 'ENOENT') {
254 logForDebugging(
255 `[TeammateMailbox] markMessageAsReadByIndex: file does not exist at ${inboxPath}`,
256 )
257 return
258 }

Callers 2

Calls 7

getInboxPathFunction · 0.85
logForDebuggingFunction · 0.85
readMailboxFunction · 0.85
jsonStringifyFunction · 0.85
getErrnoCodeFunction · 0.85
logErrorFunction · 0.70
releaseFunction · 0.50

Tested by

no test coverage detected