@estiva-app/conversation 0.1.0 → 0.2.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.2.0 — 2026-10-01
10
+
11
+ **Read state and membership** (CON-19): SPEC §11, and §11.8 as amended in
12
+ estiva-docs#201, #202 and the placement clarification of 2026-10-01. Needs
13
+ protocol 0.24.0, unchanged.
14
+
15
+ - **Membership** (`membership.ts`, §11.8): `membershipOf`, `membersOf`,
16
+ `streamOf`, the discovery `membershipFilters` with `candidateFilesOf`, and
17
+ `buildMembershipChange` (`kind:1851`, `member:<P>`, tags `a field value h ts
18
+ p`). A placement counts by its `p` alone, and only with a non-empty `value`
19
+ (an unassign places nobody). The creation orders before every other event
20
+ for the file, so an edit does not re-join an author who left. The private mute list
21
+ (`estiva:muted:v1`) and the one-time `mutedFromFollowed` migration, which
22
+ never returns a follow.
23
+ - **Read state** (`readState.ts`, §11.1–§11.6): ported from Peek and Ship.
24
+ Where the two differed: the cap is in **bytes** (Peek; Ship capped at
25
+ 10,000 contexts, which never binds), eviction and the merged cap are
26
+ deterministic to the tie, a coordinate holding another installation's
27
+ `client_id` is reported, and an unreachable relay and an undecryptable own
28
+ slot are kept apart from "no slots" (Ship). Storage, randomness, the relay,
29
+ the signer and NIP-44 are parameters. Peek's `containerContext` is
30
+ `channelContext` here.
31
+ - **Unread** (`unread.ts`): `unreadIn` and `isUnread`, §11.8's four
32
+ conditions over §11.3's effective marker.
33
+ - `peopleNamedInBody`, which `mentionTagsFor` now uses.
34
+
35
+ **SPEC:** §9 C17 (membership fold) and C18 (unread for a member) are
36
+ `test/membership.test.ts`. Nothing about how a conversation is read or
37
+ written in §6 changed.
38
+
9
39
  ## 0.1.0 — 2026-09-30
10
40
 
11
41
  **First release** (CON-5). Extracted from Peek (`src/nostr/fileConversation.ts`,
package/README.md CHANGED
@@ -5,9 +5,9 @@ The conversation rules of the [Estiva SPEC](https://github.com/estiva-app/estiva
5
5
  and estiva-agent read conversations through it.
6
6
 
7
7
  **A convenience, never a requirement.** SPEC §9's conversation checks
8
- (C10–C16) are written so an app can build conversations from the specification
8
+ (C10–C18) are written so an app can build conversations from the specification
9
9
  alone, and this package's tests are those checks
10
- (`test/conformance.test.ts`). If you find this package disagreeing with the
10
+ (`test/conformance.test.ts` for C10–C16, `test/membership.test.ts` for C17 and C18). If you find this package disagreeing with the
11
11
  SPEC, the package is wrong.
12
12
 
13
13
  ```bash
@@ -31,12 +31,28 @@ pass, the clock is a `createdAtMs` you pass, and drafts take their storage.
31
31
  | one read for all of the above | §6.6, §6.8 | `decorationsOf` |
32
32
  | which controls to offer | §6.5 | `offersEditAndDelete` |
33
33
  | drafts | — | `createDraftStore`, `draftKeys` |
34
+ | membership | §11.8 | `membershipOf`, `membersOf`, `streamOf`, `membershipFilters`, `candidateFilesOf`, `buildMembershipChange` |
35
+ | muting | §11.8 | `parseMutedBlob`, `serializeMutedBlob`, `buildMutedEvent`, `mutedFilter`, `mutedFromFollowed` |
36
+ | read state | §11.1–§11.6 | `channelContext`, `fileContext`, `threadContext`, `loadSlotIdentity`, `advanceContexts`, `fetchReadState`, `publishReadState`, `mergeSlots`, `effectiveReadAt` |
37
+ | unread | §11.3, §11.8 | `unreadIn`, `isUnread` |
34
38
 
35
39
  Chat, an edit, a reaction and a deletion are built with
36
40
  `@estiva-app/protocol`'s `buildMessage`, `buildEdit`, `buildReaction` and
37
41
  `buildDeletion`.
38
42
 
43
+ Read state takes its environment like the rest: slot storage and randomness
44
+ (`loadSlotIdentity`), the relay query, the signer and NIP-44 (`fetchReadState`,
45
+ `publishReadState`). When to write — the debounce, the dwell before a view
46
+ counts as read — stays the app's.
47
+
48
+ **Light a dot from the files you already load, not from discovery alone.** A
49
+ file's membership comes from `membershipOf` over that file's own events, which
50
+ an app already holds for any file it shows. `membershipFilters` is for listing
51
+ "your files", and a busy person's results are cut short by the relay's limit
52
+ (each filter returned 2,000 events for one person in 90 days on 2026-10-01). A
53
+ dot built only on discovery would miss a file the limit dropped.
54
+
39
55
  ## What is not in it
40
56
 
41
- The views (CON-18), unread (CON-19), the composer's editor, and anything only
42
- one app needs.
57
+ The views (CON-18), the composer's editor, a Folder's roster (the relay's
58
+ `kind:39002`), and anything only one app needs.
@@ -1 +1 @@
1
- {"version":3,"file":"builders.d.ts","sourceRoot":"","sources":["../src/builders.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AACH,OAAO,EAA4B,KAAK,KAAK,EAAE,KAAK,QAAQ,EAAE,KAAK,aAAa,EAAE,MAAM,sBAAsB,CAAA;AAqB9G;;;;;;;;;;GAUG;AACH,wBAAgB,YAAY,CAC1B,MAAM,EAAE,MAAM,EACd,WAAW,EAAE,MAAM,EACnB,IAAI,EAAE;IAAE,KAAK,EAAE,MAAM,CAAC;IAAC,MAAM,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,MAAM,CAAC;IAAC,OAAO,CAAC,EAAE,MAAM,CAAC;IAAC,KAAK,CAAC,EAAE,SAAS,KAAK,EAAE,CAAC;IAAC,IAAI,CAAC,EAAE,SAAS,QAAQ,EAAE,CAAA;CAAE,GAC5H,aAAa,CAsBf;AAED,6CAA6C;AAC7C,MAAM,WAAW,UAAU;IACzB,oBAAoB;IACpB,EAAE,EAAE,MAAM,CAAA;IACV,+CAA+C;IAC/C,MAAM,EAAE,MAAM,CAAA;IACd;;;OAGG;IACH,MAAM,CAAC,EAAE,MAAM,CAAA;CAChB;AAED;;;;;;;;GAQG;AACH,wBAAgB,UAAU,CACxB,MAAM,EAAE,MAAM,EACd,WAAW,EAAE,MAAM,EACnB,IAAI,EAAE;IAAE,OAAO,EAAE,UAAU,CAAC;IAAC,MAAM,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,MAAM,CAAC;IAAC,KAAK,CAAC,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AC;IAAC,KAAK,CAAC,EAAE,SAAS,KAAK,EAAE,CAAC;IAAC,IAAI,CAAC,EAAE,SAAS,QAAQ,EAAE,CAAA;CAAE,GAChH,aAAa,CAsBf;AAED;;;;;;;;;GASG;AACH,wBAAgB,mBAAmB,CAAC,IAAI,EAAE;IAAE,MAAM,EAAE,MAAM,GAAG,IAAI,GAAG,SAAS,CAAC;IAAC,MAAM,EAAE,MAAM,CAAC;IAAC,WAAW,EAAE,OAAO,GAAG,SAAS,CAAA;CAAE,GAAG,OAAO,CAG1I"}
package/dist/builders.js CHANGED
@@ -8,8 +8,7 @@
8
8
  * NIP-22 pair below, whose shape the SPEC decided rather than Buzz.
9
9
  */
10
10
  import { imetaTag, toNostrSeconds } from '@estiva-app/protocol';
11
- import { KIND_COMMENT } from './kinds.js';
12
- const FOLDER_ID = /^[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/;
11
+ import { FOLDER_ID, KIND_COMMENT } from './kinds.js';
13
12
  /**
14
13
  * A `kind:1111` is channel-scoped when it carries an `h` and **global when it
15
14
  * does not**, and the relay accepts both — so a comment without one is stored
@@ -1 +1 @@
1
- {"version":3,"file":"builders.js","sourceRoot":"","sources":["../src/builders.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AACH,OAAO,EAAE,QAAQ,EAAE,cAAc,EAAiD,MAAM,sBAAsB,CAAA;AAC9G,OAAO,EAAE,YAAY,EAAE,MAAM,YAAY,CAAA;AAEzC,MAAM,SAAS,GAAG,uEAAuE,CAAA;AAEzF;;;;GAIG;AACH,SAAS,YAAY,CAAC,MAAc;IAClC,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,MAAM,CAAC;QAAE,MAAM,IAAI,KAAK,CAAC,wCAAwC,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,EAAE,CAAC,CAAA;AAChH,CAAC;AAED,kEAAkE;AAClE,SAAS,aAAa,CAAC,OAAe;IACpC,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 -12,14 +12,17 @@
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.1.0";
15
+ export declare const CONVERSATION_VERSION = "0.2.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
- export { namedInBody, isReply, anchorsOf, isCommentOn, referencesAddress, strengthOn, threadStrength, referenceTagsFor, mentionTagsFor, MAX_MENTIONED_PEOPLE, type Strength, } from './strength.js';
18
+ export { namedInBody, isReply, anchorsOf, isCommentOn, referencesAddress, strengthOn, threadStrength, referenceTagsFor, mentionTagsFor, peopleNamedInBody, MAX_MENTIONED_PEOPLE, type Strength, } from './strength.js';
19
19
  export { parentOf, groupThreads, type Threaded } from './threads.js';
20
20
  export { editTargetOf, editsByTarget, foldEdits, foldAttachments, type EditFold } from './edits.js';
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 { 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';
25
+ 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';
26
+ export { unreadIn, isUnread, type StreamJudge } from './unread.js';
24
27
  export { createDraftStore, draftKeys, NO_DRAFTS, DRAFT_MAX_AGE_MS, DRAFT_MAX_CHARS, type DraftStore, type DraftStorage, } from './drafts.js';
25
28
  //# 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,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,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;AAEn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nB,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,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,14 +12,17 @@
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.1.0';
15
+ export const CONVERSATION_VERSION = '0.2.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
- export { namedInBody, isReply, anchorsOf, isCommentOn, referencesAddress, strengthOn, threadStrength, referenceTagsFor, mentionTagsFor, MAX_MENTIONED_PEOPLE, } from './strength.js';
18
+ export { namedInBody, isReply, anchorsOf, isCommentOn, referencesAddress, strengthOn, threadStrength, referenceTagsFor, mentionTagsFor, peopleNamedInBody, MAX_MENTIONED_PEOPLE, } from './strength.js';
19
19
  export { parentOf, groupThreads } from './threads.js';
20
20
  export { editTargetOf, editsByTarget, foldEdits, foldAttachments } from './edits.js';
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 { 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';
25
+ 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';
26
+ export { unreadIn, isUnread } from './unread.js';
24
27
  export { createDraftStore, draftKeys, NO_DRAFTS, DRAFT_MAX_AGE_MS, DRAFT_MAX_CHARS, } from './drafts.js';
25
28
  //# 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,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,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,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AA;AAElH,OAAO,EAAE,YAAY,EAAE,UAAU,EAAE,mBAAmB,EAAmB,MAAM,eAAe,CAAA;AAE9F,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/dist/kinds.d.ts CHANGED
@@ -10,6 +10,14 @@ export declare const KIND_REACTION: 7;
10
10
  export declare const KIND_DELETION: 5;
11
11
  /** An assertion; with `t=resolution` it resolves or reopens a comment (PEEK-128). */
12
12
  export declare const KIND_ASSERTION: 9101;
13
+ /** A field change (SPEC §6.2). Not in protocol's `KIND`; the number is the SPEC's. */
14
+ export declare const KIND_CHANGE = 1851;
15
+ /** NIP-78 app data: read state (§11.6) and app-private storage (§12). */
16
+ export declare const KIND_APP_DATA: 30078;
17
+ /** A Folder's channel id: a lowercase UUID v4. */
18
+ export declare const FOLDER_ID: RegExp;
19
+ /** A file's address, `<kind>:<pubkey>:<d>`: kind 30000–39999, 64 lowercase hex, `d` verbatim and without whitespace. */
20
+ export declare const FILE_ADDRESS: RegExp;
13
21
  /** Whether the event is a message or a comment — what a conversation lists. */
14
22
  export declare const isConversationKind: (kind: number) => boolean;
15
23
  /** A 64-hex event id. */
@@ -1 +1 @@
1
- {"version":3,"file":"kinds.d.ts","sourceRoot":"","sources":["../src/kinds.ts"],"names":[],"mappings":"AAMA,uDAAuD;AACvD,eAAO,MAAM,YAAY,GAAsB,CAAA;AAC/C,gEAAgE;AAChE,eAAO,MAAM,YAAY,MAAe,CAAA;AACxC,8CAA8C;AAC9C,eAAO,MAAM,SAAS,OAAoB,CAAA;AAC1C,gCAAgC;AAChC,eAAO,MAAM,aAAa,GAAgB,CAAA;AAC1C,wCAAwC;AACxC,eAAO,MAAM,aAAa,GAAgB,CAAA;AAC1C,qFAAqF;AACrF,eAAO,MAAM,cAAc,MAAiB,CAAA;AAE5C,+EAA+E;AAC/E,eAAO,MAAM,kBAAkB,GAAI,MAAM,MAAM,KAAG,OAAyD,CAAA;AAE3G,yBAAyB;AACzB,eAAO,MAAM,SAAS,GAAI,OAAO,OAAO,KAAG,KAAK,IAAI,MAAsE,CAAA"}
1
+ {"version":3,"file":"kinds.d.ts","sourceRoot":"","sources":["../src/kinds.ts"],"names":[],"mappings":"AAMA,uDAAuD;AACvD,eAAO,MAAM,YAAY,GAAsB,CAAA;AAC/C,gEAAgE;AAChE,eAAO,MAAM,YAAY,MAAe,CAAA;AACxC,8CAA8C;AAC9C,eAAO,MAAM,SAAS,OAAoB,CAAA;AAC1C,gCAAgC;AAChC,eAAO,MAAM,aAAa,GAAgB,CAAA;AAC1C,wCAAwC;AACxC,eAAO,MAAM,aAAa,GAAgB,CAAA;AAC1C,qFAAqF;AACrF,eAAO,MAAM,cAAc,MAAiB,CAAA;AAE5C,sFAAsF;AACtF,eAAO,MAAM,WAAW,OAAO,CAAA;AAC/B,yEAAyE;AACzE,eAAO,MAAM,aAAa,OAAgB,CAAA;AAE1C,kDAAkD;AAClD,eAAO,MAAM,SAAS,QAA0E,CAAA;AAChG,wHAAwH;AACxH,eAAO,MAAM,YAAY,QAAoC,CAAA;AAE7D,+EAA+E;AAC/E,eAAO,MAAM,kBAAkB,GAAI,MAAM,MAAM,KAAG,OAAyD,CAAA;AAE3G,yBAAyB;AACzB,eAAO,MAAM,SAAS,GAAI,OAAO,OAAO,KAAG,KAAK,IAAI,MAAsE,CAAA"}
package/dist/kinds.js CHANGED
@@ -15,6 +15,14 @@ export const KIND_REACTION = KIND.REACTION;
15
15
  export const KIND_DELETION = KIND.DELETION;
16
16
  /** An assertion; with `t=resolution` it resolves or reopens a comment (PEEK-128). */
17
17
  export const KIND_ASSERTION = KIND.ASSERTION;
18
+ /** A field change (SPEC §6.2). Not in protocol's `KIND`; the number is the SPEC's. */
19
+ export const KIND_CHANGE = 1851;
20
+ /** NIP-78 app data: read state (§11.6) and app-private storage (§12). */
21
+ export const KIND_APP_DATA = KIND.APP_DATA;
22
+ /** A Folder's channel id: a lowercase UUID v4. */
23
+ export const FOLDER_ID = /^[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/;
24
+ /** A file's address, `<kind>:<pubkey>:<d>`: kind 30000–39999, 64 lowercase hex, `d` verbatim and without whitespace. */
25
+ export const FILE_ADDRESS = /^3[0-9]{4}:[0-9a-f]{64}:[^\s]*$/;
18
26
  /** Whether the event is a message or a comment — what a conversation lists. */
19
27
  export const isConversationKind = (kind) => kind === KIND_MESSAGE || kind === KIND_COMMENT;
20
28
  /** A 64-hex event id. */
package/dist/kinds.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"kinds.js","sourceRoot":"","sources":["../src/kinds.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,OAAO,EAAE,IAAI,EAAE,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M,CAAC,MAAM,aAAa,GAAG,IAAI,CAAC,QAAQ,CAAA;AAC1C,qFAAqF;AACrF,MAAM,CAAC,MAAM,cAAc,GAAG,IAAI,CAAC,SAAS,CAAA;AAE5C,sFAAsF;AACtF,MAAM,CAAC,MAAM,WAAW,GAAG,IAAI,CAAA;AAC/B,yEAAyE;AACzE,MAAM,CAAC,MAAM,aAAa,GAAG,IAAI,CAAC,QAAQ,CAAA;AAE1C,kDAAkD;AAClD,MAAM,CAAC,MAAM,SAAS,GAAG,uEAAuE,CAAA;AAChG,wHAAwH;AACxH,MAAM,CAAC,MAAM,YAAY,GAAG,iCAAiC,CAAA;AAE7D,+EAA+E;AAC/E,MAAM,CAAC,MAAM,kBAAkB,GAAG,CAAC,IAAY,EAAW,EAAE,CAAC,IAAI,KAAK,YAAY,IAAI,IAAI,KAAK,YAAY,CAAA;AAE3G,yBAAyB;AACzB,MAAM,CAAC,MAAM,SAAS,GAAG,CAAC,KAAc,EAAmB,EAAE,CAAC,OAAO,KAAK,KAAK,QAAQ,IAAI,mBAAmB,CAAC,IAAI,CAAC,KAAK,CAAC,CAAA"}
@@ -0,0 +1,132 @@
1
+ /**
2
+ * Membership — SPEC §11.8: whose unread a file's conversation is.
3
+ *
4
+ * A person is told about a file's conversation when they are a **member** of
5
+ * the file, and every app computes that the same way, from public events: the
6
+ * file's root, the messages in its stream (§11.1) and its `kind:1851`
7
+ * changes. A Folder's members are its channel roster, which is the relay's
8
+ * and not folded here.
9
+ *
10
+ * | join | the event |
11
+ * | --- | --- |
12
+ * | created it | the root, ordered before every other event for the file |
13
+ * | took part | a message in the stream, by `P` |
14
+ * | was mentioned | a message in the stream whose content names `P` (`nostr:npub…`) |
15
+ * | was placed | a `kind:1851` on the file, not a membership field, with a non-empty `value`, carrying `["p", P]` |
16
+ * | was added, or joined | a `kind:1851` setting `member:<P>` to `true`, by anyone |
17
+ *
18
+ * A **leave** is a `member:<P>` = `false` signed by `P`; one signed by anybody
19
+ * else is ignored. Joins and leaves order as §6.3 orders changes, `P` is a
20
+ * member when the last is a join, and a member **since** the earliest join
21
+ * after the last leave.
22
+ *
23
+ * *Placed* is the `p` alone, so membership and the `#p` discovery query are
24
+ * the same set. A placement written without one does not count (on production,
25
+ * most assignee changes before 2026-10-01).
26
+ *
27
+ * Muting is private and separate (§11.8 *Muting is private*): see
28
+ * {@link parseMutedBlob}.
29
+ */
30
+ import type { SignedEvent, UnsignedEvent } from '@estiva-app/protocol';
31
+ import { KIND_CHANGE } from './kinds.js';
32
+ export { KIND_CHANGE };
33
+ /** The field prefix of a membership change: `member:<pubkey>`. */
34
+ export declare const MEMBER_FIELD_PREFIX = "member:";
35
+ type Event = Pick<SignedEvent, 'id' | 'pubkey' | 'kind' | 'created_at' | 'tags' | 'content'>;
36
+ /** A relay filter, as `QueryFn` takes one. */
37
+ type Filter = Record<string, unknown>;
38
+ /** The membership field for a person: `member:<pubkey>`. */
39
+ export declare function memberField(pubkey: string): string;
40
+ /** The person a `member:<pubkey>` field names, or undefined when it is not one. */
41
+ export declare function memberOfField(field: string | undefined): string | undefined;
42
+ /**
43
+ * Does the message's content mention the person — a `nostr:npub…` in its body.
44
+ * A `p` tag alone is not a mention for membership: the comment builders tag
45
+ * the file's author and the parent's on every comment (§6.4), so a `p` would
46
+ * re-join an author who left.
47
+ */
48
+ export declare function mentions(event: Pick<SignedEvent, 'content'>, pubkey: string): boolean;
49
+ /**
50
+ * The messages in a file's stream (§11.1): every root that is a comment on it,
51
+ * and every reply in those threads. A `kind:1111` reply whose root the read
52
+ * does not hold still counts when its `A` is the file — a reply copies its
53
+ * thread's object. A `kind:9` never roots a file's stream (§6.4, CON-20).
54
+ */
55
+ export declare function streamOf<E extends Event>(file: string, events: readonly E[]): E[];
56
+ /** Whether a person is a member of a file, and since which second. */
57
+ export interface Membership {
58
+ member: boolean;
59
+ /** Unix seconds: the `created_at` of the first join after the last leave. Undefined when not a member. */
60
+ since?: number;
61
+ }
62
+ /**
63
+ * One person's membership of one file (§11.8 *The fold*), from the file's own
64
+ * events: its root, its stream and its changes.
65
+ */
66
+ export declare function membershipOf(file: string, person: string, events: readonly Event[]): Membership;
67
+ /** Every member of a file and since when, from the file's own events. People who left are absent. */
68
+ export declare function membersOf(file: string, events: readonly Event[]): Map<string, Membership>;
69
+ /**
70
+ * The filters that find every file a person may be a member of (§11.8): the
71
+ * changes that name them, what they wrote, and what mentions them. Each
72
+ * candidate file is then read and folded with {@link membershipOf}. The files
73
+ * they created are the app's own query; `since` bounds all three.
74
+ */
75
+ export declare function membershipFilters(person: string, since?: number): Filter[];
76
+ /**
77
+ * The files an event can make a person a member of: a change's `a`, a
78
+ * comment's `A` (or every `a` when it has none). A `kind:9` names none — its
79
+ * file, if any, is its root's, which the app resolves by reading the thread.
80
+ */
81
+ export declare function candidateFilesOf(event: Pick<SignedEvent, 'kind' | 'tags'>): string[];
82
+ /**
83
+ * A membership change (§11.8 *The membership change*): `true` adds a person,
84
+ * by anyone; `false` is a leave and counts only when the person signs it
85
+ * themselves. Tag order: `a`, `field`, `value`, `h`, `ts`, `p`.
86
+ *
87
+ * Sign one only when the person chose it — joining, leaving, or adding
88
+ * somebody. Never to migrate a private follow (§11.8 *Following, retired*).
89
+ *
90
+ * `content` is the note an activity feed shows, as for every change: a change
91
+ * with none renders as a blank line in Ship's feed. "Join", "Leave" or "Add"
92
+ * by default.
93
+ */
94
+ export declare function buildMembershipChange(pubkey: string, createdAtMs: number, args: {
95
+ file: string;
96
+ folder: string;
97
+ person: string;
98
+ member: boolean;
99
+ note?: string;
100
+ }): UnsignedEvent;
101
+ /** The `d` of the person's mute list. */
102
+ export declare const MUTED_D_TAG = "estiva:muted:v1";
103
+ /** The `t` every §12 app-private blob carries. */
104
+ export declare const APPDATA_TAG = "estiva-appdata";
105
+ /** The decrypted mute list: file addresses and channel uuids. */
106
+ export interface MutedList {
107
+ v: 1;
108
+ updatedAt: number;
109
+ keys: string[];
110
+ }
111
+ /** The mute list from its decrypted content, or undefined when it is not a v1 list. Unknown keys are dropped. */
112
+ export declare function parseMutedBlob(plaintext: string): MutedList | undefined;
113
+ /** The plaintext to encrypt to self: keys de-duplicated and sorted, so equal lists are equal bytes. */
114
+ export declare function serializeMutedBlob(keys: Iterable<string>, updatedAt: number): string;
115
+ /**
116
+ * The unsigned `kind:30078` holding the encrypted mute list. Whole blob, last
117
+ * write wins (§12.3): a writer reads the current list, changes it, and writes
118
+ * all of it.
119
+ */
120
+ export declare function buildMutedEvent(pubkey: string, createdAtMs: number, ciphertext: string): UnsignedEvent;
121
+ /** The filter for the person's mute list. */
122
+ export declare function mutedFilter(pubkey: string): Filter;
123
+ /**
124
+ * The one migration from a retired `estiva:followed:v1` blob: its `muted`
125
+ * keys, to merge into the mute list. Peek wrote `muted` as a map of key to
126
+ * epoch ms, and for one day as a plain list; both read. Its followed `keys`
127
+ * are **not** returned — the list was private, so nothing may publish them as
128
+ * memberships — and a followed Folder is dropped, since the roster decides a
129
+ * general stream.
130
+ */
131
+ export declare function mutedFromFollowed(followedPlaintext: string): string[];
132
+ //# sourceMappingURL=membership.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"membership.d.ts","sourceRoot":"","sources":["../src/membership.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AACH,OAAO,KAAK,EAAE,WAAW,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAA;AACtE,OAAO,EAAqD,WAAW,EAA8B,MAAM,YAAY,CAAA;AAKvH,OAAO,EAAE,WAAW,EAAE,CAAA;AAEtB,kEAAkE;AAClE,eAAO,MAAM,mBAAmB,YAAY,CAAA;AAI5C,KAAK,KAAK,GAAG,IAAI,CAAC,WAAW,EAAE,IAAI,GAAG,QAAQ,GAAG,MAAM,GAAG,YAAY,GAAG,MAAM,GAAG,SAAS,CAAC,CAAA;AAE5F,8CAA8C;AAC9C,KAAK,MAAM,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;AAIrC,4DAA4D;AA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AC,MAAM,EAAE,MAAM,CAAC;IAAC,MAAM,EAAE,MAAM,CAAC;IAAC,MAAM,EAAE,OAAO,CAAC;IAAC,IAAI,CAAC,EAAE,MAAM,CAAA;CAAE,GACrF,aAAa,CAmBf;AAID,yCAAyC;AACzC,eAAO,MAAM,WAAW,oBAAoB,CAAA;AAE5C,kDAAkD;AAClD,eAAO,MAAM,WAAW,mBAAmB,CAAA;AAE3C,iEAAiE;AACjE,MAAM,WAAW,SAAS;IACxB,CAAC,EAAE,CAAC,CAAA;IACJ,SAAS,EAAE,MAAM,CAAA;IACjB,IAAI,EAAE,MAAM,EAAE,CAAA;CACf;AAID,iHAAiH;AACjH,wBAAgB,cAAc,CAAC,SAAS,EAAE,MAAM,GAAG,SAAS,GAAG,SAAS,CAWvE;AAED,uGAAuG;AACvG,wBAAgB,kBAAkB,CAAC,IAAI,EAAE,QAAQ,CAAC,MAAM,CAAC,EAAE,SAAS,EAAE,MAAM,GAAG,MAAM,CAEpF;AAED;;;;GAIG;AACH,wBAAgB,eAAe,CAAC,MAAM,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,GAAG,aAAa,CAWtG;AAED,6CAA6C;AAC7C,wBAAgB,WAAW,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,CAElD;AAED;;;;;;;GAOG;AACH,wBAAgB,iBAAiB,CAAC,iBAAiB,EAAE,MAAM,GAAG,MAAM,EAAE,CAUrE"}
@@ -0,0 +1,271 @@
1
+ import { FILE_ADDRESS as ADDRESS, FOLDER_ID, KIND_APP_DATA, KIND_CHANGE, KIND_COMMENT, KIND_MESSAGE } from './kinds.js';
2
+ import { byOrder } from './order.js';
3
+ import { anchorsOf, isCommentOn, peopleNamedInBody } from './strength.js';
4
+ import { groupThreads } from './threads.js';
5
+ export { KIND_CHANGE };
6
+ /** The field prefix of a membership change: `member:<pubkey>`. */
7
+ export const MEMBER_FIELD_PREFIX = 'member:';
8
+ const PUBKEY = /^[0-9a-f]{64}$/;
9
+ const tag = (event, name) => event.tags.find((t) => t[0] === name)?.[1];
10
+ /** The membership field for a person: `member:<pubkey>`. */
11
+ export function memberField(pubkey) {
12
+ if (!PUBKEY.test(pubkey))
13
+ throw new Error(`not a lowercase hex pubkey: ${JSON.stringify(pubkey)}`);
14
+ return `${MEMBER_FIELD_PREFIX}${pubkey}`;
15
+ }
16
+ /** The person a `member:<pubkey>` field names, or undefined when it is not one. */
17
+ export function memberOfField(field) {
18
+ if (!field?.startsWith(MEMBER_FIELD_PREFIX))
19
+ return undefined;
20
+ const pubkey = field.slice(MEMBER_FIELD_PREFIX.length);
21
+ return PUBKEY.test(pubkey) ? pubkey : undefined;
22
+ }
23
+ /**
24
+ * Does the message's content mention the person — a `nostr:npub…` in its body.
25
+ * A `p` tag alone is not a mention for membership: the comment builders tag
26
+ * the file's author and the parent's on every comment (§6.4), so a `p` would
27
+ * re-join an author who left.
28
+ */
29
+ export function mentions(event, pubkey) {
30
+ return peopleNamedInBody(event.content).has(pubkey);
31
+ }
32
+ /** The address of an addressable event, `<kind>:<pubkey>:<d>`. */
33
+ function addressOf(event) {
34
+ if (event.kind < 30000 || event.kind > 39999)
35
+ return undefined;
36
+ return `${event.kind}:${event.pubkey}:${tag(event, 'd') ?? ''}`;
37
+ }
38
+ /**
39
+ * The messages in a file's stream (§11.1): every root that is a comment on it,
40
+ * and every reply in those threads. A `kind:1111` reply whose root the read
41
+ * does not hold still counts when its `A` is the file — a reply copies its
42
+ * thread's object. A `kind:9` never roots a file's stream (§6.4, CON-20).
43
+ */
44
+ export function streamOf(file, events) {
45
+ const conversation = events.filter((e) => e.kind === KIND_COMMENT || e.kind === KIND_MESSAGE);
46
+ const { roots, replies, missingRoots } = groupThreads(conversation);
47
+ const missing = new Set(missingRoots);
48
+ const out = [];
49
+ for (const root of roots) {
50
+ if (!isCommentOn(root, file))
51
+ continue;
52
+ out.push(root, ...(replies[root.id] ?? []));
53
+ }
54
+ for (const id of missing) {
55
+ for (const reply of replies[id] ?? [])
56
+ if (reply.kind === KIND_COMMENT && anchorsOf(reply).includes(file))
57
+ out.push(reply);
58
+ }
59
+ return out.sort(byOrder);
60
+ }
61
+ const NOT_A_MEMBER = { member: false };
62
+ /**
63
+ * Every join and leave in a file's events, per person. `events` may hold
64
+ * anything; only the file's root versions, its stream and its `kind:1851`
65
+ * changes are read.
66
+ */
67
+ function stepsOf(file, events) {
68
+ const steps = new Map();
69
+ const add = (person, event, join, creation = false) => {
70
+ if (!PUBKEY.test(person))
71
+ return;
72
+ const list = steps.get(person) ?? [];
73
+ list.push({ event, join, creation });
74
+ steps.set(person, list);
75
+ };
76
+ // A relay keeps only the latest version of an addressable event, so the root
77
+ // the reader holds is usually the last edit. Its join is ordered first, so
78
+ // an edit after a leave does not make the author a member again.
79
+ const versions = events.filter((e) => addressOf(e) === file).sort(byOrder);
80
+ if (versions[0])
81
+ add(versions[0].pubkey, versions[0], true, true);
82
+ for (const message of streamOf(file, events)) {
83
+ add(message.pubkey, message, true);
84
+ for (const person of peopleNamedInBody(message.content))
85
+ add(person, message, true);
86
+ }
87
+ for (const change of events) {
88
+ if (change.kind !== KIND_CHANGE || !change.tags.some((t) => t[0] === 'a' && t[1] === file))
89
+ continue;
90
+ const field = tag(change, 'field');
91
+ const value = tag(change, 'value');
92
+ const member = memberOfField(field);
93
+ if (member !== undefined) {
94
+ if (value === 'true')
95
+ add(member, change, true);
96
+ else if (value === 'false' && change.pubkey === member)
97
+ add(member, change, false);
98
+ continue;
99
+ }
100
+ // A change with an empty value takes someone off (an unassign) and places nobody, whatever `p` it carries.
101
+ if (field?.startsWith(MEMBER_FIELD_PREFIX) || !value)
102
+ continue;
103
+ for (const t of change.tags)
104
+ if (t[0] === 'p' && typeof t[1] === 'string')
105
+ add(t[1], change, true);
106
+ }
107
+ return steps;
108
+ }
109
+ function fold(steps) {
110
+ if (!steps || steps.length === 0)
111
+ return NOT_A_MEMBER;
112
+ const ordered = [...steps].sort((a, b) => Number(b.creation ?? false) - Number(a.creation ?? false) || byOrder(a.event, b.event) || Number(a.join) - Number(b.join));
113
+ if (!ordered[ordered.length - 1].join)
114
+ return NOT_A_MEMBER;
115
+ // Since: the earliest second among the joins after the last leave — the creation's
116
+ // held version can be a later edit than the author's first comment.
117
+ let since;
118
+ for (const step of ordered) {
119
+ if (!step.join)
120
+ since = undefined;
121
+ else
122
+ since = since === undefined ? step.event.created_at : Math.min(since, step.event.created_at);
123
+ }
124
+ return { member: true, since };
125
+ }
126
+ /**
127
+ * One person's membership of one file (§11.8 *The fold*), from the file's own
128
+ * events: its root, its stream and its changes.
129
+ */
130
+ export function membershipOf(file, person, events) {
131
+ return fold(stepsOf(file, events).get(person));
132
+ }
133
+ /** Every member of a file and since when, from the file's own events. People who left are absent. */
134
+ export function membersOf(file, events) {
135
+ const members = new Map();
136
+ for (const [person, steps] of stepsOf(file, events)) {
137
+ const membership = fold(steps);
138
+ if (membership.member)
139
+ members.set(person, membership);
140
+ }
141
+ return members;
142
+ }
143
+ /**
144
+ * The filters that find every file a person may be a member of (§11.8): the
145
+ * changes that name them, what they wrote, and what mentions them. Each
146
+ * candidate file is then read and folded with {@link membershipOf}. The files
147
+ * they created are the app's own query; `since` bounds all three.
148
+ */
149
+ export function membershipFilters(person, since) {
150
+ if (!PUBKEY.test(person))
151
+ throw new Error(`not a lowercase hex pubkey: ${JSON.stringify(person)}`);
152
+ const bound = since === undefined ? {} : { since };
153
+ return [
154
+ { kinds: [KIND_CHANGE], '#p': [person], ...bound },
155
+ { kinds: [KIND_COMMENT, KIND_MESSAGE], authors: [person], ...bound },
156
+ { kinds: [KIND_COMMENT, KIND_MESSAGE], '#p': [person], ...bound },
157
+ ];
158
+ }
159
+ /**
160
+ * The files an event can make a person a member of: a change's `a`, a
161
+ * comment's `A` (or every `a` when it has none). A `kind:9` names none — its
162
+ * file, if any, is its root's, which the app resolves by reading the thread.
163
+ */
164
+ export function candidateFilesOf(event) {
165
+ if (event.kind === KIND_CHANGE)
166
+ return event.tags.filter((t) => t[0] === 'a' && ADDRESS.test(t[1] ?? '')).map((t) => t[1]);
167
+ return anchorsOf(event).filter((a) => ADDRESS.test(a));
168
+ }
169
+ /**
170
+ * A membership change (§11.8 *The membership change*): `true` adds a person,
171
+ * by anyone; `false` is a leave and counts only when the person signs it
172
+ * themselves. Tag order: `a`, `field`, `value`, `h`, `ts`, `p`.
173
+ *
174
+ * Sign one only when the person chose it — joining, leaving, or adding
175
+ * somebody. Never to migrate a private follow (§11.8 *Following, retired*).
176
+ *
177
+ * `content` is the note an activity feed shows, as for every change: a change
178
+ * with none renders as a blank line in Ship's feed. "Join", "Leave" or "Add"
179
+ * by default.
180
+ */
181
+ export function buildMembershipChange(pubkey, createdAtMs, args) {
182
+ const note = args.note ?? (!args.member ? 'Leave' : args.person === pubkey ? 'Join' : 'Add');
183
+ if (!ADDRESS.test(args.file))
184
+ throw new Error(`not a file address: ${JSON.stringify(args.file)}`);
185
+ if (!FOLDER_ID.test(args.folder))
186
+ throw new Error(`not a Folder id (lowercase UUID v4): ${JSON.stringify(args.folder)}`);
187
+ if (!Number.isSafeInteger(createdAtMs) || createdAtMs < 0)
188
+ throw new Error(`not epoch milliseconds: ${createdAtMs}`);
189
+ return {
190
+ pubkey,
191
+ created_at: Math.floor(createdAtMs / 1000),
192
+ kind: KIND_CHANGE,
193
+ tags: [
194
+ ['a', args.file],
195
+ ['field', memberField(args.person)],
196
+ ['value', args.member ? 'true' : 'false'],
197
+ ['h', args.folder],
198
+ ['ts', String(createdAtMs)],
199
+ ['p', args.person],
200
+ ],
201
+ content: note,
202
+ };
203
+ }
204
+ // ── Muting: private, suite-wide (§11.8 *Muting is private*, §12) ────────────
205
+ /** The `d` of the person's mute list. */
206
+ export const MUTED_D_TAG = 'estiva:muted:v1';
207
+ /** The `t` every §12 app-private blob carries. */
208
+ export const APPDATA_TAG = 'estiva-appdata';
209
+ const isMuteKey = (key) => typeof key === 'string' && (ADDRESS.test(key) || FOLDER_ID.test(key));
210
+ /** The mute list from its decrypted content, or undefined when it is not a v1 list. Unknown keys are dropped. */
211
+ export function parseMutedBlob(plaintext) {
212
+ let value;
213
+ try {
214
+ value = JSON.parse(plaintext);
215
+ }
216
+ catch {
217
+ return undefined;
218
+ }
219
+ if (!value || typeof value !== 'object')
220
+ return undefined;
221
+ const { v, updatedAt, keys } = value;
222
+ if (v !== 1 || typeof updatedAt !== 'number' || !Number.isFinite(updatedAt) || !Array.isArray(keys))
223
+ return undefined;
224
+ return { v: 1, updatedAt, keys: [...new Set(keys.filter(isMuteKey))].sort() };
225
+ }
226
+ /** The plaintext to encrypt to self: keys de-duplicated and sorted, so equal lists are equal bytes. */
227
+ export function serializeMutedBlob(keys, updatedAt) {
228
+ return JSON.stringify({ v: 1, updatedAt, keys: [...new Set([...keys].filter(isMuteKey))].sort() });
229
+ }
230
+ /**
231
+ * The unsigned `kind:30078` holding the encrypted mute list. Whole blob, last
232
+ * write wins (§12.3): a writer reads the current list, changes it, and writes
233
+ * all of it.
234
+ */
235
+ export function buildMutedEvent(pubkey, createdAtMs, ciphertext) {
236
+ return {
237
+ pubkey,
238
+ created_at: Math.floor(createdAtMs / 1000),
239
+ kind: KIND_APP_DATA,
240
+ tags: [
241
+ ['d', MUTED_D_TAG],
242
+ ['t', APPDATA_TAG],
243
+ ],
244
+ content: ciphertext,
245
+ };
246
+ }
247
+ /** The filter for the person's mute list. */
248
+ export function mutedFilter(pubkey) {
249
+ return { kinds: [KIND_APP_DATA], authors: [pubkey], '#d': [MUTED_D_TAG], limit: 1 };
250
+ }
251
+ /**
252
+ * The one migration from a retired `estiva:followed:v1` blob: its `muted`
253
+ * keys, to merge into the mute list. Peek wrote `muted` as a map of key to
254
+ * epoch ms, and for one day as a plain list; both read. Its followed `keys`
255
+ * are **not** returned — the list was private, so nothing may publish them as
256
+ * memberships — and a followed Folder is dropped, since the roster decides a
257
+ * general stream.
258
+ */
259
+ export function mutedFromFollowed(followedPlaintext) {
260
+ let value;
261
+ try {
262
+ value = JSON.parse(followedPlaintext);
263
+ }
264
+ catch {
265
+ return [];
266
+ }
267
+ const muted = value && typeof value === 'object' ? value.muted : undefined;
268
+ const keys = Array.isArray(muted) ? muted : muted && typeof muted === 'object' ? Object.keys(muted) : [];
269
+ return [...new Set(keys.filter(isMuteKey))].sort();
270
+ }
271
+ //# sourceMappingURL=membership.js.map