Automations: when this happens, do that (daily time, task finished, new mail)
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
f80b718bd4
commit
94d13b82d7
10 files changed
+165
-4
No files matched your search
@@ -146,7 +146,8 @@ async function handle(req, res) {
|
||||
const b = JSON.parse(await readBody(req));
|
||||
if (isLocal(b.list)) {
|
||||
const d = load(), t = d.tasks.find(x => x.id === b.id); if (!t) throw new Error('Task not found');
|
||||
const rolled = finishLocal(t, !!b.done); save(d); return json(res, 200, { ok: true, rolled });
|
||||
const was = !!t.done, rolled = finishLocal(t, !!b.done); save(d); if (b.done && !was) require('./automations').fire(users.current().id, 'task.done', { title: t.title }).catch(() => {});
|
||||
return json(res, 200, { ok: true, rolled });
|
||||
}
|
||||
const cur = await caldav.getResource(b.list, b.href);
|
||||
const t = parseTodos(cur.ics)[0]; if (!t) throw new Error('Could not read that task');
|
||||
@@ -190,4 +191,9 @@ async function allTasks() {
|
||||
|
||||
/** Open tasks on the shared Family list, soonest first, for the family board. */
|
||||
const familyOpen = () => { const t = readJ(famFile(), { tasks: [] }).tasks || []; return t.filter(x => !x.done && !x.parent).sort((a, b) => (a.due || '9999').localeCompare(b.due || '9999') || a.title.localeCompare(b.title)).slice(0, 40).map(x => ({ id: x.id, title: x.title, due: x.due || '', by: x.by || '' })); };
|
||||
module.exports = { familyOpen, handle, parseTodos, allTasks, nextDue, stepDate };
|
||||
/** Add a task to one of the current person's own lists by name (the first list when none is given or found). Used by automations. */
|
||||
function addLocalTask(listName, title) {
|
||||
const d = load(), n = String(listName || '').toLowerCase(), l = (n && d.lists.find(x => x.id !== FAMILY && x.name.toLowerCase() === n)) || d.lists[0];
|
||||
d.tasks.push({ id: crypto.randomUUID(), list: l.id, title: String(title).slice(0, 200), notes: 'From an automation', due: '', done: false, completedAt: null, repeat: 'none', created: Date.now(), updated: Date.now(), by: users.current().name, byId: users.current().id }); save(d);
|
||||
}
|
||||
module.exports = { addLocalTask, familyOpen, handle, parseTodos, allTasks, nextDue, stepDate };
|
||||
Reference in new issue
Block a user