@estiva-app/conversation 0.38.0 → 0.40.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.
@@ -0,0 +1,86 @@
1
+ import type { SignedEvent, UnsignedEvent } from '@estiva-app/protocol';
2
+ import type { QueryFn } from './decorations.js';
3
+ import { type Nip44, type RandomBytes, type SlotIdentity, type SlotStorage } from './readState.js';
4
+ /** Long enough to batch a few marks, short enough to survive a tab close. */
5
+ export declare const READ_STATE_PUBLISH_DEBOUNCE_MS = 3000;
6
+ /** How long something must be on screen before it counts as read (Peek's, Ship's and Leaf's). */
7
+ export declare const READ_DWELL_MS = 1500;
8
+ /** The longest wait between attempts while publishing keeps failing. */
9
+ export declare const READ_STATE_MAX_RETRY_MS = 60000;
10
+ /** The part of a browser's `document` the queue and the dwell listen to. */
11
+ export interface VisibilitySource {
12
+ readonly hidden: boolean;
13
+ addEventListener(type: 'visibilitychange', listener: () => void): void;
14
+ removeEventListener(type: 'visibilitychange', listener: () => void): void;
15
+ }
16
+ /** What a flush did, for an app's diagnostic. */
17
+ export type ReadStateAttempt = 'nothing-pending' | 'no-session' | 'not-hydrated' | 'unchanged' | 'published' | 'rejected' | 'failed';
18
+ export interface ReadStateQueueOptions {
19
+ /** Where the slot id lives (`localStorage`); read when the slot is first needed. It may throw, or be absent. */
20
+ storage: () => SlotStorage | undefined;
21
+ /** The app's own key (`ship.readstate.slot`, `leaf.readstate.slot`), so it keeps the slot it has. */
22
+ storageKey: string;
23
+ /** Names the app in a new `client_id`: `ship` → `ship-1a2b3c4d`. */
24
+ clientPrefix: string;
25
+ random: RandomBytes;
26
+ /** Who is signed in now, or undefined. A mark made by nobody is dropped; a change of person drops the last one's queue. */
27
+ pubkey: () => string | undefined;
28
+ /**
29
+ * Whether a write can go out now — false while an access token is being renewed. The markers wait and the
30
+ * queue comes back, backing off. Absent: always.
31
+ */
32
+ canWrite?: () => boolean;
33
+ query: QueryFn;
34
+ nip44: Nip44;
35
+ sign: (event: UnsignedEvent) => Promise<SignedEvent>;
36
+ publish: (event: SignedEvent) => Promise<{
37
+ ok: boolean;
38
+ reason?: string;
39
+ }>;
40
+ /** Each mark that moved a context, at once — before the publish — so a page can draw it read now. */
41
+ onMarked?: (contexts: Readonly<Record<string, number>>) => void;
42
+ /** Each flush's outcome, for a diagnostic. */
43
+ onAttempt?: (outcome: ReadStateAttempt, detail?: string, contexts?: number) => void;
44
+ debounceMs?: number;
45
+ }
46
+ export interface ReadStateQueue {
47
+ /** Mark these contexts read at `atMs`; the publish follows, debounced. Contexts come from this package's builders. */
48
+ markRead(contexts: readonly (string | undefined)[], atMs?: number): void;
49
+ /** Publish what is pending now. */
50
+ flush(): Promise<void>;
51
+ /** This installation's slot, minted on first use. */
52
+ identity(): SlotIdentity;
53
+ /** Publish before the tab goes away: `visibilitychange` is the one a phone fires. Returns the uninstall. */
54
+ installFlushOnHide(doc: VisibilitySource): () => void;
55
+ /** What the queue holds now, copied, for a diagnostic: what can no probe outside the tab can see. */
56
+ state(): ReadStateQueueState;
57
+ /** Drop the tab's state, timers included, so a test starts clean. */
58
+ reset(): void;
59
+ }
60
+ export interface ReadStateQueueState {
61
+ /** Everything this slot believes it has read. */
62
+ known: Record<string, number>;
63
+ /** Marked but not yet in an accepted publish. Non-empty for long is the smell. */
64
+ pending: Record<string, number>;
65
+ /** What the relay is believed to hold for this slot. */
66
+ published: Record<string, number> | undefined;
67
+ hydrated: boolean;
68
+ /** The wait before the next retry, 0 when none is backing off. */
69
+ retryMs: number;
70
+ }
71
+ export declare function createReadStateQueue(options: ReadStateQueueOptions): ReadStateQueue;
72
+ /**
73
+ * Mark `contexts` read once they have stayed on screen for {@link READ_DWELL_MS}: a conversation glanced past is not
74
+ * read. Only while the page is shown, and again when it comes back. `newestAtMs` is the newest message drawn for
75
+ * them: the mark never runs past it or past the clock, and a message dated ahead of the clock is read once the clock
76
+ * gets there, asked again at most a minute apart (a date far ahead would overflow the timer). With none drawn, the
77
+ * clock. Returns the cleanup — what a React effect returns.
78
+ */
79
+ export declare function watchDwell(contexts: readonly string[], newestAtMs: number | undefined, mark: (contexts: readonly string[], atMs: number) => void, doc: VisibilitySource, dwellMs?: number): () => void;
80
+ /**
81
+ * The key a dwell restarts on: the set of contexts, not the array a render made. JSON, so it is never split back on a
82
+ * character an address may hold; {@link dwellContexts} turns it back.
83
+ */
84
+ export declare function dwellKey(contexts: readonly (string | undefined)[]): string;
85
+ export declare function dwellContexts(key: string): string[];
86
+ //# sourceMappingURL=readStateQueue.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"readStateQueue.d.ts","sourceRoot":"","sources":["../src/readStateQueue.ts"],"names":[],"mappings":"AAsBA,OAAO,KAAK,EAAE,WAAW,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAA;AACtE,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,kBAAkB,CAAA;AAE/C,OAAO,EASL,KAAK,KAAK,EACV,KAAK,WAAW,EAChB,KAAK,YAAY,EACjB,KAAK,WAAW,EACjB,MAAM,gBAAgB,CAAA;AAMvB,6EAA6E;AAC7E,eAAO,MAAM,8BAA8B,OAAO,CAAA;AAElD,iGAAiG;AACjG,eAAO,MAAM,aAAa,OAAO,CAAA;AAEjC,wEAAwE;AACxE,eAAO,MAAM,uBAAuB,QAAS,CAAA;AAE7C,4EAA4E;AAC5E,MAAM,WAAW,gBAAgB;IAC/B,QAAQ,CAAC,MAAM,EAAE,OAAO,CAAA;IACxB,gBAAgB,CAAC,IAAI,EAAE,kBAAkB,EAAE,QAAQ,EAAE,MAAM,IAAI,GAAG,IAAI,CAAA;IACtE,mBAAmB,CAAC,IAAI,EAAE,kBAAkB,EAAE,QAAQ,EAAE,MAAM,IAAI,GAAG,IAAI,CAAA;CAC1E;AAED,iDAAiD;AACjD,MAAM,MAAM,gBAAgB,GACxB,iBAAiB,GACjB,YAAY,GACZ,cAAc,GACd,WAAW,GACX,WAAW,GACX,UAAU,GACV,QAAQ,CAAA;AA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AAC,GAAG,EAAE,gBAAgB,GAAG,MAAM,IAAI,CAAA;IACrD,qGAAqG;IACrG,KAAK,IAAI,mBAAmB,CAAA;IAC5B,qEAAqE;IACrE,KAAK,IAAI,IAAI,CAAA;CACd;AAED,MAAM,WAAW,mBAAmB;IAClC,iDAAiD;IACjD,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;IAC7B,kFAAkF;IAClF,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;IAC/B,wDAAwD;IACxD,SAAS,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,SAAS,CAAA;IAC7C,QAAQ,EAAE,OAAO,CAAA;IACjB,kEAAkE;IAClE,OAAO,EAAE,MAAM,CAAA;CAChB;AAED,wBAAgB,oBAAoB,CAAC,OAAO,EAAE,qBAAqB,GAAG,cAAc,CA+NnF;AAED;;;;;;GAMG;AACH,wBAAgB,UAAU,CACxB,QAAQ,EAAE,SAAS,MAAM,EAAE,EAC3B,UAAU,EAAE,MAAM,GAAG,SAAS,EAC9B,IAAI,EAAE,CAAC,QAAQ,EAAE,SAAS,MAAM,EAAE,EAAE,IAAI,EAAE,MAAM,KAAK,IAAI,EACzD,GAAG,EAAE,gBAAgB,EACrB,OAAO,GAAE,MAAsB,GAC9B,MAAM,IAAI,CAkBZ;AAED;;;GAGG;AACH,wBAAgB,QAAQ,CAAC,QAAQ,EAAE,SAAS,CAAC,MAAM,GAAG,SAAS,CAAC,EAAE,GAAG,MAAM,CAE1E;AAED,wBAAgB,aAAa,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,EAAE,CAEnD"}
@@ -0,0 +1,288 @@
1
+ import { KIND_APP_DATA } from './kinds.js';
2
+ import { REPLY_FLOOR_CONTEXT, advanceContexts as advance, loadSlotIdentity, parseReadStateBlob, publishReadState, readStateDTag, rotateSlotId, toContextSeconds, } from './readState.js';
3
+ const timers = globalThis;
4
+ const consoleWarn = (...args) => globalThis.console?.warn(...args);
5
+ /** Long enough to batch a few marks, short enough to survive a tab close. */
6
+ export const READ_STATE_PUBLISH_DEBOUNCE_MS = 3000;
7
+ /** How long something must be on screen before it counts as read (Peek's, Ship's and Leaf's). */
8
+ export const READ_DWELL_MS = 1500;
9
+ /** The longest wait between attempts while publishing keeps failing. */
10
+ export const READ_STATE_MAX_RETRY_MS = 60_000;
11
+ export function createReadStateQueue(options) {
12
+ const { storageKey, clientPrefix, random, query, nip44 } = options;
13
+ const debounceMs = options.debounceMs ?? READ_STATE_PUBLISH_DEBOUNCE_MS;
14
+ const canWrite = options.canWrite ?? (() => true);
15
+ const attempt = (outcome, detail, contexts) => options.onAttempt?.(outcome, detail, contexts);
16
+ let identity;
17
+ /** Whose read state this queue holds. */
18
+ let owner;
19
+ /** Everything this slot holds: its own blob from the relay, plus what was marked here. */
20
+ let known = {};
21
+ /** Marked but not yet in an accepted publish. */
22
+ let pending = {};
23
+ /** What the relay is believed to hold, so an unchanged blob is not published again. */
24
+ let published;
25
+ /** The last content seen at our coordinate and what it held, so an unchanged slot is not decrypted again. */
26
+ let ownCopy;
27
+ let hydrated = false;
28
+ /** When the copy of our slot read back was written (unix seconds), so the next publish is dated after it. */
29
+ let slotAt = 0;
30
+ let timer;
31
+ let retryMs = 0;
32
+ let inFlight = Promise.resolve();
33
+ function currentIdentity() {
34
+ identity ??= loadSlotIdentity({ storage: safe(options.storage), storageKey, clientPrefix, random });
35
+ return identity;
36
+ }
37
+ function advanceContexts(current, updates) {
38
+ const { contexts, evicted } = advance(current, updates);
39
+ if (evicted.length > 0)
40
+ consoleWarn(`[read-state] over the byte cap; ${evicted.length} oldest markers dropped`);
41
+ return contexts;
42
+ }
43
+ /** Another person in this tab: nothing of the last one's — what they read, what waits to be published — carries over. */
44
+ function forPerson(pubkey) {
45
+ if (owner === pubkey)
46
+ return;
47
+ owner = pubkey;
48
+ known = {};
49
+ pending = {};
50
+ published = undefined;
51
+ ownCopy = undefined;
52
+ hydrated = false;
53
+ }
54
+ /**
55
+ * Read this installation's own blob back. Only our own coordinate: the write needs nothing of the other slots,
56
+ * and each would cost a `/nip44/decrypt` from the quota the rest of the app shares. Unreachable is not empty, and
57
+ * a slot that would not decrypt this time (a 429 above all) is not ours to write over: both throw, leaving the
58
+ * queue unhydrated so it comes back.
59
+ */
60
+ async function hydrate(pubkey) {
61
+ hydrated = false;
62
+ const slot = currentIdentity();
63
+ const events = await query([{ kinds: [KIND_APP_DATA], authors: [pubkey], '#d': [readStateDTag(slot.slotId)] }]);
64
+ const newest = events.filter((e) => e.pubkey === pubkey).sort((a, b) => b.created_at - a.created_at)[0];
65
+ let own = {};
66
+ slotAt = newest?.created_at ?? 0;
67
+ if (newest && ownCopy?.content === newest.content)
68
+ own = ownCopy.contexts;
69
+ else if (newest) {
70
+ const blob = parseReadStateBlob(await nip44.decrypt(newest.content));
71
+ if (blob?.client_id === slot.clientId) {
72
+ own = blob.contexts;
73
+ ownCopy = { content: newest.content, contexts: own };
74
+ }
75
+ else {
76
+ // Another installation's blob at our coordinate (a copied profile), or one that will never decrypt (a rotated
77
+ // key): take a new slot id and start it empty, never writing over it.
78
+ identity = rotateSlotId(slot, { storage: safe(options.storage), storageKey, random });
79
+ ownCopy = undefined;
80
+ }
81
+ }
82
+ if (owner !== pubkey)
83
+ return;
84
+ // Seeded from our own slot, never the merge: a slot is this installation's account of what it read, and seeding
85
+ // from the merge grows every slot to everything the person has read. The floor goes in as `current`, since
86
+ // `advanceContexts` refuses one among the updates.
87
+ const { [REPLY_FLOOR_CONTEXT]: floor, ...marked } = known;
88
+ const held = floor === undefined ? own : { ...own, [REPLY_FLOOR_CONTEXT]: Math.max(floor, own[REPLY_FLOOR_CONTEXT] ?? 0) };
89
+ known = advanceContexts(held, marked);
90
+ published = own;
91
+ hydrated = true;
92
+ }
93
+ function schedule(ms) {
94
+ timer = timers.setTimeout(() => {
95
+ timer = undefined;
96
+ void flush();
97
+ }, ms);
98
+ }
99
+ /** Markers are still pending after a failed attempt: come back, backing off so an outage is not a busy loop. */
100
+ function retryLater() {
101
+ if (timer !== undefined)
102
+ return;
103
+ retryMs = retryMs === 0 ? debounceMs : Math.min(retryMs * 2, READ_STATE_MAX_RETRY_MS);
104
+ schedule(retryMs);
105
+ }
106
+ function flush() {
107
+ if (timer !== undefined) {
108
+ timers.clearTimeout(timer);
109
+ timer = undefined;
110
+ }
111
+ inFlight = inFlight.then(async () => {
112
+ if (Object.keys(pending).length === 0)
113
+ return attempt('nothing-pending');
114
+ const pubkey = options.pubkey();
115
+ if (!pubkey || !canWrite()) {
116
+ attempt('no-session', 'retrying');
117
+ return retryLater();
118
+ }
119
+ // Marked by someone else who has since left this tab: theirs, never this person's.
120
+ forPerson(pubkey);
121
+ if (Object.keys(pending).length === 0)
122
+ return attempt('nothing-pending');
123
+ try {
124
+ await hydrate(pubkey);
125
+ }
126
+ catch (error) {
127
+ consoleWarn('[read-state] could not read the slot back:', error);
128
+ }
129
+ if (!hydrated) {
130
+ attempt('not-hydrated', 'relay unreachable, or our slot would not decrypt; retrying');
131
+ return retryLater();
132
+ }
133
+ const sending = pending;
134
+ const contexts = { ...known };
135
+ pending = {};
136
+ if (published && sameContexts(published, contexts))
137
+ return attempt('unchanged');
138
+ try {
139
+ // Signed only as the person whose markers these are: a sign-in in another tab since the flush began would
140
+ // put them in that person's slot. What goes out is remembered, so reading it back costs no decrypt.
141
+ const result = await publishReadState({
142
+ sign: (event) => (options.pubkey() === pubkey ? options.sign(event) : Promise.reject(new Error('the person signed in changed'))),
143
+ publish: async (event) => {
144
+ const answer = await options.publish(event);
145
+ if (answer.ok)
146
+ ownCopy = { content: event.content, contexts };
147
+ return answer;
148
+ },
149
+ nip44,
150
+ }, pubkey, currentIdentity(), contexts,
151
+ // After the copy read back, never in the same second: on a tie the relay keeps the lower id and answers
152
+ // "duplicate" as accepted, so a larger blob published within the second (a flush on hide right after the
153
+ // debounced one) could lose to the smaller one with nothing to say so.
154
+ Math.max(Date.now(), (slotAt + 1) * 1000));
155
+ if (result.ok) {
156
+ published = contexts;
157
+ retryMs = 0;
158
+ return attempt('published', undefined, Object.keys(contexts).length);
159
+ }
160
+ consoleWarn('[read-state] publish refused:', result.reason);
161
+ attempt('rejected', result.reason);
162
+ }
163
+ catch (error) {
164
+ consoleWarn('[read-state] publish failed:', error);
165
+ attempt('failed', error instanceof Error ? error.message : String(error));
166
+ }
167
+ pending = advanceContexts(pending, sending);
168
+ retryLater();
169
+ });
170
+ // A throw nobody expected (an app's callback) must not leave the chain rejected: every later flush would be skipped
171
+ // and nothing marked in this tab would reach the relay again.
172
+ const run = inFlight;
173
+ inFlight = run.catch((error) => {
174
+ consoleWarn('[read-state] flush failed:', error);
175
+ if (Object.keys(pending).length > 0)
176
+ retryLater();
177
+ });
178
+ return run;
179
+ }
180
+ function markRead(contexts, atMs = Date.now()) {
181
+ const pubkey = options.pubkey();
182
+ if (!pubkey)
183
+ return;
184
+ forPerson(pubkey);
185
+ const seconds = toContextSeconds(atMs);
186
+ const moved = {};
187
+ for (const context of contexts) {
188
+ if (!context)
189
+ continue;
190
+ const advanced = advanceContexts(known, { [context]: seconds });
191
+ // Not newer, or not a context the blob takes: nothing to publish.
192
+ if (advanced[context] === known[context])
193
+ continue;
194
+ known = advanced;
195
+ pending = advanceContexts(pending, { [context]: seconds });
196
+ moved[context] = seconds;
197
+ }
198
+ if (Object.keys(moved).length === 0)
199
+ return;
200
+ options.onMarked?.(moved);
201
+ if (timer !== undefined)
202
+ timers.clearTimeout(timer);
203
+ schedule(debounceMs);
204
+ }
205
+ function installFlushOnHide(doc) {
206
+ const onHidden = () => {
207
+ if (doc.hidden)
208
+ void flush();
209
+ };
210
+ doc.addEventListener('visibilitychange', onHidden);
211
+ return () => doc.removeEventListener('visibilitychange', onHidden);
212
+ }
213
+ function reset() {
214
+ if (timer !== undefined)
215
+ timers.clearTimeout(timer);
216
+ timer = undefined;
217
+ identity = undefined;
218
+ owner = undefined;
219
+ known = {};
220
+ pending = {};
221
+ published = undefined;
222
+ ownCopy = undefined;
223
+ hydrated = false;
224
+ slotAt = 0;
225
+ retryMs = 0;
226
+ inFlight = Promise.resolve();
227
+ }
228
+ const state = () => ({
229
+ known: { ...known },
230
+ pending: { ...pending },
231
+ published: published ? { ...published } : undefined,
232
+ hydrated,
233
+ retryMs,
234
+ });
235
+ return { markRead, flush, identity: currentIdentity, installFlushOnHide, state, reset };
236
+ }
237
+ /**
238
+ * Mark `contexts` read once they have stayed on screen for {@link READ_DWELL_MS}: a conversation glanced past is not
239
+ * read. Only while the page is shown, and again when it comes back. `newestAtMs` is the newest message drawn for
240
+ * them: the mark never runs past it or past the clock, and a message dated ahead of the clock is read once the clock
241
+ * gets there, asked again at most a minute apart (a date far ahead would overflow the timer). With none drawn, the
242
+ * clock. Returns the cleanup — what a React effect returns.
243
+ */
244
+ export function watchDwell(contexts, newestAtMs, mark, doc, dwellMs = READ_DWELL_MS) {
245
+ if (contexts.length === 0)
246
+ return () => { };
247
+ let t;
248
+ const fire = () => {
249
+ const now = Date.now();
250
+ mark(contexts, newestAtMs === undefined ? now : Math.min(newestAtMs, now));
251
+ if (newestAtMs !== undefined && newestAtMs > now)
252
+ t = timers.setTimeout(fire, Math.min(newestAtMs - now, 60_000));
253
+ };
254
+ const arm = () => {
255
+ timers.clearTimeout(t);
256
+ if (!doc.hidden)
257
+ t = timers.setTimeout(fire, dwellMs);
258
+ };
259
+ arm();
260
+ doc.addEventListener('visibilitychange', arm);
261
+ return () => {
262
+ timers.clearTimeout(t);
263
+ doc.removeEventListener('visibilitychange', arm);
264
+ };
265
+ }
266
+ /**
267
+ * The key a dwell restarts on: the set of contexts, not the array a render made. JSON, so it is never split back on a
268
+ * character an address may hold; {@link dwellContexts} turns it back.
269
+ */
270
+ export function dwellKey(contexts) {
271
+ return JSON.stringify(contexts.filter((c) => Boolean(c)).sort());
272
+ }
273
+ export function dwellContexts(key) {
274
+ return JSON.parse(key);
275
+ }
276
+ function safe(storage) {
277
+ try {
278
+ return storage();
279
+ }
280
+ catch {
281
+ return undefined;
282
+ }
283
+ }
284
+ function sameContexts(a, b) {
285
+ const keys = Object.keys(a);
286
+ return keys.length === Object.keys(b).length && keys.every((k) => a[k] === b[k]);
287
+ }
288
+ //# sourceMappingURL=readStateQueue.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"readStateQueue.js","sourceRoot":"","sources":["../src/readStateQueue.ts"],"names":[],"mappings":"AAwBA,OAAO,EAAE,aAAa,EAAE,MAAM,YAAY,CAAA;AAC1C,OAAO,EACL,mBAAmB,EACnB,eAAe,IAAI,OAAO,EAC1B,gBAAgB,EAChB,kBAAkB,EAClB,gBAAgB,EAChB,aAAa,EACb,YAAY,EACZ,gBAAgB,GAKjB,MAAM,gBAAgB,CAAA;AAGvB,MAAM,MAAM,GAAG,UAA0G,CAAA;AACzH,MAAM,WAAW,GAAG,CAAC,GAAG,IAAe,EAAQ,EAAE,CAAE,UAAuE,CAAC,OAAO,EAAE,IAAI,CAAC,GAAG,IAAI,CAAC,CAAA;AAEjJ,6EAA6E;AAC7E,MAAM,CAAC,MAAM,8BAA8B,GAAG,IAAI,CAAA;AAElD,iGAAiG;AACjG,MAAM,CAAC,MAAM,aAAa,GAAG,IAAI,CAAA;AAEjC,wEAAwE;AACxE,MAAM,CAAC,MAAM,uBAAuB,GAAG,MAAM,CAAA;AAwE7C,MAAM,UAAU,oBAAoB,CAAC,OAA8B;IACjE,MAAM,EAAE,UAAU,EAAE,YAAY,EAAE,MAAM,EAAE,KAAK,EAAE,KAAK,EAAE,GAAG,OAAO,CAAA;IAClE,MAAM,UAAU,GAAG,OAAO,CAAC,UAAU,IAAI,8BAA8B,CAAA;IACvE,MAAM,QAAQ,GAAG,OAAO,CAAC,QAAQ,IAAI,CAAC,GAAG,EAAE,CAAC,IAAI,CAAC,CAAA;IACjD,MAAM,OAAO,GAAG,CAAC,OAAyB,EAAE,MAAe,EAAE,QAAiB,EAAE,EAAE,CAAC,OAAO,CAAC,SAAS,EAAE,CAAC,OAAO,EAAE,M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CAAC,kBAAkB,EAAE,GAAG,CAAC,CAAA;IAC7C,OAAO,GAAG,EAAE;QACV,MAAM,CAAC,YAAY,CAAC,CAAC,CAAC,CAAA;QACtB,GAAG,CAAC,mBAAmB,CAAC,kBAAkB,EAAE,GAAG,CAAC,CAAA;IAClD,CAAC,CAAA;AACH,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,QAAQ,CAAC,QAAyC;IAChE,OAAO,IAAI,CAAC,SAAS,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC,CAAC,EAAe,EAAE,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC,CAAA;AAC/E,CAAC;AAED,MAAM,UAAU,aAAa,CAAC,GAAW;IACvC,OAAO,IAAI,CAAC,KAAK,CAAC,GAAG,CAAa,CAAA;AACpC,CAAC;AAED,SAAS,IAAI,CAAC,OAAsC;IAClD,IAAI,CAAC;QACH,OAAO,OAAO,EAAE,CAAA;IAClB,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,SAAS,CAAA;IAClB,CAAC;AACH,CAAC;AAED,SAAS,YAAY,CAAC,CAAyB,EAAE,CAAyB;IACxE,MAAM,IAAI,GAAG,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC,CAAA;IAC3B,OAAO,IAAI,CAAC,MAAM,KAAK,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,MAAM,IAAI,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,CAAA;AAClF,CAAC"}
package/dist/unread.d.ts CHANGED
@@ -50,5 +50,13 @@ export interface StreamJudge {
50
50
  export declare function unreadIn<E extends Message>(messages: readonly E[], merged: Readonly<Record<string, number>>, judge: StreamJudge): E[];
51
51
  /** Whether one message is unread: §11.8's four conditions. `root` is its thread's root id when it is a reply. */
52
52
  export declare function isUnread(message: Message, root: string | undefined, merged: Readonly<Record<string, number>>, judge: StreamJudge): boolean;
53
+ /**
54
+ * Whether one message lights the stream for `P` at all, read or not: §11.8's first three conditions. A message that
55
+ * lights and is not {@link seenIn} is unread; one that lights and is seen is a line of the stream's list (§11.8 *What
56
+ * lit a stream, new and seen*).
57
+ */
58
+ export declare function lightsIn(message: Pick<Message, 'pubkey' | 'content' | 'created_at'>, judge: StreamJudge): boolean;
59
+ /** Whether a message that lights is seen: at or below its effective marker (§11.3), or below the reply floor or the floor (§11.6). */
60
+ export declare function seenIn(message: Pick<Message, 'created_at'>, root: string | undefined, merged: Readonly<Record<string, number>>, judge: StreamJudge): boolean;
53
61
  export {};
54
62
  //# sourceMappingURL=unread.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"unread.d.ts","sourceRoot":"","sources":["../src/unread.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;GAmBG;AACH,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAA;AAKvD,KAAK,OAAO,GAAG,IAAI,CAAC,WAAW,EAAE,IAAI,GAAG,QAAQ,GAAG,MAAM,GAAG,YAAY,GAAG,MAAM,GAAG,SAAS,CAAC,CAAA;AAE9F,oDAAoD;AACpD,MAAM,WAAW,WAAW;IAC1B,oGAAoG;IACpG,MAAM,EAAE,MAAM,CAAA;IACd,0BAA0B;IAC1B,EAAE,EAAE,MAAM,CAAA;IACV,4FAA4F;IAC5F,MAAM,EAAE,OAAO,CAAA;IACf,qGAAqG;IACrG,KAAK,CAAC,EAAE,MAAM,CAAA;IACd,iFAAiF;IACjF,KAAK,CAAC,EAAE,OAAO,CAAA;IACf;;;;OAIG;IACH,KAAK,CAAC,EAAE,MAAM,CAAA;CACf;AAED;;;;;;;GAOG;AACH,wBAAgB,QAAQ,CAAC,CAAC,SAAS,OAAO,EAAE,QAAQ,EAAE,SAAS,CAAC,EAAE,EAAE,MAAM,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAA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AAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,EAAE,KAAK,EAAE,WAAW,GAAG,OAAO,CAE1I;AAED;;;;GAIG;AACH,wBAAgB,QAAQ,CAAC,OAAO,EAAE,IAAI,CAAC,OAAO,EAAE,QAAQ,GAAG,SAAS,GAAG,YAAY,CAAC,EAAE,KAAK,EAAE,WAAW,GAAG,OAAO,CAKjH;AAED,sIAAsI;AACtI,wBAAgB,MAAM,CAAC,OAAO,EAAE,IAAI,CAAC,OAAO,EAAE,YAAY,CAAC,EAAE,IAAI,EAAE,MAAM,GAAG,SAAS,EAAE,MAAM,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,EAAE,KAAK,EAAE,WAAW,GAAG,OAAO,CAE5J"}
package/dist/unread.js CHANGED
@@ -32,13 +32,26 @@ export function unreadIn(messages, merged, judge) {
32
32
  }
33
33
  /** Whether one message is unread: §11.8's four conditions. `root` is its thread's root id when it is a reply. */
34
34
  export function isUnread(message, root, merged, judge) {
35
+ return lightsIn(message, judge) && !seenIn(message, root, merged, judge);
36
+ }
37
+ /**
38
+ * Whether one message lights the stream for `P` at all, read or not: §11.8's first three conditions. A message that
39
+ * lights and is not {@link seenIn} is unread; one that lights and is seen is a line of the stream's list (§11.8 *What
40
+ * lit a stream, new and seen*).
41
+ */
42
+ export function lightsIn(message, judge) {
35
43
  if (message.pubkey === judge.me)
36
44
  return false;
37
45
  const mentioned = peopleNamedInBody(message.content).has(judge.me);
38
46
  if (!mentioned && (!judge.member || judge.muted))
39
47
  return false;
40
- if (judge.since !== undefined && message.created_at < judge.since)
41
- return false;
48
+ return judge.since === undefined || message.created_at >= judge.since;
49
+ }
50
+ /** Whether a message that lights is seen: at or below its effective marker (§11.3), or below the reply floor or the floor (§11.6). */
51
+ export function seenIn(message, root, merged, judge) {
52
+ return !newerThanMarker(message, root, merged, judge);
53
+ }
54
+ function newerThanMarker(message, root, merged, judge) {
42
55
  const thread = root === undefined ? undefined : threadContext(root);
43
56
  const marker = thread === undefined ? streamMarkerOf(merged, judge.stream) : effectiveReadAt(merged, thread, judge.stream);
44
57
  if (marker !== undefined)
@@ -1 +1 @@
1
- {"version":3,"file":"unread.js","sourceRoot":"","sources":["../src/unread.ts"],"names":[],"mappings":"AAqBA,OAAO,EAAE,mBAAmB,EAAE,eAAe,EAAE,eAAe,EAAE,cAAc,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAA;AACrH,OAAO,EAAE,iBAAiB,EAAE,MAAM,eAAe,CAAA;AACjD,OAAO,EAAE,YAAY,EAAE,MAAM,cAAc,CAAA;AAwB3C;;;;;;;GAOG;AACH,MAAM,UAAU,QAAQ,CAAoB,QAAsB,EAAE,MAAwC,EAAE,KAAkB;IAC9H,MAAM,EAAE,KAAK,EAAE,OAAO,EAAE,GAAG,YAAY,CAAC,QAAQ,CAAC,CAAA;IACjD,MAAM,GAAG,GAAQ,EAAE,CAAA;IACnB,MAAM,QAAQ,GAAG,CAAC,OAAU,EAAE,IAAwB,EAAE,EAAE;QACxD,IAAI,QAAQ,CAAC,OAAO,EAAE,IAAI,EAAE,MAAM,EAAE,KAAK,CAAC;YAAE,GAAG,CAAC,IAAI,CAAC,OAAO,CAAC,CAAA;IAC/D,CAAC,CAAA;IACD,KAAK,MAAM,IAAI,IAAI,KAAK,EAAE,CAAC;QACzB,QAAQ,CAAC,IAAI,EAAE,SAAS,CAAC,CAAA;QACzB,KAAK,MAAM,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC,EAAE,CAAC,IAAI,EAAE;YAAE,QAAQ,CAAC,KAAK,EAAE,IAAI,CAAC,EAAE,CAAC,CAAA;IACtE,CAAC;IACD,MAAM,IAAI,GAAG,IAAI,GAAG,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAA;IAC5C,KAAK,MAAM,CAAC,IAAI,EAAE,IAAI,CAAC,IAAI,MAAM,CAAC,OA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S,eAAe,CAAC,OAAoC,EAAE,IAAwB,EAAE,MAAwC,EAAE,KAAkB;IACnJ,MAAM,MAAM,GAAG,IAAI,KAAK,SAAS,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,aAAa,CAAC,IAAI,CAAC,CAAA;IACnE,MAAM,MAAM,GAAG,MAAM,KAAK,SAAS,CAAC,CAAC,CAAC,cAAc,CAAC,MAAM,EAAE,KAAK,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,eAAe,CAAC,MAAM,EAAE,MAAM,EAAE,KAAK,CAAC,MAAM,CAAC,CAAA;IAC1H,IAAI,MAAM,KAAK,SAAS;QAAE,OAAO,OAAO,CAAC,UAAU,GAAG,MAAM,CAAA;IAC5D,IAAI,MAAM,KAAK,SAAS,IAAI,eAAe,CAAC,OAAO,CAAC,UAAU,EAAE,MAAM,CAAC,mBAAmB,CAAC,CAAC;QAAE,OAAO,KAAK,CAAA;IAC1G,IAAI,KAAK,CAAC,KAAK,KAAK,SAAS;QAAE,OAAO,IAAI,CAAA;IAC1C,OAAO,KAAK,CAAC,KAAK,KAAK,SAAS,IAAI,OAAO,CAAC,UAAU,IAAI,KAAK,CAAC,KAAK,CAAA;AACvE,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@estiva-app/conversation",
3
- "version": "0.38.0",
3
+ "version": "0.40.0",
4
4
  "description": "The conversation rules of the Estiva SPEC (§6.2–§6.8, §11): comment and mention strengths, threading, one shape for a message and a thread, resolving a thread, the line rule, the edit, reaction and attachment folds, NIP-22 comment and reply builders, drafts, NIP-RS read state, membership and unread. A convenience an app adopts, never a requirement.",
5
5
  "license": "MIT",
6
6
  "type": "module",
package/src/index.ts CHANGED
@@ -12,7 +12,7 @@
12
12
  * apps: it imports no app's data layer, opens no socket, and takes every
13
13
  * environment touch — the relay read, the clock, storage — as a parameter.
14
14
  */
15
- export const CONVERSATION_VERSION = '0.38.0'
15
+ export const CONVERSATION_VERSION = '0.40.0'
16
16
 
17
17
  export {
18
18
  KIND_MESSAGE,
@@ -162,6 +162,12 @@ export {
162
162
  unreadOnListedFile,
163
163
  unreadReason,
164
164
  unreadReasons,
165
+ whatLitPlace,
166
+ whatLitListedFile,
167
+ whatLitStream,
168
+ mergeLitLines,
169
+ type LitLine,
170
+ type LitLineOptions,
165
171
  type UnreadReason,
166
172
  type UnreadReasonOptions,
167
173
  isUnreadOnPlace,
@@ -245,6 +251,21 @@ export {
245
251
  type FetchedReadState,
246
252
  } from './readState.js'
247
253
 
254
+ export {
255
+ createReadStateQueue,
256
+ watchDwell,
257
+ dwellKey,
258
+ dwellContexts,
259
+ READ_DWELL_MS,
260
+ READ_STATE_PUBLISH_DEBOUNCE_MS,
261
+ READ_STATE_MAX_RETRY_MS,
262
+ type ReadStateQueue,
263
+ type ReadStateQueueOptions,
264
+ type ReadStateQueueState,
265
+ type ReadStateAttempt,
266
+ type VisibilitySource,
267
+ } from './readStateQueue.js'
268
+
248
269
  export { unreadIn, isUnread, type StreamJudge } from './unread.js'
249
270
 
250
271
  export {