@estiva-app/conversation 0.18.0 → 0.20.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,36 @@ 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.20.0 — 2026-10-27
10
+
11
+ **Who `@` offers, and a comment's opening words, once for every app**
12
+ (PEEKM-6; record *a-conversation-is-one-shared-thing-and-only-its-colours-are-the-apps*).
13
+ `namedProfilesOf`, `rosterOf` and `mentionablePeople` map the relay's NIP-43
14
+ roster (`kind:13534`) and each key's `kind:0` into the people `@` and `!@`
15
+ offer: the roster's named profiles, agents included, never the viewer, by
16
+ name ignoring case and accents (`byName`). `openingWords` is a message's
17
+ caption on one line, as `[`'s row for a comment shows it: marks and line
18
+ prefixes gone, a link as its words, a person as `@Name`, and any other
19
+ reference by its type word ("Issue", "Message", "File") so it is never blank
20
+ (SPEC §13.1). Peek, Ship and Leaf each had their own copy, and Ship's and
21
+ Leaf's dropped a reference and kept a link's raw `[words](url)`.
22
+
23
+ SPEC: none changed. These read §13.1's references and NIP-43's roster as
24
+ before; they only move the reading into one place.
25
+
26
+ ## 0.19.0 — 2026-10-27
27
+
28
+ **An edit with no files takes every file off** (SPEC §6.8 as amended in
29
+ estiva-docs#334; record *an-edit-is-the-whole-new-message*; 8de3e4b4). A
30
+ message's files are the `imeta` of its latest edit, and an edit listing none
31
+ leaves it with none; before, an edit with no `imeta` meant "unchanged" and the
32
+ latest edit carrying any won. `foldAttachments` drops a message whose latest
33
+ edit lists nothing, and `EditFold.attachments` is now always present — the
34
+ latest edit's set, empty for none. Cards (`embed`) keep their fold. Every
35
+ writer has listed a message's files on every edit since 27 Oct (Peek, Ship,
36
+ Leaf, estiva-agent), and the messages whose files this would have hidden were
37
+ re-saved first, so nothing on production changes but the ability to empty.
38
+
9
39
  ## 0.18.0 — 2026-10-20
10
40
 
11
41
  **An edit opens a nested list nested** (SPEC §13.2; PEE-57; Miky,
package/dist/edits.d.ts CHANGED
@@ -8,9 +8,9 @@
8
8
  * edits up by id.
9
9
  *
10
10
  * An edit changes the body, the attachments and the cards, and nothing else.
11
- * Attachments fold separately: the set is the `imeta` of the latest edit
12
- * carrying at least one, and a set replaces rather than appends. Cards
13
- * (`embed`, §13.6.2) fold the same way ({@link foldEmbeds}). The "edited" mark is about the
11
+ * An edit is the whole new message: the files are the `imeta` of the latest
12
+ * edit, and an edit with none takes every file off. Cards (`embed`, §13.6.2)
13
+ * keep the older fold, the latest edit carrying any ({@link foldEmbeds}). The "edited" mark is about the
14
14
  * **body**: an edit byte-identical to the body it replaces, judged against the
15
15
  * body as it then stood, does not mark the message edited.
16
16
  *
@@ -46,11 +46,12 @@ export interface EditFold {
46
46
  /** Who wrote the edit that last changed the body. Absent unless `edited`. */
47
47
  editedBy?: string;
48
48
  /**
49
- * The `imeta` set of the latest edit carrying at least one. Absent when no
50
- * edit carries one: the message's own attachments stand, because an edit
51
- * with no `imeta` means "unchanged", never "none".
49
+ * The `imeta` set of the latest edit, which replaces the message's own;
50
+ * empty when that edit lists none, and then the message has no files.
51
+ *
52
+ * why: https://github.com/estiva-app/estiva-docs/blob/main/decisions/an-edit-is-the-whole-new-message.md
52
53
  */
53
- attachments?: Imeta[];
54
+ attachments: Imeta[];
54
55
  }
55
56
  /**
56
57
  * Every `kind:40003` in `events`, grouped by {@link editTargetOf}, oldest first
@@ -71,13 +72,16 @@ export declare function foldEdits(events: readonly SignedEvent[], targets?: read
71
72
  }[]): Record<string, EditFold>;
72
73
  /**
73
74
  * Every message's current attachment set: its own `imeta`, replaced by the
74
- * latest edit carrying any (§6.8, C15). Messages with none are absent.
75
+ * latest edit's, an edit with none taking every file off (§6.8, C15).
76
+ * Messages with none are absent.
77
+ *
78
+ * why: https://github.com/estiva-app/estiva-docs/blob/main/decisions/an-edit-is-the-whole-new-message.md
75
79
  */
76
80
  export declare function foldAttachments(events: readonly SignedEvent[]): Record<string, Imeta[]>;
77
81
  /**
78
82
  * Every message's current card set: its own `embed` tags, replaced by the
79
- * latest edit carrying any (§6.8, §13.6.2, C20) — the same fold as
80
- * {@link foldAttachments}. An edit with none leaves the set; `none` is how an
83
+ * latest edit carrying any (§6.8, §13.6.2, C20) — the fold attachments
84
+ * had before an edit became the whole new message. An edit with none leaves the set; `none` is how an
81
85
  * edit removes a card. Which of these the body still names is
82
86
  * `cardsIn`'s question, asked of the folded body. Messages with none are absent.
83
87
  *
@@ -1 +1 @@
1
- {"version":3,"file":"edits.d.ts","sourceRoot":"","sources":["../src/edits.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;GAmBG;AACH,OAAO,EAAqB,KAAK,KAAK,EAAE,KAAK,KAAK,EAAE,KAAK,WAAW,EAAE,MAAM,sBAAsB,CAAA;AAIlG;;;;;;;;;;GAUG;AACH,wBAAgB,YAAY,CAAC,KAAK,EAAE,IAAI,CAAC,WAAW,EAAE,MAAM,CAAC,GAAG,MAAM,GAAG,SAAS,CAGjF;AAED,mCAAmC;AACnC,MAAM,WAAW,QAAQ;IACvB,mDAAmD;IACnD,IAAI,EAAE,MAAM,CAAA;IACZ;;;;OAIG;IACH,MAAM,EAAE,OAAO,CAAA;IACf,kGAAkG;IAClG,QAAQ,CAAC,EAAE,MAAM,CAAA;IACjB,6EAA6E;IAC7E,QAAQ,CAAC,EAAE,MAAM,CAAA;IACjB;;;;OAIG;IACH,WAAW,CAAC,EAAE,KAAK,EAAE,CAAA;CACtB;AAED;;;GAGG;AACH,wBAAgB,aAAa,CAAC,MAAM,EAAE,SAAS,WAAW,EAAE,GAAG,GAAG,CAAC,MAAM,EAAE,WAAW,EAAE,CAAC,CAcxF;AAED;;;;;;;GAOG;AACH,wBAAgB,SAAS,CACvB,MAAM,EAAE,SAAS,WAAW,EAAE,EAC9B,OAAO,GAAE,SAAS;IAAE,EAAE,EAAE,MAAM,CAAC;IAAC,I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M,CAAA;CAAE,EAAO,GACpD,MAAM,CAAC,MAAM,EAAE,QAAQ,CAAC,CAsB1B;AAED;;;;;;GAMG;AACH,wBAAgB,eAAe,CAAC,MAAM,EAAE,SAAS,WAAW,EAAE,GAAG,MAAM,CAAC,MAAM,EAAE,KAAK,EAAE,CAAC,CAavF;AAED;;;;;;;;GAQG;AACH,wBAAgB,UAAU,CAAC,MAAM,EAAE,SAAS,WAAW,EAAE,GAAG,MAAM,CAAC,MAAM,EAAE,KAAK,EAAE,CAAC,CAgBlF"}
package/dist/edits.js CHANGED
@@ -8,9 +8,9 @@
8
8
  * edits up by id.
9
9
  *
10
10
  * An edit changes the body, the attachments and the cards, and nothing else.
11
- * Attachments fold separately: the set is the `imeta` of the latest edit
12
- * carrying at least one, and a set replaces rather than appends. Cards
13
- * (`embed`, §13.6.2) fold the same way ({@link foldEmbeds}). The "edited" mark is about the
11
+ * An edit is the whole new message: the files are the `imeta` of the latest
12
+ * edit, and an edit with none takes every file off. Cards (`embed`, §13.6.2)
13
+ * keep the older fold, the latest edit carrying any ({@link foldEmbeds}). The "edited" mark is about the
14
14
  * **body**: an edit byte-identical to the body it replaces, judged against the
15
15
  * body as it then stood, does not mark the message edited.
16
16
  *
@@ -79,27 +79,27 @@ export function foldEdits(events, targets = []) {
79
79
  for (const [target, list] of editsByTarget(events)) {
80
80
  let body = bodies.get(target);
81
81
  let changed;
82
- let attachments;
83
82
  for (const edit of list) {
84
83
  if (body === undefined || edit.content !== body)
85
84
  changed = edit;
86
85
  body = edit.content;
87
- const files = imetaOf(edit);
88
- if (files.length > 0)
89
- attachments = files;
90
86
  }
87
+ const latest = list[list.length - 1];
91
88
  out[target] = {
92
- body: list[list.length - 1].content,
89
+ body: latest.content,
93
90
  edited: changed !== undefined,
94
91
  ...(changed ? { editedAt: orderingMs(changed), editedBy: changed.pubkey } : {}),
95
- ...(attachments ? { attachments } : {}),
92
+ attachments: imetaOf(latest),
96
93
  };
97
94
  }
98
95
  return out;
99
96
  }
100
97
  /**
101
98
  * Every message's current attachment set: its own `imeta`, replaced by the
102
- * latest edit carrying any (§6.8, C15). Messages with none are absent.
99
+ * latest edit's, an edit with none taking every file off (§6.8, C15).
100
+ * Messages with none are absent.
101
+ *
102
+ * why: https://github.com/estiva-app/estiva-docs/blob/main/decisions/an-edit-is-the-whole-new-message.md
103
103
  */
104
104
  export function foldAttachments(events) {
105
105
  const out = {};
@@ -111,20 +111,18 @@ export function foldAttachments(events) {
111
111
  out[event.id.toLowerCase()] = files;
112
112
  }
113
113
  for (const [target, list] of editsByTarget(events)) {
114
- for (let i = list.length - 1; i >= 0; i--) {
115
- const files = imetaOf(list[i]);
116
- if (files.length === 0)
117
- continue;
114
+ const files = imetaOf(list[list.length - 1]);
115
+ if (files.length > 0)
118
116
  out[target] = files;
119
- break;
120
- }
117
+ else
118
+ delete out[target];
121
119
  }
122
120
  return out;
123
121
  }
124
122
  /**
125
123
  * Every message's current card set: its own `embed` tags, replaced by the
126
- * latest edit carrying any (§6.8, §13.6.2, C20) — the same fold as
127
- * {@link foldAttachments}. An edit with none leaves the set; `none` is how an
124
+ * latest edit carrying any (§6.8, §13.6.2, C20) — the fold attachments
125
+ * had before an edit became the whole new message. An edit with none leaves the set; `none` is how an
128
126
  * edit removes a card. Which of these the body still names is
129
127
  * `cardsIn`'s question, asked of the folded body. Messages with none are absent.
130
128
  *
package/dist/edits.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"edits.js","sourceRoot":"","sources":["../src/edits.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;GAmBG;AACH,OAAO,EAAE,QAAQ,EAAE,OAAO,EAA4C,MAAM,sBAAsB,CAAA;AAClG,OAAO,EAAE,kBAAkB,EAAE,SAAS,EAAE,SAAS,EAAE,MAAM,YAAY,CAAA;AACrE,OAAO,EAAE,OAAO,EAAE,UAAU,EAAE,MAAM,YAAY,CAAA;AAEhD;;;;;;;;;;GAUG;AACH,MAAM,UAAU,YAAY,CAAC,KA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AAC;IACH,CAAC;IACD,OAAO,GAAG,CAAA;AACZ,CAAC"}
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.18.0";
15
+ export declare const CONVERSATION_VERSION = "0.20.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';
@@ -29,5 +29,7 @@ export { KIND_CHANGE, MEMBER_FIELD_PREFIX, memberField, memberOfField, mentions,
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
31
  export { peopleNamedInText, newlyNamedPeople, mentionAddsFor, type FileText } from './textMentions.js';
32
+ export { KIND_MEMBERSHIP_LIST, namedProfilesOf, rosterOf, byName, mentionablePeople, type NamedProfile } from './people.js';
33
+ export { openingWords, referenceWord } from './openingWords.js';
32
34
  export { createDraftStore, draftKeys, NO_DRAFTS, DRAFT_MAX_AGE_MS, DRAFT_MAX_CHARS, type Draft, type DraftStore, type DraftStorage, } from './drafts.js';
33
35
  //# 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,WAAW,EACX,iBAAiB,EACjB,UAAU,EACV,cAAc,EACd,gBAAgB,EAChB,cAAc,EACd,iBAAiB,EACjB,oBAAoB,EACpB,KAAK,QAAQ,GACd,MAAM,eAAe,CAAA;AAEtB,OAAO,EAAE,QAAQ,EAAE,YAAY,EAAE,KAAK,QAAQ,EAAE,MAAM,cAAc,CAAA;AAEpE,OAAO,EAAE,YAAY,EAAE,aAAa,EAAE,SAAS,EAAE,eAAe,EAAE,UAAU,EAAE,KAAK,QAAQ,EAAE,MAAM,YAAY,CAAA;AAE/G,OAAO,EACL,gBAAgB,EAChB,cAAc,EACd,gBAAgB,EAChB,eAAe,EACf,eAAe,EACf,gBAAgB,EAChB,aAAa,EACb,cAAc,EACd,KAAK,eAAe,EACpB,KAAK,aAAa,EAClB,KAAK,QAAQ,GACd,MAAM,gBAAgB,CAAA;AAEvB,OAAO,EAAE,aAAa,EAAE,KAAK,UAAU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Aa,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,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"}
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,UAA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AAgB,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,EAAE,oBAAoB,EAAE,eAAe,EAAE,QAAQ,EAAE,MAAM,EAAE,iBAAiB,EAAE,KAAK,YAAY,EAAE,MAAM,aAAa,CAAA;AAE3H,OAAO,EAAE,YAAY,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAA;AAE/D,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.18.0';
15
+ export const CONVERSATION_VERSION = '0.20.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';
@@ -29,5 +29,7 @@ export { KIND_CHANGE, MEMBER_FIELD_PREFIX, memberField, memberOfField, mentions,
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
31
  export { peopleNamedInText, newlyNamedPeople, mentionAddsFor } from './textMentions.js';
32
+ export { KIND_MEMBERSHIP_LIST, namedProfilesOf, rosterOf, byName, mentionablePeople } from './people.js';
33
+ export { openingWords, referenceWord } from './openingWords.js';
32
34
  export { createDraftStore, draftKeys, NO_DRAFTS, DRAFT_MAX_AGE_MS, DRAFT_MAX_CHARS, } from './drafts.js';
33
35
  //# 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,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,WAAW,EACX,iBAAiB,EACjB,UAAU,EACV,cAAc,EACd,gBAAgB,EAChB,cAAc,EACd,iBAAiB,EACjB,oBAAoB,GAErB,MAAM,eAAe,CAAA;AAEtB,OAAO,EAAE,QAAQ,EAAE,YAAY,EAAiB,MAAM,cAAc,CAAA;AAEpE,OAAO,EAAE,YAAY,EAAE,aAAa,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,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,EAAE,oBAAoB,EAAE,eAAe,EAAE,QAAQ,EAAE,MAAM,EAAE,iBAAiB,EAAqB,MAAM,aAAa,CAAA;AAE3H,OAAO,EAAE,YAAY,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAA;AAE/D,OAAO,EACL,gBAAgB,EAChB,SAAS,EACT,SAAS,EACT,gBAAgB,EAChB,eAAe,GAIhB,MAAM,aAAa,CAAA"}
@@ -0,0 +1,5 @@
1
+ /** What a `nostr:` reference reads as in a caption, by its kind alone, or a person by name. */
2
+ export declare function referenceWord(uri: string, nameOf: (pubkey: string) => string | undefined): string;
3
+ /** A message body's opening words on one line, as a caption: see the module's note. */
4
+ export declare function openingWords(body: string, nameOf: (pubkey: string) => string | undefined): string;
5
+ //# sourceMappingURL=openingWords.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"openingWords.d.ts","sourceRoot":"","sources":["../src/openingWords.ts"],"names":[],"mappings":"AAuCA,+FAA+F;AAC/F,wBAAgB,aAAa,CAAC,GAAG,EAAE,MAAM,EAAE,MAAM,EAAE,CAAC,MAAM,EAAE,MAAM,KAAK,MAAM,GAAG,SAAS,GAAG,MAAM,CAoBjG;AAiBD,uFAAuF;AACvF,wBAAgB,YAAY,CAAC,IAAI,EAAE,MAAM,EAAE,MAAM,EAAE,CAAC,MAAM,EAAE,MAAM,KAAK,MAAM,GAAG,SAAS,GAAG,MAAM,CAQjG"}
@@ -0,0 +1,86 @@
1
+ /**
2
+ * A message's opening words, as a caption — what `[`'s row for a comment
3
+ * shows under its author, the same in every app (PEEKM-6).
4
+ *
5
+ * One line of plain words: marks and line prefixes gone, a link on words as
6
+ * its words, a fenced code block's fences dropped. A `nostr:` reference reads
7
+ * as its chip would without resolving anything (SPEC §13.1: "the URI's own
8
+ * label or its shortened form, never blank"):
9
+ *
10
+ * - a person as `@Name`, or `@` and the key's shortened form when nobody here
11
+ * can name them;
12
+ * - a message as "Message", a file by its type word ("Issue", "Project",
13
+ * "Topic", "Document"), any other address as "File" — never by its title,
14
+ * so the same comment reads the same in an app that has the file loaded and
15
+ * one that does not (Miky, 27 October, PEEKM-6's kickoff).
16
+ *
17
+ * why: https://github.com/estiva-app/estiva-docs/blob/main/decisions/a-conversation-is-one-shared-thing-and-only-its-colours-are-the-apps.md
18
+ */
19
+ import { decodeNpub, parseInlineMarks, referenceToPointer } from '@estiva-app/protocol';
20
+ /** A file's type word by its kind, as `[`'s Files rows name it. */
21
+ const TYPE_WORDS = { 30850: 'Project', 30851: 'Issue', 30840: 'Topic', 30842: 'Document', 39000: 'Folder' };
22
+ const FENCE = /^\s*(?:```|~~~)/;
23
+ /** A line's block prefixes: quotes and headings, then one list or task marker. */
24
+ const LINE_PREFIX = /^\s*(?:(?:>|#{1,6})\s+)*(?:(?:[-*+]|\d+[.)])\s+(?:\[[ xX]\]\s+)?)?/;
25
+ /**
26
+ * A link on words, `[words](url)`: its words are what a reader sees. Swapped before the marks are read, so a `_` in a
27
+ * URL is never one. The grammar is protocol's `parseInlineMarksAndLinks`, so what reads as a link here is what a reader
28
+ * draws as one: a URL with an unclosed `(` (`…/Foo_(bar)`) is no link there, and stays as written here.
29
+ */
30
+ const LINK_ON_WORDS = /(?<!!)\[([^[\]\n]+)\]\(((?:https?:\/\/|mailto:)[^\s)]+)\)/g;
31
+ const linkWords = (whole, words, url) => (url.split('(').length > url.split(')').length ? whole : words);
32
+ /** The shortened form §13.1 asks for when a reference names nobody here. */
33
+ function shortened(uri) {
34
+ return `${uri.replace(/^nostr:/i, '').slice(0, 12)}…`;
35
+ }
36
+ /** What a `nostr:` reference reads as in a caption, by its kind alone, or a person by name. */
37
+ export function referenceWord(uri, nameOf) {
38
+ const bare = uri.replace(/^nostr:/i, '').toLowerCase();
39
+ if (bare.startsWith('npub1')) {
40
+ let name;
41
+ try {
42
+ name = nameOf(decodeNpub(bare));
43
+ }
44
+ catch {
45
+ name = undefined;
46
+ }
47
+ return `@${name || shortened(uri)}`;
48
+ }
49
+ if (bare.startsWith('naddr1')) {
50
+ try {
51
+ return TYPE_WORDS[referenceToPointer(bare).kind] ?? 'File';
52
+ }
53
+ catch {
54
+ return 'File';
55
+ }
56
+ }
57
+ if (bare.startsWith('nevent1') || bare.startsWith('note1'))
58
+ return 'Message';
59
+ return `@${shortened(uri)}`;
60
+ }
61
+ /**
62
+ * One line's words. Protocol's mark reader recurses once per mark, so a line of a few thousand (anyone can post one)
63
+ * overflows the stack; that line then reads as its text with the marker characters dropped, rather than taking down
64
+ * every `[` list that captions it (Peek: Feedback & Bugs 4acb43ac is the reader's own fix).
65
+ */
66
+ function lineWords(line, nameOf) {
67
+ try {
68
+ return parseInlineMarks(line)
69
+ .map((span) => (span.reference ? referenceWord(span.reference, nameOf) : span.text))
70
+ .join('');
71
+ }
72
+ catch {
73
+ return line.replace(/[*_~`]+/g, '');
74
+ }
75
+ }
76
+ /** A message body's opening words on one line, as a caption: see the module's note. */
77
+ export function openingWords(body, nameOf) {
78
+ return body
79
+ .split('\n')
80
+ .filter((line) => !FENCE.test(line))
81
+ .map((line) => lineWords(line.replace(LINE_PREFIX, '').replace(LINK_ON_WORDS, linkWords), nameOf))
82
+ .join(' ')
83
+ .replace(/\s+/g, ' ')
84
+ .trim();
85
+ }
86
+ //# sourceMappingURL=openingWords.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"openingWords.js","sourceRoot":"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CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,SAAS,CAAC,IAAI,CAAC,OAAO,CAAC,WAAW,EAAE,EAAE,CAAC,CAAC,OAAO,CAAC,aAAa,EAAE,SAAS,CAAC,EAAE,MAAM,CAAC,CAAC;SACjG,IAAI,CAAC,GAAG,CAAC;SACT,OAAO,CAAC,MAAM,EAAE,GAAG,CAAC;SACpB,IAAI,EAAE,CAAA;AACX,CAAC"}
@@ -0,0 +1,48 @@
1
+ /** NIP-43's relay membership list. */
2
+ export declare const KIND_MEMBERSHIP_LIST = 13534;
3
+ /** A named profile: what `@`'s row draws, and what a mention of the key reads as. */
4
+ export interface NamedProfile {
5
+ pubkey: string;
6
+ name: string;
7
+ picture?: string;
8
+ /** NIP-24's `bot: true`, an agent's profile. Present only when true. */
9
+ bot?: true;
10
+ }
11
+ type ProfileEvent = {
12
+ kind: number;
13
+ pubkey: string;
14
+ created_at: number;
15
+ content: string;
16
+ id?: string;
17
+ };
18
+ type RosterEvent = {
19
+ kind: number;
20
+ created_at: number;
21
+ tags: string[][];
22
+ id?: string;
23
+ };
24
+ /**
25
+ * Every named profile, newest `kind:0` per key, as protocol's `parseProfile`
26
+ * reads one. Not narrowed to the roster: this answers "what is this key
27
+ * called", which a mention of the viewer, or of someone who has left, still
28
+ * needs answered.
29
+ */
30
+ export declare function namedProfilesOf(events: readonly ProfileEvent[]): Map<string, NamedProfile>;
31
+ /** The newest roster's members, or `null` when the relay keeps no roster. */
32
+ export declare function rosterOf(events: readonly RosterEvent[]): Set<string> | null;
33
+ /** By name, ignoring case and accents: "anna" sits beside "Anna", "Émile" beside "Emile". */
34
+ export declare function byName(a: {
35
+ name: string;
36
+ }, b: {
37
+ name: string;
38
+ }): number;
39
+ /**
40
+ * Whom `@` and `!@` offer: the named profiles on the roster, never the viewer,
41
+ * by name. With no roster (a relay that keeps none), every named profile given.
42
+ */
43
+ export declare function mentionablePeople<P extends {
44
+ pubkey: string;
45
+ name: string;
46
+ }>(profiles: Iterable<P>, roster: ReadonlySet<string> | null, me: string | null | undefined): P[];
47
+ export {};
48
+ //# sourceMappingURL=people.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"people.d.ts","sourceRoot":"","sources":["../src/people.ts"],"names":[],"mappings":"AAmBA,sCAAsC;AACtC,eAAO,MAAM,oBAAoB,QAAQ,CAAA;AAEzC,qFAAqF;AACrF,MAAM,WAAW,YAAY;IAC3B,MAAM,EAAE,MAAM,CAAA;IACd,IAAI,EAAE,MAAM,CAAA;IACZ,OAAO,CAAC,EAAE,MAAM,CAAA;IAChB,wEAAwE;IACxE,GAAG,CAAC,EAAE,IAAI,CAAA;CACX;AAED,KAAK,YAAY,GAAG;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,MAAM,EAAE,MAAM,CAAC;IAAC,UAAU,EAAE,MAAM,CAAC;IAAC,OAAO,EAAE,MAAM,CAAC;IAAC,EAAE,CAAC,EAAE,MAAM,CAAA;CAAE,CAAA;AACtG,KAAK,WAAW,GAAG;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,UAAU,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,MAAM,EAAE,EAAE,CAAC;IAAC,EAAE,CAAC,EAAE,MAAM,CAAA;CAAE,CAAA;AAOtF;;;;;GAKG;AACH,wBAAgB,eAAe,CAAC,MAAM,EAAE,SAAS,YAAY,EAAE,GAAG,GAAG,CAAC,MAAM,EAAE,YAAY,CAAC,CAe1F;AAED,6EAA6E;AAC7E,wBAAgB,QAAQ,CAAC,MAAM,EAAE,SAAS,WAAW,EAAE,GAAG,GAAG,CAAC,MAAM,CAAC,GAAG,IAAI,CAI3E;AAED,6FAA6F;AAC7F,wBAAgB,MAAM,CAAC,CAAC,EAAE;IAAE,IAAI,EAAE,MAAM,CAAA;CAAE,EAAE,CAAC,EAAE;IAAE,IAAI,EAAE,MAAM,CAAA;CAAE,GAAG,MAAM,CAEvE;AAED;;;GAGG;AACH,wBAAgB,iBAAiB,CAAC,CAAC,SAAS;IAAE,MAAM,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,MAAM,CAAA;CAAE,EAC1E,QAAQ,EAAE,QAAQ,CAAC,CAAC,CAAC,EACrB,MAAM,EAAE,WAAW,CAAC,MAAM,CAAC,GAAG,IAAI,EAClC,EAAE,EAAE,MAAM,GAAG,IAAI,GAAG,SAAS,GAC5B,CAAC,EAAE,CAEL"}
package/dist/people.js ADDED
@@ -0,0 +1,68 @@
1
+ /**
2
+ * Who `@` and `!@` offer in a comment box — one list of people in every app
3
+ * (PEEKM-6; Miky, 20 October: "There is one set of people").
4
+ *
5
+ * The workspace's people are two relay facts: the relay's NIP-43 roster
6
+ * (`kind:13534`, one `member` tag per admitted key) and each key's profile
7
+ * (`kind:0`). `@` offers the roster's keys that have a named profile, agents
8
+ * included (mentioning one is how you ask it something), never the viewer,
9
+ * by name. A roster key with no named profile is left out: the roster also
10
+ * lists keys that are not people (an app's manifest key), and a shortened key
11
+ * is nobody a person can pick.
12
+ *
13
+ * Each app still reads the events its own way; this only maps them, so the
14
+ * same events give the same list, in the same order, everywhere.
15
+ *
16
+ * why: https://github.com/estiva-app/estiva-docs/blob/main/decisions/a-conversation-is-one-shared-thing-and-only-its-colours-are-the-apps.md
17
+ */
18
+ import { parseProfile } from '@estiva-app/protocol';
19
+ /** NIP-43's relay membership list. */
20
+ export const KIND_MEMBERSHIP_LIST = 13534;
21
+ /** Newer first; on the same second, the lowest id (NIP-01), so every app picks the same one whatever order its events came in. */
22
+ function newerFirst(a, b) {
23
+ return b.created_at - a.created_at || (a.id ?? '').localeCompare(b.id ?? '');
24
+ }
25
+ /**
26
+ * Every named profile, newest `kind:0` per key, as protocol's `parseProfile`
27
+ * reads one. Not narrowed to the roster: this answers "what is this key
28
+ * called", which a mention of the viewer, or of someone who has left, still
29
+ * needs answered.
30
+ */
31
+ export function namedProfilesOf(events) {
32
+ const newest = new Map();
33
+ for (const e of events) {
34
+ if (e.kind !== 0)
35
+ continue;
36
+ const seen = newest.get(e.pubkey);
37
+ if (!seen || newerFirst(e, seen) < 0)
38
+ newest.set(e.pubkey, e);
39
+ }
40
+ const out = new Map();
41
+ for (const [pubkey, event] of newest) {
42
+ const { displayName, picture, bot } = parseProfile(event);
43
+ const name = displayName?.trim() ? displayName : undefined;
44
+ if (!name)
45
+ continue;
46
+ out.set(pubkey, { pubkey, name, ...(picture ? { picture } : {}), ...(bot ? { bot } : {}) });
47
+ }
48
+ return out;
49
+ }
50
+ /** The newest roster's members, or `null` when the relay keeps no roster. */
51
+ export function rosterOf(events) {
52
+ const roster = events.filter((e) => e.kind === KIND_MEMBERSHIP_LIST).sort(newerFirst)[0];
53
+ if (!roster)
54
+ return null;
55
+ return new Set(roster.tags.filter((t) => (t[0] === 'member' || t[0] === 'p') && /^[0-9a-f]{64}$/.test(t[1] ?? '')).map((t) => t[1]));
56
+ }
57
+ /** By name, ignoring case and accents: "anna" sits beside "Anna", "Émile" beside "Emile". */
58
+ export function byName(a, b) {
59
+ return a.name.localeCompare(b.name, undefined, { sensitivity: 'base' });
60
+ }
61
+ /**
62
+ * Whom `@` and `!@` offer: the named profiles on the roster, never the viewer,
63
+ * by name. With no roster (a relay that keeps none), every named profile given.
64
+ */
65
+ export function mentionablePeople(profiles, roster, me) {
66
+ return [...profiles].filter((p) => p.pubkey !== me && p.name.trim() !== '' && (!roster || roster.has(p.pubkey))).sort(byName);
67
+ }
68
+ //# sourceMappingURL=people.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"people.js","sourceRoot":"","sources":["../src/people.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AACH,OAAO,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAA;AAEnD,sCAAsC;AACtC,MAAM,CAAC,MAAM,oBAAoB,GAAG,KAAK,CAAA;AAczC,kIAAkI;AAClI,SAAS,UAAU,CAAC,CAAsC,EAAE,CAAsC;IAChG,OAAO,CAAC,CAAC,UAAU,GAAG,CAAC,CAAC,UAAU,IAAI,CAAC,C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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@estiva-app/conversation",
3
- "version": "0.18.0",
3
+ "version": "0.20.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/edits.ts CHANGED
@@ -8,9 +8,9 @@
8
8
  * edits up by id.
9
9
  *
10
10
  * An edit changes the body, the attachments and the cards, and nothing else.
11
- * Attachments fold separately: the set is the `imeta` of the latest edit
12
- * carrying at least one, and a set replaces rather than appends. Cards
13
- * (`embed`, §13.6.2) fold the same way ({@link foldEmbeds}). The "edited" mark is about the
11
+ * An edit is the whole new message: the files are the `imeta` of the latest
12
+ * edit, and an edit with none takes every file off. Cards (`embed`, §13.6.2)
13
+ * keep the older fold, the latest edit carrying any ({@link foldEmbeds}). The "edited" mark is about the
14
14
  * **body**: an edit byte-identical to the body it replaces, judged against the
15
15
  * body as it then stood, does not mark the message edited.
16
16
  *
@@ -53,11 +53,12 @@ export interface EditFold {
53
53
  /** Who wrote the edit that last changed the body. Absent unless `edited`. */
54
54
  editedBy?: string
55
55
  /**
56
- * The `imeta` set of the latest edit carrying at least one. Absent when no
57
- * edit carries one: the message's own attachments stand, because an edit
58
- * with no `imeta` means "unchanged", never "none".
56
+ * The `imeta` set of the latest edit, which replaces the message's own;
57
+ * empty when that edit lists none, and then the message has no files.
58
+ *
59
+ * why: https://github.com/estiva-app/estiva-docs/blob/main/decisions/an-edit-is-the-whole-new-message.md
59
60
  */
60
- attachments?: Imeta[]
61
+ attachments: Imeta[]
61
62
  }
62
63
 
63
64
  /**
@@ -100,18 +101,16 @@ export function foldEdits(
100
101
  for (const [target, list] of editsByTarget(events)) {
101
102
  let body = bodies.get(target)
102
103
  let changed: SignedEvent | undefined
103
- let attachments: Imeta[] | undefined
104
104
  for (const edit of list) {
105
105
  if (body === undefined || edit.content !== body) changed = edit
106
106
  body = edit.content
107
- const files = imetaOf(edit)
108
- if (files.length > 0) attachments = files
109
107
  }
108
+ const latest = list[list.length - 1]
110
109
  out[target] = {
111
- body: list[list.length - 1].content,
110
+ body: latest.content,
112
111
  edited: changed !== undefined,
113
112
  ...(changed ? { editedAt: orderingMs(changed), editedBy: changed.pubkey } : {}),
114
- ...(attachments ? { attachments } : {}),
113
+ attachments: imetaOf(latest),
115
114
  }
116
115
  }
117
116
  return out
@@ -119,7 +118,10 @@ export function foldEdits(
119
118
 
120
119
  /**
121
120
  * Every message's current attachment set: its own `imeta`, replaced by the
122
- * latest edit carrying any (§6.8, C15). Messages with none are absent.
121
+ * latest edit's, an edit with none taking every file off (§6.8, C15).
122
+ * Messages with none are absent.
123
+ *
124
+ * why: https://github.com/estiva-app/estiva-docs/blob/main/decisions/an-edit-is-the-whole-new-message.md
123
125
  */
124
126
  export function foldAttachments(events: readonly SignedEvent[]): Record<string, Imeta[]> {
125
127
  const out: Record<string, Imeta[]> = {}
@@ -129,20 +131,17 @@ export function foldAttachments(events: readonly SignedEvent[]): Record<string,
129
131
  if (files.length > 0) out[event.id.toLowerCase()] = files
130
132
  }
131
133
  for (const [target, list] of editsByTarget(events)) {
132
- for (let i = list.length - 1; i >= 0; i--) {
133
- const files = imetaOf(list[i])
134
- if (files.length === 0) continue
135
- out[target] = files
136
- break
137
- }
134
+ const files = imetaOf(list[list.length - 1])
135
+ if (files.length > 0) out[target] = files
136
+ else delete out[target]
138
137
  }
139
138
  return out
140
139
  }
141
140
 
142
141
  /**
143
142
  * Every message's current card set: its own `embed` tags, replaced by the
144
- * latest edit carrying any (§6.8, §13.6.2, C20) — the same fold as
145
- * {@link foldAttachments}. An edit with none leaves the set; `none` is how an
143
+ * latest edit carrying any (§6.8, §13.6.2, C20) — the fold attachments
144
+ * had before an edit became the whole new message. An edit with none leaves the set; `none` is how an
146
145
  * edit removes a card. Which of these the body still names is
147
146
  * `cardsIn`'s question, asked of the folded body. Messages with none are absent.
148
147
  *
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.18.0'
15
+ export const CONVERSATION_VERSION = '0.20.0'
16
16
 
17
17
  export {
18
18
  KIND_MESSAGE,
@@ -183,6 +183,10 @@ export { unreadIn, isUnread, type StreamJudge } from './unread.js'
183
183
 
184
184
  export { peopleNamedInText, newlyNamedPeople, mentionAddsFor, type FileText } from './textMentions.js'
185
185
 
186
+ export { KIND_MEMBERSHIP_LIST, namedProfilesOf, rosterOf, byName, mentionablePeople, type NamedProfile } from './people.js'
187
+
188
+ export { openingWords, referenceWord } from './openingWords.js'
189
+
186
190
  export {
187
191
  createDraftStore,
188
192
  draftKeys,
@@ -0,0 +1,87 @@
1
+ /**
2
+ * A message's opening words, as a caption — what `[`'s row for a comment
3
+ * shows under its author, the same in every app (PEEKM-6).
4
+ *
5
+ * One line of plain words: marks and line prefixes gone, a link on words as
6
+ * its words, a fenced code block's fences dropped. A `nostr:` reference reads
7
+ * as its chip would without resolving anything (SPEC §13.1: "the URI's own
8
+ * label or its shortened form, never blank"):
9
+ *
10
+ * - a person as `@Name`, or `@` and the key's shortened form when nobody here
11
+ * can name them;
12
+ * - a message as "Message", a file by its type word ("Issue", "Project",
13
+ * "Topic", "Document"), any other address as "File" — never by its title,
14
+ * so the same comment reads the same in an app that has the file loaded and
15
+ * one that does not (Miky, 27 October, PEEKM-6's kickoff).
16
+ *
17
+ * why: https://github.com/estiva-app/estiva-docs/blob/main/decisions/a-conversation-is-one-shared-thing-and-only-its-colours-are-the-apps.md
18
+ */
19
+ import { decodeNpub, parseInlineMarks, referenceToPointer } from '@estiva-app/protocol'
20
+
21
+ /** A file's type word by its kind, as `[`'s Files rows name it. */
22
+ const TYPE_WORDS: Record<number, string> = { 30850: 'Project', 30851: 'Issue', 30840: 'Topic', 30842: 'Document', 39000: 'Folder' }
23
+
24
+ const FENCE = /^\s*(?:```|~~~)/
25
+ /** A line's block prefixes: quotes and headings, then one list or task marker. */
26
+ const LINE_PREFIX = /^\s*(?:(?:>|#{1,6})\s+)*(?:(?:[-*+]|\d+[.)])\s+(?:\[[ xX]\]\s+)?)?/
27
+ /**
28
+ * A link on words, `[words](url)`: its words are what a reader sees. Swapped before the marks are read, so a `_` in a
29
+ * URL is never one. The grammar is protocol's `parseInlineMarksAndLinks`, so what reads as a link here is what a reader
30
+ * draws as one: a URL with an unclosed `(` (`…/Foo_(bar)`) is no link there, and stays as written here.
31
+ */
32
+ const LINK_ON_WORDS = /(?<!!)\[([^[\]\n]+)\]\(((?:https?:\/\/|mailto:)[^\s)]+)\)/g
33
+ const linkWords = (whole: string, words: string, url: string) => (url.split('(').length > url.split(')').length ? whole : words)
34
+
35
+ /** The shortened form §13.1 asks for when a reference names nobody here. */
36
+ function shortened(uri: string): string {
37
+ return `${uri.replace(/^nostr:/i, '').slice(0, 12)}…`
38
+ }
39
+
40
+ /** What a `nostr:` reference reads as in a caption, by its kind alone, or a person by name. */
41
+ export function referenceWord(uri: string, nameOf: (pubkey: string) => string | undefined): string {
42
+ const bare = uri.replace(/^nostr:/i, '').toLowerCase()
43
+ if (bare.startsWith('npub1')) {
44
+ let name: string | undefined
45
+ try {
46
+ name = nameOf(decodeNpub(bare))
47
+ } catch {
48
+ name = undefined
49
+ }
50
+ return `@${name || shortened(uri)}`
51
+ }
52
+ if (bare.startsWith('naddr1')) {
53
+ try {
54
+ return TYPE_WORDS[referenceToPointer(bare).kind] ?? 'File'
55
+ } catch {
56
+ return 'File'
57
+ }
58
+ }
59
+ if (bare.startsWith('nevent1') || bare.startsWith('note1')) return 'Message'
60
+ return `@${shortened(uri)}`
61
+ }
62
+
63
+ /**
64
+ * One line's words. Protocol's mark reader recurses once per mark, so a line of a few thousand (anyone can post one)
65
+ * overflows the stack; that line then reads as its text with the marker characters dropped, rather than taking down
66
+ * every `[` list that captions it (Peek: Feedback & Bugs 4acb43ac is the reader's own fix).
67
+ */
68
+ function lineWords(line: string, nameOf: (pubkey: string) => string | undefined): string {
69
+ try {
70
+ return parseInlineMarks(line)
71
+ .map((span) => (span.reference ? referenceWord(span.reference, nameOf) : span.text))
72
+ .join('')
73
+ } catch {
74
+ return line.replace(/[*_~`]+/g, '')
75
+ }
76
+ }
77
+
78
+ /** A message body's opening words on one line, as a caption: see the module's note. */
79
+ export function openingWords(body: string, nameOf: (pubkey: string) => string | undefined): string {
80
+ return body
81
+ .split('\n')
82
+ .filter((line) => !FENCE.test(line))
83
+ .map((line) => lineWords(line.replace(LINE_PREFIX, '').replace(LINK_ON_WORDS, linkWords), nameOf))
84
+ .join(' ')
85
+ .replace(/\s+/g, ' ')
86
+ .trim()
87
+ }
package/src/people.ts ADDED
@@ -0,0 +1,85 @@
1
+ /**
2
+ * Who `@` and `!@` offer in a comment box — one list of people in every app
3
+ * (PEEKM-6; Miky, 20 October: "There is one set of people").
4
+ *
5
+ * The workspace's people are two relay facts: the relay's NIP-43 roster
6
+ * (`kind:13534`, one `member` tag per admitted key) and each key's profile
7
+ * (`kind:0`). `@` offers the roster's keys that have a named profile, agents
8
+ * included (mentioning one is how you ask it something), never the viewer,
9
+ * by name. A roster key with no named profile is left out: the roster also
10
+ * lists keys that are not people (an app's manifest key), and a shortened key
11
+ * is nobody a person can pick.
12
+ *
13
+ * Each app still reads the events its own way; this only maps them, so the
14
+ * same events give the same list, in the same order, everywhere.
15
+ *
16
+ * why: https://github.com/estiva-app/estiva-docs/blob/main/decisions/a-conversation-is-one-shared-thing-and-only-its-colours-are-the-apps.md
17
+ */
18
+ import { parseProfile } from '@estiva-app/protocol'
19
+
20
+ /** NIP-43's relay membership list. */
21
+ export const KIND_MEMBERSHIP_LIST = 13534
22
+
23
+ /** A named profile: what `@`'s row draws, and what a mention of the key reads as. */
24
+ export interface NamedProfile {
25
+ pubkey: string
26
+ name: string
27
+ picture?: string
28
+ /** NIP-24's `bot: true`, an agent's profile. Present only when true. */
29
+ bot?: true
30
+ }
31
+
32
+ type ProfileEvent = { kind: number; pubkey: string; created_at: number; content: string; id?: string }
33
+ type RosterEvent = { kind: number; created_at: number; tags: string[][]; id?: string }
34
+
35
+ /** Newer first; on the same second, the lowest id (NIP-01), so every app picks the same one whatever order its events came in. */
36
+ function newerFirst(a: { created_at: number; id?: string }, b: { created_at: number; id?: string }): number {
37
+ return b.created_at - a.created_at || (a.id ?? '').localeCompare(b.id ?? '')
38
+ }
39
+
40
+ /**
41
+ * Every named profile, newest `kind:0` per key, as protocol's `parseProfile`
42
+ * reads one. Not narrowed to the roster: this answers "what is this key
43
+ * called", which a mention of the viewer, or of someone who has left, still
44
+ * needs answered.
45
+ */
46
+ export function namedProfilesOf(events: readonly ProfileEvent[]): Map<string, NamedProfile> {
47
+ const newest = new Map<string, ProfileEvent>()
48
+ for (const e of events) {
49
+ if (e.kind !== 0) continue
50
+ const seen = newest.get(e.pubkey)
51
+ if (!seen || newerFirst(e, seen) < 0) newest.set(e.pubkey, e)
52
+ }
53
+ const out = new Map<string, NamedProfile>()
54
+ for (const [pubkey, event] of newest) {
55
+ const { displayName, picture, bot } = parseProfile(event)
56
+ const name = displayName?.trim() ? displayName : undefined
57
+ if (!name) continue
58
+ out.set(pubkey, { pubkey, name, ...(picture ? { picture } : {}), ...(bot ? { bot } : {}) })
59
+ }
60
+ return out
61
+ }
62
+
63
+ /** The newest roster's members, or `null` when the relay keeps no roster. */
64
+ export function rosterOf(events: readonly RosterEvent[]): Set<string> | null {
65
+ const roster = events.filter((e) => e.kind === KIND_MEMBERSHIP_LIST).sort(newerFirst)[0]
66
+ if (!roster) return null
67
+ return new Set(roster.tags.filter((t) => (t[0] === 'member' || t[0] === 'p') && /^[0-9a-f]{64}$/.test(t[1] ?? '')).map((t) => t[1]))
68
+ }
69
+
70
+ /** By name, ignoring case and accents: "anna" sits beside "Anna", "Émile" beside "Emile". */
71
+ export function byName(a: { name: string }, b: { name: string }): number {
72
+ return a.name.localeCompare(b.name, undefined, { sensitivity: 'base' })
73
+ }
74
+
75
+ /**
76
+ * Whom `@` and `!@` offer: the named profiles on the roster, never the viewer,
77
+ * by name. With no roster (a relay that keeps none), every named profile given.
78
+ */
79
+ export function mentionablePeople<P extends { pubkey: string; name: string }>(
80
+ profiles: Iterable<P>,
81
+ roster: ReadonlySet<string> | null,
82
+ me: string | null | undefined,
83
+ ): P[] {
84
+ return [...profiles].filter((p) => p.pubkey !== me && p.name.trim() !== '' && (!roster || roster.has(p.pubkey))).sort(byName)
85
+ }