@estiva-app/conversation 0.16.0 → 0.17.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/CHANGELOG.md CHANGED
@@ -6,6 +6,26 @@ none. A change to how an event is read is a MINOR in `0.x` even when no
6
6
  signature moved, because two apps on different versions would then disagree
7
7
  about a conversation.
8
8
 
9
+ ## 0.17.0 — 2026-10-20
10
+
11
+ **A mention in a file's text adds the person** (WBD-2; record
12
+ *a-mention-in-a-files-text-adds-the-person-with-no-unread*).
13
+ `mentionAddsFor(writer, atMs, { file, folder, saved, editedFrom })` is the one
14
+ helper every writer of a page or a description uses: it returns the Add
15
+ (`member:<P>` = `true`, `buildMembershipChange`'s event) for each person the
16
+ saved text names by `nostr:npub` and the version it was edited from did not. A
17
+ creation passes `editedFrom: null`. A typo fix returns nothing, the writer is
18
+ never added, and a run in code or a code block names nobody.
19
+ `peopleNamedInText` reads a block document (a `reference` mark's `uri` only)
20
+ or marker text. Being added shows no unread: that belongs to a document's own
21
+ read state, shaped later.
22
+
23
+ Nothing in how a conversation is read changed, so an app on 0.16 reads
24
+ everything as before, and folds the Add as a join.
25
+
26
+ SPEC: §11.8 *A mention in a file's text*, *Being added is not unread by
27
+ itself*; §13.1 *A file's text is not a message*; §7.3 `format`; C28.
28
+
9
29
  ## 0.16.0 — 2026-10-19
10
30
 
11
31
  **What a comment box shows under itself, for every app's box** (COMM-8; record
package/README.md CHANGED
@@ -7,7 +7,7 @@ and estiva-agent read conversations through it.
7
7
  **A convenience, never a requirement.** SPEC §9's conversation checks
8
8
  (C10–C18) are written so an app can build conversations from the specification
9
9
  alone, and this package's tests are those checks
10
- (`test/conformance.test.ts` for C10–C16, `test/membership.test.ts` for C17 and C18). If you find this package disagreeing with the
10
+ (`test/conformance.test.ts` for C10–C16, `test/membership.test.ts` for C17 and C18, `test/textMentions.test.ts` for C28). If you find this package disagreeing with the
11
11
  SPEC, the package is wrong.
12
12
 
13
13
  ```bash
@@ -39,6 +39,7 @@ pass, the clock is a `createdAtMs` you pass, and drafts take their storage.
39
39
  | muting | §11.8 | `parseMutedBlob`, `serializeMutedBlob`, `buildMutedEvent`, `mutedFilter`, `mutedFromFollowed` |
40
40
  | read state | §11.1–§11.6 | `channelContext`, `fileContext`, `threadContext`, `loadSlotIdentity`, `advanceContexts`, `fetchReadState`, `publishReadState`, `mergeSlots`, `effectiveReadAt`, `THREAD_RULE_FROM`, `REPLY_FLOOR_CONTEXT`, `capReadStateContexts` |
41
41
  | unread | §11.3, §11.8 | `unreadIn`, `isUnread` |
42
+ | a mention in a file's text | §11.8, §13.1 | `mentionAddsFor`, `newlyNamedPeople`, `peopleNamedInText` |
42
43
 
43
44
  Chat, an edit, a reaction and a deletion are built with
44
45
  `@estiva-app/protocol`'s `buildMessage`, `buildEdit`, `buildReaction` and
package/dist/index.d.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 declare const CONVERSATION_VERSION = "0.16.0";
15
+ export declare const CONVERSATION_VERSION = "0.17.0";
16
16
  export { KIND_MESSAGE, KIND_COMMENT, KIND_EDIT, KIND_REACTION, KIND_DELETION, KIND_ASSERTION, isConversationKind, isEventId, } from './kinds.js';
17
17
  export { trustedTs, orderingMs, byOrder } from './order.js';
18
18
  export { namedInBody, isReply, anchorsOf, isCommentOn, referencesAddress, strengthOn, threadStrength, referenceTagsFor, mentionTagsFor, peopleNamedInBody, MAX_MENTIONED_PEOPLE, type Strength, } from './strength.js';
@@ -28,5 +28,6 @@ export { FILE_TIER, fileReference, MESSAGE_TIER, rankReferences, REFERENCE_CAPS,
28
28
  export { KIND_CHANGE, MEMBER_FIELD_PREFIX, memberField, memberOfField, mentions, streamOf, membershipOf, membersOf, membershipFilters, candidateFilesOf, buildMembershipChange, MUTED_D_TAG, APPDATA_TAG, parseMutedBlob, serializeMutedBlob, buildMutedEvent, mutedFilter, mutedFromFollowed, type Membership, type MutedList, } from './membership.js';
29
29
  export { READ_STATE_TAG, READ_STATE_D_PREFIX, MAX_CONTEXTS, MAX_CONTEXT_ID_BYTES, MAX_TIMESTAMP, MAX_CLIENT_ID_BYTES, MAX_BLOB_BYTES, MAX_CONTEXTS_BYTES, READ_STATE_HORIZON_DAYS, channelContext, fileContext, threadContext, messageContext, toContextSeconds, isPublishableContextId, loadSlotIdentity, rotateSlotId, readStateDTag, parseReadStateBlob, serializeReadStateBlob, capContextsToBytes, capReadStateContexts, THREAD_RULE_FROM, REPLY_FLOOR_CONTEXT, advanceContexts, buildReadStateEvent, allSlotsFilter, mergeSlots, classifyOwnSlots, effectiveReadAt, threadReadAt, belowReplyFloor, fetchReadState, createSlotCache, publishReadState, type SlotCache, type SlotIdentity, type SlotStorage, type SlotSource, type RandomBytes, type ReadStateBlob, type CappedContexts, type SlotBlob, type OwnSlotVerdict, type Nip44, type FetchedReadState, } from './readState.js';
30
30
  export { unreadIn, isUnread, type StreamJudge } from './unread.js';
31
+ export { peopleNamedInText, newlyNamedPeople, mentionAddsFor, type FileText } from './textMentions.js';
31
32
  export { createDraftStore, draftKeys, NO_DRAFTS, DRAFT_MAX_AGE_MS, DRAFT_MAX_CHARS, type Draft, type DraftStore, type DraftStorage, } from './drafts.js';
32
33
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AACH,eAAO,MAAM,oBAAoB,WAAW,CAAA;AAE5C,OAAO,EACL,YAAY,EACZ,YAAY,EACZ,SAAS,EACT,aAAa,EACb,aAAa,EACb,cAAc,EACd,kBAAkB,EAClB,SAAS,GACV,MAAM,YAAY,CAAA;AAEnB,OAAO,EAAE,SAAS,EAAE,UAAU,EAAE,OAAO,EAAE,MAAM,YAAY,CAAA;AAE3D,OAAO,EACL,WAAW,EACX,OAAO,EACP,SAAS,EACT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gBAAgB,EAChB,sBAAsB,EACtB,gBAAgB,EAChB,YAAY,EACZ,aAAa,EACb,kBAAkB,EAClB,sBAAsB,EACtB,kBAAkB,EAClB,oBAAoB,EACpB,gBAAgB,EAChB,mBAAmB,EACnB,eAAe,EACf,mBAAmB,EACnB,cAAc,EACd,UAAU,EACV,gBAAgB,EAChB,eAAe,EACf,YAAY,EACZ,eAAe,EACf,cAAc,EACd,eAAe,EACf,gBAAgB,EAChB,KAAK,SAAS,EACd,KAAK,YAAY,EACjB,KAAK,WAAW,EAChB,KAAK,UAAU,EACf,KAAK,WAAW,EAChB,KAAK,aAAa,EAClB,KAAK,cAAc,EACnB,KAAK,QAAQ,EACb,KAAK,cAAc,EACnB,KAAK,KAAK,EACV,KAAK,gBAAgB,GACtB,MAAM,gBAAgB,CAAA;AAEvB,OAAO,EAAE,QAAQ,EAAE,QAAQ,EAAE,KAAK,WAAW,EAAE,MAAM,aAAa,CAAA;AAElE,OAAO,EAAE,iBAAiB,EAAE,gBAAgB,EAAE,cAAc,EAAE,KAAK,QAAQ,EAAE,MAAM,mBAAmB,CAAA;AAEtG,OAAO,EACL,gBAAgB,EAChB,SAAS,EACT,SAAS,EACT,gBAAgB,EAChB,eAAe,EACf,KAAK,KAAK,EACV,KAAK,UAAU,EACf,KAAK,YAAY,GAClB,MAAM,aAAa,CAAA"}
package/dist/index.js 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.16.0';
15
+ export const CONVERSATION_VERSION = '0.17.0';
16
16
  export { KIND_MESSAGE, KIND_COMMENT, KIND_EDIT, KIND_REACTION, KIND_DELETION, KIND_ASSERTION, isConversationKind, isEventId, } from './kinds.js';
17
17
  export { trustedTs, orderingMs, byOrder } from './order.js';
18
18
  export { namedInBody, isReply, anchorsOf, isCommentOn, referencesAddress, strengthOn, threadStrength, referenceTagsFor, mentionTagsFor, peopleNamedInBody, MAX_MENTIONED_PEOPLE, } from './strength.js';
@@ -28,5 +28,6 @@ export { FILE_TIER, fileReference, MESSAGE_TIER, rankReferences, REFERENCE_CAPS,
28
28
  export { KIND_CHANGE, MEMBER_FIELD_PREFIX, memberField, memberOfField, mentions, streamOf, membershipOf, membersOf, membershipFilters, candidateFilesOf, buildMembershipChange, MUTED_D_TAG, APPDATA_TAG, parseMutedBlob, serializeMutedBlob, buildMutedEvent, mutedFilter, mutedFromFollowed, } from './membership.js';
29
29
  export { READ_STATE_TAG, READ_STATE_D_PREFIX, MAX_CONTEXTS, MAX_CONTEXT_ID_BYTES, MAX_TIMESTAMP, MAX_CLIENT_ID_BYTES, MAX_BLOB_BYTES, MAX_CONTEXTS_BYTES, READ_STATE_HORIZON_DAYS, channelContext, fileContext, threadContext, messageContext, toContextSeconds, isPublishableContextId, loadSlotIdentity, rotateSlotId, readStateDTag, parseReadStateBlob, serializeReadStateBlob, capContextsToBytes, capReadStateContexts, THREAD_RULE_FROM, REPLY_FLOOR_CONTEXT, advanceContexts, buildReadStateEvent, allSlotsFilter, mergeSlots, classifyOwnSlots, effectiveReadAt, threadReadAt, belowReplyFloor, fetchReadState, createSlotCache, publishReadState, } from './readState.js';
30
30
  export { unreadIn, isUnread } from './unread.js';
31
+ export { peopleNamedInText, newlyNamedPeople, mentionAddsFor } from './textMentions.js';
31
32
  export { createDraftStore, draftKeys, NO_DRAFTS, DRAFT_MAX_AGE_MS, DRAFT_MAX_CHARS, } from './drafts.js';
32
33
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AACH,MAAM,CAAC,MAAM,oBAAoB,GAAG,QAAQ,CAAA;AAE5C,OAAO,EACL,YAAY,EACZ,YAAY,EACZ,SAAS,EACT,aAAa,EACb,aAAa,EACb,cAAc,EACd,kBAAkB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AAa,EACb,QAAQ,EACR,QAAQ,EACR,YAAY,EACZ,SAAS,EACT,iBAAiB,EACjB,gBAAgB,EAChB,qBAAqB,EACrB,WAAW,EACX,WAAW,EACX,cAAc,EACd,kBAAkB,EAClB,eAAe,EACf,WAAW,EACX,iBAAiB,GAGlB,MAAM,iBAAiB,CAAA;AAExB,OAAO,EACL,cAAc,EACd,mBAAmB,EACnB,YAAY,EACZ,oBAAoB,EACpB,aAAa,EACb,mBAAmB,EACnB,cAAc,EACd,kBAAkB,EAClB,uBAAuB,EACvB,cAAc,EACd,WAAW,EACX,aAAa,EACb,cAAc,EACd,gBAAgB,EAChB,sBAAsB,EACtB,gBAAgB,EAChB,YAAY,EACZ,aAAa,EACb,kBAAkB,EAClB,sBAAsB,EACtB,kBAAkB,EAClB,oBAAoB,EACpB,gBAAgB,EAChB,mBAAmB,EACnB,eAAe,EACf,mBAAmB,EACnB,cAAc,EACd,UAAU,EACV,gBAAgB,EAChB,eAAe,EACf,YAAY,EACZ,eAAe,EACf,cAAc,EACd,eAAe,EACf,gBAAgB,GAYjB,MAAM,gBAAgB,CAAA;AAEvB,OAAO,EAAE,QAAQ,EAAE,QAAQ,EAAoB,MAAM,aAAa,CAAA;AAElE,OAAO,EACL,gBAAgB,EAChB,SAAS,EACT,SAAS,EACT,gBAAgB,EAChB,eAAe,GAIhB,MAAM,aAAa,CAAA"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AACH,MAAM,CAAC,MAAM,oBAAoB,GAAG,QAAQ,CAAA;AAE5C,OAAO,EACL,YAAY,EACZ,YAAY,EACZ,SAAS,EACT,aAAa,EACb,aAAa,EACb,cAAc,EACd,kBAAkB,EAClB,SAAS,GACV,MAAM,YAAY,CAAA;AAEnB,OAAO,EAAE,SAAS,EAAE,UAAU,EAAE,OAAO,EAAE,MAAM,YAAY,CAAA;AAE3D,OAAO,EACL,WAAW,EACX,OAAO,EACP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AAe,EACf,WAAW,EACX,iBAAiB,GAGlB,MAAM,iBAAiB,CAAA;AAExB,OAAO,EACL,cAAc,EACd,mBAAmB,EACnB,YAAY,EACZ,oBAAoB,EACpB,aAAa,EACb,mBAAmB,EACnB,cAAc,EACd,kBAAkB,EAClB,uBAAuB,EACvB,cAAc,EACd,WAAW,EACX,aAAa,EACb,cAAc,EACd,gBAAgB,EAChB,sBAAsB,EACtB,gBAAgB,EAChB,YAAY,EACZ,aAAa,EACb,kBAAkB,EAClB,sBAAsB,EACtB,kBAAkB,EAClB,oBAAoB,EACpB,gBAAgB,EAChB,mBAAmB,EACnB,eAAe,EACf,mBAAmB,EACnB,cAAc,EACd,UAAU,EACV,gBAAgB,EAChB,eAAe,EACf,YAAY,EACZ,eAAe,EACf,cAAc,EACd,eAAe,EACf,gBAAgB,GAYjB,MAAM,gBAAgB,CAAA;AAEvB,OAAO,EAAE,QAAQ,EAAE,QAAQ,EAAoB,MAAM,aAAa,CAAA;AAElE,OAAO,EAAE,iBAAiB,EAAE,gBAAgB,EAAE,cAAc,EAAiB,MAAM,mBAAmB,CAAA;AAEtG,OAAO,EACL,gBAAgB,EAChB,SAAS,EACT,SAAS,EACT,gBAAgB,EAChB,eAAe,GAIhB,MAAM,aAAa,CAAA"}
@@ -0,0 +1,57 @@
1
+ /**
2
+ * A mention in a file's text — SPEC §11.8 *A mention in a file's text*.
3
+ *
4
+ * A file's text (its root's content, or a prose field's value, §7.3) is not a
5
+ * message: a save of it carries no `p` for the people it names (§13.1). What
6
+ * adds a person is the membership change the writer signs when its save names
7
+ * them and the version it edited from did not, the same Add a Members button
8
+ * writes. A typo fix names nobody new, so it writes nothing, and a person who
9
+ * left stays out. Being added shows no unread by itself.
10
+ *
11
+ * The writer compares the two versions it holds, the one it loaded and the one
12
+ * it saves; nothing is kept between edits. Leaf, Ship, Peek's panel and the
13
+ * agent's description writes all use {@link mentionAddsFor}.
14
+ *
15
+ * why: https://github.com/estiva-app/estiva-docs/blob/main/decisions/a-mention-in-a-files-text-adds-the-person-with-no-unread.md
16
+ */
17
+ import { type BlockDocument, type UnsignedEvent } from '@estiva-app/protocol';
18
+ /**
19
+ * One version of a file's text: what goes in the event's content (or a
20
+ * change's `value`), and its `content-format` tag. A block document may be
21
+ * passed parsed. With no `format`, a string is §13.2 marker text.
22
+ */
23
+ export interface FileText {
24
+ content: string | BlockDocument;
25
+ format?: string;
26
+ }
27
+ /**
28
+ * The people a version of a file's text names by `nostr:npub…`: a `reference`
29
+ * mark in a block document (§13.3), or the URI itself in marker text (§13.2).
30
+ * A bare key in a document's plain run, a run marked `code`, and a code block
31
+ * name nobody.
32
+ */
33
+ export declare function peopleNamedInText(text: FileText): Set<string>;
34
+ /**
35
+ * The people `saved` names and `editedFrom` did not, in the order `saved`
36
+ * names them. `editedFrom` is `null` for a creation, which is edited from
37
+ * nothing.
38
+ */
39
+ export declare function newlyNamedPeople(saved: FileText, editedFrom: FileText | null): string[];
40
+ /**
41
+ * The membership changes a save of a file's text writes beside itself
42
+ * (§11.8): one Add (`member:<P>` = `true`) for each person `saved` names and
43
+ * `editedFrom` did not, signed by `writer`, at most
44
+ * {@link MAX_MENTIONED_PEOPLE}. None for the writer, whose own Add would be a
45
+ * Join, and none when nobody is named anew — a typo fix writes nothing.
46
+ *
47
+ * The save itself carries no `p` for these people (§13.1). Publish each Add
48
+ * with the save; an Add the relay refuses is the person not being told, and is
49
+ * surfaced like any failed write (C9).
50
+ */
51
+ export declare function mentionAddsFor(writer: string, createdAtMs: number, args: {
52
+ file: string;
53
+ folder: string;
54
+ saved: FileText;
55
+ editedFrom: FileText | null;
56
+ }): UnsignedEvent[];
57
+ //# sourceMappingURL=textMentions.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"textMentions.d.ts","sourceRoot":"","sources":["../src/textMentions.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AACH,OAAO,EAKL,KAAK,aAAa,EAElB,KAAK,aAAa,EACnB,MAAM,sBAAsB,CAAA;AAI7B;;;;GAIG;AACH,MAAM,WAAW,QAAQ;IACvB,OAAO,EAAE,MAAM,GAAG,aAAa,CAAA;IAC/B,MAAM,CAAC,EAAE,MAAM,CAAA;CAChB;AAiCD;;;;;GAKG;AACH,wBAAgB,iBAAiB,CAAC,IAAI,EAAE,QAAQ,GAAG,GAAG,CAAC,MAAM,CAAC,CAe7D;AAED;;;;GAIG;AACH,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,QAAQ,EAAE,UAAU,EAAE,QAAQ,GAAG,IAAI,GAAG,MAAM,EAAE,CAGvF;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,cAAc,CAC5B,MAAM,EAAE,MAAM,EACd,WAAW,EAAE,MAAM,EACnB,IAAI,EAAE;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,MAAM,EAAE,MAAM,CAAC;IAAC,KAAK,EAAE,QAAQ,CAAC;IAAC,UAAU,EAAE,QAAQ,GAAG,IAAI,CAAA;CAAE,GACnF,aAAa,EAAE,CAKjB"}
@@ -0,0 +1,102 @@
1
+ /**
2
+ * A mention in a file's text — SPEC §11.8 *A mention in a file's text*.
3
+ *
4
+ * A file's text (its root's content, or a prose field's value, §7.3) is not a
5
+ * message: a save of it carries no `p` for the people it names (§13.1). What
6
+ * adds a person is the membership change the writer signs when its save names
7
+ * them and the version it edited from did not, the same Add a Members button
8
+ * writes. A typo fix names nobody new, so it writes nothing, and a person who
9
+ * left stays out. Being added shows no unread by itself.
10
+ *
11
+ * The writer compares the two versions it holds, the one it loaded and the one
12
+ * it saves; nothing is kept between edits. Leaf, Ship, Peek's panel and the
13
+ * agent's description writes all use {@link mentionAddsFor}.
14
+ *
15
+ * why: https://github.com/estiva-app/estiva-docs/blob/main/decisions/a-mention-in-a-files-text-adds-the-person-with-no-unread.md
16
+ */
17
+ import { BLOCK_DOCUMENT_FORMAT, markersToInlineNodes, parseBlockDocument, } from '@estiva-app/protocol';
18
+ import { buildMembershipChange } from './membership.js';
19
+ import { MAX_MENTIONED_PEOPLE, peopleNamedInBody } from './strength.js';
20
+ const isInlineRun = (content) => Array.isArray(content) && content.every((n) => typeof n === 'object' && n !== null && n.type === 'text');
21
+ /** A `reference` mark's `uri`, when the mark is well formed; somebody else's JSON may hold `"attrs": null`. */
22
+ function referenceUri(node) {
23
+ const attrs = node.marks?.find((m) => m.type === 'reference')?.attrs;
24
+ const uri = attrs && typeof attrs === 'object' ? attrs.uri : undefined;
25
+ return typeof uri === 'string' && uri !== '' ? uri : undefined;
26
+ }
27
+ function namedInBlocks(blocks, out) {
28
+ for (const block of blocks) {
29
+ // A code block's text is code, not prose (§13.1): a key in it names nobody.
30
+ if (block.type === 'codeBlock' || !Array.isArray(block.content))
31
+ continue;
32
+ if (!isInlineRun(block.content)) {
33
+ namedInBlocks(block.content, out);
34
+ continue;
35
+ }
36
+ namedInRuns(block.content, out);
37
+ }
38
+ }
39
+ /** Only a `reference` mark names a person (§13.1); a bare key in a run's text is text, as a reader draws it. */
40
+ function namedInRuns(nodes, out) {
41
+ for (const node of nodes) {
42
+ if (node.marks?.some((m) => m.type === 'code'))
43
+ continue;
44
+ const uri = referenceUri(node);
45
+ if (uri)
46
+ for (const person of peopleNamedInBody(uri))
47
+ out.add(person);
48
+ }
49
+ }
50
+ /**
51
+ * The people a version of a file's text names by `nostr:npub…`: a `reference`
52
+ * mark in a block document (§13.3), or the URI itself in marker text (§13.2).
53
+ * A bare key in a document's plain run, a run marked `code`, and a code block
54
+ * name nobody.
55
+ */
56
+ export function peopleNamedInText(text) {
57
+ const out = new Set();
58
+ let doc;
59
+ if (typeof text.content !== 'string')
60
+ doc = text.content;
61
+ else if (text.format === BLOCK_DOCUMENT_FORMAT) {
62
+ try {
63
+ doc = parseBlockDocument(text.content);
64
+ }
65
+ catch {
66
+ // A tag that lies about its content: read the string as marker text, as a message is read.
67
+ }
68
+ }
69
+ if (doc)
70
+ namedInBlocks(doc.content, out);
71
+ // Marker text through §13.2's own parse, so a key inside `code` stays code.
72
+ else if (typeof text.content === 'string')
73
+ namedInRuns(markersToInlineNodes(text.content), out);
74
+ return out;
75
+ }
76
+ /**
77
+ * The people `saved` names and `editedFrom` did not, in the order `saved`
78
+ * names them. `editedFrom` is `null` for a creation, which is edited from
79
+ * nothing.
80
+ */
81
+ export function newlyNamedPeople(saved, editedFrom) {
82
+ const before = editedFrom ? peopleNamedInText(editedFrom) : new Set();
83
+ return [...peopleNamedInText(saved)].filter((person) => !before.has(person));
84
+ }
85
+ /**
86
+ * The membership changes a save of a file's text writes beside itself
87
+ * (§11.8): one Add (`member:<P>` = `true`) for each person `saved` names and
88
+ * `editedFrom` did not, signed by `writer`, at most
89
+ * {@link MAX_MENTIONED_PEOPLE}. None for the writer, whose own Add would be a
90
+ * Join, and none when nobody is named anew — a typo fix writes nothing.
91
+ *
92
+ * The save itself carries no `p` for these people (§13.1). Publish each Add
93
+ * with the save; an Add the relay refuses is the person not being told, and is
94
+ * surfaced like any failed write (C9).
95
+ */
96
+ export function mentionAddsFor(writer, createdAtMs, args) {
97
+ return newlyNamedPeople(args.saved, args.editedFrom)
98
+ .filter((person) => person !== writer)
99
+ .slice(0, MAX_MENTIONED_PEOPLE)
100
+ .map((person) => buildMembershipChange(writer, createdAtMs, { file: args.file, folder: args.folder, person, member: true }));
101
+ }
102
+ //# sourceMappingURL=textMentions.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"textMentions.js","sourceRoot":"","sources":["../src/textMentions.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AACH,OAAO,EACL,qBAAqB,EACrB,oBAAoB,EACpB,kBAAkB,GAKnB,MAAM,sBAAsB,CAAA;AAC7B,OAAO,EAAE,qBAAqB,EAAE,MAAM,iBAAiB,CAAA;AACvD,OAAO,EAAE,oBAAoB,EAAE,iBAAiB,EAAE,MAAM,eAAe,CAAA;AAYvE,MAAM,WAAW,GAAG,CAAC,OAAgB,EAA+B,EAAE,CACpE,KAAK,CAAC,OAAO,CAAC,OAAO,CAAC,IA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AE,CAAC,CAAC,MAAM,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC,CAAA;AAC9E,CAAC;AAED;;;;;;;;;;GAUG;AACH,MAAM,UAAU,cAAc,CAC5B,MAAc,EACd,WAAmB,EACnB,IAAoF;IAEpF,OAAO,gBAAgB,CAAC,IAAI,CAAC,KAAK,EAAE,IAAI,CAAC,UAAU,CAAC;SACjD,MAAM,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,MAAM,KAAK,MAAM,CAAC;SACrC,KAAK,CAAC,CAAC,EAAE,oBAAoB,CAAC;SAC9B,GAAG,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,qBAAqB,CAAC,MAAM,EAAE,WAAW,EAAE,EAAE,IAAI,EAAE,IAAI,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,CAAC,CAAC,CAAA;AAChI,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@estiva-app/conversation",
3
- "version": "0.16.0",
3
+ "version": "0.17.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",
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.16.0'
15
+ export const CONVERSATION_VERSION = '0.17.0'
16
16
 
17
17
  export {
18
18
  KIND_MESSAGE,
@@ -181,6 +181,8 @@ export {
181
181
 
182
182
  export { unreadIn, isUnread, type StreamJudge } from './unread.js'
183
183
 
184
+ export { peopleNamedInText, newlyNamedPeople, mentionAddsFor, type FileText } from './textMentions.js'
185
+
184
186
  export {
185
187
  createDraftStore,
186
188
  draftKeys,
@@ -0,0 +1,123 @@
1
+ /**
2
+ * A mention in a file's text — SPEC §11.8 *A mention in a file's text*.
3
+ *
4
+ * A file's text (its root's content, or a prose field's value, §7.3) is not a
5
+ * message: a save of it carries no `p` for the people it names (§13.1). What
6
+ * adds a person is the membership change the writer signs when its save names
7
+ * them and the version it edited from did not, the same Add a Members button
8
+ * writes. A typo fix names nobody new, so it writes nothing, and a person who
9
+ * left stays out. Being added shows no unread by itself.
10
+ *
11
+ * The writer compares the two versions it holds, the one it loaded and the one
12
+ * it saves; nothing is kept between edits. Leaf, Ship, Peek's panel and the
13
+ * agent's description writes all use {@link mentionAddsFor}.
14
+ *
15
+ * why: https://github.com/estiva-app/estiva-docs/blob/main/decisions/a-mention-in-a-files-text-adds-the-person-with-no-unread.md
16
+ */
17
+ import {
18
+ BLOCK_DOCUMENT_FORMAT,
19
+ markersToInlineNodes,
20
+ parseBlockDocument,
21
+ type Block,
22
+ type BlockDocument,
23
+ type InlineTextNode,
24
+ type UnsignedEvent,
25
+ } from '@estiva-app/protocol'
26
+ import { buildMembershipChange } from './membership.js'
27
+ import { MAX_MENTIONED_PEOPLE, peopleNamedInBody } from './strength.js'
28
+
29
+ /**
30
+ * One version of a file's text: what goes in the event's content (or a
31
+ * change's `value`), and its `content-format` tag. A block document may be
32
+ * passed parsed. With no `format`, a string is §13.2 marker text.
33
+ */
34
+ export interface FileText {
35
+ content: string | BlockDocument
36
+ format?: string
37
+ }
38
+
39
+ const isInlineRun = (content: unknown): content is InlineTextNode[] =>
40
+ Array.isArray(content) && content.every((n) => typeof n === 'object' && n !== null && (n as { type?: unknown }).type === 'text')
41
+
42
+ /** A `reference` mark's `uri`, when the mark is well formed; somebody else's JSON may hold `"attrs": null`. */
43
+ function referenceUri(node: InlineTextNode): string | undefined {
44
+ const attrs = (node.marks?.find((m) => m.type === 'reference') as { attrs?: unknown } | undefined)?.attrs
45
+ const uri = attrs && typeof attrs === 'object' ? (attrs as { uri?: unknown }).uri : undefined
46
+ return typeof uri === 'string' && uri !== '' ? uri : undefined
47
+ }
48
+
49
+ function namedInBlocks(blocks: readonly Block[], out: Set<string>): void {
50
+ for (const block of blocks) {
51
+ // A code block's text is code, not prose (§13.1): a key in it names nobody.
52
+ if (block.type === 'codeBlock' || !Array.isArray(block.content)) continue
53
+ if (!isInlineRun(block.content)) {
54
+ namedInBlocks(block.content as Block[], out)
55
+ continue
56
+ }
57
+ namedInRuns(block.content, out)
58
+ }
59
+ }
60
+
61
+ /** Only a `reference` mark names a person (§13.1); a bare key in a run's text is text, as a reader draws it. */
62
+ function namedInRuns(nodes: readonly InlineTextNode[], out: Set<string>): void {
63
+ for (const node of nodes) {
64
+ if (node.marks?.some((m) => m.type === 'code')) continue
65
+ const uri = referenceUri(node)
66
+ if (uri) for (const person of peopleNamedInBody(uri)) out.add(person)
67
+ }
68
+ }
69
+
70
+ /**
71
+ * The people a version of a file's text names by `nostr:npub…`: a `reference`
72
+ * mark in a block document (§13.3), or the URI itself in marker text (§13.2).
73
+ * A bare key in a document's plain run, a run marked `code`, and a code block
74
+ * name nobody.
75
+ */
76
+ export function peopleNamedInText(text: FileText): Set<string> {
77
+ const out = new Set<string>()
78
+ let doc: BlockDocument | undefined
79
+ if (typeof text.content !== 'string') doc = text.content
80
+ else if (text.format === BLOCK_DOCUMENT_FORMAT) {
81
+ try {
82
+ doc = parseBlockDocument(text.content)
83
+ } catch {
84
+ // A tag that lies about its content: read the string as marker text, as a message is read.
85
+ }
86
+ }
87
+ if (doc) namedInBlocks(doc.content, out)
88
+ // Marker text through §13.2's own parse, so a key inside `code` stays code.
89
+ else if (typeof text.content === 'string') namedInRuns(markersToInlineNodes(text.content), out)
90
+ return out
91
+ }
92
+
93
+ /**
94
+ * The people `saved` names and `editedFrom` did not, in the order `saved`
95
+ * names them. `editedFrom` is `null` for a creation, which is edited from
96
+ * nothing.
97
+ */
98
+ export function newlyNamedPeople(saved: FileText, editedFrom: FileText | null): string[] {
99
+ const before = editedFrom ? peopleNamedInText(editedFrom) : new Set<string>()
100
+ return [...peopleNamedInText(saved)].filter((person) => !before.has(person))
101
+ }
102
+
103
+ /**
104
+ * The membership changes a save of a file's text writes beside itself
105
+ * (§11.8): one Add (`member:<P>` = `true`) for each person `saved` names and
106
+ * `editedFrom` did not, signed by `writer`, at most
107
+ * {@link MAX_MENTIONED_PEOPLE}. None for the writer, whose own Add would be a
108
+ * Join, and none when nobody is named anew — a typo fix writes nothing.
109
+ *
110
+ * The save itself carries no `p` for these people (§13.1). Publish each Add
111
+ * with the save; an Add the relay refuses is the person not being told, and is
112
+ * surfaced like any failed write (C9).
113
+ */
114
+ export function mentionAddsFor(
115
+ writer: string,
116
+ createdAtMs: number,
117
+ args: { file: string; folder: string; saved: FileText; editedFrom: FileText | null },
118
+ ): UnsignedEvent[] {
119
+ return newlyNamedPeople(args.saved, args.editedFrom)
120
+ .filter((person) => person !== writer)
121
+ .slice(0, MAX_MENTIONED_PEOPLE)
122
+ .map((person) => buildMembershipChange(writer, createdAtMs, { file: args.file, folder: args.folder, person, member: true }))
123
+ }