@estiva-app/conversation 0.24.0 → 0.26.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,133 @@
1
+ /**
2
+ * A list row's dot — SPEC §11.8 over a stream's messages, for a reader that
3
+ * holds only who said what and when, never the bodies.
4
+ *
5
+ * Moved here from Peek (SHIPS-2) so Peek's Topics and Ship's Topics judge a
6
+ * topic's dot by one rule: which files the viewer is a member of, read from
7
+ * the relay and folded ({@link membershipQueries}, {@link foldMemberships}),
8
+ * the terms that fold gives a stream ({@link streamTermsOf}), and whether any
9
+ * of the stream's messages is unread on them ({@link streamHasUnread}).
10
+ *
11
+ * The read state and the muted list are encrypted (NIP-44), so nothing here
12
+ * reads them: the app hands in the merged markers and the muted set it holds.
13
+ */
14
+ import { encodeNpub } from '@estiva-app/protocol';
15
+ import { candidateFilesOf, membershipFilters, membershipOf, mentions } from './membership.js';
16
+ import { READ_STATE_HORIZON_DAYS, fileContext } from './readState.js';
17
+ import { isUnread } from './unread.js';
18
+ /**
19
+ * Is anything in this stream unread for the viewer — SPEC §11.8's four
20
+ * conditions over §11.3's markers, judged by {@link isUnread}.
21
+ *
22
+ * `context` is the stream's read-state context (§11.1): `fileContext(address)`
23
+ * for a file, `channelContext(uuid)` for a Folder's general stream. A message is
24
+ * judged against its thread's marker as well as the stream's (§11.3).
25
+ *
26
+ * The messages carry no body, so whether one *names the viewer* comes from
27
+ * `isMentioned` (the ids the membership read's `#p` filter returned) and is
28
+ * handed to the judge as the body it would have had. Without a marker, a file
29
+ * member is told from the second they joined; a Folder's own chat has no
30
+ * members here and lights only for a message that names the viewer, so
31
+ * absence there is the horizon (§11.6).
32
+ */
33
+ export function streamHasUnread(messages, context, terms, frontier, isMentioned) {
34
+ const { me } = frontier;
35
+ if (!me)
36
+ return false;
37
+ // Only for a message that names the viewer, so a viewer without a hex key judges the rest.
38
+ const named = () => `nostr:${encodeNpub(me)}`;
39
+ const judge = {
40
+ stream: context,
41
+ me,
42
+ member: terms.member,
43
+ since: terms.since,
44
+ muted: terms.muted,
45
+ floor: frontier.nowSeconds - frontier.horizonSeconds,
46
+ };
47
+ for (const message of messages) {
48
+ const root = message.root === message.id ? undefined : message.root;
49
+ const unread = isUnread({ id: message.id, pubkey: message.by, kind: 1111, created_at: message.at, tags: [], content: isMentioned(message.id) ? named() : '' }, root, frontier.merged, judge);
50
+ if (unread)
51
+ return true;
52
+ }
53
+ return false;
54
+ }
55
+ /** Per filter. Measured on production as the agent, the most-named identity there: 700 events in 90 days. */
56
+ export const MEMBERSHIP_LIMIT = 1000;
57
+ /** The read horizon, in seconds: nothing before it can light a dot. */
58
+ export const HORIZON_SECONDS = READ_STATE_HORIZON_DAYS * 24 * 60 * 60;
59
+ /** The three filters that find every file the viewer may be a member of (§11.8), bounded by the horizon. */
60
+ export function membershipQueries(pubkey, nowSeconds, limit = MEMBERSHIP_LIMIT) {
61
+ return membershipFilters(pubkey, nowSeconds - HORIZON_SECONDS).map((filter) => ({ ...filter, limit }));
62
+ }
63
+ /** The address's author, or undefined when it is not a file address. */
64
+ export function authorOfAddress(address) {
65
+ if (fileContext(address) === undefined)
66
+ return undefined;
67
+ return address.split(':')[1];
68
+ }
69
+ /**
70
+ * Fold what {@link membershipQueries} returned. Pure: the clock is `nowSeconds`.
71
+ *
72
+ * A file's address names its author, so a file the viewer created needs no
73
+ * query: a candidate whose address is theirs is folded with its root added,
74
+ * dated to the horizon's start — the earliest the viewer could be told about —
75
+ * and a leave of theirs among the changes still takes them off. Membership the
76
+ * horizon hides lapses for this reader and comes back with the next event
77
+ * naming the viewer (§11.8 *The fold*).
78
+ */
79
+ export function foldMemberships(pubkey, events, nowSeconds) {
80
+ const floor = nowSeconds - HORIZON_SECONDS;
81
+ const byFile = new Map();
82
+ const mentioned = new Set();
83
+ for (const event of events) {
84
+ if (mentions(event, pubkey))
85
+ mentioned.add(event.id);
86
+ for (const file of candidateFilesOf(event)) {
87
+ const list = byFile.get(file);
88
+ if (list)
89
+ list.push(event);
90
+ else
91
+ byFile.set(file, [event]);
92
+ }
93
+ }
94
+ const files = new Map();
95
+ for (const [file, held] of byFile) {
96
+ const [kind, , d] = file.split(':');
97
+ const own = authorOfAddress(file) === pubkey;
98
+ // The root the viewer created, when they did — ordered before everything else for the file.
99
+ const root = own ? [{ id: '', pubkey, kind: Number(kind), created_at: floor, tags: [['d', d ?? '']], content: '', sig: '' }] : [];
100
+ files.set(file, membershipOf(file, pubkey, [...root, ...held]));
101
+ }
102
+ return { files, mentioned, floor };
103
+ }
104
+ /**
105
+ * The terms a stream is judged on, from the membership read and the muted set.
106
+ *
107
+ * A file is a member by the fold, else by authorship (a file the viewer
108
+ * created is theirs unless a leave of theirs says otherwise, and a leave is
109
+ * among the files read). Anything that is not a file address — a Folder's
110
+ * general stream — has nothing to read (Miky, 2026-10-01): nobody is a member
111
+ * of it, so it lights only for a message that names the viewer.
112
+ */
113
+ export function streamTermsOf(key, read, me, muted) {
114
+ const isMuted = muted.has(key);
115
+ if (fileContext(key) === undefined)
116
+ return { member: false, muted: isMuted };
117
+ const folded = read.files.get(key);
118
+ if (folded)
119
+ return { member: folded.member, since: folded.since, muted: isMuted };
120
+ if (me && authorOfAddress(key) === me)
121
+ return { member: true, since: read.floor, muted: isMuted };
122
+ return { member: false, muted: isMuted };
123
+ }
124
+ /**
125
+ * Whether the horizon's read has a word on the viewer in this file: an event
126
+ * naming them within it, or the file is theirs. Without one, "not a member"
127
+ * may only mean they joined before the horizon; a list that must say whose a
128
+ * file is reads those over all history.
129
+ */
130
+ export function membershipJudges(key, read, me) {
131
+ return read.files.has(key) || (!!me && authorOfAddress(key) === me);
132
+ }
133
+ //# sourceMappingURL=streamUnread.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"streamUnread.js","sourceRoot":"","sources":["../src/streamUnread.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AACH,OAAO,EAAE,UAAU,EAAoB,MAAM,sBAAsB,CAA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B,MAAM,OAAO,GAAG,KAAK,CAAC,GAAG,CAAC,GAAG,CAAC,CAAA;IAC9B,IAAI,WAAW,CAAC,GAAG,CAAC,KAAK,SAAS;QAAE,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,KAAK,EAAE,OAAO,EAAE,CAAA;IAC5E,MAAM,MAAM,GAAG,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,GAAG,CAAC,CAAA;IAClC,IAAI,MAAM;QAAE,OAAO,EAAE,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,KAAK,EAAE,MAAM,CAAC,KAAK,EAAE,KAAK,EAAE,OAAO,EAAE,CAAA;IACjF,IAAI,EAAE,IAAI,eAAe,CAAC,GAAG,CAAC,KAAK,EAAE;QAAE,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,KAAK,EAAE,IAAI,CAAC,KAAK,EAAE,KAAK,EAAE,OAAO,EAAE,CAAA;IACjG,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,KAAK,EAAE,OAAO,EAAE,CAAA;AAC1C,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,gBAAgB,CAAC,GAAW,EAAE,IAAmC,EAAE,EAAsB;IACvG,OAAO,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,IAAI,eAAe,CAAC,GAAG,CAAC,KAAK,EAAE,CAAC,CAAA;AACrE,CAAC"}
@@ -51,6 +51,29 @@ export declare function isReply(event: Pick<SignedEvent, 'kind' | 'tags'>): bool
51
51
  * test for whether the event itself lists as a comment.
52
52
  */
53
53
  export declare function anchorsOf(event: Tagged): string[];
54
+ /**
55
+ * The ids of the files the event's thread is about by its `O` tags (§6.4, "A
56
+ * comment in both forms"), beside {@link anchorsOf}'s addresses. Empty for a
57
+ * comment whose `A` and `O` name different files: that one is about neither.
58
+ */
59
+ export declare function anchorIdsOf(event: Tagged): string[];
60
+ /** Whether the event is a comment whose root and `O` name different files: one ignored under every file (§6.4). */
61
+ export declare function isCrossedComment(event: Tagged): boolean;
62
+ /**
63
+ * {@link isCrossedComment}, or a comment whose `O` has the id of the file at
64
+ * `address` under a root that is not that address (another author's): its
65
+ * root and `O` disagree for this file, so under it it is nothing, not even a
66
+ * mention (§6.4).
67
+ */
68
+ export declare function isCrossedCommentOn(event: Tagged, address: string): boolean;
69
+ /**
70
+ * Whether a `kind:1111`'s thread is about the file at `address`: by its
71
+ * {@link anchorsOf} root when it has one, so an `O` with the file's id under
72
+ * an address of another author is not about it; by its `O` only when it
73
+ * carries neither `A` nor `a` (§6.4). A root or a reply alike;
74
+ * {@link isCommentOn} adds the root test.
75
+ */
76
+ export declare function isAbout(event: Tagged, address: string): boolean;
54
77
  /**
55
78
  * Is the event a **comment** on the address: a root whose thread is about it
56
79
  * (C10, C11).
@@ -66,7 +89,12 @@ export declare function anchorsOf(event: Tagged): string[];
66
89
  * why: https://github.com/estiva-app/estiva-docs/blob/main/decisions/early-shapes-are-migrated-or-deleted.md
67
90
  */
68
91
  export declare function isCommentOn(event: Readable, address: string, declaredKinds?: readonly number[]): boolean;
69
- /** Does the event name the address at all — any `a` or `A`, or a `nostr:naddr…` in its body. */
92
+ /**
93
+ * Does the event name the address at all — any `a` or `A`, an `o` or `O` with
94
+ * the file's id (§6.4), or a `nostr:naddr…` in its body. A comment whose `A`
95
+ * and `O` disagree names nothing: it is ignored under every file (§6.4), and
96
+ * one whose `O` has this file's id under another address is about that one.
97
+ */
70
98
  export declare function referencesAddress(event: Readable, address: string): boolean;
71
99
  /**
72
100
  * How one event attaches to the address on its own: a comment, a mention, or
@@ -1 +1 @@
1
- {"version":3,"file":"strength.d.ts","sourceRoot":"","sources":["../src/strength.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AACH,OAAO,EAAwE,KAAK,QAAQ,EAAE,KAAK,WAAW,EAAE,MAAM,sBAAsB,CAAA;AAG5I,KAAK,MAAM,GAAG,IAAI,CAAC,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,MAAM,EAAE,OAAO,EAAE,MAAM,GAAG,OAAO,CAK/D;AAKD;;;;;;;;;;;;;GAaG;AACH,wBAAgB,WAAW,CAAC,KAAK,EAAE,QAAQ,EAAE,OAAO,EAAE,MAAM,EAAE,aAAa,GAAE,SAAS,MAAM,EAAmB,GAAG,OAAO,CAKxH;AAED;;;;;GAKG;AACH,wBAAgB,iBAAiB,CAAC,KAAK,EAAE,QAAQ,EAAE,OAAO,EAAE,MAAM,GAAG,OAAO,CAK3E;AAED;;;;;;;GAOG;AACH,wBAAgB,UAAU,CAAC,KAAK,EAAE,QAAQ,EAAE,OAAO,EAAE,MAAM,GAAG,QAAQ,GAAG,IAAI,CAI5E;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,cAAc,CAAC,IAAI,EAAE,QAAQ,GAAG,SAAS,EAAE,OAAO,EAAE,SAAS,QAAQ,EAAE,EAAE,OAAO,EAAE,MAAM,GAAG,QAAQ,GAAG,IAAI,CAIzH;AAED;;;;;;;GAOG;AACH,wBAAgB,gBAAgB,CAAC,IAAI,EAAE,MAAM,EAAE,GAAG,SAAK,GAAG,QAAQ,EAAE,CAInE;AAED,8EAA8E;AAC9E,eAAO,MAAM,oBAAoB,KAAK,CAAA;AAEtC,uFAAuF;AACvF,wBAAgB,iBAAiB,CAAC,IAAI,EAAE,MAAM,GAAG,GAAG,CAAC,MAAM,CAAC,CAW3D;AAED,wGAAwG;AACxG,wBAAgB,cAAc,CAAC,IAAI,EAAE,MAAM,GAAG,QAAQ,EAAE,CAEvD"}
package/dist/strength.js CHANGED
@@ -27,7 +27,7 @@
27
27
  * reply `e` — a `kind:9` with any `e`, a `kind:1111` with a lowercase `e` that
28
28
  * differs from its `E` — is not a comment of its own, whatever `a` it carries.
29
29
  */
30
- import { decodeNaddr, decodeNpub, findNaddrs, findNostrUris, pointerToAddress } from '@estiva-app/protocol';
30
+ import { decodeNaddr, decodeNpub, findNaddrs, findNostrUris, FILE_KINDS, fileIdOf, pointerToAddress } from '@estiva-app/protocol';
31
31
  import { KIND_COMMENT } from './kinds.js';
32
32
  const values = (event, name) => event.tags.filter((t) => t[0] === name && typeof t[1] === 'string' && t[1] !== '').map((t) => t[1]);
33
33
  /** The addresses a body names by `nostr:naddr…`. A pointer that will not decode is prose. */
@@ -69,11 +69,74 @@ export function isReply(event) {
69
69
  * test for whether the event itself lists as a comment.
70
70
  */
71
71
  export function anchorsOf(event) {
72
- if (event.kind !== KIND_COMMENT)
72
+ if (event.kind !== KIND_COMMENT || crossed(event))
73
73
  return [];
74
74
  const roots = values(event, 'A');
75
75
  return [...new Set(roots.length > 0 ? roots : values(event, 'a'))];
76
76
  }
77
+ /**
78
+ * The ids of the files the event's thread is about by its `O` tags (§6.4, "A
79
+ * comment in both forms"), beside {@link anchorsOf}'s addresses. Empty for a
80
+ * comment whose `A` and `O` name different files: that one is about neither.
81
+ */
82
+ export function anchorIdsOf(event) {
83
+ if (event.kind !== KIND_COMMENT || crossed(event))
84
+ return [];
85
+ return [...new Set(values(event, 'O'))];
86
+ }
87
+ /**
88
+ * A comment §6.4 ignores, as a change is (§6.2): two `O`s or two `A`s, or a
89
+ * root and an `O` that name different files, or it would show under one file
90
+ * for a reader asking by address and under another for one asking `#O`. The
91
+ * root is its `A`, or its `a` when it carries no `A`, as {@link anchorsOf}
92
+ * reads it, and names the `O`'s file only as a file kind's address with that
93
+ * id. That the author is the file's is {@link isAbout}'s to check: the
94
+ * comment is about its root.
95
+ */
96
+ function crossed(event) {
97
+ const ids = new Set(values(event, 'O'));
98
+ const roots = new Set(values(event, 'A'));
99
+ if (ids.size > 1 || roots.size > 1)
100
+ return true;
101
+ if (ids.size === 0)
102
+ return false;
103
+ const [id] = ids;
104
+ return [...(roots.size > 0 ? roots : values(event, 'a'))].some((address) => !FILE_KINDS.includes(Number(address.split(':')[0])) || fileIdOf(address) !== id);
105
+ }
106
+ /** Whether the event is a comment whose root and `O` name different files: one ignored under every file (§6.4). */
107
+ export function isCrossedComment(event) {
108
+ return event.kind === KIND_COMMENT && crossed(event);
109
+ }
110
+ /**
111
+ * {@link isCrossedComment}, or a comment whose `O` has the id of the file at
112
+ * `address` under a root that is not that address (another author's): its
113
+ * root and `O` disagree for this file, so under it it is nothing, not even a
114
+ * mention (§6.4).
115
+ */
116
+ export function isCrossedCommentOn(event, address) {
117
+ if (event.kind !== KIND_COMMENT)
118
+ return false;
119
+ if (crossed(event))
120
+ return true;
121
+ const roots = anchorsOf(event);
122
+ return roots.length > 0 && !roots.includes(address) && values(event, 'O').some((id) => namesById(id, address));
123
+ }
124
+ /**
125
+ * Whether a `kind:1111`'s thread is about the file at `address`: by its
126
+ * {@link anchorsOf} root when it has one, so an `O` with the file's id under
127
+ * an address of another author is not about it; by its `O` only when it
128
+ * carries neither `A` nor `a` (§6.4). A root or a reply alike;
129
+ * {@link isCommentOn} adds the root test.
130
+ */
131
+ export function isAbout(event, address) {
132
+ const roots = anchorsOf(event);
133
+ if (roots.length > 0)
134
+ return roots.includes(address);
135
+ // No root: neither `A` nor `a`, or an ignored comment, whose `O`s are none.
136
+ return anchorIdsOf(event).some((id) => namesById(id, address));
137
+ }
138
+ /** Whether a tag naming a file by its id (`O`, `o`) names the file at `address`. */
139
+ const namesById = (id, address) => fileIdOf(address) === id;
77
140
  /**
78
141
  * Is the event a **comment** on the address: a root whose thread is about it
79
142
  * (C10, C11).
@@ -92,15 +155,24 @@ export function isCommentOn(event, address, declaredKinds = [KIND_COMMENT]) {
92
155
  if (isReply(event))
93
156
  return false;
94
157
  if (event.kind === KIND_COMMENT)
95
- return anchorsOf(event).includes(address);
158
+ return isAbout(event, address);
96
159
  if (!declaredKinds.includes(event.kind))
97
160
  return false;
98
161
  return event.tags.some((t) => t[0] === 'a' && t[1] === address) && !namedInBody(event.content).has(address);
99
162
  }
100
- /** Does the event name the address at all — any `a` or `A`, or a `nostr:naddr…` in its body. */
163
+ /**
164
+ * Does the event name the address at all — any `a` or `A`, an `o` or `O` with
165
+ * the file's id (§6.4), or a `nostr:naddr…` in its body. A comment whose `A`
166
+ * and `O` disagree names nothing: it is ignored under every file (§6.4), and
167
+ * one whose `O` has this file's id under another address is about that one.
168
+ */
101
169
  export function referencesAddress(event, address) {
170
+ if (isCrossedCommentOn(event, address))
171
+ return false;
102
172
  if (event.tags.some((t) => (t[0] === 'a' || t[0] === 'A') && t[1] === address))
103
173
  return true;
174
+ if (event.tags.some((t) => (t[0] === 'o' || t[0] === 'O') && typeof t[1] === 'string' && namesById(t[1], address)))
175
+ return true;
104
176
  return namedInBody(event.content).has(address);
105
177
  }
106
178
  /**
@@ -1 +1 @@
1
- {"version":3,"file":"strength.js","sourceRoot":"","sources":["../src/strength.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AACH,OAAO,EAAE,WAAW,EAAE,UAAU,EAAE,UAAU,EAAE,aAAa,EAAE,gBAAgB,EAAmC,MAAM,sBAAsB,CAAA;AAC5I,OAAO,EAAE,YAAY,EAAE,MAAM,YAAY,CAAA;AAQzC,MAAM,MAAM,GAAG,CAAC,KAAgC,EAAE,IAAY,EAAY,EAAE,CAC1E,KAAK,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,KAAK,IAAI,IAAI,OAAO,CAAC,CAAC,CAAC,CAAC,KAAK,QAAQ,IAAI,CAAC,CAAC,CAAC,CAAC,KAAK,EAAE,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAA;AAErG,6FAA6F;AAC7F,MAAM,UAAU,WAAW,CAAC,IAAY;IACtC,MAAM,SAAS,GAAG,IAAI,GAAG,EAAU,CAAA;IACnC,KAAK,MAAM,KAAK,IAAI,UAAU,CAAC,IAAI,CAAC,EAAE,CAAC;QACrC,IAAI,CAAC;YACH,SAAS,CAAC,GAAG,CAAC,gBAAgB,CAAC,WAAW,CAAC,KAAK,CAAC,CAAC,CAAC,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MAAM,OAAO,GAAG,IAAI,GAAG,EAAU,CAAA;IACjC,KAAK,MAAM,GAAG,IAAI,aAAa,CAAC,IAAI,CAAC,EAAE,CAAC;QACtC,IAAI,CAAC,eAAe,CAAC,IAAI,CAAC,GAAG,CAAC;YAAE,SAAQ;QACxC,IAAI,CAAC;YACH,OAAO,CAAC,GAAG,CAAC,UAAU,CAAC,GAAG,CAAC,CAAC,CAAA;QAC9B,CAAC;QAAC,MAAM,CAAC;YACP,4BAA4B;QAC9B,CAAC;IACH,CAAC;IACD,OAAO,OAAO,CAAA;AAChB,CAAC;AAED,wGAAwG;AACxG,MAAM,UAAU,cAAc,CAAC,IAAY;IACzC,OAAO,CAAC,GAAG,iBAAiB,CAAC,IAAI,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,EAAE,oBAAoB,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,GAAG,EAAE,CAAC,CAAC,CAAC,CAAA;AACzF,CAAC"}
package/dist/unread.js CHANGED
@@ -1,4 +1,4 @@
1
- import { REPLY_FLOOR_CONTEXT, belowReplyFloor, effectiveReadAt, threadContext } from './readState.js';
1
+ import { REPLY_FLOOR_CONTEXT, belowReplyFloor, effectiveReadAt, streamMarkerOf, threadContext } from './readState.js';
2
2
  import { peopleNamedInBody } from './strength.js';
3
3
  import { groupThreads } from './threads.js';
4
4
  /**
@@ -40,7 +40,7 @@ export function isUnread(message, root, merged, judge) {
40
40
  if (judge.since !== undefined && message.created_at < judge.since)
41
41
  return false;
42
42
  const thread = root === undefined ? undefined : threadContext(root);
43
- const marker = thread === undefined ? merged[judge.stream] : effectiveReadAt(merged, thread, judge.stream);
43
+ const marker = thread === undefined ? streamMarkerOf(merged, judge.stream) : effectiveReadAt(merged, thread, judge.stream);
44
44
  if (marker !== undefined)
45
45
  return message.created_at > marker;
46
46
  if (thread !== undefined && belowReplyFloor(message.created_at, merged[REPLY_FLOOR_CONTEXT]))
@@ -1 +1 @@
1
- {"version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AC,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.24.0",
3
+ "version": "0.26.0",
4
4
  "description": "The conversation rules of the Estiva SPEC (§6.2–§6.8, §11): comment and mention strengths, threading, 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",
@@ -47,10 +47,10 @@
47
47
  "prepublishOnly": "npm run build"
48
48
  },
49
49
  "peerDependencies": {
50
- "@estiva-app/protocol": ">=0.45.0"
50
+ "@estiva-app/protocol": ">=0.50.0"
51
51
  },
52
52
  "devDependencies": {
53
- "@estiva-app/protocol": ">=0.45.0",
53
+ "@estiva-app/protocol": ">=0.50.0",
54
54
  "typescript": "~5.9.3"
55
55
  }
56
56
  }
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.24.0'
15
+ export const CONVERSATION_VERSION = '0.26.0'
16
16
 
17
17
  export {
18
18
  KIND_MESSAGE,
@@ -31,6 +31,10 @@ export {
31
31
  namedInBody,
32
32
  isReply,
33
33
  anchorsOf,
34
+ anchorIdsOf,
35
+ isAbout,
36
+ isCrossedComment,
37
+ isCrossedCommentOn,
34
38
  isCommentOn,
35
39
  referencesAddress,
36
40
  strengthOn,
@@ -146,6 +150,8 @@ export {
146
150
  READ_STATE_HORIZON_DAYS,
147
151
  channelContext,
148
152
  fileContext,
153
+ fileIdContext,
154
+ streamMarkerOf,
149
155
  threadContext,
150
156
  messageContext,
151
157
  toContextSeconds,
@@ -185,6 +191,21 @@ export {
185
191
 
186
192
  export { unreadIn, isUnread, type StreamJudge } from './unread.js'
187
193
 
194
+ export {
195
+ streamHasUnread,
196
+ MEMBERSHIP_LIMIT,
197
+ HORIZON_SECONDS,
198
+ membershipQueries,
199
+ authorOfAddress,
200
+ foldMemberships,
201
+ streamTermsOf,
202
+ membershipJudges,
203
+ type StreamMessage,
204
+ type StreamFrontier,
205
+ type StreamTerms,
206
+ type MembershipRead,
207
+ } from './streamUnread.js'
208
+
188
209
  export { peopleNamedInText, newlyNamedPeople, mentionAddsFor, type FileText } from './textMentions.js'
189
210
 
190
211
  export { KIND_MEMBERSHIP_LIST, namedProfilesOf, rosterOf, byName, mentionablePeople, type NamedProfile } from './people.js'
package/src/membership.ts CHANGED
@@ -30,7 +30,7 @@
30
30
  import type { SignedEvent, UnsignedEvent } from '@estiva-app/protocol'
31
31
  import { FILE_ADDRESS as ADDRESS, FOLDER_ID, KIND_APP_DATA, KIND_CHANGE, KIND_COMMENT, KIND_MESSAGE } from './kinds.js'
32
32
  import { byOrder } from './order.js'
33
- import { anchorsOf, isCommentOn, peopleNamedInBody } from './strength.js'
33
+ import { anchorsOf, isAbout, isCommentOn, peopleNamedInBody } from './strength.js'
34
34
  import { groupThreads } from './threads.js'
35
35
 
36
36
  export { KIND_CHANGE }
@@ -92,7 +92,7 @@ export function streamOf<E extends Event>(file: string, events: readonly E[]): E
92
92
  out.push(root, ...(replies[root.id] ?? []))
93
93
  }
94
94
  for (const id of missing) {
95
- for (const reply of replies[id] ?? []) if (reply.kind === KIND_COMMENT && anchorsOf(reply).includes(file)) out.push(reply)
95
+ for (const reply of replies[id] ?? []) if (reply.kind === KIND_COMMENT && isAbout(reply, file)) out.push(reply)
96
96
  }
97
97
  return out.sort(byOrder)
98
98
  }
@@ -134,8 +134,16 @@ function stepsOf(file: string, events: readonly Event[]): Map<string, Step[]> {
134
134
  for (const person of peopleNamedInBody(message.content)) add(person, message, true)
135
135
  }
136
136
 
137
+ const id = file.split(':').slice(2).join(':')
137
138
  for (const change of events) {
138
- if (change.kind !== KIND_CHANGE || !change.tags.some((t) => t[0] === 'a' && t[1] === file)) continue
139
+ if (change.kind !== KIND_CHANGE || !isChangeTo(change, file, id)) continue
140
+ const sets = change.tags.filter((t) => t[0] === 'set' && typeof t[1] === 'string')
141
+ if (sets.length) {
142
+ // A several-field change never carries a `member:<P>` (§11.8), so one is not read here;
143
+ // the `p` it carries places people when any field it sets has a value.
144
+ if (sets.some((t) => !t[1].startsWith(MEMBER_FIELD_PREFIX) && t[2])) addNamed(change)
145
+ continue
146
+ }
139
147
  const field = tag(change, 'field')
140
148
  const value = tag(change, 'value')
141
149
  const member = memberOfField(field)
@@ -146,9 +154,25 @@ function stepsOf(file: string, events: readonly Event[]): Map<string, Step[]> {
146
154
  }
147
155
  // A change with an empty value takes someone off (an unassign) and places nobody, whatever `p` it carries.
148
156
  if (field?.startsWith(MEMBER_FIELD_PREFIX) || !value) continue
149
- for (const t of change.tags) if (t[0] === 'p' && typeof t[1] === 'string') add(t[1], change, true)
157
+ addNamed(change)
150
158
  }
151
159
  return steps
160
+
161
+ function addNamed(change: Event) {
162
+ for (const t of change.tags) if (t[0] === 'p' && typeof t[1] === 'string') add(t[1], change, true)
163
+ }
164
+ }
165
+
166
+ /**
167
+ * Whether a change is to the file: its first `a` names it, the one the relay
168
+ * checks the change against, and any `O` is the file's id. A change with no
169
+ * `a` is checked against nothing, so it is to no file; one whose `O` is not
170
+ * its `a`'s file is about neither (§6.2).
171
+ */
172
+ function isChangeTo(change: Pick<SignedEvent, 'tags'>, file: string, id: string): boolean {
173
+ const O = tag(change, 'O')
174
+ if (O !== undefined && O !== id) return false
175
+ return tag(change, 'a') === file
152
176
  }
153
177
 
154
178
  function fold(steps: readonly Step[] | undefined): Membership {
package/src/readState.ts CHANGED
@@ -24,6 +24,7 @@
24
24
  */
25
25
  import type { SignedEvent, UnsignedEvent } from '@estiva-app/protocol'
26
26
  import { FILE_ADDRESS as ADDRESS_RE, FOLDER_ID as UUID_RE, KIND_APP_DATA } from './kinds.js'
27
+ import { fileIdOf, isFileId } from '@estiva-app/protocol'
27
28
  import type { QueryFn } from './decorations.js'
28
29
 
29
30
  /** NIP-RS's own `t` tag. */
@@ -105,6 +106,39 @@ export function fileContext(address: string | null | undefined): string | undefi
105
106
  return ADDRESS_RE.test(address) ? address : undefined
106
107
  }
107
108
 
109
+ /**
110
+ * A file's context by its id: `file:<d>`, for a lowercase UUID (§11.1, *added
111
+ * 2026-10-30*). Where a new read of a file is written once its comments name
112
+ * it by id; {@link streamMarkerOf} reads it beside the address key.
113
+ *
114
+ * why: https://github.com/estiva-app/estiva-docs/blob/main/decisions/a-files-unread-state-is-keyed-file-and-its-id.md
115
+ */
116
+ export function fileIdContext(id: string | null | undefined): string | undefined {
117
+ return id && isFileId(id) ? `${FILE_ID_PREFIX}${id}` : undefined
118
+ }
119
+
120
+ const FILE_ID_PREFIX = 'file:'
121
+
122
+ /**
123
+ * A stream's marker. For a file, the later of its address key and its
124
+ * `file:<d>` key (§11.1, §11.6, *added 2026-11-02*): either one is a marker,
125
+ * so a file whose comments moved to its id keeps what was read, whichever form
126
+ * the stream is passed in. A `file:<d>` stream reads every address key whose
127
+ * `d` is that id. Any other stream reads its own key.
128
+ */
129
+ export function streamMarkerOf(merged: Readonly<Record<string, number>>, stream: string): number | undefined {
130
+ const own = merged[stream]
131
+ if (ADDRESS_RE.test(stream)) {
132
+ const byId = fileIdContext(fileIdOf(stream))
133
+ return byId === undefined ? own : later(own, merged[byId])
134
+ }
135
+ if (!stream.startsWith(FILE_ID_PREFIX)) return own
136
+ const id = stream.slice(FILE_ID_PREFIX.length)
137
+ let out: number | undefined = own
138
+ for (const [key, at] of Object.entries(merged)) if (ADDRESS_RE.test(key) && fileIdOf(key) === id) out = later(out, at)
139
+ return out
140
+ }
141
+
108
142
  /** `thread:<root-event-id>`, NIP-RS's own scheme. */
109
143
  export function threadContext(rootEventId: string | null | undefined): string | undefined {
110
144
  if (!rootEventId) return undefined
@@ -136,6 +170,8 @@ export function isPublishableContextId(id: string): boolean {
136
170
  if (id.length === 0 || utf8(id) > MAX_CONTEXT_ID_BYTES) return false
137
171
  if (id.startsWith('thread:')) return EVENT_ID_RE.test(id.slice('thread:'.length))
138
172
  if (id.startsWith('msg:')) return EVENT_ID_RE.test(id.slice('msg:'.length))
173
+ // A key beginning `file:` whose remainder is not a lowercase UUID is not a file context (§11.1).
174
+ if (id.startsWith(FILE_ID_PREFIX)) return isFileId(id.slice(FILE_ID_PREFIX.length))
139
175
  return UUID_RE.test(id) || ADDRESS_RE.test(id)
140
176
  }
141
177
 
@@ -450,7 +486,7 @@ export function effectiveReadAt(
450
486
  from: number = THREAD_RULE_FROM,
451
487
  ): number | undefined {
452
488
  const own = merged[context]
453
- const parent = stream === undefined ? undefined : merged[stream]
489
+ const parent = stream === undefined ? undefined : streamMarkerOf(merged, stream)
454
490
  if (isThreadKey(context)) return threadReadAt({ thread: own, stream: parent, floor: merged[REPLY_FLOOR_CONTEXT] }, from)
455
491
  return later(own, parent)
456
492
  }