create-pmos 0.436.0 → 0.437.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +13 -13
- package/payload/KIT-VERSION +1 -1
- package/payload/planning/evals/eval-calibration.md +1 -1
- package/payload/planning/okrs/health-budgets.md +1 -1
- package/payload/state/discoveries.md +1 -1
- package/workspace/changelog.json +12 -0
- package/workspace/guide/home.md +21 -10
- package/workspace/home-rows-test.js +188 -115
- package/workspace/lib/mention-cli.js +45 -21
- package/workspace/lib/mention-store.js +196 -27
- package/workspace/lib/news-for-you.js +8 -16
- package/workspace/lib/routes-mentions.js +7 -2
- package/workspace/lib/routes-news.js +5 -11
- package/workspace/lib/source-reads.js +1 -1
- package/workspace/package-lock.json +2 -2
- package/workspace/package.json +1 -1
- package/workspace/premium-briefing-depth-test.js +2 -2
- package/workspace/public/pm/cozy-home-rows.css +88 -62
- package/workspace/public/pm/cozy-news.js +8 -27
- package/workspace/public/pm/home-day.js +4 -6
- package/workspace/public/pm/home-mentions.js +327 -193
- package/workspace/skills/morning-brief.skill +2 -1
- package/workspace/skills/sources-read.skill +1 -0
|
@@ -1,48 +1,64 @@
|
|
|
1
|
-
/* pm/home-mentions.js — @Mentions on Home: a permanent row at the top of the list and the Mentions Viewer (
|
|
2
|
-
*
|
|
1
|
+
/* pm/home-mentions.js — @Mentions on Home: a permanent row at the top of the list and the Mentions Viewer ("Mentions, calm", batch 16
|
|
2
|
+
* item 12; canvas MnA1Calm, MnA2Waits, MnA3Thread, MnA4Desk, MnA5Busy, MnA6Edges and the 25 moments of MnGrill).
|
|
3
3
|
*
|
|
4
|
-
* rowHtml(D, { sel }) → the row's markup: "@ Mentions" and a badge with how many
|
|
5
|
-
* answering does
|
|
6
|
-
*
|
|
7
|
-
* openMentions(ctx) → the Mentions Viewer
|
|
8
|
-
*
|
|
9
|
-
*
|
|
10
|
-
*
|
|
11
|
-
*
|
|
12
|
-
*
|
|
13
|
-
*
|
|
4
|
+
* rowHtml(D, { sel }) → the row's markup: "@ Mentions" and a badge with how many conversations wait on the PM (Your move). Reading does
|
|
5
|
+
* not clear it, answering does; no badge at zero. A new ask since the PM last opened Mentions adds one line under
|
|
6
|
+
* the name ("Maya asks for the launch budget cap"). The press is data-hr-mentions.
|
|
7
|
+
* openMentions(ctx) → the Mentions Viewer. Adler's M face opens on what is handled first, and the mood is never happier than the data;
|
|
8
|
+
* on a heavy day one button starts on the oldest ask. Three folds, each hidden at zero: Your move (an open ask,
|
|
9
|
+
* oldest first, 3 then "N more"; the age turns amber after 2 days), To read (FYIs; a blue dot is not opened; ✓✓
|
|
10
|
+
* marks all read; closed while Your move has items) and Answered this week (closed, a small stack of faces).
|
|
11
|
+
* One row per conversation: a face with the source's badge, first names ("Maya and Dion", "Maya and 2 others"),
|
|
12
|
+
* the place, the message count and Claude's one-line gist (the real latest message in quotes until a gist
|
|
13
|
+
* exists). Rows carry no day. A drafted reply shows with ✎ and send only; when Claude cannot draft, it says why
|
|
14
|
+
* and ✎ "Write it with Claude" is the only button. After send: "Sent from Slack? I’ll see it at the next read."
|
|
15
|
+
* What PMOS could not read is one line each at the end; a failed read keeps the last list and says from when.
|
|
16
|
+
* openOne(m, ctx, o) → one conversation (MnA3): who, where, how many messages since when, ↗ to the source; the open ask first, with
|
|
17
|
+
* the reply and four one-tap acts, each with Undo (✓ answered, clock: remind me at 09:00, task: make it a task,
|
|
18
|
+
* × not an ask), then ✎ and send; "Where it stands" (hidden when nothing is settled); Claude's offer to watch for
|
|
19
|
+
* a dated promise (✓ ×); the messages last, in a fold.
|
|
20
|
+
* On a wide Viewer (desktop, MnA4) the list and the conversation sit side by side; ✎ moves the reply into the chat.
|
|
14
21
|
* load(ctx) → GET /api/mentions into ctx.D().mentions, keeping the last good list when the read fails
|
|
15
|
-
* ctx: { D() → Home's data, pmGet, pmPost, toast, toastUndo(msg, undo), reload(), iniTitle(id), stageOf(id), onBoard(id),
|
|
16
|
-
* goIni(id), draft(m) }
|
|
22
|
+
* ctx: { D() → Home's data, pmGet, pmPost, toast, toastUndo(msg, undo), reload(), redrawList(), iniTitle(id), stageOf(id), onBoard(id),
|
|
23
|
+
* board() → { ws, board }, goIni(id), draft(m) }
|
|
17
24
|
*
|
|
18
|
-
* The data is GET /api/mentions (lib/mention-store.js): its own store, so the brief's 30-item cap cannot crowd
|
|
19
|
-
* POST /api/mentions/act (one mark, undone by act: undo). Nothing here replies or posts: send
|
|
20
|
-
* the
|
|
25
|
+
* The data is GET /api/mentions (lib/mention-store.js): conversations from its own store, so the brief's 30-item cap cannot crowd one out.
|
|
26
|
+
* Every press is POST /api/mentions/act (one mark under the conversation's id, undone by act: undo). Nothing here replies or posts: send
|
|
27
|
+
* copies the reply and opens the source, and the PM sends it there. Mentions owns every mention: New for you shows none. */
|
|
21
28
|
import * as VW from './cozy-viewer.js';
|
|
29
|
+
import { adler } from './cozy-adler.js';
|
|
22
30
|
|
|
23
31
|
const esc = (s) => String(s == null ? '' : s).replace(/[&<>"']/g, (c) => ({ '&': '&', '<': '<', '>': '>', '"': '"', "'": ''' }[c]));
|
|
24
|
-
const SRC = { slack: 'Slack', jira: 'Jira', confluence: 'Confluence', mail: '
|
|
25
|
-
const ICON = { jira: 'jira', confluence: 'doc', doc: 'doc', mail: 'M3.5 5.5h17v13h-17zM3.5 6l8.5 7 8.5-7', gmail: 'M3.5 5.5h17v13h-17zM3.5 6l8.5 7 8.5-7' };
|
|
32
|
+
const SRC = { slack: 'Slack', jira: 'Jira', confluence: 'Confluence', mail: 'email', gmail: 'Gmail', figma: 'Figma', doc: 'the document' };
|
|
26
33
|
const P = {
|
|
27
34
|
tick: 'M5 12.5l4.5 4.5L19 7.5', clock: 'M12 3a9 9 0 1 0 0 18 9 9 0 0 0 0-18M12 7.5V12l3 2', task: 'M4 4h11v11H4zM7 9.5l2 2 3-3.5M18 13v8M14 17h8',
|
|
28
|
-
x: 'M6 6l12 12M18 6L6 18',
|
|
29
|
-
plug: 'M9 3v5M15 3v5M6 8h12v3a6 6 0 0 1-12 0zM12 17v4', again: 'M20 11a8 8 0 1 0-2.3 5.7M20 5v6h-6',
|
|
35
|
+
x: 'M6 6l12 12M18 6L6 18', pen: 'M4 20h4L19 9l-4-4L4 16zM13.5 6.5l4 4', send: 'M21 3L10 14M21 3l-7 18-4-7-7-4z', go: 'M5 12h14M13 6l6 6-6 6',
|
|
36
|
+
plug: 'M9 3v5M15 3v5M6 8h12v3a6 6 0 0 1-12 0zM12 17v4', again: 'M20 11a8 8 0 1 0-2.3 5.7M20 5v6h-6', out: 'M14 4h6v6M20 4l-9 9M18 14v6H4V6h6',
|
|
37
|
+
all: 'M2 12.5l4.5 4.5L15 8M9 15l2 2L22 7', spark: VW.ICONS.spark,
|
|
30
38
|
};
|
|
39
|
+
const BADGE = { slack: 'M9 4l-2 16M17 4l-2 16M4 9h16M3 15h16', mail: 'M3.5 5.5h17v13h-17zM3.5 6l8.5 7 8.5-7', gmail: 'M3.5 5.5h17v13h-17zM3.5 6l8.5 7 8.5-7',
|
|
40
|
+
jira: 'M12 3l9 9-9 9-9-9z', confluence: 'M7 3h7l4 4v14H7zM14 3v4h4', doc: 'M7 3h7l4 4v14H7zM14 3v4h4' };
|
|
31
41
|
const svg = (d, w = 16, sw = 2) => `<svg aria-hidden="true" width="${w}" height="${w}" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="${sw}" stroke-linecap="round" stroke-linejoin="round"><path d="${d}"/></svg>`;
|
|
32
42
|
const srcName = (s) => SRC[s] || (s ? String(s).charAt(0).toUpperCase() + String(s).slice(1) : 'its source');
|
|
43
|
+
const sendIn = (s) => (s === 'mail' ? 'your email' : srcName(s));
|
|
33
44
|
const first = (who) => String(who || 'someone').trim().split(/\s+/)[0];
|
|
34
45
|
const clip = (s, n) => { s = String(s || '').replace(/\s+/g, ' ').trim(); return s.length > n ? s.slice(0, n - 1).trimEnd() + '…' : s; };
|
|
35
46
|
const https = (u) => (/^https:\/\/\S+$/i.test(String(u || '')) ? u : '');
|
|
36
47
|
const isMail = (s) => s === 'mail' || s === 'gmail';
|
|
37
48
|
const isDoc = (s) => s === 'confluence' || s === 'doc';
|
|
38
|
-
const T = (iso) => { const t = Date.parse(iso || ''); return Number.isFinite(t) ? t : 0; };
|
|
49
|
+
const T = (iso) => { const t = typeof iso === 'number' ? iso : Date.parse(iso || ''); return Number.isFinite(t) ? t : 0; };
|
|
39
50
|
const DAY = 86400000;
|
|
51
|
+
const SHOWN = 3;
|
|
52
|
+
const WORDS = ['no', 'one', 'two', 'three', 'four', 'five', 'six', 'seven', 'eight', 'nine', 'ten'];
|
|
53
|
+
const word = (n) => WORDS[n] || String(n);
|
|
54
|
+
const cap = (s) => s.charAt(0).toUpperCase() + s.slice(1);
|
|
40
55
|
const store = {
|
|
41
56
|
get(k) { try { return localStorage.getItem(k); } catch { return null; } },
|
|
42
57
|
set(k, v) { try { localStorage.setItem(k, String(v)); } catch { /* a private window */ } },
|
|
43
58
|
};
|
|
44
59
|
const SEEN = 'cz-men-seen'; // when the PM last opened Mentions: a newer ask adds its line under the row's name
|
|
45
|
-
const CACHE = 'cz-men-last'; // the last list that loaded, with its time, for a read that fails (
|
|
60
|
+
const CACHE = 'cz-men-last'; // the last list that loaded, with its time, for a read that fails (MnA6)
|
|
61
|
+
const HEARD = 'cz-men-heard'; // the landed promises the opening line already said (it says each once)
|
|
46
62
|
|
|
47
63
|
/* ── the data ── */
|
|
48
64
|
/** Load GET /api/mentions into D.mentions. A failed read keeps the last good list and says when it is from. */
|
|
@@ -57,24 +73,28 @@ export async function load(ctx) {
|
|
|
57
73
|
}
|
|
58
74
|
let last = D.mentions && !D.mentions.failed ? D.mentions : null;
|
|
59
75
|
if (!last) { try { last = JSON.parse(store.get(CACHE) || 'null'); } catch { last = null; } }
|
|
60
|
-
D.mentions = { ...(last || { waiting: [],
|
|
76
|
+
D.mentions = { ...(last || { waiting: [], toread: [], answered: [], gaps: [], count: 0 }), failed: true, from: last ? last.at : 0 };
|
|
61
77
|
return D.mentions;
|
|
62
78
|
}
|
|
63
|
-
/**
|
|
79
|
+
/** The lists of Home's data; empty before the first read. An answer from before conversations (no toread) reads its recent as To read. */
|
|
64
80
|
export function mentionsOf(D) {
|
|
65
81
|
const m = (D && D.mentions) || null;
|
|
66
|
-
|
|
82
|
+
const A = (k) => (m && Array.isArray(m[k]) ? m[k] : []);
|
|
83
|
+
const toread = m && Array.isArray(m.toread) ? m.toread : A('recent').filter((x) => x.fyi), answered = m && Array.isArray(m.answered) ? m.answered : A('recent').filter((x) => !x.fyi);
|
|
84
|
+
return { waiting: A('waiting'), toread, answered, gaps: A('gaps'), watching: A('watching'), landed: A('landed'), sources: A('sources'),
|
|
85
|
+
as_of: (m && m.as_of) || null, failed: !!(m && m.failed), from: (m && m.from) || 0, loaded: !!m };
|
|
67
86
|
}
|
|
68
|
-
|
|
87
|
+
const allOf = (L) => [...L.waiting, ...L.toread, ...L.answered];
|
|
88
|
+
/** A task made from a mention closes itself when the PM replies in the source (MnGrill). */
|
|
69
89
|
async function closeTasks(ctx, r) {
|
|
70
|
-
for (const m of r.recent || []) {
|
|
90
|
+
for (const m of [...(r.answered || r.recent || [])]) {
|
|
71
91
|
if (m.status !== 'replied' || !m.task || m.task_closed) continue;
|
|
72
92
|
const t = m.task;
|
|
73
93
|
const res = t.kind === 'board' ? await ctx.pmPost('/api/boards/tasks/state', { ws: t.ws, board: t.board, task: t.id, state: 'Done' }) : await ctx.pmPost('/api/pm-items/done', { id: t.id, how: 'confirmed' });
|
|
74
94
|
if (res && res.ok) await ctx.pmPost('/api/mentions/act', { id: m.id, act: 'closed' });
|
|
75
95
|
}
|
|
76
96
|
}
|
|
77
|
-
/** "40 min", "
|
|
97
|
+
/** "40 min", "5 h", "1 day", "3 days"; '' with no time. */
|
|
78
98
|
export function age(at, now = Date.now()) {
|
|
79
99
|
const t = T(at); if (!t) return '';
|
|
80
100
|
const m = Math.max(0, Math.round((now - t) / 60000));
|
|
@@ -84,185 +104,282 @@ export function age(at, now = Date.now()) {
|
|
|
84
104
|
}
|
|
85
105
|
const late = (at, now = Date.now()) => now - T(at) >= 2 * DAY;
|
|
86
106
|
const WD = ['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat'];
|
|
107
|
+
const WDL = ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday'];
|
|
87
108
|
const MO = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'];
|
|
88
109
|
const day0 = (t) => { const d = new Date(t); d.setHours(0, 0, 0, 0); return d.getTime(); };
|
|
89
|
-
|
|
110
|
+
const daysAgo = (t, now) => Math.round((day0(now) - day0(t)) / DAY);
|
|
111
|
+
/** The PM's local day of a time: "Today", "Yesterday", "Tue 27 Oct". */
|
|
90
112
|
export function dayLabel(at, now = Date.now()) {
|
|
91
|
-
const t = T(at), d = new Date(t), n =
|
|
92
|
-
|
|
93
|
-
return n <= 0 ? 'Today' : n === 1 ? 'Yesterday, ' + dated : dated;
|
|
113
|
+
const t = T(at), d = new Date(t), n = daysAgo(t, now);
|
|
114
|
+
return n <= 0 ? 'Today' : n === 1 ? 'Yesterday' : WD[d.getDay()] + ' ' + d.getDate() + ' ' + MO[d.getMonth()];
|
|
94
115
|
}
|
|
95
|
-
|
|
116
|
+
const hmOf = (t) => { const d = new Date(t); return String(d.getHours()).padStart(2, '0') + ':' + String(d.getMinutes()).padStart(2, '0'); };
|
|
117
|
+
/** Where the conversation is, as the frames say it: "#tech-team-cem", "DM", "PAY-312 comment", "comment on PRD v3", "email". */
|
|
96
118
|
export function placeOf(m) {
|
|
97
119
|
const w = String(m.where || '').trim();
|
|
98
|
-
if (m.source === 'slack') return
|
|
120
|
+
if (m.source === 'slack') return w || (m.via === 'dm' ? 'DM' : 'Slack');
|
|
99
121
|
if (m.source === 'jira') return (w || 'Jira') + ' comment';
|
|
100
122
|
if (isDoc(m.source)) return 'comment on ' + (w || srcName(m.source));
|
|
101
123
|
if (isMail(m.source)) return 'email';
|
|
102
124
|
return [srcName(m.source), w].filter(Boolean).join(' ');
|
|
103
125
|
}
|
|
104
|
-
const
|
|
105
|
-
|
|
126
|
+
const peopleOf = (m) => (Array.isArray(m.people) && m.people.length ? m.people : [m.who || srcName(m.source)]);
|
|
127
|
+
/** The row's name: a first name; "Maya and Dion"; "Maya and 2 others" for 3 or more (MnGrill). */
|
|
128
|
+
export function nameOf(m) {
|
|
129
|
+
const p = peopleOf(m).map(first);
|
|
130
|
+
return p.length === 1 ? p[0] : p.length === 2 ? p[0] + ' and ' + p[1] : p[0] + ' and ' + (p.length - 1) + ' others';
|
|
131
|
+
}
|
|
132
|
+
/** The conversation's title: the full names ("Samuel Chandra"; "Maya Tan and Dion Lee"; "Maya Tan, Dion Lee and Rina Sari"). */
|
|
133
|
+
export function fullNames(m) {
|
|
134
|
+
const p = peopleOf(m);
|
|
135
|
+
return p.length <= 2 ? p.join(' and ') : p.slice(0, -1).join(', ') + ' and ' + p[p.length - 1];
|
|
136
|
+
}
|
|
137
|
+
const initials = (who) => { const w = String(who || '?').replace(/[^\p{L}\s]/gu, '').trim().split(/\s+/); return esc(((w[0] || '?')[0] + (w[1] ? w[1][0] : (w[0] || '')[1] || '')).toUpperCase()); };
|
|
138
|
+
/** The row's line: Claude's gist, else the real latest message in quotes (never a made-up gist). */
|
|
139
|
+
export function gistOf(m) { return m.gist ? m.gist : '“' + clip(m.text || m.ask || '', 140) + '”'; }
|
|
106
140
|
|
|
107
|
-
/* ── the row on Home
|
|
141
|
+
/* ── the row on Home ── */
|
|
108
142
|
export function rowHtml(D, o = {}) {
|
|
109
143
|
const { waiting } = mentionsOf(D);
|
|
110
144
|
const n = waiting.length;
|
|
111
145
|
const sel = o.sel === 'mentions';
|
|
112
146
|
const seen = +(store.get(SEEN) || 0);
|
|
113
147
|
const nu = seen ? waiting.filter((m) => T(m.since) > seen || (m.count > 1 && T(m.last) > seen)).sort((a, b) => T(b.last) - T(a.last))[0] : null;
|
|
114
|
-
const sub = nu ? clip(
|
|
148
|
+
const sub = nu ? clip(nameOf(nu) + (nu.ask ? ' asks ' + nu.ask.replace(/^[A-Z](?=[a-z])/, (c) => c.toLowerCase()).replace(/[.?!]+$/, '') : ' asks you something'), 60) : '';
|
|
115
149
|
return `<div class="hv-card hr-card hr-men-card"><div class="hm-r hv-r hr-men${sel ? ' sel' : ''}${n ? ' new' : ''}" data-id="mentions">`
|
|
116
150
|
+ `<button type="button" class="hm-rm" data-hr-mentions${sel ? ' aria-current="true"' : ''} aria-label="Mentions${n ? ', ' + n + (n === 1 ? ' waits' : ' wait') + ' on your reply' : ''}">`
|
|
117
151
|
+ `<span class="hv-mk hr-at" aria-hidden="true">@</span><span class="hm-rt"><b>Mentions</b>${sub ? `<small class="hr-sub">${esc(sub)}</small>` : ''}</span>`
|
|
118
152
|
+ (n ? `<span class="hr-bd" aria-hidden="true">${n}</span>` : '') + '<span class="hv-xc" aria-hidden="true"></span></button></div></div>';
|
|
119
153
|
}
|
|
120
154
|
|
|
121
|
-
/* ── the
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
155
|
+
/* ── the opening line (MnA1, MnA2, MnA5, MnA6) ── */
|
|
156
|
+
const heard = () => { try { return new Set(JSON.parse(store.get(HEARD) || '[]')); } catch { return new Set(); } };
|
|
157
|
+
const landedKey = (x) => x.id + '@' + x.at;
|
|
158
|
+
const joinOr = (l) => (l.length <= 1 ? l.join('') : l.slice(0, -1).join(', ') + ' or ' + l[l.length - 1]);
|
|
159
|
+
const joinAnd = (l) => (l.length <= 1 ? l.join('') : l.slice(0, -1).join(', ') + ' and ' + l[l.length - 1]);
|
|
160
|
+
/** Adler's opening line: what is handled first, said as plainly as the data. Pure. L: mentionsOf(); o: { heard: Set of landed keys said }.
|
|
161
|
+
* → { mood, html, go (start on the oldest ask), retry, said: [landed keys this line says] } */
|
|
162
|
+
export function openingOf(L, now = Date.now(), o = {}) {
|
|
163
|
+
const w = L.waiting, n = w.length;
|
|
164
|
+
const said = (L.landed || []).filter((x) => !(o.heard || new Set()).has(landedKey(x)));
|
|
165
|
+
const landed = said.map((x) => ' ' + esc(String(x.text).replace(/[.!]?$/, '.'))).join('');
|
|
166
|
+
const watch = (L.watching || []).length ? ' I’m watching for ' + esc(joinAnd(L.watching.map((x) => x.what))) + ' and will tell you when ' + (L.watching.length === 1 ? 'it lands' : 'they land') + '.' : '';
|
|
167
|
+
if (L.failed) return { mood: 'honest', html: 'I couldn’t refresh Mentions. ' + (L.from ? 'This is the list from <b>' + esc(hmOf(L.from)) + '</b>.' : 'There is no list to show yet.'), retry: true, said: [] };
|
|
168
|
+
const missing = (L.gaps || []).some((g) => g.kind === 'source');
|
|
169
|
+
const inSrc = missing && (L.sources || []).length ? ' in ' + esc(joinOr(L.sources.map((s) => (s === 'mail' ? 'email' : srcName(s))))) : '';
|
|
170
|
+
if (!n) {
|
|
171
|
+
const answered = L.answered.filter((m) => m.status === 'replied' || m.status === 'answered').length;
|
|
172
|
+
if (!L.toread.length && !watch && !landed) {
|
|
173
|
+
const lastT = Math.max(0, ...L.answered.map((m) => T(m.last)));
|
|
174
|
+
const d = lastT ? daysAgo(lastT, now) : 0;
|
|
175
|
+
const since = !lastT ? '' : d <= 0 ? 'this morning' : d === 1 ? 'yesterday' : WDL[new Date(lastT).getDay()];
|
|
176
|
+
return { mood: 'resting', html: lastT ? 'A quiet week. Nobody has mentioned you since ' + since + ', so nothing waits.' : 'A quiet week. Nobody has mentioned you in the last 7 days.', said: [] };
|
|
177
|
+
}
|
|
178
|
+
const done = answered ? ' You answered ' + (answered === 1 ? 'the one ask' : 'all <b>' + answered + ' asks</b>') + ' this week.' : '';
|
|
179
|
+
return { mood: landed ? 'celebrating' : 'handled', html: 'Nothing waits on you' + inSrc + '.' + done + landed + watch, said: said.map(landedKey) };
|
|
180
|
+
}
|
|
181
|
+
const people = [...new Set(w.flatMap((m) => peopleOf(m).map(first)))];
|
|
182
|
+
const lead = people.length === 1 ? esc(people[0]) + ' waits on you' : cap(word(people.length)) + ' people wait on you';
|
|
183
|
+
const drafted = w.filter((m) => m.draft && !m.drafted).length, cant = w.filter((m) => m.nodraft);
|
|
184
|
+
const heavy = n > SHOWN;
|
|
185
|
+
let html;
|
|
186
|
+
if (heavy) {
|
|
187
|
+
const o0 = w[0];
|
|
188
|
+
html = lead + ', and ' + esc(nameOf(o0)) + '’s has waited ' + esc(age(o0.since, now)) + '.' + (drafted ? ' I drafted ' + word(drafted) + (drafted >= 2 ? ', so the first few are quick.' : '.') : '')
|
|
189
|
+
+ ' Want me to start you on ' + esc(nameOf(o0)) + '’s?';
|
|
190
|
+
} else {
|
|
191
|
+
const dr = !drafted ? '' : drafted === n ? (n === 1 ? ' I drafted your reply.' : ' I drafted all ' + word(n) + ' replies.')
|
|
192
|
+
: ' I drafted ' + word(drafted) + (drafted === 1 ? ' reply' : ' replies') + (cant.length ? '; ' + esc(nameOf(cant[0])) + '’s needs you.' : '.');
|
|
193
|
+
html = lead + '.' + dr;
|
|
194
|
+
}
|
|
195
|
+
return { mood: 'needs-you', html: html + landed + watch, go: heavy, said: said.map(landedKey) };
|
|
133
196
|
}
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
197
|
+
|
|
198
|
+
/* ── the rows ── */
|
|
199
|
+
const ib = (attrs, label, d, solid = false) => `<button type="button" class="${solid ? 'hr-rp mn-sb' : 'czs-ib mn-ib'}" ${attrs} aria-label="${esc(label)}" title="${esc(label)}">${svg(d, solid ? 17 : 16, 2.2)}</button>`;
|
|
200
|
+
const face = (m) => `<span class="mn-av" aria-hidden="true">${initials(peopleOf(m)[0])}${BADGE[m.source] ? `<i class="mn-bg">${svg(BADGE[m.source], 9, 2.4)}</i>` : ''}</span>`;
|
|
201
|
+
function draftHtml(m, o = {}) {
|
|
202
|
+
if (m.drafted) return `<p class="mn-sent">${svg(P.send, 12, 2.2)}<span>Sent from ${esc(srcName(m.source))}? I’ll see it at the next read.</span></p>`;
|
|
203
|
+
if (m.nodraft) return `<div class="mn-dr no"><p class="mn-drh">${svg(P.spark, 12, 2)}<span>I can’t draft this one</span></p><p>${esc(m.nodraft)}</p></div>`
|
|
204
|
+
+ (o.acts === false ? '' : `<div class="mn-acts">${ib(`data-mn="pen" data-id="${esc(m.id)}"`, 'Write it with Claude', P.pen, true)}</div>`);
|
|
205
|
+
if (m.draft) return `<div class="mn-dr"><p class="mn-drh">${svg(P.spark, 12, 2)}<span>I drafted your reply</span></p><p data-mn-draft>${esc(m.draft)}</p></div>`
|
|
206
|
+
+ (o.acts === false ? '' : `<div class="mn-acts">${ib(`data-mn="pen" data-id="${esc(m.id)}"`, 'Change it with Claude', P.pen)}${ib(`data-mn="send" data-id="${esc(m.id)}"`, 'Copy it and open ' + srcName(m.source) + '. PMOS never posts.', P.send, true)}</div>`);
|
|
139
207
|
return '';
|
|
140
208
|
}
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
const
|
|
147
|
-
const dot = m.
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
+ `<span class="
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
return
|
|
209
|
+
const checkHtml = (m) => (m.check ? `<div class="hr-ck" role="group" aria-label="${esc('Did you answer ' + nameOf(m) + ' already?')}"><span>Did you answer this already?</span>`
|
|
210
|
+
+ `<button type="button" class="hr-ckb" data-mn="ck-yes" data-id="${esc(m.id)}" aria-label="Yes, I answered it" title="Yes, I answered it">${svg(P.tick, 15, 2.2)}</button>`
|
|
211
|
+
+ `<button type="button" class="hr-ckb" data-mn="ck-no" data-id="${esc(m.id)}" aria-label="No, keep it waiting" title="No, keep it waiting">${svg(P.x, 15, 2.2)}</button></div>` : '');
|
|
212
|
+
/** One conversation's row. kind: 'move' | 'read' | 'done'. o: { full: the drafted reply in full (a calm day), sel, now } */
|
|
213
|
+
export function rowOf(m, kind, o = {}) {
|
|
214
|
+
const now = o.now || Date.now();
|
|
215
|
+
const dot = kind === 'read' && !m.read && !m.broadcast;
|
|
216
|
+
const n = m.messages || 1;
|
|
217
|
+
const right = (n > 1 ? `<i class="mn-n" aria-label="${n} messages">${n}</i>` : '')
|
|
218
|
+
+ (kind === 'move' && m.since ? `<span class="mn-age${late(m.since, now) ? ' late' : ''}">${esc(age(m.since, now))}</span>` : '')
|
|
219
|
+
+ (dot ? '<span class="mn-dot" aria-hidden="true"></span>' : '');
|
|
220
|
+
const tag = kind === 'move' && !o.full ? (m.drafted ? `<span class="mn-tag">${svg(P.send, 11, 2.2)} Sent from ${esc(srcName(m.source))}? I’ll see it at the next read.</span>`
|
|
221
|
+
: m.draft ? `<span class="mn-tag">${svg(P.pen, 11, 2.2)} Reply drafted</span>` : '') : '';
|
|
222
|
+
const label = nameOf(m) + ', ' + placeOf(m) + (kind === 'move' && m.since ? ', waiting ' + age(m.since, now) : '') + (dot ? ', not opened' : '') + '. Open';
|
|
223
|
+
return `<div class="mn-row k-${kind}${o.sel ? ' sel' : ''}${dot ? ' un' : ''}" data-mn-row="${esc(m.id)}">`
|
|
224
|
+
+ `<button type="button" class="mn-open" data-mn="open" data-id="${esc(m.id)}" aria-label="${esc(label)}"${o.sel ? ' aria-current="true"' : ''}>${face(m)}`
|
|
225
|
+
+ `<span class="mn-main"><span class="mn-top"><b class="mn-nm">${esc(nameOf(m))}</b><span class="mn-pl">· ${esc(placeOf(m))}</span><span class="mn-r">${right}</span></span>`
|
|
226
|
+
+ `<span class="mn-gist">${m.since_reply ? '<em>New since your reply.</em> ' : ''}${esc(gistOf(m))}</span>${tag}</span></button>`
|
|
227
|
+
+ (kind === 'move' && o.full ? draftHtml(m) : '') + (kind === 'move' ? checkHtml(m) : '') + '</div>';
|
|
156
228
|
}
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
229
|
+
|
|
230
|
+
/* ── the list ── */
|
|
231
|
+
function gapsHtml(L) {
|
|
232
|
+
const out = (L.gaps || []).map((g) => {
|
|
160
233
|
if (g.kind === 'stale') {
|
|
161
|
-
const t = T(g.upto),
|
|
162
|
-
return `<div class="
|
|
163
|
-
+
|
|
234
|
+
const t = T(g.upto), d = daysAgo(t, Date.now());
|
|
235
|
+
return `<div class="mn-gap"><p>Last read ${esc(hmOf(t) + (d === 1 ? ' yesterday' : d > 1 ? ' on ' + dayLabel(g.upto) : ''))}. Today’s read hasn’t run.</p>`
|
|
236
|
+
+ ib('data-mn="check"', 'Read now', P.again) + '</div>';
|
|
164
237
|
}
|
|
165
|
-
const s = srcName(g.source);
|
|
166
|
-
const said = g.state === 'not-reached' ? `<b>PMOS couldn’t reach ${esc(s)}</b> at the last
|
|
167
|
-
return `<div class="
|
|
238
|
+
const s = srcName(g.source), S = cap(s);
|
|
239
|
+
const said = g.state === 'not-reached' ? `<b>PMOS couldn’t reach ${esc(s)}</b> at the last read, so ${esc(s)} mentions may be missing.` : `<b>${esc(S)} isn’t connected</b>, so ${esc(s)} mentions are missing.`;
|
|
240
|
+
return `<div class="mn-gap"><p>${said}</p>${ib('data-mn="connect"', 'Connect ' + S, P.plug)}</div>`;
|
|
168
241
|
}).join('');
|
|
242
|
+
if (out || L.failed || !L.as_of || !(L.sources || []).length) return out;
|
|
243
|
+
// nothing is missing: one quiet line says what was read and when (honest state)
|
|
244
|
+
const names = L.sources.map((s) => (s === 'mail' ? 'email' : srcName(s)));
|
|
245
|
+
return `<p class="mn-foot">${esc(cap(joinAnd(names)))} read at ${esc(hmOf(T(L.as_of)))}.</p>`;
|
|
169
246
|
}
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
const
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
}
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
text = said.join(' ') + (n > 2 ? ' And ' + (n - 2) + ' more.' : '');
|
|
189
|
-
}
|
|
190
|
-
return { line: n + (n === 1 ? ' waits' : ' wait') + ' on your reply', right: 'oldest ' + age(waiting[0].since, now), text, reply: true };
|
|
247
|
+
const stack = (list) => `<span class="mn-stk" aria-hidden="true">${list.slice(0, 4).map((m) => `<i>${initials(peopleOf(m)[0])}</i>`).join('')}</span>`;
|
|
248
|
+
function foldsHtml(L, X, now, sel) {
|
|
249
|
+
// a calm day shows each drafted reply in full on its row; side by side, the conversation beside the list shows it (say it once)
|
|
250
|
+
const w = L.waiting, full = w.length <= SHOWN && !X.split;
|
|
251
|
+
const showW = X.all ? w : w.slice(0, SHOWN);
|
|
252
|
+
const restW = w.slice(showW.length);
|
|
253
|
+
const newest = restW.length ? Math.max(...restW.map((m) => T(m.since))) : 0;
|
|
254
|
+
const moreW = restW.length ? `<button type="button" class="mn-more" data-mn="more-move">${esc(restW.length + ' more' + (newest && daysAgo(newest, now) <= 0 ? ', newest today' : ''))}</button>` : '';
|
|
255
|
+
const showR = X.allRead ? L.toread : L.toread.slice(0, SHOWN), moreR = L.toread.length - showR.length;
|
|
256
|
+
const unread = L.toread.filter((m) => !m.read && !m.broadcast);
|
|
257
|
+
const row = (k) => (m) => rowOf(m, k, { full, now, sel: sel === m.id });
|
|
258
|
+
return VW.czSections([
|
|
259
|
+
w.length ? { id: 'move', title: 'Your move', count: w.length, open: true, html: `<div class="mn-list">${showW.map(row('move')).join('')}${moreW}</div>` } : null,
|
|
260
|
+
L.toread.length ? { id: 'toread', title: 'To read', count: L.toread.length, open: !w.length,
|
|
261
|
+
tail: unread.length ? `<button type="button" class="mn-all" data-mn="all-read" aria-label="${esc('Mark all ' + unread.length + ' read')}" title="Mark all read">${svg(P.all, 18, 1.9)}</button>` : '',
|
|
262
|
+
html: `<div class="mn-list">${showR.map(row('read')).join('')}${moreR > 0 ? `<button type="button" class="mn-more" data-mn="more-read">${moreR} more</button>` : ''}</div>` } : null,
|
|
263
|
+
L.answered.length ? { id: 'answered', title: 'Answered this week', count: L.answered.length, open: false, tail: stack(L.answered), html: `<div class="mn-list">${L.answered.map(row('done')).join('')}</div>` } : null,
|
|
264
|
+
], { key: 'mentions-' + (w.length ? 'busy' : 'calm') });
|
|
191
265
|
}
|
|
192
266
|
function listHtml(ctx, X) {
|
|
193
267
|
const now = Date.now();
|
|
194
268
|
const L = mentionsOf(ctx.D());
|
|
195
|
-
const s =
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
const
|
|
199
|
-
|
|
200
|
-
if (s.bare) return '<div class="hr-vb">' + sum + gapsHtml(L.gaps) + '</div>';
|
|
201
|
-
const w = L.waiting, show = X.all || w.length <= 5 ? w : w.slice(0, 5);
|
|
202
|
-
const wHtml = '<div class="hr-ml">' + show.map((m) => waitRow(m, now)).join('') + (show.length < w.length ? `<button type="button" class="hr-all" data-hr-act="all">Show all ${w.length}</button>` : '') + '</div>';
|
|
203
|
-
const secs = VW.czSections([
|
|
204
|
-
w.length ? { id: 'waiting', title: 'Waiting on you', count: w.length, open: true, html: wHtml } : null,
|
|
205
|
-
L.recent.length ? { id: 'recent', title: 'Last 7 days', count: L.recent.length, open: false, html: '<div class="hr-ml">' + byDay(L.recent, now) + '</div>' } : null,
|
|
206
|
-
], { key: 'mentions' });
|
|
207
|
-
return '<div class="hr-vb">' + sum + secs + gapsHtml(L.gaps) + '</div>';
|
|
269
|
+
const s = openingOf(L, now, { heard: heard() });
|
|
270
|
+
if (s.said.length) { const h = heard(); s.said.forEach((k) => h.add(k)); store.set(HEARD, JSON.stringify([...h].slice(-40))); }
|
|
271
|
+
const btn = s.go && L.waiting[0] ? ib('data-mn="go"', 'Start on ' + nameOf(L.waiting[0]) + '’s', P.go, true) : s.retry ? ib('data-mn="retry"', 'Try again', P.again, true) : '';
|
|
272
|
+
const open = `<div class="mn-open-card m-${s.mood}">${adler(s.mood, 'm', { label: false })}<div class="mn-oc"><p>${s.html}</p>${btn ? `<div class="mn-acts">${btn}</div>` : ''}</div></div>`;
|
|
273
|
+
return `<div class="mn-vb">${open}${foldsHtml(L, X, now, X.split ? X.sel : null)}${gapsHtml(L)}</div>`;
|
|
208
274
|
}
|
|
209
|
-
|
|
275
|
+
|
|
276
|
+
let LIST = null; // the list Viewer that is open: { body, X, draw }, so a press elsewhere redraws it
|
|
277
|
+
const SPLIT = 720; // a Viewer this wide shows the list and the conversation side by side (MnA4)
|
|
278
|
+
const canSplit = (b) => !!b && !(typeof innerWidth === 'number' && innerWidth <= VW.PHONE) && (b.clientWidth || 0) >= SPLIT;
|
|
210
279
|
export function openMentions(ctx) {
|
|
211
280
|
sheet();
|
|
212
281
|
store.set(SEEN, Date.now());
|
|
213
|
-
const X = { all: false };
|
|
282
|
+
const X = { all: false, allRead: false, sel: null, split: false };
|
|
283
|
+
const find = (id) => allOf(mentionsOf(ctx.D())).find((x) => x.id === id) || null;
|
|
214
284
|
const draw = (b) => {
|
|
215
|
-
LIST = { body: b, X };
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
const t = e.target.closest('[data-hr-mi],[data-hr-act],[data-hr-ck],[data-hr-gap]'); if (!t || !b.contains(t)) return;
|
|
285
|
+
LIST = { body: b, X, draw };
|
|
286
|
+
X.split = canSplit(b);
|
|
287
|
+
if (X.split) {
|
|
219
288
|
const L = mentionsOf(ctx.D());
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
if (t.dataset.hrMi) { const m = all.find((x) => x.id === t.dataset.hrMi); if (m) openOne(m, ctx, { back: true }); return; }
|
|
227
|
-
if (t.dataset.hrAct === 'reply' && L.waiting[0]) { openOne(L.waiting[0], ctx, { back: true }); return; }
|
|
228
|
-
if (t.dataset.hrAct === 'all') { X.all = true; draw(b); return; }
|
|
229
|
-
if (t.dataset.hrAct === 'retry') { await load(ctx); draw(b); ctx.redrawList(); return; }
|
|
230
|
-
if (t.dataset.hrGap === 'connect') { import('./cozy-settings.js').then((S) => S.openSettings('connectors')).catch(() => {}); return; }
|
|
231
|
-
if (t.dataset.hrGap === 'check') {
|
|
232
|
-
const r = await ctx.pmPost('/api/sources/refresh-all', { ws: (ctx.board() || {}).ws || '' });
|
|
233
|
-
ctx.toast(r && r.ok ? 'Checking every source now. Mentions update when it is done.' : 'The check did not start: ' + ((r && r.error) || 'the workspace did not answer') + '.');
|
|
234
|
-
}
|
|
235
|
-
};
|
|
289
|
+
if (!X.sel || !find(X.sel)) X.sel = (L.waiting[0] || L.toread[0] || L.answered[0] || {}).id || null;
|
|
290
|
+
const m = X.sel ? find(X.sel) : null;
|
|
291
|
+
b.innerHTML = `<div class="mn-split"><div class="mn-col">${listHtml(ctx, X)}</div><div class="mn-col mn-conv" data-mn-conv>${m ? convHtml(m, ctx, { split: true }) : ''}</div></div>`;
|
|
292
|
+
if (m) markRead(ctx, m);
|
|
293
|
+
} else b.innerHTML = listHtml(ctx, X);
|
|
294
|
+
b.onclick = (e) => press(e, b);
|
|
236
295
|
};
|
|
237
|
-
const
|
|
296
|
+
const press = async (e, b) => {
|
|
297
|
+
const t = e.target.closest('[data-mn],[data-czs-act]'); if (!t || !b.contains(t)) return;
|
|
298
|
+
const k = t.dataset.mn || t.dataset.czsAct, L = mentionsOf(ctx.D());
|
|
299
|
+
const m = t.dataset.id ? find(t.dataset.id) : X.split && t.closest('[data-mn-conv]') ? find(X.sel) : null;
|
|
300
|
+
if (k === 'open' && m) { if (X.split) { X.sel = m.id; draw(b); } else openOne(m, ctx, { back: true }); return; }
|
|
301
|
+
if (k === 'go' && L.waiting[0]) { if (X.split) { X.sel = L.waiting[0].id; draw(b); } else openOne(L.waiting[0], ctx, { back: true }); return; }
|
|
302
|
+
if (k === 'more-move') { X.all = true; draw(b); return; }
|
|
303
|
+
if (k === 'more-read') { X.allRead = true; draw(b); return; }
|
|
304
|
+
if (k === 'retry') { await load(ctx); draw(b); ctx.redrawList(); return; }
|
|
305
|
+
if (k === 'all-read') { await allRead(ctx, L); return; }
|
|
306
|
+
if (k === 'connect') { import('./cozy-settings.js').then((S) => S.openSettings('connectors')).catch(() => {}); return; }
|
|
307
|
+
if (k === 'check') {
|
|
308
|
+
const r = await ctx.pmPost('/api/sources/refresh-all', { ws: (ctx.board() || {}).ws || '' });
|
|
309
|
+
ctx.toast(r && r.ok ? 'Reading every source now. Mentions update when it is done.' : 'The read did not start: ' + ((r && r.error) || 'the workspace did not answer') + '.');
|
|
310
|
+
return;
|
|
311
|
+
}
|
|
312
|
+
const x = m || (X.split ? find(X.sel) : null);
|
|
313
|
+
if (x) await onAct(ctx, x, k);
|
|
314
|
+
};
|
|
315
|
+
const body = VW.open({ id: 'mentions', kind: 'Mentions', title: 'Mentions', icon: 'at', render: draw });
|
|
316
|
+
// side by side, Claude changes the reply from the chat (pmos mention draft): read again while the list is open, and show the new reply
|
|
317
|
+
const tick = async () => {
|
|
318
|
+
const c = VW.current(); if (!c || c.id !== 'mentions' || !LIST || LIST.body !== body || !body.isConnected) return;
|
|
319
|
+
if (X.split && X.sel && (typeof document === 'undefined' || !document.hidden)) {
|
|
320
|
+
const was = (find(X.sel) || {}).draft;
|
|
321
|
+
await load(ctx);
|
|
322
|
+
const now = find(X.sel) || {};
|
|
323
|
+
if (now.draft !== was && body.isConnected) { const p = body.querySelector('[data-mn-conv] [data-mn-draft]'); if (p && now.draft) p.textContent = now.draft; else draw(body); }
|
|
324
|
+
}
|
|
325
|
+
setTimeout(tick, 5000);
|
|
326
|
+
};
|
|
327
|
+
setTimeout(tick, 5000);
|
|
328
|
+
// the desktop opens wide, so the list and the conversation sit side by side (MnA4); "Back to the side" keeps the one-column list
|
|
329
|
+
if (!(typeof innerWidth === 'number' && innerWidth < 1280)) { VW.wide(true); if (LIST && LIST.body === body && canSplit(body) !== X.split) draw(body); }
|
|
238
330
|
// read again on open, so the list is never older than the press that opened it
|
|
239
331
|
load(ctx).then(() => { const c = VW.current(); if (c && c.id === 'mentions' && LIST && LIST.body === body) draw(body); ctx.redrawList(); });
|
|
240
332
|
return body;
|
|
241
333
|
}
|
|
242
334
|
function redrawOpen(ctx) {
|
|
243
335
|
const c = VW.current(); if (!c) return;
|
|
244
|
-
if (c.id === 'mentions' && LIST && LIST.body.isConnected) { LIST.
|
|
336
|
+
if (c.id === 'mentions' && LIST && LIST.body.isConnected) { LIST.draw(LIST.body); return; }
|
|
337
|
+
if (ONE && ONE.body && ONE.body.isConnected && c.id === 'mention:' + ONE.id) ONE.draw(ONE.body);
|
|
245
338
|
}
|
|
246
339
|
|
|
247
340
|
/* ── the one-tap acts, each with Undo ── */
|
|
248
341
|
const SAID = {
|
|
249
|
-
answered: (m) => 'Marked answered: ' +
|
|
250
|
-
snooze: () => '
|
|
251
|
-
notask: (m) => 'Not an ask: ' +
|
|
342
|
+
answered: (m) => 'Marked answered: ' + nameOf(m) + '’s ' + (isMail(m.source) ? 'email' : 'ask'),
|
|
343
|
+
snooze: (m) => 'I’ll bring ' + nameOf(m) + '’s back at 09:00',
|
|
344
|
+
notask: (m) => 'Not an ask: ' + nameOf(m) + '’s stops counting',
|
|
252
345
|
keep: () => 'Kept waiting. I’ll ask again in 30 days.',
|
|
346
|
+
watch: (m) => 'I’ll watch for ' + ((m.offer && m.offer.what) || 'it') + ' and tell you when it lands',
|
|
347
|
+
nowatch: () => 'I won’t watch for it',
|
|
253
348
|
};
|
|
254
349
|
async function act(ctx, m, kind, extra = {}) {
|
|
255
350
|
const r = await ctx.pmPost('/api/mentions/act', { id: m.id, act: kind, ...extra });
|
|
256
351
|
if (!r || !r.ok) { ctx.toast('That did not go through' + (r && r.error ? ': ' + r.error : '.')); return false; }
|
|
257
352
|
await load(ctx);
|
|
258
353
|
const c = VW.current();
|
|
259
|
-
|
|
354
|
+
const gone = ['answered', 'snooze', 'notask'].includes(kind);
|
|
355
|
+
if (c && c.id === 'mention:' + m.id && gone) VW.back(); else redrawOpen(ctx);
|
|
260
356
|
ctx.redrawList();
|
|
261
357
|
if (SAID[kind]) ctx.toastUndo(SAID[kind](m), async () => { const u = await ctx.pmPost('/api/mentions/act', { id: m.id, act: 'undo' }); await load(ctx); redrawOpen(ctx); ctx.redrawList(); return u; });
|
|
262
358
|
return true;
|
|
263
359
|
}
|
|
264
|
-
|
|
265
|
-
|
|
360
|
+
async function onAct(ctx, m, k) {
|
|
361
|
+
if (k === 'pen') { ctx.draft(m); return; }
|
|
362
|
+
if (k === 'send') { await sendReply(ctx, m); return; }
|
|
363
|
+
if (k === 'task') { await makeTask(ctx, m); return; }
|
|
364
|
+
if (k === 'src') { const l = https(m.link); if (l) window.open(l, '_blank', 'noopener'); return; }
|
|
365
|
+
if (k === 'ck-yes' || k === 'ck-no') { await act(ctx, m, k === 'ck-yes' ? 'answered' : 'keep'); return; } // a 30+ day ask, asked once
|
|
366
|
+
if (['answered', 'snooze', 'notask', 'watch', 'nowatch'].includes(k)) await act(ctx, m, k);
|
|
367
|
+
}
|
|
368
|
+
/** Opening a conversation that has something unread marks it read (one mark under the conversation's id). */
|
|
369
|
+
function markRead(ctx, m) {
|
|
370
|
+
if (m.read || m.broadcast || !(m.fyi || m.since_reply)) return;
|
|
371
|
+
m.read = true;
|
|
372
|
+
ctx.pmPost('/api/mentions/act', { id: m.id, act: 'read' }).then((r) => { if (r && r.ok) { const D = ctx.D(); for (const x of allOf(mentionsOf(D))) if (x.id === m.id) x.read = true; ctx.redrawList(); } });
|
|
373
|
+
}
|
|
374
|
+
/** ✓✓: every To read conversation not opened yet, read at once. */
|
|
375
|
+
async function allRead(ctx, L) {
|
|
376
|
+
const ids = L.toread.filter((m) => !m.read && !m.broadcast).map((m) => m.id); if (!ids.length) return;
|
|
377
|
+
const r = await ctx.pmPost('/api/mentions/act', { ids, act: 'read' });
|
|
378
|
+
if (!r || !r.ok) { ctx.toast('That did not go through' + (r && r.error ? ': ' + r.error : '.')); return; }
|
|
379
|
+
await load(ctx); redrawOpen(ctx); ctx.redrawList();
|
|
380
|
+
}
|
|
381
|
+
const taskTitle = (m) => 'Reply to ' + nameOf(m);
|
|
382
|
+
/** Make it a task: on the conversation's initiative when Home's board holds it, else the PM's own tasks. The toast says where, with Undo. */
|
|
266
383
|
async function makeTask(ctx, m) {
|
|
267
384
|
const title = taskTitle(m);
|
|
268
385
|
const b = ctx.board() || {};
|
|
@@ -278,7 +395,7 @@ async function makeTask(ctx, m) {
|
|
|
278
395
|
task = { id: r.item.id, kind: 'item', title };
|
|
279
396
|
}
|
|
280
397
|
const r2 = await ctx.pmPost('/api/mentions/act', { id: m.id, act: 'task', task });
|
|
281
|
-
if (!r2 || !r2.ok) { ctx.toast('The task was added, but the
|
|
398
|
+
if (!r2 || !r2.ok) { ctx.toast('The task was added, but the conversation still waits: ' + ((r2 && r2.error) || 'the workspace did not answer') + '.'); return; }
|
|
282
399
|
await load(ctx);
|
|
283
400
|
const c = VW.current(); if (c && c.id === 'mention:' + m.id) VW.back(); else redrawOpen(ctx);
|
|
284
401
|
ctx.reload();
|
|
@@ -289,79 +406,96 @@ async function makeTask(ctx, m) {
|
|
|
289
406
|
return u;
|
|
290
407
|
});
|
|
291
408
|
}
|
|
292
|
-
/** Send: PMOS never posts. It copies the reply, opens the source, and the row says
|
|
409
|
+
/** Send: PMOS never posts. It copies the reply, opens the source, and the row says "Sent from Slack? I’ll see it at the next read." */
|
|
293
410
|
async function sendReply(ctx, m) {
|
|
294
411
|
const text = m.draft || '';
|
|
295
412
|
let copied = false;
|
|
296
413
|
try { if (text && navigator.clipboard) { await navigator.clipboard.writeText(text); copied = true; } } catch { copied = false; }
|
|
297
414
|
const l = https(m.link); if (l) window.open(l, '_blank', 'noopener');
|
|
298
415
|
await act(ctx, m, 'drafted', { to: srcName(m.source) });
|
|
299
|
-
ctx.toast((copied ? 'Copied. ' : 'Copy the reply, then ') + 'Paste it in ' +
|
|
416
|
+
ctx.toast((copied ? 'Copied. ' : 'Copy the reply, then ') + 'Paste it in ' + sendIn(m.source) + ' to send it.' + (l ? '' : ' This conversation has no link, so open ' + sendIn(m.source) + ' yourself.'));
|
|
300
417
|
}
|
|
301
418
|
|
|
302
|
-
/* ── one
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
const
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
419
|
+
/* ── one conversation (MnA3, MnA4) ── */
|
|
420
|
+
/** The messages, by day; the PM's on the right (the store marks them me: true). Only what the record holds: the thread when the read kept
|
|
421
|
+
* it, else the conversation's latest words. */
|
|
422
|
+
export function messagesHtml(m) {
|
|
423
|
+
const th = Array.isArray(m.thread) && m.thread.length ? m.thread : [{ who: m.who, at: m.since || m.last, text: m.text || '' }];
|
|
424
|
+
const many = peopleOf(m).length > 1;
|
|
425
|
+
let out = '', cur = '';
|
|
426
|
+
for (const x of th) {
|
|
427
|
+
const d = T(x.at) ? dayLabel(x.at) : '';
|
|
428
|
+
if (d && d !== cur) { out += `<p class="mn-day">${esc(d)}</p>`; cur = d; }
|
|
429
|
+
out += `<div class="mn-msg${x.me ? ' me' : ''}">${many && !x.me ? `<small>${esc(first(x.who))}</small>` : ''}<span>${esc(x.text)}</span></div>`;
|
|
430
|
+
}
|
|
431
|
+
return `<div class="mn-thr">${out}</div>`;
|
|
314
432
|
}
|
|
315
|
-
function
|
|
433
|
+
function statusLine(m) {
|
|
434
|
+
if (m.since_reply) return 'New since your reply';
|
|
435
|
+
if (m.status === 'replied') return 'You replied in the thread';
|
|
436
|
+
if (m.status === 'answered') return 'You marked it answered';
|
|
437
|
+
if (m.status === 'task') return 'A task now: ' + ((m.task && m.task.title) || taskTitle(m));
|
|
438
|
+
if (m.status === 'notask') return 'You said it is not an ask';
|
|
439
|
+
return m.broadcast ? 'To everyone in ' + placeOf(m) : 'For your information';
|
|
440
|
+
}
|
|
441
|
+
export function convHtml(m, ctx, o = {}) {
|
|
316
442
|
const now = Date.now();
|
|
317
|
-
const
|
|
318
|
-
|
|
319
|
-
const
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
const
|
|
333
|
-
|
|
334
|
-
|
|
443
|
+
const four = [['answered', 'Mark answered', P.tick], ['snooze', 'Remind me at 09:00', P.clock], ['task', 'Make it a task', P.task], ['notask', 'Not an ask', P.x]]
|
|
444
|
+
.map(([k, l, d]) => ib(`data-mn="${k}" data-id="${esc(m.id)}"`, l, d)).join('');
|
|
445
|
+
const head = o.split ? `<div class="mn-ch">${face(m)}<div class="mn-cht"><b>${esc(fullNames(m))}</b><small>${esc(subOf(m))}</small></div>${https(m.link) ? ib(`data-mn="src" data-id="${esc(m.id)}"`, 'Open in ' + srcName(m.source), P.out) : ''}</div>` : '';
|
|
446
|
+
let top;
|
|
447
|
+
if (m.waiting) {
|
|
448
|
+
const reply = m.drafted ? draftHtml(m) : m.draft ? `<div class="mn-dr in"><p class="mn-drh">${svg(P.spark, 12, 2)}<span>I drafted your reply</span></p><p data-mn-draft>${esc(m.draft)}</p></div>`
|
|
449
|
+
: m.nodraft ? `<div class="mn-dr no in"><p class="mn-drh">${svg(P.spark, 12, 2)}<span>I can’t draft this one</span></p><p>${esc(m.nodraft)}</p></div>` : '';
|
|
450
|
+
const right = m.draft && !m.drafted ? ib(`data-mn="pen" data-id="${esc(m.id)}"`, 'Change it with Claude', P.pen) + ib(`data-mn="send" data-id="${esc(m.id)}"`, 'Copy it and open ' + srcName(m.source) + '. PMOS never posts.', P.send, true)
|
|
451
|
+
: m.drafted ? '' : ib(`data-mn="pen" data-id="${esc(m.id)}"`, 'Write it with Claude', P.pen, true);
|
|
452
|
+
top = `<div class="mn-ask"><p class="mn-ak${late(m.since, now) ? ' late' : ''}">Asks you · ${esc(age(m.since, now))}</p><p class="mn-aq">${esc(m.ask || gistOf(m))}</p>${reply}`
|
|
453
|
+
+ `<div class="mn-acts sp"><span class="mn-four">${four}</span><span>${right}</span></div>${checkHtml(m)}</div>`;
|
|
454
|
+
} else top = `<div class="mn-ask calm"><p class="mn-ak">${esc(statusLine(m))}</p><p class="mn-aq">${esc(gistOf(m))}</p></div>`;
|
|
455
|
+
const st = m.stands && m.stands.settled && m.stands.settled.length
|
|
456
|
+
? `<div class="mn-card"><p class="mn-h">${svg(P.spark, 13, 2)}<b>Where it stands</b></p><ul class="mn-st">${m.stands.settled.map((t) => `<li>${svg(P.tick, 14, 2.2)}<span>${esc(t)}</span></li>`).join('')}`
|
|
457
|
+
+ (m.stands.open || []).map((t) => `<li class="open">${svg(P.clock, 14, 2)}<span>${esc(t)}</span></li>`).join('') + '</ul></div>' : '';
|
|
458
|
+
const watch = m.offer ? `<div class="mn-card mn-watch">${svg(P.spark, 13, 2)}<p>${esc(m.offer.text)}</p>${ib(`data-mn="nowatch" data-id="${esc(m.id)}"`, 'No, don’t watch', P.x)}${ib(`data-mn="watch" data-id="${esc(m.id)}"`, 'Yes, watch for it', P.tick, true)}</div>`
|
|
459
|
+
: m.watch ? `<p class="mn-wl">${svg(P.spark, 12, 2)}<span>I’m watching for ${esc(m.watch.what)}.</span></p>`
|
|
460
|
+
: m.landed ? `<p class="mn-wl">${svg(P.spark, 12, 2)}<span>${esc(m.landed.text)}</span></p>` : '';
|
|
461
|
+
const found = Array.isArray(m.found) && m.found.length && m.waiting
|
|
462
|
+
? `<div class="mn-card"><p class="mn-h">${svg(P.spark, 13, 2)}<b>What I found</b></p><ul class="mn-fd">${m.found.map((f) => `<li>${f.label ? `<b>${esc(f.label)}</b>${f.text ? ' ' + esc(f.text) : ''}` : esc(f.text)}</li>`).join('')}</ul></div>` : '';
|
|
463
|
+
const secs = VW.czSections([{ id: 'msgs', title: 'The messages', count: m.messages || 1, open: !!o.split, html: messagesHtml(m) }], { key: o.split ? 'mention-desk' : 'mention' });
|
|
464
|
+
return `<div class="mn-vb">${head}${top}${st}${watch}${found}${secs}</div>`;
|
|
465
|
+
}
|
|
466
|
+
/** "#tech-team-cem · 9 messages since Mon" */
|
|
467
|
+
function subOf(m) {
|
|
468
|
+
const n = m.messages || 1, f = T(m.first);
|
|
469
|
+
const since = f ? (daysAgo(f, Date.now()) <= 0 ? ' today' : ' since ' + (daysAgo(f, Date.now()) === 1 ? 'yesterday' : WD[new Date(f).getDay()])) : '';
|
|
470
|
+
return placeOf(m) + ' · ' + n + (n === 1 ? ' message' : ' messages') + since;
|
|
335
471
|
}
|
|
472
|
+
let ONE = null; // the conversation Viewer that is open: { id, body, draw }
|
|
336
473
|
export function openOne(m, ctx, o = {}) {
|
|
337
474
|
sheet();
|
|
338
475
|
const id = m.id;
|
|
339
|
-
const cur = () =>
|
|
340
|
-
|
|
476
|
+
const cur = () => allOf(mentionsOf(ctx.D())).find((x) => x.id === id) || m;
|
|
477
|
+
markRead(ctx, m);
|
|
341
478
|
let body = null;
|
|
342
479
|
const draw = (b) => {
|
|
343
|
-
body = b;
|
|
344
|
-
b.innerHTML =
|
|
480
|
+
body = b; ONE = { id, body: b, draw };
|
|
481
|
+
b.innerHTML = convHtml(cur(), ctx);
|
|
345
482
|
b.onclick = async (e) => {
|
|
346
|
-
const t = e.target.closest('[data-
|
|
347
|
-
|
|
348
|
-
if (k === 'src') { const l = https(x.link); if (l) window.open(l, '_blank', 'noopener'); return; }
|
|
349
|
-
if (k === 'pen') { ctx.draft(x); return; }
|
|
350
|
-
if (k === 'send') { await sendReply(ctx, x); if (body && body.isConnected) draw(body); return; }
|
|
351
|
-
if (k === 'task') { await makeTask(ctx, x); return; }
|
|
352
|
-
if (k === 'answered' || k === 'snooze' || k === 'notask') await act(ctx, x, k);
|
|
483
|
+
const t = e.target.closest('[data-mn]'); if (!t || !b.contains(t)) return;
|
|
484
|
+
await onAct(ctx, cur(), t.dataset.mn);
|
|
353
485
|
};
|
|
354
486
|
};
|
|
355
|
-
const
|
|
356
|
-
const out = VW.open({
|
|
357
|
-
|
|
487
|
+
const x = cur();
|
|
488
|
+
const out = VW.open({ id: 'mention:' + id, kind: 'Mention', title: fullNames(x), sub: subOf(x), icon: 'at', render: draw, back: !!o.back,
|
|
489
|
+
presses: https(x.link) ? [{ act: 'src', label: 'Open in ' + srcName(x.source), icon: P.out }] : null,
|
|
490
|
+
onPress: (k) => { if (k === 'src') onAct(ctx, cur(), 'src'); } });
|
|
491
|
+
// Claude changes the reply from the chat (pmos mention draft): read again while this conversation is open, and show the new reply
|
|
358
492
|
const tick = async () => {
|
|
359
493
|
const c = VW.current(); if (!c || c.id !== 'mention:' + id || !body || !body.isConnected) return;
|
|
360
494
|
if (typeof document === 'undefined' || !document.hidden) {
|
|
361
495
|
const was = cur().draft;
|
|
362
496
|
await load(ctx);
|
|
363
497
|
const now = cur();
|
|
364
|
-
if (now.draft !== was && body.isConnected) { const p = body.querySelector('[data-
|
|
498
|
+
if (now.draft !== was && body.isConnected) { const p = body.querySelector('[data-mn-draft]'); if (p) p.textContent = now.draft; else draw(body); }
|
|
365
499
|
}
|
|
366
500
|
setTimeout(tick, 5000);
|
|
367
501
|
};
|