A workspace's task now carries the bot that has it there (bot_id with workspace_id), or none while it's shared. A bot reaches its own list and, in its workspaces, its own tasks plus the shared ones; a workspace admin every task there. Bots create workspace tasks for themselves by default, take a shared one by starting it, and hand-overs record the new bot. Removing or deleting a bot makes its workspace tasks shared again. The conversation's Tasks modal shows that bot's tasks in the workspace. Co-Authored-By: Claude Opus 5.5 <[email protected]>
34 lines
1.1 KiB
TypeScript
34 lines
1.1 KiB
TypeScript
import type { BUN_SQLITE_COBBLE_TASKS } from "@/db/types/db";
|
|
|
|
type Params = {
|
|
tasks: BUN_SQLITE_COBBLE_TASKS[];
|
|
title: string;
|
|
/**
|
|
* Same list: a bot's own, or a workspace's (whoever has it there).
|
|
*/
|
|
bot_id?: number | null;
|
|
workspace_id?: number | null;
|
|
};
|
|
|
|
/**
|
|
* A task in the same collection with the same title that's still open, so
|
|
* `ActionCheckNote` gets real behaviour: a bot updates the existing task
|
|
* instead of adding a second one for the same work.
|
|
*/
|
|
export default function findDuplicateTask({ tasks, title, bot_id, workspace_id }: Params) {
|
|
const wanted = title.trim().toLowerCase();
|
|
|
|
return (
|
|
tasks.find((task) => {
|
|
if (task.status == "done" || task.status == "cancelled") return false;
|
|
if (workspace_id) {
|
|
if (Number(task.workspace_id || 0) != Number(workspace_id)) return false;
|
|
} else if (task.workspace_id || Number(task.bot_id || 0) != Number(bot_id || 0)) {
|
|
return false;
|
|
}
|
|
|
|
return (task.title || "").trim().toLowerCase() == wanted;
|
|
}) || null
|
|
);
|
|
}
|