@estiva-app/conversation 0.3.0 → 0.4.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 +16 -0
- package/dist/compose.d.ts +13 -1
- package/dist/compose.d.ts.map +1 -1
- package/dist/compose.js +43 -2
- package/dist/compose.js.map +1 -1
- package/dist/index.d.ts +2 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -2
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/src/compose.ts +41 -2
- package/src/index.ts +2 -2
package/CHANGELOG.md
CHANGED
|
@@ -6,6 +6,22 @@ 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.4.0 — 2026-10-02
|
|
10
|
+
|
|
11
|
+
**A reference records which message it points at** (CON-25, Miky
|
|
12
|
+
2026-10-02). Needs protocol 0.24.0, unchanged.
|
|
13
|
+
|
|
14
|
+
- `quoteTagsFor(body, own?)` — `["q", <event id>]`, one per message the body
|
|
15
|
+
references by `nostr:nevent…` or `nostr:note…`, deduplicated, leaving out
|
|
16
|
+
`own`. A writer appends it to a `kind:9` or a `kind:1111` beside the `p`
|
|
17
|
+
and `a` tags the body earns.
|
|
18
|
+
- `eventsNamedInBody` — the ids behind them.
|
|
19
|
+
|
|
20
|
+
**SPEC:** §13.1 gains the `q` rule (estiva-docs, CON-25): a `q` is an index
|
|
21
|
+
of what a message points at, never a reply, and a writer MUST NOT write one
|
|
22
|
+
for an event its body does not name. Reading is unchanged — nothing in this
|
|
23
|
+
package reads `q` yet.
|
|
24
|
+
|
|
9
25
|
## 0.3.0 — 2026-10-02
|
|
10
26
|
|
|
11
27
|
**What a composer's pick writes** (CON-27): SPEC §13.1, unchanged. Needs
|
package/dist/compose.d.ts
CHANGED
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
* | --- | --- | --- |
|
|
12
12
|
* | a person (`@`) | `nostr:npub…`, or `@Name` with no key | `p`, from {@link mentionTagsFor} |
|
|
13
13
|
* | a person, urgently (`!@`) | the same `nostr:npub…`, or `!@Name` | `p`, and {@link urgentTagsFor}'s `["urgent", <pubkey>]` |
|
|
14
|
-
* | a message (`[`) | `nostr:nevent…` with its kind and no relay |
|
|
14
|
+
* | a message (`[`) | `nostr:nevent…` with its kind and no relay | `q`, from {@link quoteTagsFor} (CON-25) |
|
|
15
15
|
*/
|
|
16
16
|
import { type NostrTag } from '@estiva-app/protocol';
|
|
17
17
|
/**
|
|
@@ -50,4 +50,16 @@ export declare const URGENT_TAG = "urgent";
|
|
|
50
50
|
* cannot say which of the people it names were urgent.
|
|
51
51
|
*/
|
|
52
52
|
export declare function urgentTagsFor(body: string, urgent: readonly string[] | undefined): NostrTag[];
|
|
53
|
+
/** The events a body references by `nostr:nevent…` or `nostr:note…` (§13.1), in the order it names them. */
|
|
54
|
+
export declare function eventsNamedInBody(body: string): Set<string>;
|
|
55
|
+
/**
|
|
56
|
+
* The `q` tags a body earns: `["q", <event id>]`, one per event it references
|
|
57
|
+
* (SPEC §13.1, CON-25). NIP-18's quote, as an index of *which message this one
|
|
58
|
+
* points at* — never a reply, which is `e` (§6.4). Two elements: the relay is
|
|
59
|
+
* the workspace's, and a `[` pick's `nevent` carries no author to fill a third.
|
|
60
|
+
*
|
|
61
|
+
* `own`, when given, is left out — the event a reply already names by `e`, so
|
|
62
|
+
* one message is not both answered and quoted.
|
|
63
|
+
*/
|
|
64
|
+
export declare function quoteTagsFor(body: string, own?: string): NostrTag[];
|
|
53
65
|
//# sourceMappingURL=compose.d.ts.map
|
package/dist/compose.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"compose.d.ts","sourceRoot":"","sources":["../src/compose.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AACH,OAAO,
|
|
1
|
+
{"version":3,"file":"compose.d.ts","sourceRoot":"","sources":["../src/compose.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AACH,OAAO,EAAoF,KAAK,QAAQ,EAAE,MAAM,sBAAsB,CAAA;AAGtI;;;;;;;;;;;GAWG;AACH,wBAAgB,WAAW,CAAC,MAAM,EAAE;IAAE,MAAM,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IAAC,KAAK,EAAE,MAAM,CAAA;CAAE,EAAE,MAAM,UAAQ,GAAG,MAAM,CAGrG;AAED;;;;;;;GAOG;AACH,wBAAgB,gBAAgB,CAAC,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,MAAM,CAEtE;AAED,6FAA6F;AAC7F,eAAO,MAAM,UAAU,WAAW,CAAA;AAElC;;;;;;;GAOG;AACH,wBAAgB,aAAa,CAAC,IAAI,EAAE,MAAM,EAAE,MAAM,EAAE,SAAS,MAAM,EAAE,GAAG,SAAS,GAAG,QAAQ,EAAE,CAI7F;AAWD,4GAA4G;AAC5G,wBAAgB,iBAAiB,CAAC,IAAI,EAAE,MAAM,GAAG,GAAG,CAAC,MAAM,CAAC,CAY3D;AAED;;;;;;;;GAQG;AACH,wBAAgB,YAAY,CAAC,IAAI,EAAE,MAAM,EAAE,GAAG,SAAK,GAAG,QAAQ,EAAE,CAI/D"}
|
package/dist/compose.js
CHANGED
|
@@ -11,9 +11,9 @@
|
|
|
11
11
|
* | --- | --- | --- |
|
|
12
12
|
* | a person (`@`) | `nostr:npub…`, or `@Name` with no key | `p`, from {@link mentionTagsFor} |
|
|
13
13
|
* | a person, urgently (`!@`) | the same `nostr:npub…`, or `!@Name` | `p`, and {@link urgentTagsFor}'s `["urgent", <pubkey>]` |
|
|
14
|
-
* | a message (`[`) | `nostr:nevent…` with its kind and no relay |
|
|
14
|
+
* | a message (`[`) | `nostr:nevent…` with its kind and no relay | `q`, from {@link quoteTagsFor} (CON-25) |
|
|
15
15
|
*/
|
|
16
|
-
import { encodeNevent, encodeNpub } from '@estiva-app/protocol';
|
|
16
|
+
import { bech32Decode, convertBits, decodeNevent, encodeNevent, encodeNpub, findNostrUris } from '@estiva-app/protocol';
|
|
17
17
|
import { mentionTagsFor } from './strength.js';
|
|
18
18
|
/**
|
|
19
19
|
* A person as the body names them.
|
|
@@ -59,4 +59,45 @@ export function urgentTagsFor(body, urgent) {
|
|
|
59
59
|
const named = new Set(mentionTagsFor(body).map((tag) => tag[1]));
|
|
60
60
|
return [...new Set(urgent)].filter((pubkey) => named.has(pubkey)).map((pubkey) => [URGENT_TAG, pubkey]);
|
|
61
61
|
}
|
|
62
|
+
/** The event id a `note1…` names: its 32 bytes, as hex. Throws on anything else. */
|
|
63
|
+
function decodeNote(encoded) {
|
|
64
|
+
const { hrp, data } = bech32Decode(encoded.toLowerCase());
|
|
65
|
+
if (hrp !== 'note')
|
|
66
|
+
throw new Error(`expected a note, got ${hrp}`);
|
|
67
|
+
const bytes = convertBits(data, 5, 8, false);
|
|
68
|
+
if (bytes.length !== 32)
|
|
69
|
+
throw new Error('a note is 32 bytes');
|
|
70
|
+
return bytes.map((b) => b.toString(16).padStart(2, '0')).join('');
|
|
71
|
+
}
|
|
72
|
+
/** The events a body references by `nostr:nevent…` or `nostr:note…` (§13.1), in the order it names them. */
|
|
73
|
+
export function eventsNamedInBody(body) {
|
|
74
|
+
const ids = new Set();
|
|
75
|
+
for (const uri of findNostrUris(body)) {
|
|
76
|
+
const bech = uri.slice('nostr:'.length);
|
|
77
|
+
try {
|
|
78
|
+
if (bech.startsWith('nevent1'))
|
|
79
|
+
ids.add(decodeNevent(bech).id);
|
|
80
|
+
else if (bech.startsWith('note1'))
|
|
81
|
+
ids.add(decodeNote(bech));
|
|
82
|
+
}
|
|
83
|
+
catch {
|
|
84
|
+
// A malformed pointer is prose.
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
return ids;
|
|
88
|
+
}
|
|
89
|
+
/**
|
|
90
|
+
* The `q` tags a body earns: `["q", <event id>]`, one per event it references
|
|
91
|
+
* (SPEC §13.1, CON-25). NIP-18's quote, as an index of *which message this one
|
|
92
|
+
* points at* — never a reply, which is `e` (§6.4). Two elements: the relay is
|
|
93
|
+
* the workspace's, and a `[` pick's `nevent` carries no author to fill a third.
|
|
94
|
+
*
|
|
95
|
+
* `own`, when given, is left out — the event a reply already names by `e`, so
|
|
96
|
+
* one message is not both answered and quoted.
|
|
97
|
+
*/
|
|
98
|
+
export function quoteTagsFor(body, own = '') {
|
|
99
|
+
const ids = eventsNamedInBody(body);
|
|
100
|
+
ids.delete(own);
|
|
101
|
+
return [...ids].map((id) => ['q', id]);
|
|
102
|
+
}
|
|
62
103
|
//# sourceMappingURL=compose.js.map
|
package/dist/compose.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"compose.js","sourceRoot":"","sources":["../src/compose.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AACH,OAAO,EAAE,YAAY,EAAE,UAAU,EAAiB,MAAM,sBAAsB,CAAA;
|
|
1
|
+
{"version":3,"file":"compose.js","sourceRoot":"","sources":["../src/compose.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AACH,OAAO,EAAE,YAAY,EAAE,WAAW,EAAE,YAAY,EAAE,YAAY,EAAE,UAAU,EAAE,aAAa,EAAiB,MAAM,sBAAsB,CAAA;AACtI,OAAO,EAAE,cAAc,EAAE,MAAM,eAAe,CAAA;AAE9C;;;;;;;;;;;GAWG;AACH,MAAM,UAAU,WAAW,CAAC,MAAiD,EAAE,MAAM,GAAG,KAAK;IAC3F,IAAI,MAAM,CAAC,MAAM;QAAE,OAAO,SAAS,UAAU,CAAC,MAAM,CAAC,MAAM,CAAC,EAAE,CAAA;IAC9D,OAAO,GAAG,MAAM,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,GAAG,GAAG,MAAM,CAAC,KAAK,EAAE,CAAA;AAChD,CAAC;AAED;;;;;;;GAOG;AACH,MAAM,UAAU,gBAAgB,CAAC,OAAe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,EAAE,EAAE,CAAC,CAAC,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC,QAAQ,CAAC,CAAC,EAAE,GAAG,CAAC,CAAC,CAAC,IAAI,CAAC,EAAE,CAAC,CAAA;AACnE,CAAC;AAED,4GAA4G;AAC5G,MAAM,UAAU,iBAAiB,CAAC,IAAY;IAC5C,MAAM,GAAG,GAAG,IAAI,GAAG,EAAU,CAAA;IAC7B,KAAK,MAAM,GAAG,IAAI,aAAa,CAAC,IAAI,CAAC,EAAE,CAAC;QACtC,MAAM,IAAI,GAAG,GAAG,CAAC,KAAK,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAA;QACvC,IAAI,CAAC;YACH,IAAI,IAAI,CAAC,UAAU,CAAC,SAAS,CAAC;gBAAE,GAAG,CAAC,GAAG,CAAC,YAAY,CAAC,IAAI,CAAC,CAAC,EAAE,CAAC,CAAA;iBACzD,IAAI,IAAI,CAAC,UAAU,CAAC,OAAO,CAAC;gBAAE,GAAG,CAAC,GAAG,CAAC,UAAU,CAAC,IAAI,CAAC,CAAC,CAAA;QAC9D,CAAC;QAAC,MAAM,CAAC;YACP,gCAAgC;QAClC,CAAC;IACH,CAAC;IACD,OAAO,GAAG,CAAA;AACZ,CAAC;AAED;;;;;;;;GAQG;AACH,MAAM,UAAU,YAAY,CAAC,IAAY,EAAE,GAAG,GAAG,EAAE;IACjD,MAAM,GAAG,GAAG,iBAAiB,CAAC,IAAI,CAAC,CAAA;IACnC,GAAG,CAAC,MAAM,CAAC,GAAG,CAAC,CAAA;IACf,OAAO,CAAC,GAAG,GAAG,CAAC,CAAC,GAAG,CAAC,CAAC,EAAE,EAAE,EAAE,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,CAAC,CAAA;AACxC,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.
|
|
15
|
+
export declare const CONVERSATION_VERSION = "0.4.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';
|
|
@@ -21,7 +21,7 @@ export { editTargetOf, editsByTarget, foldEdits, foldAttachments, type EditFold
|
|
|
21
21
|
export { REACTION_HORIZON, REACTION_EMOJI, reactionTargetOf, reactionEmojiOf, reactionHorizon, reactionEventsOf, foldReactions, groupReactions, type ReactionHorizon, type ReactionEvent, type Reaction, } from './reactions.js';
|
|
22
22
|
export { decorationsOf, type Decoration, type Decorations, type Resolution, type QueryFn } from './decorations.js';
|
|
23
23
|
export { buildComment, buildReply, offersEditAndDelete, type CommentRef } from './builders.js';
|
|
24
|
-
export { mentionText, messageReference, URGENT_TAG, urgentTagsFor } from './compose.js';
|
|
24
|
+
export { eventsNamedInBody, mentionText, messageReference, quoteTagsFor, URGENT_TAG, urgentTagsFor } from './compose.js';
|
|
25
25
|
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';
|
|
26
26
|
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, advanceContexts, buildReadStateEvent, allSlotsFilter, mergeSlots, classifyOwnSlots, effectiveReadAt, fetchReadState, publishReadState, type SlotIdentity, type SlotStorage, type SlotSource, type RandomBytes, type ReadStateBlob, type CappedContexts, type SlotBlob, type OwnSlotVerdict, type Nip44, type FetchedReadState, } from './readState.js';
|
|
27
27
|
export { unreadIn, isUnread, type StreamJudge } from './unread.js';
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AACH,eAAO,MAAM,oBAAoB,UAAU,CAAA;AAE3C,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,KAAK,QAAQ,EAAE,MAAM,YAAY,CAAA;AAEnG,OAAO,EACL,gBAAgB,EAChB,cAAc,EACd,gBAAgB,EAChB,eAAe,EACf,eAAe,EACf,gBAAgB,EAChB,aAAa,EACb,cAAc,EACd,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ACtB,MAAM,gBAAgB,CAAA;AAEvB,OAAO,EAAE,QAAQ,EAAE,QAAQ,EAAE,KAAK,WAAW,EAAE,MAAM,aAAa,CAAA;AAElE,OAAO,EACL,gBAAgB,EAChB,SAAS,EACT,SAAS,EACT,gBAAgB,EAChB,eAAe,EACf,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.
|
|
15
|
+
export const CONVERSATION_VERSION = '0.4.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';
|
|
@@ -21,7 +21,7 @@ export { editTargetOf, editsByTarget, foldEdits, foldAttachments } from './edits
|
|
|
21
21
|
export { REACTION_HORIZON, REACTION_EMOJI, reactionTargetOf, reactionEmojiOf, reactionHorizon, reactionEventsOf, foldReactions, groupReactions, } from './reactions.js';
|
|
22
22
|
export { decorationsOf } from './decorations.js';
|
|
23
23
|
export { buildComment, buildReply, offersEditAndDelete } from './builders.js';
|
|
24
|
-
export { mentionText, messageReference, URGENT_TAG, urgentTagsFor } from './compose.js';
|
|
24
|
+
export { eventsNamedInBody, mentionText, messageReference, quoteTagsFor, URGENT_TAG, urgentTagsFor } from './compose.js';
|
|
25
25
|
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';
|
|
26
26
|
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, advanceContexts, buildReadStateEvent, allSlotsFilter, mergeSlots, classifyOwnSlots, effectiveReadAt, fetchReadState, publishReadState, } from './readState.js';
|
|
27
27
|
export { unreadIn, isUnread } from './unread.js';
|
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,OAAO,CAAA;AAE3C,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,EAAE,SAAS,EAAE,eAAe,EAAiB,MAAM,YA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,EAAE,YAAY,EAAE,UAAU,EAAE,mBAAmB,EAAmB,MAAM,eAAe,CAAA;AAE9F,OAAO,EAAE,iBAAiB,EAAE,WAAW,EAAE,gBAAgB,EAAE,YAAY,EAAE,UAAU,EAAE,aAAa,EAAE,MAAM,cAAc,CAAA;AAExH,OAAO,EACL,WAAW,EACX,mBAAmB,EACnB,WAAW,EACX,aAAa,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,eAAe,EACf,mBAAmB,EACnB,cAAc,EACd,UAAU,EACV,gBAAgB,EAChB,eAAe,EACf,cAAc,EACd,gBAAgB,GAWjB,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,GAGhB,MAAM,aAAa,CAAA"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@estiva-app/conversation",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.4.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/compose.ts
CHANGED
|
@@ -11,9 +11,9 @@
|
|
|
11
11
|
* | --- | --- | --- |
|
|
12
12
|
* | a person (`@`) | `nostr:npub…`, or `@Name` with no key | `p`, from {@link mentionTagsFor} |
|
|
13
13
|
* | a person, urgently (`!@`) | the same `nostr:npub…`, or `!@Name` | `p`, and {@link urgentTagsFor}'s `["urgent", <pubkey>]` |
|
|
14
|
-
* | a message (`[`) | `nostr:nevent…` with its kind and no relay |
|
|
14
|
+
* | a message (`[`) | `nostr:nevent…` with its kind and no relay | `q`, from {@link quoteTagsFor} (CON-25) |
|
|
15
15
|
*/
|
|
16
|
-
import { encodeNevent, encodeNpub, type NostrTag } from '@estiva-app/protocol'
|
|
16
|
+
import { bech32Decode, convertBits, decodeNevent, encodeNevent, encodeNpub, findNostrUris, type NostrTag } from '@estiva-app/protocol'
|
|
17
17
|
import { mentionTagsFor } from './strength.js'
|
|
18
18
|
|
|
19
19
|
/**
|
|
@@ -61,3 +61,42 @@ export function urgentTagsFor(body: string, urgent: readonly string[] | undefine
|
|
|
61
61
|
const named = new Set(mentionTagsFor(body).map((tag) => tag[1]))
|
|
62
62
|
return [...new Set(urgent)].filter((pubkey) => named.has(pubkey)).map((pubkey) => [URGENT_TAG, pubkey])
|
|
63
63
|
}
|
|
64
|
+
|
|
65
|
+
/** The event id a `note1…` names: its 32 bytes, as hex. Throws on anything else. */
|
|
66
|
+
function decodeNote(encoded: string): string {
|
|
67
|
+
const { hrp, data } = bech32Decode(encoded.toLowerCase())
|
|
68
|
+
if (hrp !== 'note') throw new Error(`expected a note, got ${hrp}`)
|
|
69
|
+
const bytes = convertBits(data, 5, 8, false)
|
|
70
|
+
if (bytes.length !== 32) throw new Error('a note is 32 bytes')
|
|
71
|
+
return bytes.map((b) => b.toString(16).padStart(2, '0')).join('')
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
/** The events a body references by `nostr:nevent…` or `nostr:note…` (§13.1), in the order it names them. */
|
|
75
|
+
export function eventsNamedInBody(body: string): Set<string> {
|
|
76
|
+
const ids = new Set<string>()
|
|
77
|
+
for (const uri of findNostrUris(body)) {
|
|
78
|
+
const bech = uri.slice('nostr:'.length)
|
|
79
|
+
try {
|
|
80
|
+
if (bech.startsWith('nevent1')) ids.add(decodeNevent(bech).id)
|
|
81
|
+
else if (bech.startsWith('note1')) ids.add(decodeNote(bech))
|
|
82
|
+
} catch {
|
|
83
|
+
// A malformed pointer is prose.
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
return ids
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
/**
|
|
90
|
+
* The `q` tags a body earns: `["q", <event id>]`, one per event it references
|
|
91
|
+
* (SPEC §13.1, CON-25). NIP-18's quote, as an index of *which message this one
|
|
92
|
+
* points at* — never a reply, which is `e` (§6.4). Two elements: the relay is
|
|
93
|
+
* the workspace's, and a `[` pick's `nevent` carries no author to fill a third.
|
|
94
|
+
*
|
|
95
|
+
* `own`, when given, is left out — the event a reply already names by `e`, so
|
|
96
|
+
* one message is not both answered and quoted.
|
|
97
|
+
*/
|
|
98
|
+
export function quoteTagsFor(body: string, own = ''): NostrTag[] {
|
|
99
|
+
const ids = eventsNamedInBody(body)
|
|
100
|
+
ids.delete(own)
|
|
101
|
+
return [...ids].map((id) => ['q', id])
|
|
102
|
+
}
|
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.
|
|
15
|
+
export const CONVERSATION_VERSION = '0.4.0'
|
|
16
16
|
|
|
17
17
|
export {
|
|
18
18
|
KIND_MESSAGE,
|
|
@@ -64,7 +64,7 @@ export { decorationsOf, type Decoration, type Decorations, type Resolution, type
|
|
|
64
64
|
|
|
65
65
|
export { buildComment, buildReply, offersEditAndDelete, type CommentRef } from './builders.js'
|
|
66
66
|
|
|
67
|
-
export { mentionText, messageReference, URGENT_TAG, urgentTagsFor } from './compose.js'
|
|
67
|
+
export { eventsNamedInBody, mentionText, messageReference, quoteTagsFor, URGENT_TAG, urgentTagsFor } from './compose.js'
|
|
68
68
|
|
|
69
69
|
export {
|
|
70
70
|
KIND_CHANGE,
|