@estiva-app/conversation 0.24.0 → 0.25.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,23 @@ 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.25.0 — 2026-11-03
10
+
11
+ **SPEC: none changed.** Peek's rule for a list row's dot moves here, so Ship
12
+ and Peek judge a topic's dot the same way (SHIPS-2). Each is Peek's code as it
13
+ ran, made pure: the read state and the muted list stay the app's to decrypt
14
+ and hand in.
15
+
16
+ - `streamHasUnread(messages, context, terms, frontier, isMentioned)`: §11.8's
17
+ four conditions over bodiless messages (`StreamMessage`: id, at, by, root).
18
+ - `membershipQueries(pubkey, now)`, `foldMemberships(pubkey, events, now)`:
19
+ the three filters bounded by the 90-day horizon (`HORIZON_SECONDS`,
20
+ `MEMBERSHIP_LIMIT` per filter), folded per candidate file, a created file
21
+ the viewer's from the horizon's start; the ids that name the viewer.
22
+ - `streamTermsOf(key, read, me, muted)`: member, since and muted for a file;
23
+ a Folder's own stream has no members. `membershipJudges(key, read, me)`:
24
+ whether the horizon has a word on the viewer there. `authorOfAddress`.
25
+
9
26
  ## 0.24.0 — 2026-10-30
10
27
 
11
28
  Three of Katerina's calls from the widget review (30 October), once for
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.24.0";
15
+ export declare const CONVERSATION_VERSION = "0.25.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,6 +28,7 @@ export { FILE_TIER, fileReference, MESSAGE_TIER, messageCandidate, rankReference
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 { streamHasUnread, MEMBERSHIP_LIMIT, HORIZON_SECONDS, membershipQueries, authorOfAddress, foldMemberships, streamTermsOf, membershipJudges, type StreamMessage, type StreamFrontier, type StreamTerms, type MembershipRead, } from './streamUnread.js';
31
32
  export { peopleNamedInText, newlyNamedPeople, mentionAddsFor, type FileText } from './textMentions.js';
32
33
  export { KIND_MEMBERSHIP_LIST, namedProfilesOf, rosterOf, byName, mentionablePeople, type NamedProfile } from './people.js';
33
34
  export { messageWords, openingWords, referenceWord, type OpeningWordsOptions } from './openingWords.js';
@@ -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,EAAE,KAAK,WAAW,EAAE,KAAK,UAAU,EAAE,KAAK,OAAO,EAAE,MAAM,kBAAkB,CAAA;AAElH,OAAO,EAAE,YAAY,EAAE,UAAU,EAAE,mBAAmB,EAAE,OAAO,EAAE,KAAK,UAAU,EAAE,MAAM,eAAe,CAAA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Ac,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,EACL,eAAe,EACf,gBAAgB,EAChB,eAAe,EACf,iBAAiB,EACjB,eAAe,EACf,eAAe,EACf,aAAa,EACb,gBAAgB,EAChB,KAAK,aAAa,EAClB,KAAK,cAAc,EACnB,KAAK,WAAW,EAChB,KAAK,cAAc,GACpB,MAAM,mBAAmB,CAAA;AAE1B,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,YAAY,EAAE,aAAa,EAAE,KAAK,mBAAmB,EAAE,MAAM,mBAAmB,CAAA;AAEvG,OAAO,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAA;AAEhD,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.24.0';
15
+ export const CONVERSATION_VERSION = '0.25.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,6 +28,7 @@ export { FILE_TIER, fileReference, MESSAGE_TIER, messageCandidate, rankReference
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 { streamHasUnread, MEMBERSHIP_LIMIT, HORIZON_SECONDS, membershipQueries, authorOfAddress, foldMemberships, streamTermsOf, membershipJudges, } from './streamUnread.js';
31
32
  export { peopleNamedInText, newlyNamedPeople, mentionAddsFor } from './textMentions.js';
32
33
  export { KIND_MEMBERSHIP_LIST, namedProfilesOf, rosterOf, byName, mentionablePeople } from './people.js';
33
34
  export { messageWords, openingWords, referenceWord } from './openingWords.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,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,EAAE,SAAS,EAAE,eAAe,EAAE,UAAU,EAAiB,MAAM,YAAY,CAAA;AAE/G,OAAO,EACL,gBAAgB,EAChB,cAAc,EACd,gBAAgB,EAChB,eAAe,EACf,eAAe,EACf,gBAAgB,EAChB,aAAa,EACb,cAAc,GAIf,MAAM,gBAAgB,CAAA;AAEvB,OAAO,EAAE,aAAa,EAAoE,MAAM,kBAAkB,CAAA;AAElH,OAAO,EAAE,YAAY,EAAE,UAAU,EAAE,mBAAmB,EAAE,OAAO,EAAmB,MAAM,eAAe,CAAA;AAEvG,OAAO,EAAE,iBAAiB,EAAE,WAAW,EAAE,gBAAgB,EAAE,YAAY,EAAE,UAAU,EAAE,aAAa,EAAE,MAAM,cAAc,CAAA;AAExH,OAAO,EACL,gBAAgB,EAChB,aAAa,EACb,YAAY,EACZ,iBAAiB,GAIlB,MA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CAAA;AAEvB,OAAO,EAAE,QAAQ,EAAE,QAAQ,EAAoB,MAAM,aAAa,CAAA;AAElE,OAAO,EACL,eAAe,EACf,gBAAgB,EAChB,eAAe,EACf,iBAAiB,EACjB,eAAe,EACf,eAAe,EACf,aAAa,EACb,gBAAgB,GAKjB,MAAM,mBAAmB,CAAA;AAE1B,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,YAAY,EAAE,aAAa,EAA4B,MAAM,mBAAmB,CAAA;AAEvG,OAAO,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAA;AAEhD,OAAO,EACL,gBAAgB,EAChB,SAAS,EACT,SAAS,EACT,gBAAgB,EAChB,eAAe,GAIhB,MAAM,aAAa,CAAA"}
@@ -0,0 +1,102 @@
1
+ /**
2
+ * A list row's dot — SPEC §11.8 over a stream's messages, for a reader that
3
+ * holds only who said what and when, never the bodies.
4
+ *
5
+ * Moved here from Peek (SHIPS-2) so Peek's Topics and Ship's Topics judge a
6
+ * topic's dot by one rule: which files the viewer is a member of, read from
7
+ * the relay and folded ({@link membershipQueries}, {@link foldMemberships}),
8
+ * the terms that fold gives a stream ({@link streamTermsOf}), and whether any
9
+ * of the stream's messages is unread on them ({@link streamHasUnread}).
10
+ *
11
+ * The read state and the muted list are encrypted (NIP-44), so nothing here
12
+ * reads them: the app hands in the merged markers and the muted set it holds.
13
+ */
14
+ import { type SignedEvent } from '@estiva-app/protocol';
15
+ import { type Membership } from './membership.js';
16
+ /** What a list holds of a message: no body. `root` is the thread root's id, the message's own when it is one. */
17
+ export interface StreamMessage {
18
+ id: string;
19
+ /** Unix seconds. */
20
+ at: number;
21
+ /** Author pubkey. */
22
+ by: string;
23
+ root: string;
24
+ }
25
+ /** What a stream is judged against besides its messages. */
26
+ export interface StreamFrontier {
27
+ /** The merged read state: context → unix seconds. */
28
+ merged: Readonly<Record<string, number>>;
29
+ /** The viewer's pubkey; their own messages do not count. */
30
+ me: string | undefined;
31
+ /** Now, unix seconds. */
32
+ nowSeconds: number;
33
+ horizonSeconds: number;
34
+ }
35
+ /** The terms a stream is told about on: SPEC §11.8's membership, join time and mute. */
36
+ export interface StreamTerms {
37
+ member: boolean;
38
+ since?: number;
39
+ muted: boolean;
40
+ }
41
+ /**
42
+ * Is anything in this stream unread for the viewer — SPEC §11.8's four
43
+ * conditions over §11.3's markers, judged by {@link isUnread}.
44
+ *
45
+ * `context` is the stream's read-state context (§11.1): `fileContext(address)`
46
+ * for a file, `channelContext(uuid)` for a Folder's general stream. A message is
47
+ * judged against its thread's marker as well as the stream's (§11.3).
48
+ *
49
+ * The messages carry no body, so whether one *names the viewer* comes from
50
+ * `isMentioned` (the ids the membership read's `#p` filter returned) and is
51
+ * handed to the judge as the body it would have had. Without a marker, a file
52
+ * member is told from the second they joined; a Folder's own chat has no
53
+ * members here and lights only for a message that names the viewer, so
54
+ * absence there is the horizon (§11.6).
55
+ */
56
+ export declare function streamHasUnread(messages: readonly StreamMessage[], context: string, terms: StreamTerms, frontier: StreamFrontier, isMentioned: (messageId: string) => boolean): boolean;
57
+ /** Per filter. Measured on production as the agent, the most-named identity there: 700 events in 90 days. */
58
+ export declare const MEMBERSHIP_LIMIT = 1000;
59
+ /** The read horizon, in seconds: nothing before it can light a dot. */
60
+ export declare const HORIZON_SECONDS: number;
61
+ /** The three filters that find every file the viewer may be a member of (§11.8), bounded by the horizon. */
62
+ export declare function membershipQueries(pubkey: string, nowSeconds: number, limit?: number): Record<string, unknown>[];
63
+ /** What the relay says the viewer is a member of, within the horizon. */
64
+ export interface MembershipRead {
65
+ /** Every candidate file, folded: the ones the viewer is in and the ones they left. */
66
+ files: ReadonlyMap<string, Membership>;
67
+ /** Ids of the messages whose content names the viewer. */
68
+ mentioned: ReadonlySet<string>;
69
+ /** Unix seconds a created file's membership starts at — the horizon's start. */
70
+ floor: number;
71
+ }
72
+ /** The address's author, or undefined when it is not a file address. */
73
+ export declare function authorOfAddress(address: string): string | undefined;
74
+ /**
75
+ * Fold what {@link membershipQueries} returned. Pure: the clock is `nowSeconds`.
76
+ *
77
+ * A file's address names its author, so a file the viewer created needs no
78
+ * query: a candidate whose address is theirs is folded with its root added,
79
+ * dated to the horizon's start — the earliest the viewer could be told about —
80
+ * and a leave of theirs among the changes still takes them off. Membership the
81
+ * horizon hides lapses for this reader and comes back with the next event
82
+ * naming the viewer (§11.8 *The fold*).
83
+ */
84
+ export declare function foldMemberships(pubkey: string, events: readonly SignedEvent[], nowSeconds: number): MembershipRead;
85
+ /**
86
+ * The terms a stream is judged on, from the membership read and the muted set.
87
+ *
88
+ * A file is a member by the fold, else by authorship (a file the viewer
89
+ * created is theirs unless a leave of theirs says otherwise, and a leave is
90
+ * among the files read). Anything that is not a file address — a Folder's
91
+ * general stream — has nothing to read (Miky, 2026-10-01): nobody is a member
92
+ * of it, so it lights only for a message that names the viewer.
93
+ */
94
+ export declare function streamTermsOf(key: string, read: Pick<MembershipRead, 'files' | 'floor'>, me: string | undefined, muted: ReadonlySet<string>): StreamTerms;
95
+ /**
96
+ * Whether the horizon's read has a word on the viewer in this file: an event
97
+ * naming them within it, or the file is theirs. Without one, "not a member"
98
+ * may only mean they joined before the horizon; a list that must say whose a
99
+ * file is reads those over all history.
100
+ */
101
+ export declare function membershipJudges(key: string, read: Pick<MembershipRead, 'files'>, me: string | undefined): boolean;
102
+ //# sourceMappingURL=streamUnread.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"streamUnread.d.ts","sourceRoot":"","sources":["../src/streamUnread.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AACH,OAAO,EAAc,KAAK,WAAW,EAAE,MAAM,sBAAsB,CAAA;AACnE,OAAO,EAA+D,KAAK,UAAU,EAAE,MAAM,iBAAi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D;IAC1D,SAAS,EAAE,WAAW,CAAC,MAAM,CAAC,CAAA;IAC9B,gFAAgF;IAChF,KAAK,EAAE,MAAM,CAAA;CACd;AAED,wEAAwE;AACxE,wBAAgB,eAAe,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,CAGnE;AAED;;;;;;;;;GASG;AACH,wBAAgB,eAAe,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,SAAS,WAAW,EAAE,EAAE,UAAU,EAAE,MAAM,GAAG,cAAc,CAqBlH;AAED;;;;;;;;GAQG;AACH,wBAAgB,aAAa,CAC3B,GAAG,EAAE,MAAM,EACX,IAAI,EAAE,IAAI,CAAC,cAAc,EAAE,OAAO,GAAG,OAAO,CAAC,EAC7C,EAAE,EAAE,MAAM,GAAG,SAAS,EACtB,KAAK,EAAE,WAAW,CAAC,MAAM,CAAC,GACzB,WAAW,CAOb;AAED;;;;;GAKG;AACH,wBAAgB,gBAAgB,CAAC,GAAG,EAAE,MAAM,EAAE,IAAI,EAAE,IAAI,CAAC,cAAc,EAAE,OAAO,CAAC,EAAE,EAAE,EAAE,MAAM,GAAG,SAAS,GAAG,OAAO,CAElH"}
@@ -0,0 +1,133 @@
1
+ /**
2
+ * A list row's dot — SPEC §11.8 over a stream's messages, for a reader that
3
+ * holds only who said what and when, never the bodies.
4
+ *
5
+ * Moved here from Peek (SHIPS-2) so Peek's Topics and Ship's Topics judge a
6
+ * topic's dot by one rule: which files the viewer is a member of, read from
7
+ * the relay and folded ({@link membershipQueries}, {@link foldMemberships}),
8
+ * the terms that fold gives a stream ({@link streamTermsOf}), and whether any
9
+ * of the stream's messages is unread on them ({@link streamHasUnread}).
10
+ *
11
+ * The read state and the muted list are encrypted (NIP-44), so nothing here
12
+ * reads them: the app hands in the merged markers and the muted set it holds.
13
+ */
14
+ import { encodeNpub } from '@estiva-app/protocol';
15
+ import { candidateFilesOf, membershipFilters, membershipOf, mentions } from './membership.js';
16
+ import { READ_STATE_HORIZON_DAYS, fileContext } from './readState.js';
17
+ import { isUnread } from './unread.js';
18
+ /**
19
+ * Is anything in this stream unread for the viewer — SPEC §11.8's four
20
+ * conditions over §11.3's markers, judged by {@link isUnread}.
21
+ *
22
+ * `context` is the stream's read-state context (§11.1): `fileContext(address)`
23
+ * for a file, `channelContext(uuid)` for a Folder's general stream. A message is
24
+ * judged against its thread's marker as well as the stream's (§11.3).
25
+ *
26
+ * The messages carry no body, so whether one *names the viewer* comes from
27
+ * `isMentioned` (the ids the membership read's `#p` filter returned) and is
28
+ * handed to the judge as the body it would have had. Without a marker, a file
29
+ * member is told from the second they joined; a Folder's own chat has no
30
+ * members here and lights only for a message that names the viewer, so
31
+ * absence there is the horizon (§11.6).
32
+ */
33
+ export function streamHasUnread(messages, context, terms, frontier, isMentioned) {
34
+ const { me } = frontier;
35
+ if (!me)
36
+ return false;
37
+ // Only for a message that names the viewer, so a viewer without a hex key judges the rest.
38
+ const named = () => `nostr:${encodeNpub(me)}`;
39
+ const judge = {
40
+ stream: context,
41
+ me,
42
+ member: terms.member,
43
+ since: terms.since,
44
+ muted: terms.muted,
45
+ floor: frontier.nowSeconds - frontier.horizonSeconds,
46
+ };
47
+ for (const message of messages) {
48
+ const root = message.root === message.id ? undefined : message.root;
49
+ const unread = isUnread({ id: message.id, pubkey: message.by, kind: 1111, created_at: message.at, tags: [], content: isMentioned(message.id) ? named() : '' }, root, frontier.merged, judge);
50
+ if (unread)
51
+ return true;
52
+ }
53
+ return false;
54
+ }
55
+ /** Per filter. Measured on production as the agent, the most-named identity there: 700 events in 90 days. */
56
+ export const MEMBERSHIP_LIMIT = 1000;
57
+ /** The read horizon, in seconds: nothing before it can light a dot. */
58
+ export const HORIZON_SECONDS = READ_STATE_HORIZON_DAYS * 24 * 60 * 60;
59
+ /** The three filters that find every file the viewer may be a member of (§11.8), bounded by the horizon. */
60
+ export function membershipQueries(pubkey, nowSeconds, limit = MEMBERSHIP_LIMIT) {
61
+ return membershipFilters(pubkey, nowSeconds - HORIZON_SECONDS).map((filter) => ({ ...filter, limit }));
62
+ }
63
+ /** The address's author, or undefined when it is not a file address. */
64
+ export function authorOfAddress(address) {
65
+ if (fileContext(address) === undefined)
66
+ return undefined;
67
+ return address.split(':')[1];
68
+ }
69
+ /**
70
+ * Fold what {@link membershipQueries} returned. Pure: the clock is `nowSeconds`.
71
+ *
72
+ * A file's address names its author, so a file the viewer created needs no
73
+ * query: a candidate whose address is theirs is folded with its root added,
74
+ * dated to the horizon's start — the earliest the viewer could be told about —
75
+ * and a leave of theirs among the changes still takes them off. Membership the
76
+ * horizon hides lapses for this reader and comes back with the next event
77
+ * naming the viewer (§11.8 *The fold*).
78
+ */
79
+ export function foldMemberships(pubkey, events, nowSeconds) {
80
+ const floor = nowSeconds - HORIZON_SECONDS;
81
+ const byFile = new Map();
82
+ const mentioned = new Set();
83
+ for (const event of events) {
84
+ if (mentions(event, pubkey))
85
+ mentioned.add(event.id);
86
+ for (const file of candidateFilesOf(event)) {
87
+ const list = byFile.get(file);
88
+ if (list)
89
+ list.push(event);
90
+ else
91
+ byFile.set(file, [event]);
92
+ }
93
+ }
94
+ const files = new Map();
95
+ for (const [file, held] of byFile) {
96
+ const [kind, , d] = file.split(':');
97
+ const own = authorOfAddress(file) === pubkey;
98
+ // The root the viewer created, when they did — ordered before everything else for the file.
99
+ const root = own ? [{ id: '', pubkey, kind: Number(kind), created_at: floor, tags: [['d', d ?? '']], content: '', sig: '' }] : [];
100
+ files.set(file, membershipOf(file, pubkey, [...root, ...held]));
101
+ }
102
+ return { files, mentioned, floor };
103
+ }
104
+ /**
105
+ * The terms a stream is judged on, from the membership read and the muted set.
106
+ *
107
+ * A file is a member by the fold, else by authorship (a file the viewer
108
+ * created is theirs unless a leave of theirs says otherwise, and a leave is
109
+ * among the files read). Anything that is not a file address — a Folder's
110
+ * general stream — has nothing to read (Miky, 2026-10-01): nobody is a member
111
+ * of it, so it lights only for a message that names the viewer.
112
+ */
113
+ export function streamTermsOf(key, read, me, muted) {
114
+ const isMuted = muted.has(key);
115
+ if (fileContext(key) === undefined)
116
+ return { member: false, muted: isMuted };
117
+ const folded = read.files.get(key);
118
+ if (folded)
119
+ return { member: folded.member, since: folded.since, muted: isMuted };
120
+ if (me && authorOfAddress(key) === me)
121
+ return { member: true, since: read.floor, muted: isMuted };
122
+ return { member: false, muted: isMuted };
123
+ }
124
+ /**
125
+ * Whether the horizon's read has a word on the viewer in this file: an event
126
+ * naming them within it, or the file is theirs. Without one, "not a member"
127
+ * may only mean they joined before the horizon; a list that must say whose a
128
+ * file is reads those over all history.
129
+ */
130
+ export function membershipJudges(key, read, me) {
131
+ return read.files.has(key) || (!!me && authorOfAddress(key) === me);
132
+ }
133
+ //# sourceMappingURL=streamUnread.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"streamUnread.js","sourceRoot":"","sources":["../src/streamUnread.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AACH,OAAO,EAAE,UAAU,EAAoB,MAAM,sBAAsB,CAAA;AACnE,OAAO,EAAE,gBAAgB,EAAE,iBAAiB,EAAE,YAAY,EAAE,QAAQ,EAAmB,MAAM,iBAAiB,CAAA;AAC9G,OAAO,EAAE,uBAAuB,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAA;AACrE,OAAO,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAA;AA8BtC;;;;;;;;;;;;;;GAcG;AACH,MAAM,UAAU,eAAe,CAC7B,QAAkC,EAClC,OAAe,EACf,KAAkB,EAClB,QAAwB,EACxB,WAA2C;IAE3C,MAAM,EAAE,EAAE,EAAE,GAAG,QAAQ,CAAA;IACvB,IAAI,CAAC,EAAE;QAAE,OAAO,KAAK,CAAA;IACrB,2FAA2F;IAC3F,MAAM,KAAK,GAAG,GAAG,EAAE,CAAC,SAAS,UAAU,CAAC,EAAE,CAAC,EAAE,CAAA;IAC7C,MAAM,KAAK,GAAG;QACZ,MAAM,EAAE,OAAO;QACf,EAAE;QACF,MAAM,EAAE,KAAK,C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KAAK,EAAE,OAAO,EAAE,CAAA;AAC1C,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,gBAAgB,CAAC,GAAW,EAAE,IAAmC,EAAE,EAAsB;IACvG,OAAO,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,IAAI,eAAe,CAAC,GAAG,CAAC,KAAK,EAAE,CAAC,CAAA;AACrE,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@estiva-app/conversation",
3
- "version": "0.24.0",
3
+ "version": "0.25.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.24.0'
15
+ export const CONVERSATION_VERSION = '0.25.0'
16
16
 
17
17
  export {
18
18
  KIND_MESSAGE,
@@ -185,6 +185,21 @@ export {
185
185
 
186
186
  export { unreadIn, isUnread, type StreamJudge } from './unread.js'
187
187
 
188
+ export {
189
+ streamHasUnread,
190
+ MEMBERSHIP_LIMIT,
191
+ HORIZON_SECONDS,
192
+ membershipQueries,
193
+ authorOfAddress,
194
+ foldMemberships,
195
+ streamTermsOf,
196
+ membershipJudges,
197
+ type StreamMessage,
198
+ type StreamFrontier,
199
+ type StreamTerms,
200
+ type MembershipRead,
201
+ } from './streamUnread.js'
202
+
188
203
  export { peopleNamedInText, newlyNamedPeople, mentionAddsFor, type FileText } from './textMentions.js'
189
204
 
190
205
  export { KIND_MEMBERSHIP_LIST, namedProfilesOf, rosterOf, byName, mentionablePeople, type NamedProfile } from './people.js'
@@ -0,0 +1,185 @@
1
+ /**
2
+ * A list row's dot — SPEC §11.8 over a stream's messages, for a reader that
3
+ * holds only who said what and when, never the bodies.
4
+ *
5
+ * Moved here from Peek (SHIPS-2) so Peek's Topics and Ship's Topics judge a
6
+ * topic's dot by one rule: which files the viewer is a member of, read from
7
+ * the relay and folded ({@link membershipQueries}, {@link foldMemberships}),
8
+ * the terms that fold gives a stream ({@link streamTermsOf}), and whether any
9
+ * of the stream's messages is unread on them ({@link streamHasUnread}).
10
+ *
11
+ * The read state and the muted list are encrypted (NIP-44), so nothing here
12
+ * reads them: the app hands in the merged markers and the muted set it holds.
13
+ */
14
+ import { encodeNpub, type SignedEvent } from '@estiva-app/protocol'
15
+ import { candidateFilesOf, membershipFilters, membershipOf, mentions, type Membership } from './membership.js'
16
+ import { READ_STATE_HORIZON_DAYS, fileContext } from './readState.js'
17
+ import { isUnread } from './unread.js'
18
+
19
+ /** What a list holds of a message: no body. `root` is the thread root's id, the message's own when it is one. */
20
+ export interface StreamMessage {
21
+ id: string
22
+ /** Unix seconds. */
23
+ at: number
24
+ /** Author pubkey. */
25
+ by: string
26
+ root: string
27
+ }
28
+
29
+ /** What a stream is judged against besides its messages. */
30
+ export interface StreamFrontier {
31
+ /** The merged read state: context → unix seconds. */
32
+ merged: Readonly<Record<string, number>>
33
+ /** The viewer's pubkey; their own messages do not count. */
34
+ me: string | undefined
35
+ /** Now, unix seconds. */
36
+ nowSeconds: number
37
+ horizonSeconds: number
38
+ }
39
+
40
+ /** The terms a stream is told about on: SPEC §11.8's membership, join time and mute. */
41
+ export interface StreamTerms {
42
+ member: boolean
43
+ since?: number
44
+ muted: boolean
45
+ }
46
+
47
+ /**
48
+ * Is anything in this stream unread for the viewer — SPEC §11.8's four
49
+ * conditions over §11.3's markers, judged by {@link isUnread}.
50
+ *
51
+ * `context` is the stream's read-state context (§11.1): `fileContext(address)`
52
+ * for a file, `channelContext(uuid)` for a Folder's general stream. A message is
53
+ * judged against its thread's marker as well as the stream's (§11.3).
54
+ *
55
+ * The messages carry no body, so whether one *names the viewer* comes from
56
+ * `isMentioned` (the ids the membership read's `#p` filter returned) and is
57
+ * handed to the judge as the body it would have had. Without a marker, a file
58
+ * member is told from the second they joined; a Folder's own chat has no
59
+ * members here and lights only for a message that names the viewer, so
60
+ * absence there is the horizon (§11.6).
61
+ */
62
+ export function streamHasUnread(
63
+ messages: readonly StreamMessage[],
64
+ context: string,
65
+ terms: StreamTerms,
66
+ frontier: StreamFrontier,
67
+ isMentioned: (messageId: string) => boolean,
68
+ ): boolean {
69
+ const { me } = frontier
70
+ if (!me) return false
71
+ // Only for a message that names the viewer, so a viewer without a hex key judges the rest.
72
+ const named = () => `nostr:${encodeNpub(me)}`
73
+ const judge = {
74
+ stream: context,
75
+ me,
76
+ member: terms.member,
77
+ since: terms.since,
78
+ muted: terms.muted,
79
+ floor: frontier.nowSeconds - frontier.horizonSeconds,
80
+ }
81
+ for (const message of messages) {
82
+ const root = message.root === message.id ? undefined : message.root
83
+ const unread = isUnread(
84
+ { id: message.id, pubkey: message.by, kind: 1111, created_at: message.at, tags: [], content: isMentioned(message.id) ? named() : '' },
85
+ root,
86
+ frontier.merged,
87
+ judge,
88
+ )
89
+ if (unread) return true
90
+ }
91
+ return false
92
+ }
93
+
94
+ /** Per filter. Measured on production as the agent, the most-named identity there: 700 events in 90 days. */
95
+ export const MEMBERSHIP_LIMIT = 1000
96
+
97
+ /** The read horizon, in seconds: nothing before it can light a dot. */
98
+ export const HORIZON_SECONDS = READ_STATE_HORIZON_DAYS * 24 * 60 * 60
99
+
100
+ /** The three filters that find every file the viewer may be a member of (§11.8), bounded by the horizon. */
101
+ export function membershipQueries(pubkey: string, nowSeconds: number, limit = MEMBERSHIP_LIMIT): Record<string, unknown>[] {
102
+ return membershipFilters(pubkey, nowSeconds - HORIZON_SECONDS).map((filter) => ({ ...filter, limit }))
103
+ }
104
+
105
+ /** What the relay says the viewer is a member of, within the horizon. */
106
+ export interface MembershipRead {
107
+ /** Every candidate file, folded: the ones the viewer is in and the ones they left. */
108
+ files: ReadonlyMap<string, Membership>
109
+ /** Ids of the messages whose content names the viewer. */
110
+ mentioned: ReadonlySet<string>
111
+ /** Unix seconds a created file's membership starts at — the horizon's start. */
112
+ floor: number
113
+ }
114
+
115
+ /** The address's author, or undefined when it is not a file address. */
116
+ export function authorOfAddress(address: string): string | undefined {
117
+ if (fileContext(address) === undefined) return undefined
118
+ return address.split(':')[1]
119
+ }
120
+
121
+ /**
122
+ * Fold what {@link membershipQueries} returned. Pure: the clock is `nowSeconds`.
123
+ *
124
+ * A file's address names its author, so a file the viewer created needs no
125
+ * query: a candidate whose address is theirs is folded with its root added,
126
+ * dated to the horizon's start — the earliest the viewer could be told about —
127
+ * and a leave of theirs among the changes still takes them off. Membership the
128
+ * horizon hides lapses for this reader and comes back with the next event
129
+ * naming the viewer (§11.8 *The fold*).
130
+ */
131
+ export function foldMemberships(pubkey: string, events: readonly SignedEvent[], nowSeconds: number): MembershipRead {
132
+ const floor = nowSeconds - HORIZON_SECONDS
133
+ const byFile = new Map<string, SignedEvent[]>()
134
+ const mentioned = new Set<string>()
135
+ for (const event of events) {
136
+ if (mentions(event, pubkey)) mentioned.add(event.id)
137
+ for (const file of candidateFilesOf(event)) {
138
+ const list = byFile.get(file)
139
+ if (list) list.push(event)
140
+ else byFile.set(file, [event])
141
+ }
142
+ }
143
+ const files = new Map<string, Membership>()
144
+ for (const [file, held] of byFile) {
145
+ const [kind, , d] = file.split(':')
146
+ const own = authorOfAddress(file) === pubkey
147
+ // The root the viewer created, when they did — ordered before everything else for the file.
148
+ const root = own ? [{ id: '', pubkey, kind: Number(kind), created_at: floor, tags: [['d', d ?? '']], content: '', sig: '' }] : []
149
+ files.set(file, membershipOf(file, pubkey, [...root, ...held]))
150
+ }
151
+ return { files, mentioned, floor }
152
+ }
153
+
154
+ /**
155
+ * The terms a stream is judged on, from the membership read and the muted set.
156
+ *
157
+ * A file is a member by the fold, else by authorship (a file the viewer
158
+ * created is theirs unless a leave of theirs says otherwise, and a leave is
159
+ * among the files read). Anything that is not a file address — a Folder's
160
+ * general stream — has nothing to read (Miky, 2026-10-01): nobody is a member
161
+ * of it, so it lights only for a message that names the viewer.
162
+ */
163
+ export function streamTermsOf(
164
+ key: string,
165
+ read: Pick<MembershipRead, 'files' | 'floor'>,
166
+ me: string | undefined,
167
+ muted: ReadonlySet<string>,
168
+ ): StreamTerms {
169
+ const isMuted = muted.has(key)
170
+ if (fileContext(key) === undefined) return { member: false, muted: isMuted }
171
+ const folded = read.files.get(key)
172
+ if (folded) return { member: folded.member, since: folded.since, muted: isMuted }
173
+ if (me && authorOfAddress(key) === me) return { member: true, since: read.floor, muted: isMuted }
174
+ return { member: false, muted: isMuted }
175
+ }
176
+
177
+ /**
178
+ * Whether the horizon's read has a word on the viewer in this file: an event
179
+ * naming them within it, or the file is theirs. Without one, "not a member"
180
+ * may only mean they joined before the horizon; a list that must say whose a
181
+ * file is reads those over all history.
182
+ */
183
+ export function membershipJudges(key: string, read: Pick<MembershipRead, 'files'>, me: string | undefined): boolean {
184
+ return read.files.has(key) || (!!me && authorOfAddress(key) === me)
185
+ }