@estiva-app/conversation 0.27.0 → 0.29.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 +38 -0
- package/README.md +1 -0
- package/dist/index.d.ts +3 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3 -2
- package/dist/index.js.map +1 -1
- package/dist/membership.d.ts +9 -1
- package/dist/membership.d.ts.map +1 -1
- package/dist/membership.js +22 -7
- package/dist/membership.js.map +1 -1
- package/dist/places.d.ts +181 -0
- package/dist/places.d.ts.map +1 -0
- package/dist/places.js +464 -0
- package/dist/places.js.map +1 -0
- package/package.json +1 -1
- package/src/index.ts +28 -1
- package/src/membership.ts +24 -7
- package/src/places.ts +543 -0
package/dist/places.js
ADDED
|
@@ -0,0 +1,464 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Places and following — SPEC §11.8 *Places and following*.
|
|
3
|
+
*
|
|
4
|
+
* A **place** is one of a team's three kinds (§3): its chat, a space, or a
|
|
5
|
+
* topic it leads. A person `P` is **in** a place at a level, All or
|
|
6
|
+
* Important, or not in it, and that, not file membership, decides what on the
|
|
7
|
+
* place is unread for `P`.
|
|
8
|
+
*
|
|
9
|
+
* | way in | the events |
|
|
10
|
+
* | --- | --- |
|
|
11
|
+
* | 1. chose a level | a `follow:<P>` change on the place, signed by `P`, value `all` or `important` |
|
|
12
|
+
* | 2. joined, or was added | a `member:<P>` = `true` on the place, by anyone |
|
|
13
|
+
* | 3. made it | `P` wrote the topic's or space's first record |
|
|
14
|
+
* | 4. a team's default | a space of a team `P` is a member or follower of, or the chat of a team `P` is a member of, not in `P`'s private `off` list |
|
|
15
|
+
*
|
|
16
|
+
* `P`'s own acts read in one order: `P`'s `member:<P>` = `false` ends ways 1
|
|
17
|
+
* to 3 and every level chosen before it; a level, a join or an Add after it
|
|
18
|
+
* puts `P` back in. Only the `off` list turns a default off. An archived
|
|
19
|
+
* team's places hold nobody. A mute already kept for a place still wins: it
|
|
20
|
+
* lights only what mentions `P`.
|
|
21
|
+
*
|
|
22
|
+
* Everything here is worked out from events the caller read with
|
|
23
|
+
* {@link placeFilters}; nothing is stored and no default is ever written.
|
|
24
|
+
*
|
|
25
|
+
* why: https://github.com/estiva-app/estiva-docs/blob/main/decisions/a-team-has-members-and-followers-and-a-place-is-followed-at-a-level.md
|
|
26
|
+
*/
|
|
27
|
+
import { fileIdOf, KIND } from '@estiva-app/protocol';
|
|
28
|
+
import { FILE_ADDRESS, FOLDER_ID, KIND_APP_DATA, KIND_CHANGE } from './kinds.js';
|
|
29
|
+
import { APPDATA_TAG, FOLLOW_FIELD_PREFIX, memberOfField } from './membership.js';
|
|
30
|
+
import { byOrder } from './order.js';
|
|
31
|
+
import { REPLY_FLOOR_CONTEXT, belowReplyFloor, effectiveReadAt, streamMarkerOf, threadContext } from './readState.js';
|
|
32
|
+
import { peopleNamedInBody } from './strength.js';
|
|
33
|
+
import { groupThreads } from './threads.js';
|
|
34
|
+
/** A team's own address kind: on it, a level or a member change is about the team's chat. */
|
|
35
|
+
const KIND_TEAM = 39000;
|
|
36
|
+
/** The relay's list of a team's members (NIP-29). */
|
|
37
|
+
const KIND_ROSTER = 39002;
|
|
38
|
+
/** Put a person on a team, and take one off (NIP-29). */
|
|
39
|
+
const KIND_PUT_USER = KIND.NIP29_PUT_USER;
|
|
40
|
+
const KIND_REMOVE_USER = 9001;
|
|
41
|
+
/** A person's own join and leave (NIP-29). */
|
|
42
|
+
const KIND_JOIN = 9021;
|
|
43
|
+
const KIND_LEAVE = 9022;
|
|
44
|
+
const KIND_CREATE_TEAM = KIND.NIP29_CREATE_GROUP;
|
|
45
|
+
/** A team's relay-signed list, and the command that changes it (§3.3). */
|
|
46
|
+
const KIND_FOLDER_STATE = 30890;
|
|
47
|
+
const KIND_FOLDER_COMMAND = KIND.FOLDER_COMMAND;
|
|
48
|
+
/** The role on a team list's entry that marks a topic one of the team's spaces (§3.3). */
|
|
49
|
+
const SPACE_ROLE = 'space';
|
|
50
|
+
const PUBKEY = /^[0-9a-f]{64}$/;
|
|
51
|
+
const tag = (event, name) => event.tags.find((t) => t[0] === name)?.[1];
|
|
52
|
+
const dOf = (address) => address.split(':').slice(2).join(':');
|
|
53
|
+
/** The person's own acts on the place, in §6.3's order: the first record first, a leave before a join in a tie. */
|
|
54
|
+
function actsOf(place, person, events) {
|
|
55
|
+
const id = fileIdOf(place.address) ?? dOf(place.address);
|
|
56
|
+
const acts = [];
|
|
57
|
+
const versions = place.address.startsWith(`${KIND_TEAM}:`) ? [] : events.filter((e) => addressOf(e) === place.address).sort(byOrder);
|
|
58
|
+
if (versions[0]?.pubkey === person)
|
|
59
|
+
acts.push({ event: { ...versions[0], created_at: Math.min(...versions.map((v) => v.created_at)) }, act: 'creation' });
|
|
60
|
+
// A change filed in another Folder is ignored (§6.2): the place's own Folder is the team for its chat, else its root's `h`.
|
|
61
|
+
const folder = versions.length ? (tag(versions[versions.length - 1], 'h') ?? place.team) : place.team;
|
|
62
|
+
for (const change of events) {
|
|
63
|
+
if (change.kind !== KIND_CHANGE || tag(change, 'a') !== place.address || tag(change, 'h') !== folder)
|
|
64
|
+
continue;
|
|
65
|
+
const O = tag(change, 'O');
|
|
66
|
+
if (O !== undefined && O !== id)
|
|
67
|
+
continue;
|
|
68
|
+
// A level or a membership change is never in a `set` (§11.8): one there is not read.
|
|
69
|
+
if (change.tags.some((t) => t[0] === 'set'))
|
|
70
|
+
continue;
|
|
71
|
+
const field = tag(change, 'field');
|
|
72
|
+
const value = tag(change, 'value');
|
|
73
|
+
if (field === `${FOLLOW_FIELD_PREFIX}${person}`) {
|
|
74
|
+
// Only `P` sets `P`'s level; one signed by anybody else is ignored.
|
|
75
|
+
if (change.pubkey !== person)
|
|
76
|
+
continue;
|
|
77
|
+
if (value === 'all' || value === 'important')
|
|
78
|
+
acts.push({ event: change, act: 'level', level: value });
|
|
79
|
+
else if (value === '')
|
|
80
|
+
acts.push({ event: change, act: 'clear' });
|
|
81
|
+
}
|
|
82
|
+
else if (memberOfField(field) === person) {
|
|
83
|
+
if (value === 'true')
|
|
84
|
+
acts.push({ event: change, act: 'join' });
|
|
85
|
+
else if (value === 'false' && change.pubkey === person)
|
|
86
|
+
acts.push({ event: change, act: 'leave' });
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
const rank = (a) => (a.act === 'creation' ? 0 : 1);
|
|
90
|
+
return acts.sort((a, b) => rank(a) - rank(b) || byOrder(a.event, b.event) || Number(a.act !== 'leave') - Number(b.act !== 'leave'));
|
|
91
|
+
}
|
|
92
|
+
function addressOf(event) {
|
|
93
|
+
if (event.kind < 30000 || event.kind > 39999)
|
|
94
|
+
return undefined;
|
|
95
|
+
return `${event.kind}:${event.pubkey}:${tag(event, 'd') ?? ''}`;
|
|
96
|
+
}
|
|
97
|
+
const latest = (events) => [...events].sort(byOrder).at(-1);
|
|
98
|
+
/** Whether the entry names the place: its address, or its id in the `o` form. */
|
|
99
|
+
const names = (entry, address) => (entry[0] === 'a' && entry[1] === address) || (entry[0] === 'o' && entry[1] === (fileIdOf(address) ?? dOf(address)));
|
|
100
|
+
/** Whether a list's or a command's entries mark the place a space: named, the role after an empty third element. */
|
|
101
|
+
function markOf(event, address) {
|
|
102
|
+
let mark;
|
|
103
|
+
for (const entry of event.tags) {
|
|
104
|
+
if (!names(entry, address))
|
|
105
|
+
continue;
|
|
106
|
+
if (entry[3] === SPACE_ROLE && !entry[2])
|
|
107
|
+
mark ??= 'space';
|
|
108
|
+
else
|
|
109
|
+
mark = 'plain';
|
|
110
|
+
}
|
|
111
|
+
return mark;
|
|
112
|
+
}
|
|
113
|
+
/** Whether the team's current list marks the place one of its spaces (§3.3). A list naming it without the role too keeps it plain. */
|
|
114
|
+
function isSpace(place, listing) {
|
|
115
|
+
const state = latest(listing.filter((e) => e.kind === KIND_FOLDER_STATE && tag(e, 'd') === place.team));
|
|
116
|
+
return !!state && markOf(state, place.address) === 'space';
|
|
117
|
+
}
|
|
118
|
+
/** Which of a team's three kinds the place is. */
|
|
119
|
+
export function placeKindOf(place, listing = []) {
|
|
120
|
+
if (place.address.startsWith(`${KIND_TEAM}:`))
|
|
121
|
+
return 'chat';
|
|
122
|
+
return isSpace(place, listing) ? 'space' : 'topic';
|
|
123
|
+
}
|
|
124
|
+
/**
|
|
125
|
+
* When the place became one of the team's spaces: the earliest `kind:1852`
|
|
126
|
+
* `add` or `move` into the team naming it with the `space` role, since the
|
|
127
|
+
* last command that unmarked it, removed it or moved it out. A list marking
|
|
128
|
+
* it with no such command held falls back to the list's own time, which is
|
|
129
|
+
* no earlier than the mark.
|
|
130
|
+
*/
|
|
131
|
+
function spaceStartOf(place, listing) {
|
|
132
|
+
let start;
|
|
133
|
+
const commands = listing.filter((e) => e.kind === KIND_FOLDER_COMMAND).sort(byOrder);
|
|
134
|
+
for (const command of commands) {
|
|
135
|
+
const op = tag(command, 'op');
|
|
136
|
+
const into = tag(command, 'h') === place.team;
|
|
137
|
+
const mark = markOf(command, place.address);
|
|
138
|
+
if (!into) {
|
|
139
|
+
// A move out of the team takes the mark with it.
|
|
140
|
+
if (op === 'move' && tag(command, 'from') === place.team && mark)
|
|
141
|
+
start = undefined;
|
|
142
|
+
continue;
|
|
143
|
+
}
|
|
144
|
+
if (op === 'remove' && mark)
|
|
145
|
+
start = undefined;
|
|
146
|
+
else if (op === 'set' && !mark)
|
|
147
|
+
start = undefined;
|
|
148
|
+
else if ((op === 'add' || op === 'move' || op === 'set') && mark) {
|
|
149
|
+
if (mark === 'plain')
|
|
150
|
+
start = undefined;
|
|
151
|
+
else
|
|
152
|
+
start ??= command.created_at;
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
if (start !== undefined)
|
|
156
|
+
return start;
|
|
157
|
+
return latest(listing.filter((e) => e.kind === KIND_FOLDER_STATE && tag(e, 'd') === place.team))?.created_at;
|
|
158
|
+
}
|
|
159
|
+
/** Whether the team's current roster lists the person. */
|
|
160
|
+
function onRoster(team, person, roster) {
|
|
161
|
+
const list = latest(roster.filter((e) => e.kind === KIND_ROSTER && tag(e, 'd') === team));
|
|
162
|
+
return list?.tags.some((t) => t[0] === 'p' && t[1] === person) ? list : undefined;
|
|
163
|
+
}
|
|
164
|
+
/**
|
|
165
|
+
* When the team reached a person its roster lists: the earliest stored
|
|
166
|
+
* `kind:9000` or `kind:9021` naming them on the team since their last
|
|
167
|
+
* `kind:9001` or `kind:9022` (a later `kind:9000` changing their role is not
|
|
168
|
+
* a join), or the `kind:9007` when they made the team. A roster keeps no time
|
|
169
|
+
* per person, so with none of those held the roster's own time stands in: no
|
|
170
|
+
* earlier than their join, so nothing older lights.
|
|
171
|
+
*/
|
|
172
|
+
function joinedTeamAt(team, person, roster, list) {
|
|
173
|
+
const onTeam = roster.filter((e) => tag(e, 'h') === team).sort(byOrder);
|
|
174
|
+
const namesPerson = (e) => e.tags.some((t) => t[0] === 'p' && t[1] === person);
|
|
175
|
+
let since;
|
|
176
|
+
for (const e of onTeam) {
|
|
177
|
+
const left = (e.kind === KIND_REMOVE_USER && namesPerson(e)) || (e.kind === KIND_LEAVE && e.pubkey === person);
|
|
178
|
+
const joined = (e.kind === KIND_PUT_USER && namesPerson(e)) || (e.kind === KIND_JOIN && e.pubkey === person) || (e.kind === KIND_CREATE_TEAM && e.pubkey === person);
|
|
179
|
+
if (left)
|
|
180
|
+
since = undefined;
|
|
181
|
+
else if (joined)
|
|
182
|
+
since ??= e.created_at;
|
|
183
|
+
}
|
|
184
|
+
return since ?? list.created_at;
|
|
185
|
+
}
|
|
186
|
+
/**
|
|
187
|
+
* A team's members, from the roster facts {@link placeFilters} reads (`kind:39002`
|
|
188
|
+
* and the stored `9000`, `9001`, `9021`, `9022`, `9007`): everyone its current
|
|
189
|
+
* `kind:39002` lists, each with when they joined, in the order they joined. Who
|
|
190
|
+
* is in a team is visible to anyone who can read it; who follows it is not, so
|
|
191
|
+
* this never lists a follower (§11.8).
|
|
192
|
+
*/
|
|
193
|
+
export function teamMembersOf(team, roster) {
|
|
194
|
+
const list = latest(roster.filter((e) => e.kind === KIND_ROSTER && tag(e, 'd') === team));
|
|
195
|
+
if (!list)
|
|
196
|
+
return [];
|
|
197
|
+
const people = [...new Set(list.tags.filter((t) => t[0] === 'p' && t[1]).map((t) => t[1]))];
|
|
198
|
+
return people
|
|
199
|
+
.map((pubkey) => ({ pubkey, since: joinedTeamAt(team, pubkey, roster, list) }))
|
|
200
|
+
.sort((a, b) => a.since - b.since || a.pubkey.localeCompare(b.pubkey));
|
|
201
|
+
}
|
|
202
|
+
/** The team's own start: its `kind:9007`, when held. */
|
|
203
|
+
function teamStartOf(team, roster) {
|
|
204
|
+
return roster.find((e) => e.kind === KIND_CREATE_TEAM && tag(e, 'h') === team)?.created_at;
|
|
205
|
+
}
|
|
206
|
+
/**
|
|
207
|
+
* Whether a person is in a place, at what level and since when (§11.8
|
|
208
|
+
* *Places and following*). Pure: `facts` are the events {@link placeFilters}
|
|
209
|
+
* returned, and the person's private teams list.
|
|
210
|
+
*/
|
|
211
|
+
export function followingOf(place, person, facts) {
|
|
212
|
+
if (!PUBKEY.test(person))
|
|
213
|
+
throw new Error(`not a lowercase hex pubkey: ${JSON.stringify(person)}`);
|
|
214
|
+
const kind = placeKindOf(place, facts.listing);
|
|
215
|
+
const out = { kind, in: false, ways: [] };
|
|
216
|
+
if (facts.archived)
|
|
217
|
+
return out;
|
|
218
|
+
const starts = [];
|
|
219
|
+
const acts = actsOf(place, person, facts.events);
|
|
220
|
+
const lastLeave = acts.map((a) => a.act).lastIndexOf('leave');
|
|
221
|
+
// An Add after a leave names it with `prev`, so the relay's order holds whatever the two clocks said (§11.8).
|
|
222
|
+
const leaveId = acts[lastLeave]?.event.id;
|
|
223
|
+
const named = acts.slice(0, Math.max(lastLeave, 0)).filter((a) => a.act === 'join' && leaveId !== undefined && tag(a.event, 'prev') === leaveId);
|
|
224
|
+
const after = [...named, ...acts.slice(lastLeave + 1)];
|
|
225
|
+
// 1. A level chosen since the last leave, and not cleared since; changing it keeps its start.
|
|
226
|
+
let chosen;
|
|
227
|
+
for (const a of after) {
|
|
228
|
+
if (a.act === 'level') {
|
|
229
|
+
const allSince = a.level === 'all' ? (chosen?.allSince ?? a.event.created_at) : undefined;
|
|
230
|
+
chosen = { level: a.level, since: chosen?.since ?? a.event.created_at, ...(allSince !== undefined ? { allSince } : {}) };
|
|
231
|
+
}
|
|
232
|
+
else if (a.act === 'clear')
|
|
233
|
+
chosen = undefined;
|
|
234
|
+
}
|
|
235
|
+
if (chosen) {
|
|
236
|
+
out.ways.push('level');
|
|
237
|
+
starts.push(chosen.since);
|
|
238
|
+
}
|
|
239
|
+
// 2. Joined, or added, since the last leave. An Add chooses no level.
|
|
240
|
+
const joined = after.find((a) => a.act === 'join');
|
|
241
|
+
if (joined) {
|
|
242
|
+
out.ways.push('added');
|
|
243
|
+
starts.push(joined.event.created_at);
|
|
244
|
+
}
|
|
245
|
+
// 3. Made it: the first record orders before everything, so any leave ends it.
|
|
246
|
+
const made = after.find((a) => a.act === 'creation');
|
|
247
|
+
if (made) {
|
|
248
|
+
out.ways.push('author');
|
|
249
|
+
starts.push(made.event.created_at);
|
|
250
|
+
}
|
|
251
|
+
// 4. A team's default, unless the person's private list turned it off. A topic a team leads reaches nobody.
|
|
252
|
+
const off = new Set(facts.teams?.off ?? []);
|
|
253
|
+
const id = dOf(place.address);
|
|
254
|
+
if (kind !== 'topic' && !off.has(id)) {
|
|
255
|
+
const roster = facts.roster ?? [];
|
|
256
|
+
const list = onRoster(place.team, person, roster);
|
|
257
|
+
const followed = facts.teams?.teams[place.team];
|
|
258
|
+
let reached;
|
|
259
|
+
if (list)
|
|
260
|
+
reached = joinedTeamAt(place.team, person, roster, list);
|
|
261
|
+
else if (kind === 'space' && followed !== undefined)
|
|
262
|
+
reached = Math.floor(followed / 1000);
|
|
263
|
+
if (reached !== undefined) {
|
|
264
|
+
const cameIn = kind === 'space' ? spaceStartOf(place, facts.listing ?? []) : teamStartOf(place.team, roster);
|
|
265
|
+
out.ways.push('team');
|
|
266
|
+
starts.push(Math.max(reached, cameIn ?? reached));
|
|
267
|
+
}
|
|
268
|
+
}
|
|
269
|
+
if (out.ways.length === 0)
|
|
270
|
+
return out;
|
|
271
|
+
return { ...out, in: true, level: chosen?.level ?? 'important', since: Math.min(...starts), ...(chosen?.allSince !== undefined ? { allSince: chosen.allSince } : {}) };
|
|
272
|
+
}
|
|
273
|
+
/**
|
|
274
|
+
* The filters that read what {@link followingOf} needs for one place: its
|
|
275
|
+
* root and changes, the team's roster, the team's list and the commands
|
|
276
|
+
* naming the place, and the person's teams list. A topic's or space's
|
|
277
|
+
* conversation is the app's own read (see `streamOf`); a team's chat is its
|
|
278
|
+
* general stream.
|
|
279
|
+
*/
|
|
280
|
+
export function placeFilters(place, person) {
|
|
281
|
+
if (!PUBKEY.test(person))
|
|
282
|
+
throw new Error(`not a lowercase hex pubkey: ${JSON.stringify(person)}`);
|
|
283
|
+
if (!FILE_ADDRESS.test(place.address))
|
|
284
|
+
throw new Error(`not a place address: ${JSON.stringify(place.address)}`);
|
|
285
|
+
if (!FOLDER_ID.test(place.team))
|
|
286
|
+
throw new Error(`not a team id (lowercase UUID v4): ${JSON.stringify(place.team)}`);
|
|
287
|
+
const [kind, author, d] = [Number(place.address.split(':')[0]), place.address.split(':')[1], dOf(place.address)];
|
|
288
|
+
const id = fileIdOf(place.address);
|
|
289
|
+
return [
|
|
290
|
+
{ kinds: [KIND_CHANGE], '#a': [place.address] },
|
|
291
|
+
...(kind === KIND_TEAM ? [] : [{ kinds: [kind], authors: [author], '#d': [d] }]),
|
|
292
|
+
{ kinds: [KIND_PUT_USER, KIND_REMOVE_USER, KIND_JOIN, KIND_LEAVE, KIND_CREATE_TEAM], '#h': [place.team] },
|
|
293
|
+
{ kinds: [KIND_ROSTER], '#d': [place.team] },
|
|
294
|
+
...(kind === KIND_TEAM
|
|
295
|
+
? []
|
|
296
|
+
: [
|
|
297
|
+
{ kinds: [KIND_FOLDER_STATE], '#d': [place.team] },
|
|
298
|
+
{ kinds: [KIND_FOLDER_COMMAND], '#a': [place.address] },
|
|
299
|
+
...(id !== undefined ? [{ kinds: [KIND_FOLDER_COMMAND], '#o': [id] }] : []),
|
|
300
|
+
]),
|
|
301
|
+
teamsFilter(person),
|
|
302
|
+
];
|
|
303
|
+
}
|
|
304
|
+
/**
|
|
305
|
+
* The unread messages on a place, oldest first per conversation (§11.8 *What
|
|
306
|
+
* is unread on a place*). `messages` is the place's stream: `streamOf` for a
|
|
307
|
+
* topic or space, the team's general stream for its chat.
|
|
308
|
+
*
|
|
309
|
+
* At **Important** a new conversation lights, and a reply in a conversation
|
|
310
|
+
* `me` is in — wrote its root or a reply, or was mentioned in it — from the
|
|
311
|
+
* moment they were. At **All** every message lights from the moment they
|
|
312
|
+
* chose All (`allSince`), and Important's rule before it. A mention of `me` lights
|
|
313
|
+
* at any level, and when they are not in. A file the place lists is judged
|
|
314
|
+
* at All the same way, by passing its own stream and context with this
|
|
315
|
+
* following.
|
|
316
|
+
*/
|
|
317
|
+
export function unreadOnPlace(messages, merged, judge) {
|
|
318
|
+
const { roots, replies } = groupThreads(messages);
|
|
319
|
+
const out = [];
|
|
320
|
+
const conversation = (root, list, rootId) => {
|
|
321
|
+
const all = root ? [root, ...list] : [...list];
|
|
322
|
+
const inSince = all.find((m) => m.pubkey === judge.me || peopleNamedInBody(m.content).has(judge.me))?.created_at;
|
|
323
|
+
if (root && isUnreadOnPlace(root, undefined, merged, judge, inSince))
|
|
324
|
+
out.push(root);
|
|
325
|
+
for (const reply of list)
|
|
326
|
+
if (isUnreadOnPlace(reply, rootId, merged, judge, inSince))
|
|
327
|
+
out.push(reply);
|
|
328
|
+
};
|
|
329
|
+
for (const root of roots)
|
|
330
|
+
conversation(root, replies[root.id] ?? [], root.id);
|
|
331
|
+
const held = new Set(roots.map((r) => r.id));
|
|
332
|
+
for (const [root, list] of Object.entries(replies))
|
|
333
|
+
if (!held.has(root))
|
|
334
|
+
conversation(undefined, list, root);
|
|
335
|
+
return out;
|
|
336
|
+
}
|
|
337
|
+
/**
|
|
338
|
+
* Whether one message on a place is unread. `root` is its conversation's root
|
|
339
|
+
* id when it is a reply; `inConversationSince`, the second `me` came into
|
|
340
|
+
* that conversation (wrote in it or was mentioned there), or undefined when
|
|
341
|
+
* they never did — then a reply lights at Important only by a mention.
|
|
342
|
+
*/
|
|
343
|
+
export function isUnreadOnPlace(message, root, merged, judge, inConversationSince) {
|
|
344
|
+
if (message.pubkey === judge.me)
|
|
345
|
+
return false;
|
|
346
|
+
const { following } = judge;
|
|
347
|
+
const mentioned = peopleNamedInBody(message.content).has(judge.me);
|
|
348
|
+
const started = following.in && (following.since === undefined || message.created_at >= following.since);
|
|
349
|
+
const levelLights = (following.level === 'all' && message.created_at >= (following.allSince ?? following.since ?? 0)) ||
|
|
350
|
+
root === undefined ||
|
|
351
|
+
(inConversationSince !== undefined && message.created_at >= inConversationSince);
|
|
352
|
+
if (!mentioned && (judge.muted || !started || !levelLights))
|
|
353
|
+
return false;
|
|
354
|
+
const thread = root === undefined ? undefined : threadContext(root);
|
|
355
|
+
const marker = thread === undefined ? streamMarkerOf(merged, judge.stream) : effectiveReadAt(merged, thread, judge.stream);
|
|
356
|
+
if (marker !== undefined)
|
|
357
|
+
return message.created_at > marker;
|
|
358
|
+
if (thread !== undefined && belowReplyFloor(message.created_at, merged[REPLY_FLOOR_CONTEXT]))
|
|
359
|
+
return false;
|
|
360
|
+
if (started && following.since !== undefined)
|
|
361
|
+
return true;
|
|
362
|
+
return judge.floor === undefined || message.created_at >= judge.floor;
|
|
363
|
+
}
|
|
364
|
+
// ── A level: `follow:<P>`, signed by `P` alone ──────────────────────────────
|
|
365
|
+
/** The level field for a person: `follow:<pubkey>`. */
|
|
366
|
+
export function followField(pubkey) {
|
|
367
|
+
if (!PUBKEY.test(pubkey))
|
|
368
|
+
throw new Error(`not a lowercase hex pubkey: ${JSON.stringify(pubkey)}`);
|
|
369
|
+
return `${FOLLOW_FIELD_PREFIX}${pubkey}`;
|
|
370
|
+
}
|
|
371
|
+
/**
|
|
372
|
+
* The level change (§11.8 *The level change*): `P` chooses All or Important
|
|
373
|
+
* on a place, or `''` to go back to the default. Signed by `P`, for `P`: the
|
|
374
|
+
* relay refuses, and every reader ignores, one signed by anybody else. Never
|
|
375
|
+
* in a `set`, no `prev`. Tag order: `a`, `[O]`, `field`, `value`, `h`, `ts`,
|
|
376
|
+
* `p`.
|
|
377
|
+
*
|
|
378
|
+
* Not following is never public: turning a team's default off goes in the
|
|
379
|
+
* private teams list ({@link serializeTeamsBlob}), and leaving a place one
|
|
380
|
+
* joined is {@link buildMembershipChange}'s leave.
|
|
381
|
+
*/
|
|
382
|
+
export function buildLevelChange(pubkey, createdAtMs, args) {
|
|
383
|
+
const field = followField(pubkey);
|
|
384
|
+
if (!FILE_ADDRESS.test(args.place))
|
|
385
|
+
throw new Error(`not a place address: ${JSON.stringify(args.place)}`);
|
|
386
|
+
if (!FOLDER_ID.test(args.folder))
|
|
387
|
+
throw new Error(`not a Folder id (lowercase UUID v4): ${JSON.stringify(args.folder)}`);
|
|
388
|
+
if (args.level !== 'all' && args.level !== 'important' && args.level !== '')
|
|
389
|
+
throw new Error(`not a level: ${JSON.stringify(args.level)}`);
|
|
390
|
+
if (!Number.isSafeInteger(createdAtMs) || createdAtMs < 0)
|
|
391
|
+
throw new Error(`not epoch milliseconds: ${createdAtMs}`);
|
|
392
|
+
const id = fileIdOf(args.place);
|
|
393
|
+
return {
|
|
394
|
+
pubkey,
|
|
395
|
+
created_at: Math.floor(createdAtMs / 1000),
|
|
396
|
+
kind: KIND_CHANGE,
|
|
397
|
+
tags: [
|
|
398
|
+
['a', args.place],
|
|
399
|
+
...(id !== undefined ? [['O', id]] : []),
|
|
400
|
+
['field', field],
|
|
401
|
+
['value', args.level],
|
|
402
|
+
['h', args.folder],
|
|
403
|
+
['ts', String(createdAtMs)],
|
|
404
|
+
['p', pubkey],
|
|
405
|
+
],
|
|
406
|
+
content: args.note ?? (args.level === 'all' ? 'All' : args.level === 'important' ? 'Important' : 'Default'),
|
|
407
|
+
};
|
|
408
|
+
}
|
|
409
|
+
// ── The teams a person follows, and their opt-outs: private (§11.8, §12) ────
|
|
410
|
+
/** The `d` of the person's teams list. */
|
|
411
|
+
export const TEAMS_D_TAG = 'estiva:teams:v1';
|
|
412
|
+
const isPlaceId = (id) => typeof id === 'string' && id.length > 0 && id.length <= 256 && !/\s/.test(id);
|
|
413
|
+
const isEpochMs = (ms) => typeof ms === 'number' && Number.isSafeInteger(ms) && ms >= 0;
|
|
414
|
+
/** The teams list from its decrypted content, or undefined when it is not a v1 list. Entries that are not well formed are dropped. */
|
|
415
|
+
export function parseTeamsBlob(plaintext) {
|
|
416
|
+
let value;
|
|
417
|
+
try {
|
|
418
|
+
value = JSON.parse(plaintext);
|
|
419
|
+
}
|
|
420
|
+
catch {
|
|
421
|
+
return undefined;
|
|
422
|
+
}
|
|
423
|
+
if (!value || typeof value !== 'object')
|
|
424
|
+
return undefined;
|
|
425
|
+
const { v, updatedAt, teams, off } = value;
|
|
426
|
+
if (v !== 1 || !isEpochMs(updatedAt))
|
|
427
|
+
return undefined;
|
|
428
|
+
if (!teams || typeof teams !== 'object' || Array.isArray(teams) || !Array.isArray(off))
|
|
429
|
+
return undefined;
|
|
430
|
+
const kept = Object.entries(teams).filter((e) => FOLDER_ID.test(e[0]) && isEpochMs(e[1]));
|
|
431
|
+
return { v: 1, updatedAt, teams: Object.fromEntries(kept.sort(([a], [b]) => (a < b ? -1 : 1))), off: [...new Set(off.filter(isPlaceId))].sort() };
|
|
432
|
+
}
|
|
433
|
+
/** The plaintext to encrypt to self: teams and opt-outs sorted, so equal lists are equal bytes. */
|
|
434
|
+
export function serializeTeamsBlob(list, updatedAt) {
|
|
435
|
+
const teams = Object.entries(list.teams).filter(([team, since]) => FOLDER_ID.test(team) && isEpochMs(since));
|
|
436
|
+
return JSON.stringify({
|
|
437
|
+
v: 1,
|
|
438
|
+
updatedAt,
|
|
439
|
+
teams: Object.fromEntries(teams.sort(([a], [b]) => (a < b ? -1 : 1))),
|
|
440
|
+
off: [...new Set(list.off.filter(isPlaceId))].sort(),
|
|
441
|
+
});
|
|
442
|
+
}
|
|
443
|
+
/**
|
|
444
|
+
* The unsigned `kind:30078` holding the encrypted teams list. Whole blob, last
|
|
445
|
+
* write wins (§12.3): a writer reads the current list, changes it, and writes
|
|
446
|
+
* all of it.
|
|
447
|
+
*/
|
|
448
|
+
export function buildTeamsEvent(pubkey, createdAtMs, ciphertext) {
|
|
449
|
+
return {
|
|
450
|
+
pubkey,
|
|
451
|
+
created_at: Math.floor(createdAtMs / 1000),
|
|
452
|
+
kind: KIND_APP_DATA,
|
|
453
|
+
tags: [
|
|
454
|
+
['d', TEAMS_D_TAG],
|
|
455
|
+
['t', APPDATA_TAG],
|
|
456
|
+
],
|
|
457
|
+
content: ciphertext,
|
|
458
|
+
};
|
|
459
|
+
}
|
|
460
|
+
/** The filter for the person's teams list. */
|
|
461
|
+
export function teamsFilter(pubkey) {
|
|
462
|
+
return { kinds: [KIND_APP_DATA], authors: [pubkey], '#d': [TEAMS_D_TAG], limit: 1 };
|
|
463
|
+
}
|
|
464
|
+
//# sourceMappingURL=places.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"places.js","sourceRoot":"","sources":["../src/places.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,OAAO,EAAE,QAAQ,EAAE,IAAI,EAAwC,MAAM,sBAAsB,CAAA;AAC3F,OAAO,EAAE,YAAY,EAAE,SAAS,EAAE,aAAa,EAAE,WAAW,EAAE,MAAM,YAAY,CAAA;AAChF,OAAO,EAAE,WAAW,EAAE,mBAAmB,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAA;AACjF,OAAO,EAAE,OAAO,EAAE,MAAM,YAAY,CAAA;AACpC,OAAO,EAAE,mBAAmB,EAAE,eAAe,EAAE,eAAe,EAAE,cAAc,EAAE,aAAa,EAAE,MAAM,gBAAgB,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C,IAAI,CAAC,IAAI,SAAS,CAAC,KAAK,CAAC,CAAC,CAAA;IAC5G,OAAO,IAAI,CAAC,SAAS,CAAC;QACpB,CAAC,EAAE,CAAC;QACJ,SAAS;QACT,KAAK,EAAE,MAAM,CAAC,WAAW,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;QACrE,GAAG,EAAE,CAAC,GAAG,IAAI,GAAG,CAAC,IAAI,CAAC,GAAG,CAAC,MAAM,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,IAAI,EAAE;KACrD,CAAC,CAAA;AACJ,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,eAAe,CAAC,MAAc,EAAE,WAAmB,EAAE,UAAkB;IACrF,OAAO;QACL,MAAM;QACN,UAAU,EAAE,IAAI,CAAC,KAAK,CAAC,WAAW,GAAG,IAAI,CAAC;QAC1C,IAAI,EAAE,aAAa;QACnB,IAAI,EAAE;YACJ,CAAC,GAAG,EAAE,WAAW,CAAC;YAClB,CAAC,GAAG,EAAE,WAAW,CAAC;SACnB;QACD,OAAO,EAAE,UAAU;KACpB,CAAA;AACH,CAAC;AAED,8CAA8C;AAC9C,MAAM,UAAU,WAAW,CAAC,MAAc;IACxC,OAAO,EAAE,KAAK,EAAE,CAAC,aAAa,CAAC,EAAE,OAAO,EAAE,CAAC,MAAM,CAAC,EAAE,IAAI,EAAE,CAAC,WAAW,CAAC,EAAE,KAAK,EAAE,CAAC,EAAE,CAAA;AACrF,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@estiva-app/conversation",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.29.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.
|
|
15
|
+
export const CONVERSATION_VERSION = '0.29.0'
|
|
16
16
|
|
|
17
17
|
export {
|
|
18
18
|
KIND_MESSAGE,
|
|
@@ -118,6 +118,8 @@ export {
|
|
|
118
118
|
export {
|
|
119
119
|
KIND_CHANGE,
|
|
120
120
|
MEMBER_FIELD_PREFIX,
|
|
121
|
+
FOLLOW_FIELD_PREFIX,
|
|
122
|
+
isMembershipField,
|
|
121
123
|
memberField,
|
|
122
124
|
memberOfField,
|
|
123
125
|
mentions,
|
|
@@ -138,6 +140,31 @@ export {
|
|
|
138
140
|
type MutedList,
|
|
139
141
|
} from './membership.js'
|
|
140
142
|
|
|
143
|
+
export {
|
|
144
|
+
followingOf,
|
|
145
|
+
teamMembersOf,
|
|
146
|
+
placeKindOf,
|
|
147
|
+
placeFilters,
|
|
148
|
+
unreadOnPlace,
|
|
149
|
+
isUnreadOnPlace,
|
|
150
|
+
followField,
|
|
151
|
+
buildLevelChange,
|
|
152
|
+
TEAMS_D_TAG,
|
|
153
|
+
parseTeamsBlob,
|
|
154
|
+
serializeTeamsBlob,
|
|
155
|
+
buildTeamsEvent,
|
|
156
|
+
teamsFilter,
|
|
157
|
+
type Level,
|
|
158
|
+
type PlaceKind,
|
|
159
|
+
type Place,
|
|
160
|
+
type PlaceFacts,
|
|
161
|
+
type WayIn,
|
|
162
|
+
type Following,
|
|
163
|
+
type PlaceJudge,
|
|
164
|
+
type TeamsList,
|
|
165
|
+
type TeamMember,
|
|
166
|
+
} from './places.js'
|
|
167
|
+
|
|
141
168
|
export {
|
|
142
169
|
READ_STATE_TAG,
|
|
143
170
|
READ_STATE_D_PREFIX,
|
package/src/membership.ts
CHANGED
|
@@ -12,7 +12,7 @@
|
|
|
12
12
|
* | created it | the root, ordered before every other event for the file |
|
|
13
13
|
* | took part | a message in the stream, by `P` |
|
|
14
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]` |
|
|
15
|
+
* | was placed | a `kind:1851` on the file, not a membership field (`member:` or `follow:`), with a non-empty `value`, carrying `["p", P]` |
|
|
16
16
|
* | was added, or joined | a `kind:1851` setting `member:<P>` to `true`, by anyone |
|
|
17
17
|
*
|
|
18
18
|
* A **leave** is a `member:<P>` = `false` signed by `P`; one signed by anybody
|
|
@@ -38,6 +38,18 @@ export { KIND_CHANGE }
|
|
|
38
38
|
/** The field prefix of a membership change: `member:<pubkey>`. */
|
|
39
39
|
export const MEMBER_FIELD_PREFIX = 'member:'
|
|
40
40
|
|
|
41
|
+
/** The field prefix of a level on a place: `follow:<pubkey>` (§11.8 *Places and following*). */
|
|
42
|
+
export const FOLLOW_FIELD_PREFIX = 'follow:'
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* Whether a field is a membership field, `member:<P>` or `follow:<P>` (§11.8).
|
|
46
|
+
* Its `p` places nobody: a level is not a placement, and read as one it would
|
|
47
|
+
* make whoever chose Important a member of every conversation on the place.
|
|
48
|
+
*/
|
|
49
|
+
export function isMembershipField(field: string | undefined): boolean {
|
|
50
|
+
return !!field && (field.startsWith(MEMBER_FIELD_PREFIX) || field.startsWith(FOLLOW_FIELD_PREFIX))
|
|
51
|
+
}
|
|
52
|
+
|
|
41
53
|
const PUBKEY = /^[0-9a-f]{64}$/
|
|
42
54
|
|
|
43
55
|
type Event = Pick<SignedEvent, 'id' | 'pubkey' | 'kind' | 'created_at' | 'tags' | 'content'>
|
|
@@ -139,9 +151,9 @@ function stepsOf(file: string, events: readonly Event[]): Map<string, Step[]> {
|
|
|
139
151
|
if (change.kind !== KIND_CHANGE || !isChangeTo(change, file, id)) continue
|
|
140
152
|
const sets = change.tags.filter((t) => t[0] === 'set' && typeof t[1] === 'string')
|
|
141
153
|
if (sets.length) {
|
|
142
|
-
// A several-field change never carries a `member:<P>` (§11.8), so one is not
|
|
143
|
-
// the `p` it carries places people when any field it sets has a value.
|
|
144
|
-
if (sets.some((t) => !t[1]
|
|
154
|
+
// A several-field change never carries a `member:<P>` or `follow:<P>` (§11.8), so one is not
|
|
155
|
+
// read here; the `p` it carries places people when any other field it sets has a value.
|
|
156
|
+
if (sets.some((t) => !isMembershipField(t[1]) && t[2])) addNamed(change)
|
|
145
157
|
continue
|
|
146
158
|
}
|
|
147
159
|
const field = tag(change, 'field')
|
|
@@ -152,8 +164,9 @@ function stepsOf(file: string, events: readonly Event[]): Map<string, Step[]> {
|
|
|
152
164
|
else if (value === 'false' && change.pubkey === member) add(member, change, false)
|
|
153
165
|
continue
|
|
154
166
|
}
|
|
155
|
-
// A
|
|
156
|
-
|
|
167
|
+
// A level (`follow:<P>`) is read by the places fold, not here. A change with an empty
|
|
168
|
+
// value takes someone off (an unassign) and places nobody, whatever `p` it carries.
|
|
169
|
+
if (isMembershipField(field) || !value) continue
|
|
157
170
|
addNamed(change)
|
|
158
171
|
}
|
|
159
172
|
return steps
|
|
@@ -233,7 +246,11 @@ export function membershipFilters(person: string, since?: number): Filter[] {
|
|
|
233
246
|
* file, if any, is its root's, which the app resolves by reading the thread.
|
|
234
247
|
*/
|
|
235
248
|
export function candidateFilesOf(event: Pick<SignedEvent, 'kind' | 'tags'>): string[] {
|
|
236
|
-
if (event.kind === KIND_CHANGE)
|
|
249
|
+
if (event.kind === KIND_CHANGE) {
|
|
250
|
+
// A level says nothing about file membership: counted as a candidate, it would read as a word that the person is not a member.
|
|
251
|
+
if (tag(event, 'field')?.startsWith(FOLLOW_FIELD_PREFIX)) return []
|
|
252
|
+
return event.tags.filter((t) => t[0] === 'a' && ADDRESS.test(t[1] ?? '')).map((t) => t[1])
|
|
253
|
+
}
|
|
237
254
|
return anchorsOf(event).filter((a) => ADDRESS.test(a))
|
|
238
255
|
}
|
|
239
256
|
|