@estiva-app/interop 0.101.0 → 0.102.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/src/yourTopics.ts CHANGED
@@ -9,13 +9,16 @@
9
9
  *
10
10
  * 1. every topic's root, and the viewer's mute list, in one request;
11
11
  * 2. the changes naming the viewer on any topic and the team lists naming
12
- * them (one request), beside every topic's current fields by the list read
13
- * (another: a relay refuses a list read mixed with other filters) — each
14
- * topic's title, archive and parent come from that answer, and only the
15
- * topics the viewer is in are read further;
16
- * 3. their listed ids, what the list read skipped and the manifests of their
12
+ * them, in one request: whether the viewer is in a topic does not depend on
13
+ * its fields, so this says which topics could be theirs;
14
+ * 3. only those topics' current fields, by the list read (alone: a relay
15
+ * refuses a list read mixed with other filters) — each topic's title,
16
+ * archive and parent come from that answer, and only the topics the viewer
17
+ * is in are read further. Every topic's fields were 0.13 MB of Ship's
18
+ * sidebar on Miky's workspace, 64 topics for the 25 he is in (ALO-22);
19
+ * 4. their listed ids, what the list read skipped and the manifests of their
17
20
  * parents, in one request;
18
- * 4. their parents, a level a request by the list read, to see whether one is
21
+ * 5. their parents, a level a request by the list read, to see whether one is
19
22
  * archived, while their activity is read.
20
23
  *
21
24
  * Without the list read (the relay does not advertise it), round 2 reads each
@@ -113,7 +116,7 @@ export async function readYourTopics(
113
116
  const addresses = [...roots.keys()]
114
117
  if (addresses.length === 0) return { me, topics: [], at: new Map(), muted: await mutedOpened }
115
118
 
116
- // 2. How the viewer is in each, which are spaces, and each topic's fields.
119
+ // 2. How the viewer is in each, which are spaces, and (without the list read) each topic's fields.
117
120
  const second = gathered(query)
118
121
  const partRead = readAll(second.query, [changesNamingFilter(me, addresses)])
119
122
  const statesRead = readAll(second.query, teamListFilters(roots))
@@ -121,30 +124,32 @@ export async function readYourTopics(
121
124
  const objectChangesRead = listRead ? Promise.resolve([]) : second.query(addresses.map(plainChangesFilter))
122
125
  const listChangesRead = listRead ? Promise.resolve([]) : readAll(second.query, addresses.map(topicListFilter))
123
126
  second.send()
124
- const [part, states, listed, objectChanges, listChanges, muted] = await Promise.all([
125
- partRead,
126
- statesRead,
127
- listRead ? newestChanges(query, addresses) : Promise.resolve([]),
128
- objectChangesRead,
129
- listChangesRead,
130
- mutedOpened,
131
- ])
127
+ const [part, states, objectChanges, listChanges] = await Promise.all([partRead, statesRead, objectChangesRead, listChangesRead])
132
128
  const spaces = spacesOf(states, addresses)
133
129
  const byTopic = eventsByTopic(part)
134
130
  const facts = { roots, byTopic, states, spaces }
135
- const mine = (object: ForeignObject) => {
131
+ const inIt = (object: ForeignObject) => {
136
132
  const topic = readTopicOf(object, me, facts)
137
- return topic && topic.yours && (options.spaces || !topic.space) && !muted?.has(topic.address) ? topic : undefined
133
+ return topic && topic.yours && (options.spaces || !topic.space) ? topic : undefined
138
134
  }
139
- // A topic the list read did not answer (deleted) is read plain below, as a parent is.
140
- const answered = new Set(topicRoots(listed).keys())
141
- const byList = listRead ? addresses.filter((address) => answered.has(address)) : addresses
142
- const objects = projectTopics([...byList.map((address) => roots.get(address)!), ...(listRead ? listed : objectChanges)], listRead)
135
+ let objects: ForeignObject[]
136
+ let listed: SignedEvent[] = []
143
137
  if (listRead) {
144
- const unanswered = addresses.filter((address) => !answered.has(address))
145
- // Asked about only when one would be the viewer's, by its root alone: whether they are in it does not depend on its fields.
146
- const maybe = projectTopics(unanswered.map((address) => roots.get(address)!), false).flatMap((object) => (mine(object) ? [object.address!] : []))
147
- if (maybe.length > 0) objects.push(...projectTopics([...maybe.map((address) => roots.get(address)!), ...(await query(maybe.map(plainChangesFilter)))], false))
138
+ // 3. Whether the viewer is in a topic does not depend on its fields, so its root alone says which could be theirs:
139
+ // only those are read as their current fields, not every topic in the workspace (ALO-22: 25 of Miky's 64). The
140
+ // mute list is not waited for: muting leaves out a topic below, and decides nothing here.
141
+ const maybe = projectTopics([...roots.values()], false).flatMap((object) => (inIt(object) ? [object.address!] : []))
142
+ listed = maybe.length > 0 ? await newestChanges(query, maybe) : []
143
+ const answered = new Set(topicRoots(listed).keys())
144
+ objects = projectTopics([...maybe.filter((address) => answered.has(address)).map((address) => roots.get(address)!), ...listed], true)
145
+ // A topic the list read did not answer (deleted) is read plain, as a parent is.
146
+ const unanswered = maybe.filter((address) => !answered.has(address))
147
+ if (unanswered.length > 0) objects.push(...projectTopics([...unanswered.map((address) => roots.get(address)!), ...(await query(unanswered.map(plainChangesFilter)))], false))
148
+ } else objects = projectTopics([...roots.values(), ...objectChanges], false)
149
+ const muted = await mutedOpened
150
+ const mine = (object: ForeignObject) => {
151
+ const topic = inIt(object)
152
+ return topic && !muted?.has(topic.address) ? topic : undefined
148
153
  }
149
154
  const candidates: Omit<ReadTopic, 'listed'>[] = []
150
155
  for (const object of objects) {
@@ -153,7 +158,7 @@ export async function readYourTopics(
153
158
  }
154
159
  if (candidates.length === 0) return { me, topics: [], at: new Map(), muted }
155
160
 
156
- // 3. Their listed ids, what the list read skipped, and their parents' manifests.
161
+ // 4. Their listed ids, what the list read skipped, and their parents' manifests.
157
162
  const asked = candidates.map((topic) => topic.address)
158
163
  const listEvents = listRead ? listed : listChanges
159
164
  const plan = listReadPlan(asked, roots, listEvents, listRead)
@@ -170,7 +175,7 @@ export async function readYourTopics(
170
175
  const lists = listsFrom(asked, roots, [...listEvents, ...again], resolved)
171
176
  const topics: ReadTopic[] = candidates.map((topic) => ({ ...topic, listed: lists.get(topic.address) ?? [] }))
172
177
 
173
- // 4. Their parents, while their activity is read: one archived with a parent is left out after.
178
+ // 5. Their parents, while their activity is read: one archived with a parent is left out after.
174
179
  const [activity] = await Promise.all([
175
180
  readTopicActivity(query, activityTopics(topics), { nowSeconds: options.nowSeconds, times: options.times }),
176
181
  markTopicsArchivedWith(