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
@@ -66,6 +66,7 @@ async function tick(now = new Date(), force = false) {
|
||||
if (u.disabled) continue;
|
||||
const dir = users.dirOf(u.id), st = load(dir);
|
||||
await goalReminder(u, dir, st, now).catch(e => console.warn('[push] goal reminder failed:', e.message));
|
||||
await require('./automations').tickUser(u, localNow(st.subs.length ? st.tz : Intl.DateTimeFormat().resolvedOptions().timeZone, now)).catch(e => console.warn('[push] automations failed:', e.message)); // (daily rules)
|
||||
if (!st.subs.length) continue;
|
||||
await users.runAs(u, async () => {
|
||||
const lt = localNow(st.tz, now); let dirty = false;
|
||||
@@ -118,6 +119,7 @@ async function tick(now = new Date(), force = false) {
|
||||
const fresh = now2.filter(m => !seen.includes(m.id));
|
||||
if (fresh.length) {
|
||||
st.mailSeen = seen.concat(fresh.map(m => m.id)).slice(-200); dirty = true;
|
||||
for (const m of fresh.slice(0, 10)) require('./automations').fire(u.id, 'mail.new', { from: m.from || '', subject: m.subject || '' }).catch(() => {});
|
||||
await send(dir, st, u.id, { title: fresh.length === 1 ? (fresh[0].from || 'New mail') : fresh.length + ' new messages', body: fresh.length === 1 ? fresh[0].subject : fresh.slice(0, 3).map(m => m.from || m.subject).join(', '), url: '#/mail', tag: 'mail', ref: { mail: fresh.map(m => ({ a: m.acct, id: m.mid })).filter(r => r.a && r.id) } });
|
||||
}
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user