Files
cobble/src/utils/message-task-ids.ts
T
tbenandClaude Opus 5.5 ebc9ade7e0 Link bot messages to the tracker tasks they're about
Which tasks a message concerns is now the app's record, not the bot's
word: a run's task tools report every task they read in full, add, move
along or hand over, plus a handed-over job's task, into
bot_messages.task_ids (also on its failure notice and the report relayed
to the requester). The thread shows them under the message as chips with
title and status, read per viewer and only for tasks they reach, on
loads and live pushes alike.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
2026-11-08 09:23:39 +01:00

31 lines
849 B
TypeScript

type Params = {
/**
* A bot message's `task_ids` (JSON list of task ids), or a list of ids
* to tidy before it's stored.
*/
task_ids?: string | (number | string | null | undefined)[] | null;
};
/**
* The tracker task ids a bot message is about: positive integers, each
* once, in the order they were first touched. Anything unreadable reads as
* none, so a bad row never breaks the thread.
*/
export default function messageTaskIds({ task_ids }: Params): number[] {
let list: unknown = task_ids;
if (typeof task_ids == "string") {
try {
list = JSON.parse(task_ids);
} catch {
return [];
}
}
if (!Array.isArray(list)) return [];
const ids = list.map((id) => Number(id)).filter((id) => Number.isInteger(id) && id > 0);
return [...new Set(ids)];
}