@soffits/dsh-notify-inbox 0.2.0 → 0.2.1
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/CHANGELOG.md +7 -0
- package/README.md +1 -1
- package/client.js +47 -27
- package/locale/en.json +1 -0
- package/locale/fr.json +1 -0
- package/locale/zh.json +1 -0
- package/package.json +1 -1
- package/src/routes.js +11 -5
- package/src/store.js +30 -11
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,12 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 0.2.1
|
|
4
|
+
|
|
5
|
+
- Under Unread, a notification you open, mark done or snooze stays where it is, shown as read, until you leave the view or tap Unread again, so the list never moves under your finger. Mark all read works the same way.
|
|
6
|
+
- Read notifications have a Mark unread button, in the row and in the open notification. It works on ones that Mark all read covered too.
|
|
7
|
+
- A done or snoozed notification shows its state in the collapsed row.
|
|
8
|
+
- On narrow screens the header wraps under the title instead of squeezing it.
|
|
9
|
+
|
|
3
10
|
## 0.2.0
|
|
4
11
|
|
|
5
12
|
- Every word on the page comes from `locale/<tag>.json`, one file per language, picked up by what files exist; a missing key falls back to the primary language, then English. French joins English and Chinese.
|
package/README.md
CHANGED
|
@@ -90,7 +90,7 @@ The page follows DSH's language. Its words live in `locale/<tag>.json` (`ui` for
|
|
|
90
90
|
|
|
91
91
|
## Files the plugin writes
|
|
92
92
|
|
|
93
|
-
All under `dataDir`: `<person>/read.json` (read marks), `<person>/actions.jsonl` (presses), `.push/subscriptions.json` and `.push/cursor.json` (how far each inbox was pushed, so a restart doesn't push the backlog), and the VAPID key unless `vapidFile` says otherwise. It never rewrites `inbox.jsonl`.
|
|
93
|
+
All under `dataDir`: `<person>/read.json` (read and unread marks), `<person>/actions.jsonl` (presses), `.push/subscriptions.json` and `.push/cursor.json` (how far each inbox was pushed, so a restart doesn't push the backlog), and the VAPID key unless `vapidFile` says otherwise. It never rewrites `inbox.jsonl`.
|
|
94
94
|
|
|
95
95
|
## Removing it
|
|
96
96
|
|
package/client.js
CHANGED
|
@@ -28,7 +28,7 @@ window.__ModuleLoader__.load({
|
|
|
28
28
|
.nib-content{max-width:820px;margin:0 auto;padding:0 clamp(16px,4vw,48px) 48px}
|
|
29
29
|
.nib-head{display:flex;align-items:center;flex-wrap:wrap;gap:8px 12px;padding-top:28px;margin-bottom:16px}
|
|
30
30
|
[data-platform=darwin] .nib-head{padding-top:calc(28px + var(--dsh-frame-top-clearance,0px))}
|
|
31
|
-
.nib-head h1{margin:0;font-size:20px;font-weight:500;line-height:28px;flex:1;
|
|
31
|
+
.nib-head h1{margin:0;font-size:20px;font-weight:500;line-height:28px;flex:1 0 auto;max-width:100%}
|
|
32
32
|
.nib-count{color:var(--dsw-alias-label-tertiary);font-size:13px;margin-left:8px;font-weight:400}
|
|
33
33
|
.nib-tabs{display:inline-flex;gap:2px;padding:2px;border-radius:10px;background:var(--dsw-alias-bg-layer-1,var(--dsw-alias-interactive-bg-hover))}
|
|
34
34
|
.nib-tab{border:none;background:transparent;color:var(--dsw-alias-label-secondary);font:inherit;font-size:13px;padding:2px 12px;border-radius:8px;cursor:pointer}
|
|
@@ -44,6 +44,9 @@ window.__ModuleLoader__.load({
|
|
|
44
44
|
.nib-list{display:flex;flex-direction:column;gap:2px;margin:0;padding:0;list-style:none}
|
|
45
45
|
.nib-item{border-radius:12px;padding:10px 12px;position:relative}
|
|
46
46
|
.nib-item.nib-open{background:var(--dsw-alias-bg-layer-1,var(--dsw-alias-interactive-bg-hover))}
|
|
47
|
+
.nib-line{display:flex;align-items:flex-start;gap:4px}
|
|
48
|
+
.nib-mark{flex:none;display:inline-flex;align-items:center;justify-content:center;width:28px;height:28px;margin:-3px -6px -3px 0;border:none;border-radius:var(--dsw-radius-sm,8px);background:transparent;color:var(--dsw-alias-label-tertiary);cursor:pointer}
|
|
49
|
+
@media (hover:hover){.nib-mark:hover{background:var(--dsw-alias-interactive-bg-hover);color:var(--dsw-alias-label-primary)}}
|
|
47
50
|
.nib-row{display:flex;gap:10px;align-items:flex-start;width:100%;border:none;background:transparent;color:inherit;font:inherit;text-align:left;padding:0;cursor:pointer}
|
|
48
51
|
.nib-dot{flex:none;width:8px;height:8px;border-radius:50%;margin-top:8px;background:transparent}
|
|
49
52
|
.nib-unread .nib-dot{background:var(--dsw-alias-state-business-primary)}
|
|
@@ -56,7 +59,7 @@ window.__ModuleLoader__.load({
|
|
|
56
59
|
.nib-time{flex:none;color:var(--dsw-alias-label-caption);font-size:12px}
|
|
57
60
|
.nib-spoken{color:var(--dsw-alias-label-tertiary);font-size:13px;line-height:20px;overflow:hidden;text-overflow:ellipsis;display:-webkit-box;-webkit-line-clamp:2;-webkit-box-orient:vertical;overflow-wrap:anywhere}
|
|
58
61
|
.nib-chip{display:inline-block;flex:none;padding:0 6px;border-radius:6px;font-size:11px;line-height:18px;font-weight:500;color:var(--dsw-alias-state-error-primary);box-shadow:inset 0 0 0 .5px currentColor}
|
|
59
|
-
.nib-chip.nib-muted{color:var(--dsw-alias-label-tertiary)}
|
|
62
|
+
.nib-chip.nib-muted{color:var(--dsw-alias-label-tertiary);font-weight:400;max-width:45%;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}
|
|
60
63
|
.nib-body{margin:8px 0 0 18px;display:flex;flex-direction:column;gap:10px}
|
|
61
64
|
.nib-text{white-space:pre-wrap;overflow-wrap:anywhere;font-size:14px;line-height:22px}
|
|
62
65
|
.nib-links{display:flex;flex-direction:column;gap:2px;font-size:13px}
|
|
@@ -66,13 +69,14 @@ window.__ModuleLoader__.load({
|
|
|
66
69
|
.nib-ok{color:var(--dsw-alias-state-success-primary)}
|
|
67
70
|
.nib-bad{color:var(--dsw-alias-state-error-primary)}
|
|
68
71
|
.nib-actions{display:flex;flex-wrap:wrap;gap:6px;align-items:center}
|
|
72
|
+
.nib-actions .nib-btn{height:32px;padding:0 12px}
|
|
69
73
|
.nib-status{color:var(--dsw-alias-label-tertiary);font-size:12px}
|
|
70
74
|
.nib-empty{color:var(--dsw-alias-label-tertiary);padding:24px 12px}
|
|
71
75
|
.nib-error{color:var(--dsw-alias-state-error-primary);padding:12px}
|
|
72
76
|
.nib-more{margin:12px auto 0;display:flex}
|
|
73
77
|
.nib-icon{position:relative;display:inline-flex}
|
|
74
78
|
.nib-badge{position:absolute;top:-5px;right:-8px;min-width:14px;height:14px;padding:0 3px;box-sizing:border-box;border-radius:7px;background:var(--dsw-alias-state-error-primary);color:#fff;font-size:9px;font-weight:600;line-height:14px;text-align:center;pointer-events:none}
|
|
75
|
-
@media (width<=640px),(pointer:coarse){.nib-btn,.nib-tab,.nib-page .ua-btn{min-height:40px;min-width:40px}.nib-tab{padding-inline:14px}.nib-tabs{border-radius:12px}}
|
|
79
|
+
@media (width<=640px),(pointer:coarse){.nib-btn,.nib-tab,.nib-page .ua-btn{min-height:40px;min-width:40px}.nib-mark{width:40px;height:40px;margin:-10px -8px -10px 0}.nib-tab{padding-inline:14px}.nib-tabs{border-radius:12px}}
|
|
76
80
|
@media (width<=640px){.nib-content{padding-inline:12px}.nib-head{padding-top:16px}.nib-body{margin-left:0}.nib-item{padding:10px 8px}}
|
|
77
81
|
`
|
|
78
82
|
|
|
@@ -155,8 +159,9 @@ window.__ModuleLoader__.load({
|
|
|
155
159
|
return states
|
|
156
160
|
}
|
|
157
161
|
|
|
158
|
-
function Actions({ item, t, ui }) {
|
|
159
|
-
|
|
162
|
+
function Actions({ item, t, ui, onMark }) {
|
|
163
|
+
const markUnread = item.read && h('button', { type: 'button', className: 'nib-btn', onClick: () => onMark(item, false) }, t('markUnread'))
|
|
164
|
+
if (ui === null) return markUnread ? h('div', { className: 'nib-actions' }, markUnread) : null
|
|
160
165
|
const declared = item.actions.some(action => action.kind === 'chat') ? item.actions : [{ kind: 'chat', id: 'chat', payload: {} }, ...item.actions]
|
|
161
166
|
const chat = action => ui.startChat({
|
|
162
167
|
text: ui.chatText({ prompt: action.payload?.prompt ?? '', title: item.title || item.spoken, lines: (item.text || item.spoken).split('\n'),
|
|
@@ -169,17 +174,26 @@ window.__ModuleLoader__.load({
|
|
|
169
174
|
}
|
|
170
175
|
const status = pressStatus(item, t)
|
|
171
176
|
return h('div', { className: 'nib-actions' }, h(ui.ActionBar, { actions: declared, states: pressStates(item), chat, onPress }),
|
|
177
|
+
markUnread,
|
|
172
178
|
status && h('span', { className: 'nib-status' }, status))
|
|
173
179
|
}
|
|
174
180
|
|
|
175
181
|
// ---- one notification ----
|
|
176
182
|
|
|
177
|
-
function
|
|
183
|
+
function MarkUnreadIcon() {
|
|
184
|
+
return h('svg', { width: 16, height: 16, viewBox: '0 0 16 16', fill: 'none', stroke: 'currentColor', strokeWidth: 1.3, strokeLinecap: 'round', strokeLinejoin: 'round', 'aria-hidden': true, focusable: 'false' },
|
|
185
|
+
h('path', { d: 'M9.5 3.5H3A1.5 1.5 0 0 0 1.5 5v6.5A1.5 1.5 0 0 0 3 13h9a1.5 1.5 0 0 0 1.5-1.5V8' }),
|
|
186
|
+
h('path', { d: 'M1.8 4.6 7.5 8.6l2.3-1.6' }),
|
|
187
|
+
h('circle', { cx: 12.5, cy: 3.5, r: 2, fill: 'currentColor', stroke: 'none' }))
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
function Item({ item, t, open, onToggle, onMark, ui }) {
|
|
178
191
|
const urgent = item.lane === 'interrupt'
|
|
179
192
|
const className = ['nib-item', item.read ? '' : 'nib-unread', urgent ? 'nib-urgent' : '', open ? 'nib-open' : ''].filter(Boolean).join(' ')
|
|
180
193
|
const title = item.title || item.spoken || item.text.slice(0, 80)
|
|
181
194
|
const sub = item.spoken && item.spoken !== title ? item.spoken : item.text !== title ? item.text : ''
|
|
182
195
|
return h('li', { className, id: `nib-${item.id}` },
|
|
196
|
+
h('div', { className: 'nib-line' },
|
|
183
197
|
h('button', { type: 'button', className: 'nib-row', 'aria-expanded': open, onClick: () => onToggle(item) },
|
|
184
198
|
h('span', { className: 'nib-dot', 'aria-hidden': true }),
|
|
185
199
|
h('span', { className: 'nib-main' },
|
|
@@ -187,8 +201,10 @@ window.__ModuleLoader__.load({
|
|
|
187
201
|
urgent && h('span', { className: 'nib-chip' }, t('urgent')),
|
|
188
202
|
item.test && h('span', { className: 'nib-chip nib-muted' }, t('test')),
|
|
189
203
|
h('span', { className: 'nib-title' }, title),
|
|
204
|
+
!open && item.presses.length > 0 && h('span', { className: 'nib-chip nib-muted' }, pressStatus(item, t)),
|
|
190
205
|
h('span', { className: 'nib-time', title: absolute(item.time, t) }, relative(item.time, t))),
|
|
191
206
|
!open && sub && h('span', { className: 'nib-spoken' }, sub))),
|
|
207
|
+
item.read && !open && h('button', { type: 'button', className: 'nib-mark', title: t('markUnread'), 'aria-label': t('markUnread'), onClick: () => onMark(item, false) }, h(MarkUnreadIcon))),
|
|
192
208
|
open && h('div', { className: 'nib-body' },
|
|
193
209
|
item.text && item.text !== title && h('div', { className: 'nib-text' }, item.text),
|
|
194
210
|
item.links.length > 0 && h('div', { className: 'nib-links' },
|
|
@@ -198,7 +214,7 @@ window.__ModuleLoader__.load({
|
|
|
198
214
|
item.files.map(file => file.stored
|
|
199
215
|
? h('a', { key: file.name, href: api(`file?id=${encodeURIComponent(item.id)}&name=${encodeURIComponent(file.name)}`), target: '_blank', rel: 'noopener' }, file.name)
|
|
200
216
|
: h('span', { key: file.name, className: 'nib-meta' }, `${file.name} (${t('notStored', { reason: file.reason || '?' })})`))),
|
|
201
|
-
h(Actions, { item, t, ui }),
|
|
217
|
+
h(Actions, { item, t, ui, onMark }),
|
|
202
218
|
h('div', { className: 'nib-meta' },
|
|
203
219
|
item.routed.length === 0 ? t('notSent') : h(React.Fragment, null, `${t('alsoSent')}: `,
|
|
204
220
|
item.routed.map(row => h('span', { key: row.destination, className: 'nib-route', title: row.detail || '' },
|
|
@@ -304,8 +320,10 @@ window.__ModuleLoader__.load({
|
|
|
304
320
|
const [more, setMore] = useState(false)
|
|
305
321
|
const [error, setError] = useState(null)
|
|
306
322
|
const [open, setOpen] = useState(() => shared.linked)
|
|
307
|
-
|
|
308
|
-
|
|
323
|
+
// Rows shown under Unread during this visit stay on screen as they turn read, done or snoozed,
|
|
324
|
+
// so the list never moves under the person's finger; leaving the view (or tapping its tab again) lets them go.
|
|
325
|
+
const shown = useRef(new Set())
|
|
326
|
+
const [visit, setVisit] = useState(0)
|
|
309
327
|
const [ui, setUi] = useState(null)
|
|
310
328
|
useEffect(() => {
|
|
311
329
|
let live = true
|
|
@@ -316,18 +334,14 @@ window.__ModuleLoader__.load({
|
|
|
316
334
|
const load = useCallback(async (append) => {
|
|
317
335
|
try {
|
|
318
336
|
const params = new URLSearchParams()
|
|
319
|
-
if (filter === 'unread')
|
|
337
|
+
if (filter === 'unread') {
|
|
338
|
+
params.set('unread', '1')
|
|
339
|
+
if (shown.current.size > 0) params.set('keep', [...shown.current].join(','))
|
|
340
|
+
}
|
|
320
341
|
if (append && items?.length) params.set('before', items[items.length - 1].id)
|
|
321
342
|
const page = await call(`items?${params}`)
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
// The open item stays where it was even when it no longer matches the filter (opening marks it read).
|
|
325
|
-
const kept = previous?.findIndex(row => row.id === openRef.current) ?? -1
|
|
326
|
-
if (kept < 0 || page.items.some(row => row.id === openRef.current)) return page.items
|
|
327
|
-
const next = [...page.items]
|
|
328
|
-
next.splice(Math.min(kept, next.length), 0, { ...previous[kept], read: true })
|
|
329
|
-
return next
|
|
330
|
-
})
|
|
343
|
+
if (filter === 'unread') for (const row of page.items) shown.current.add(row.id)
|
|
344
|
+
setItems(previous => (append && previous ? [...previous, ...page.items] : page.items))
|
|
331
345
|
setMore(page.more)
|
|
332
346
|
setError(null)
|
|
333
347
|
} catch (reason) {
|
|
@@ -335,23 +349,29 @@ window.__ModuleLoader__.load({
|
|
|
335
349
|
}
|
|
336
350
|
}, [filter, items])
|
|
337
351
|
|
|
338
|
-
useEffect(() => { load(false) }, [filter, version])
|
|
352
|
+
useEffect(() => { load(false) }, [filter, version, visit])
|
|
353
|
+
const showView = key => {
|
|
354
|
+
shown.current = new Set()
|
|
355
|
+
if (key === filter) setVisit(n => n + 1)
|
|
356
|
+
else setFilter(key)
|
|
357
|
+
}
|
|
339
358
|
useEffect(() => {
|
|
340
359
|
if (!linked) return
|
|
341
|
-
|
|
360
|
+
showView('all')
|
|
342
361
|
setOpen(linked)
|
|
343
362
|
shared.linked = null
|
|
344
363
|
call('read', { ids: [linked] }).then(changed, () => {})
|
|
345
364
|
setTimeout(() => document.getElementById(`nib-${linked}`)?.scrollIntoView({ block: 'center' }), 300)
|
|
346
365
|
}, [linked])
|
|
347
366
|
|
|
367
|
+
const mark = (item, read) => {
|
|
368
|
+
setItems(list => list.map(row => (row.id === item.id ? { ...row, read } : row)))
|
|
369
|
+
call('read', { ids: [item.id], read }).then(changed, reason => setError(reason.message))
|
|
370
|
+
}
|
|
348
371
|
const toggle = item => {
|
|
349
372
|
const next = open === item.id ? null : item.id
|
|
350
373
|
setOpen(next)
|
|
351
|
-
if (next !== null && !item.read)
|
|
352
|
-
setItems(list => list.map(row => (row.id === item.id ? { ...row, read: true } : row)))
|
|
353
|
-
call('read', { ids: [item.id] }).then(changed, () => {})
|
|
354
|
-
}
|
|
374
|
+
if (next !== null && !item.read) mark(item, true)
|
|
355
375
|
}
|
|
356
376
|
const markAll = () => call('read', { all: true }).then(changed, reason => setError(reason.message))
|
|
357
377
|
|
|
@@ -361,13 +381,13 @@ window.__ModuleLoader__.load({
|
|
|
361
381
|
h('div', { className: 'nib-head' },
|
|
362
382
|
h('h1', null, t('title'), unread > 0 && h('span', { className: 'nib-count' }, unread)),
|
|
363
383
|
h('div', { className: 'nib-tabs', role: 'group' },
|
|
364
|
-
['unread', 'all'].map(key => h('button', { key, type: 'button', className: 'nib-tab', 'aria-pressed': filter === key, onClick: () =>
|
|
384
|
+
['unread', 'all'].map(key => h('button', { key, type: 'button', className: 'nib-tab', 'aria-pressed': filter === key, onClick: () => showView(key) }, t(`filter.${key}`)))),
|
|
365
385
|
h('button', { type: 'button', className: 'nib-btn', disabled: unread === 0, onClick: markAll }, t('markAll'))),
|
|
366
386
|
h(PushControl, { t }),
|
|
367
387
|
error && h('p', { className: 'nib-error', role: 'alert' }, t('error', { message: error })),
|
|
368
388
|
items !== null && items.length === 0 && h('p', { className: 'nib-empty' }, t(filter === 'unread' ? 'empty.unread' : 'empty.all')),
|
|
369
389
|
items !== null && h('ul', { className: 'nib-list' },
|
|
370
|
-
items.map(item => h(Item, { key: item.id, item, t, open: open === item.id, onToggle: toggle, ui }))),
|
|
390
|
+
items.map(item => h(Item, { key: item.id, item, t, open: open === item.id, onToggle: toggle, onMark: mark, ui }))),
|
|
371
391
|
more && h('button', { type: 'button', className: 'nib-btn nib-more', onClick: () => load(true) }, t('loadMore')))))
|
|
372
392
|
}
|
|
373
393
|
|
package/locale/en.json
CHANGED
package/locale/fr.json
CHANGED
package/locale/zh.json
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@soffits/dsh-notify-inbox",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.1",
|
|
4
4
|
"description": "A notification inbox for DeepSeek Harness: each person sees their own notifications with read and unread, gets Web Push on their phone or browser, and can act on them.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
package/src/routes.js
CHANGED
|
@@ -4,8 +4,8 @@
|
|
|
4
4
|
* answer is decided here, per request, from who is asking.
|
|
5
5
|
*
|
|
6
6
|
* GET /api/notify-inbox/summary unread count and newest time (badge)
|
|
7
|
-
* GET /api/notify-inbox/items?unread=1&before=&limit=
|
|
8
|
-
* POST /api/notify-inbox/read { ids: [...] } or { all: true }
|
|
7
|
+
* GET /api/notify-inbox/items?unread=1&keep=&before=&limit=
|
|
8
|
+
* POST /api/notify-inbox/read { ids: [...], read?: false } or { all: true }
|
|
9
9
|
* POST /api/notify-inbox/action { record, action, until? } a done/snooze/event press
|
|
10
10
|
* GET /api/notify-inbox/file?id=&name= a stored attachment
|
|
11
11
|
* GET /api/notify-inbox/push/config { publicKey }
|
|
@@ -24,6 +24,8 @@ import { PERSON_PATTERN, RECORD_ID_PATTERN } from './store.js'
|
|
|
24
24
|
export const PREFIX = '/api/notify-inbox'
|
|
25
25
|
const MAX_BODY = 16 * 1024
|
|
26
26
|
const PAGE = 50
|
|
27
|
+
/** Most rows the Unread view keeps on screen after they turn read (ids in `keep`). */
|
|
28
|
+
const KEEP_MAX = 200
|
|
27
29
|
|
|
28
30
|
const HEADERS = {
|
|
29
31
|
'content-type': 'application/json; charset=utf-8',
|
|
@@ -99,7 +101,11 @@ export function createRoutes({ store, people, push, actions, identity, serviceWo
|
|
|
99
101
|
const params = new URL(request.url).searchParams
|
|
100
102
|
const limit = Math.min(Math.max(Number(params.get('limit')) || PAGE, 1), 200)
|
|
101
103
|
let { items } = await store.view(who.folders)
|
|
102
|
-
if (params.get('unread') === '1')
|
|
104
|
+
if (params.get('unread') === '1') {
|
|
105
|
+
// `keep` holds what the page already shows under Unread, so those rows stay put as they turn read.
|
|
106
|
+
const keep = new Set((params.get('keep') ?? '').split(',').filter(id => RECORD_ID_PATTERN.test(id)).slice(0, KEEP_MAX))
|
|
107
|
+
items = items.filter(item => !item.read || keep.has(item.id))
|
|
108
|
+
}
|
|
103
109
|
const before = params.get('before')
|
|
104
110
|
if (before) {
|
|
105
111
|
const at = items.findIndex(item => item.id === before)
|
|
@@ -125,7 +131,7 @@ export function createRoutes({ store, people, push, actions, identity, serviceWo
|
|
|
125
131
|
for (const person of who.folders) await store.markAllRead(person)
|
|
126
132
|
} else if (Array.isArray(value.ids)) {
|
|
127
133
|
const ids = value.ids.filter(id => typeof id === 'string').slice(0, 500)
|
|
128
|
-
for (const person of who.folders) await store.
|
|
134
|
+
for (const person of who.folders) await store.setRead(person, ids, value.read !== false)
|
|
129
135
|
} else {
|
|
130
136
|
return json(400, { error: 'Send ids or all.' })
|
|
131
137
|
}
|
|
@@ -140,7 +146,7 @@ export function createRoutes({ store, people, push, actions, identity, serviceWo
|
|
|
140
146
|
if (declared === undefined) return json(400, { error: 'This notification has no such button.' })
|
|
141
147
|
if (!['done', 'snooze', 'event'].includes(declared.kind)) return json(400, { error: 'This button acts in the page.' })
|
|
142
148
|
const result = await actions.press(record.person, record, declared, { until: value.until })
|
|
143
|
-
await store.
|
|
149
|
+
await store.setRead(record.person, [record.id], true)
|
|
144
150
|
return json(200, { press: result.event.press, published: result.published, matched: result.matched ?? 0 })
|
|
145
151
|
})
|
|
146
152
|
|
package/src/store.js
CHANGED
|
@@ -118,8 +118,13 @@ async function atomicWrite(path, value) {
|
|
|
118
118
|
await rename(tmp, path)
|
|
119
119
|
}
|
|
120
120
|
|
|
121
|
-
/**
|
|
121
|
+
/**
|
|
122
|
+
* Read marks: everything up to `readBefore` (ISO time) is read, plus the ids in
|
|
123
|
+
* `read`, except the ids in `unread` (marked unread again after the watermark
|
|
124
|
+
* passed them).
|
|
125
|
+
*/
|
|
122
126
|
export function isRead(marks, record) {
|
|
127
|
+
if (marks.unread.includes(record.id)) return false
|
|
123
128
|
return (marks.readBefore !== '' && record.time <= marks.readBefore) || marks.read.includes(record.id)
|
|
124
129
|
}
|
|
125
130
|
|
|
@@ -164,9 +169,10 @@ export function createStore(dataDir) {
|
|
|
164
169
|
async function marks(person) {
|
|
165
170
|
try {
|
|
166
171
|
const value = JSON.parse(await readFile(join(dataDir, person, READ), 'utf8'))
|
|
167
|
-
|
|
172
|
+
const ids = key => list(value[key]).filter(id => typeof id === 'string')
|
|
173
|
+
return { readBefore: text(value.readBefore), read: ids('read'), unread: ids('unread') }
|
|
168
174
|
} catch {
|
|
169
|
-
return { readBefore: '', read: [] }
|
|
175
|
+
return { readBefore: '', read: [], unread: [] }
|
|
170
176
|
}
|
|
171
177
|
}
|
|
172
178
|
|
|
@@ -175,22 +181,35 @@ export function createStore(dataDir) {
|
|
|
175
181
|
await atomicWrite(join(dataDir, person, READ), value)
|
|
176
182
|
}
|
|
177
183
|
|
|
178
|
-
/**
|
|
179
|
-
|
|
180
|
-
|
|
184
|
+
/**
|
|
185
|
+
* Mark some records read or unread; ids that aren't this person's are ignored.
|
|
186
|
+
* Each list keeps only what the watermark doesn't already say.
|
|
187
|
+
*/
|
|
188
|
+
async function setRead(person, ids, value) {
|
|
189
|
+
const byId = new Map((await records(person)).records.map(record => [record.id, record]))
|
|
181
190
|
const current = await marks(person)
|
|
182
|
-
const read =
|
|
183
|
-
|
|
191
|
+
const read = new Set(current.read)
|
|
192
|
+
const unread = new Set(current.unread)
|
|
193
|
+
for (const id of ids) {
|
|
194
|
+
const record = byId.get(id)
|
|
195
|
+
if (record === undefined) continue
|
|
196
|
+
const covered = current.readBefore !== '' && record.time <= current.readBefore
|
|
197
|
+
read.delete(id)
|
|
198
|
+
unread.delete(id)
|
|
199
|
+
if (value && !covered) read.add(id)
|
|
200
|
+
if (!value && covered) unread.add(id)
|
|
201
|
+
}
|
|
202
|
+
await saveMarks(person, { readBefore: current.readBefore, read: [...read], unread: [...unread] })
|
|
184
203
|
}
|
|
185
204
|
|
|
186
|
-
/** Mark everything up to the newest record read; the per-id
|
|
205
|
+
/** Mark everything up to the newest record read; the per-id lists drop what the watermark covers. */
|
|
187
206
|
async function markAllRead(person) {
|
|
188
207
|
const all = (await records(person)).records
|
|
189
208
|
if (all.length === 0) return
|
|
190
209
|
const readBefore = all.reduce((latest, record) => (record.time > latest ? record.time : latest), '')
|
|
191
210
|
const current = await marks(person)
|
|
192
211
|
const byId = new Map(all.map(record => [record.id, record]))
|
|
193
|
-
await saveMarks(person, { readBefore, read: current.read.filter(id => byId.has(id) && byId.get(id).time > readBefore) })
|
|
212
|
+
await saveMarks(person, { readBefore, read: current.read.filter(id => byId.has(id) && byId.get(id).time > readBefore), unread: [] })
|
|
194
213
|
}
|
|
195
214
|
|
|
196
215
|
/** The records of these people, newest first, each with `read`. */
|
|
@@ -219,5 +238,5 @@ export function createStore(dataDir) {
|
|
|
219
238
|
return undefined
|
|
220
239
|
}
|
|
221
240
|
|
|
222
|
-
return { persons, records, marks,
|
|
241
|
+
return { persons, records, marks, setRead, markAllRead, view, file }
|
|
223
242
|
}
|