@atproto/bsky 0.0.151 → 0.0.153

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.
Files changed (104) hide show
  1. package/CHANGELOG.md +14 -0
  2. package/dist/api/app/bsky/unspecced/getPostThreadHiddenV2.d.ts +4 -0
  3. package/dist/api/app/bsky/unspecced/getPostThreadHiddenV2.d.ts.map +1 -0
  4. package/dist/api/app/bsky/unspecced/getPostThreadHiddenV2.js +77 -0
  5. package/dist/api/app/bsky/unspecced/getPostThreadHiddenV2.js.map +1 -0
  6. package/dist/api/app/bsky/unspecced/getPostThreadV2.d.ts +4 -0
  7. package/dist/api/app/bsky/unspecced/getPostThreadV2.d.ts.map +1 -0
  8. package/dist/api/app/bsky/unspecced/getPostThreadV2.js +86 -0
  9. package/dist/api/app/bsky/unspecced/getPostThreadV2.js.map +1 -0
  10. package/dist/api/com/atproto/repo/getRecord.d.ts.map +1 -1
  11. package/dist/api/com/atproto/repo/getRecord.js +1 -1
  12. package/dist/api/com/atproto/repo/getRecord.js.map +1 -1
  13. package/dist/api/index.d.ts.map +1 -1
  14. package/dist/api/index.js +4 -0
  15. package/dist/api/index.js.map +1 -1
  16. package/dist/config.d.ts +6 -0
  17. package/dist/config.d.ts.map +1 -1
  18. package/dist/config.js +17 -0
  19. package/dist/config.js.map +1 -1
  20. package/dist/data-plane/server/db/migrations/20250528T221913281Z-add-record-tags.d.ts +4 -0
  21. package/dist/data-plane/server/db/migrations/20250528T221913281Z-add-record-tags.d.ts.map +1 -0
  22. package/dist/data-plane/server/db/migrations/20250528T221913281Z-add-record-tags.js +11 -0
  23. package/dist/data-plane/server/db/migrations/20250528T221913281Z-add-record-tags.js.map +1 -0
  24. package/dist/data-plane/server/db/migrations/index.d.ts +1 -0
  25. package/dist/data-plane/server/db/migrations/index.d.ts.map +1 -1
  26. package/dist/data-plane/server/db/migrations/index.js +2 -1
  27. package/dist/data-plane/server/db/migrations/index.js.map +1 -1
  28. package/dist/data-plane/server/db/tables/record.d.ts +1 -0
  29. package/dist/data-plane/server/db/tables/record.d.ts.map +1 -1
  30. package/dist/data-plane/server/db/tables/record.js.map +1 -1
  31. package/dist/data-plane/server/routes/records.d.ts.map +1 -1
  32. package/dist/data-plane/server/routes/records.js +1 -0
  33. package/dist/data-plane/server/routes/records.js.map +1 -1
  34. package/dist/hydration/feed.d.ts +1 -0
  35. package/dist/hydration/feed.d.ts.map +1 -1
  36. package/dist/hydration/feed.js +2 -0
  37. package/dist/hydration/feed.js.map +1 -1
  38. package/dist/index.d.ts.map +1 -1
  39. package/dist/index.js +2 -0
  40. package/dist/index.js.map +1 -1
  41. package/dist/lexicon/index.d.ts +6 -2
  42. package/dist/lexicon/index.d.ts.map +1 -1
  43. package/dist/lexicon/index.js +12 -4
  44. package/dist/lexicon/index.js.map +1 -1
  45. package/dist/lexicon/lexicons.d.ts +508 -82
  46. package/dist/lexicon/lexicons.d.ts.map +1 -1
  47. package/dist/lexicon/lexicons.js +264 -42
  48. package/dist/lexicon/lexicons.js.map +1 -1
  49. package/dist/lexicon/types/app/bsky/unspecced/getPostThreadHiddenV2.d.ts +63 -0
  50. package/dist/lexicon/types/app/bsky/unspecced/getPostThreadHiddenV2.d.ts.map +1 -0
  51. package/dist/lexicon/types/app/bsky/unspecced/getPostThreadHiddenV2.js +25 -0
  52. package/dist/lexicon/types/app/bsky/unspecced/getPostThreadHiddenV2.js.map +1 -0
  53. package/dist/lexicon/types/app/bsky/unspecced/getPostThreadV2.d.ts +92 -0
  54. package/dist/lexicon/types/app/bsky/unspecced/getPostThreadV2.d.ts.map +1 -0
  55. package/dist/lexicon/types/app/bsky/unspecced/getPostThreadV2.js +52 -0
  56. package/dist/lexicon/types/app/bsky/unspecced/getPostThreadV2.js.map +1 -0
  57. package/dist/proto/bsky_pb.d.ts +4 -0
  58. package/dist/proto/bsky_pb.d.ts.map +1 -1
  59. package/dist/proto/bsky_pb.js +16 -0
  60. package/dist/proto/bsky_pb.js.map +1 -1
  61. package/dist/proto/bsync_connect.d.ts +19 -1
  62. package/dist/proto/bsync_connect.d.ts.map +1 -1
  63. package/dist/proto/bsync_connect.js +18 -0
  64. package/dist/proto/bsync_connect.js.map +1 -1
  65. package/dist/proto/bsync_pb.d.ts +150 -0
  66. package/dist/proto/bsync_pb.d.ts.map +1 -1
  67. package/dist/proto/bsync_pb.js +401 -1
  68. package/dist/proto/bsync_pb.js.map +1 -1
  69. package/dist/views/index.d.ts +40 -0
  70. package/dist/views/index.d.ts.map +1 -1
  71. package/dist/views/index.js +499 -0
  72. package/dist/views/index.js.map +1 -1
  73. package/dist/views/threads-v2.d.ts +65 -0
  74. package/dist/views/threads-v2.d.ts.map +1 -0
  75. package/dist/views/threads-v2.js +205 -0
  76. package/dist/views/threads-v2.js.map +1 -0
  77. package/package.json +5 -5
  78. package/proto/bsky.proto +1 -0
  79. package/src/api/app/bsky/unspecced/getPostThreadHiddenV2.ts +117 -0
  80. package/src/api/app/bsky/unspecced/getPostThreadV2.ts +130 -0
  81. package/src/api/com/atproto/repo/getRecord.ts +4 -1
  82. package/src/api/index.ts +4 -0
  83. package/src/config.ts +24 -0
  84. package/src/data-plane/server/db/migrations/20250528T221913281Z-add-record-tags.ts +9 -0
  85. package/src/data-plane/server/db/migrations/index.ts +1 -0
  86. package/src/data-plane/server/db/tables/record.ts +1 -0
  87. package/src/data-plane/server/routes/records.ts +1 -0
  88. package/src/hydration/feed.ts +4 -0
  89. package/src/index.ts +2 -0
  90. package/src/lexicon/index.ts +33 -9
  91. package/src/lexicon/lexicons.ts +284 -43
  92. package/src/lexicon/types/app/bsky/unspecced/getPostThreadHiddenV2.ts +95 -0
  93. package/src/lexicon/types/app/bsky/unspecced/getPostThreadV2.ts +160 -0
  94. package/src/proto/bsky_pb.ts +12 -0
  95. package/src/proto/bsync_connect.ts +22 -0
  96. package/src/proto/bsync_pb.ts +355 -0
  97. package/src/views/index.ts +780 -0
  98. package/src/views/threads-v2.ts +381 -0
  99. package/tests/seed/thread-v2.ts +874 -0
  100. package/tests/seed/util.ts +52 -0
  101. package/tests/views/__snapshots__/thread-v2.test.ts.snap +1091 -0
  102. package/tests/views/thread-v2.test.ts +2121 -0
  103. package/tsconfig.build.tsbuildinfo +1 -1
  104. package/tsconfig.tests.tsbuildinfo +1 -1
@@ -0,0 +1,2121 @@
1
+ import assert from 'node:assert'
2
+ import {
3
+ AppBskyUnspeccedGetPostThreadHiddenV2,
4
+ AppBskyUnspeccedGetPostThreadV2,
5
+ AtpAgent,
6
+ } from '@atproto/api'
7
+ import { SeedClient, TestNetwork } from '@atproto/dev-env'
8
+ import { ids } from '../../src/lexicon/lexicons'
9
+ import {
10
+ OutputSchema as OutputSchemaHiddenThread,
11
+ ThreadHiddenItem,
12
+ ThreadHiddenItemPost,
13
+ } from '../../src/lexicon/types/app/bsky/unspecced/getPostThreadHiddenV2'
14
+ import {
15
+ OutputSchema as OutputSchemaThread,
16
+ QueryParams as QueryParamsThread,
17
+ ThreadItemPost,
18
+ } from '../../src/lexicon/types/app/bsky/unspecced/getPostThreadV2'
19
+ import { ThreadItemValuePost } from '../../src/views/threads-v2'
20
+ import { forSnapshot } from '../_util'
21
+ import * as seeds from '../seed/thread-v2'
22
+ import { TAG_BUMP_DOWN, TAG_HIDE } from '../seed/thread-v2'
23
+
24
+ type PostProps = Pick<ThreadItemPost, 'moreReplies' | 'opThread'>
25
+ const props = (overrides: Partial<PostProps> = {}): PostProps => ({
26
+ moreReplies: 0,
27
+ opThread: false,
28
+ ...overrides,
29
+ })
30
+
31
+ type PostPropsHidden = Pick<
32
+ ThreadHiddenItemPost,
33
+ 'hiddenByThreadgate' | 'mutedByViewer'
34
+ >
35
+ const propsHidden = (
36
+ overrides: Partial<PostPropsHidden> = {},
37
+ ): PostPropsHidden => ({
38
+ hiddenByThreadgate: false,
39
+ mutedByViewer: false,
40
+ ...overrides,
41
+ })
42
+
43
+ describe('appview thread views v2', () => {
44
+ let network: TestNetwork
45
+ let agent: AtpAgent
46
+ let labelerDid: string
47
+ let sc: SeedClient<TestNetwork>
48
+
49
+ beforeAll(async () => {
50
+ network = await TestNetwork.create({
51
+ bsky: {
52
+ maxThreadParents: 15,
53
+ threadTagsBumpDown: new Set([TAG_BUMP_DOWN]),
54
+ threadTagsHide: new Set([TAG_HIDE]),
55
+ },
56
+ dbPostgresSchema: 'bsky_views_thread_v_two',
57
+ })
58
+ agent = network.bsky.getClient()
59
+ sc = network.getSeedClient()
60
+ labelerDid = network.bsky.ctx.cfg.modServiceDid
61
+ await network.processAll()
62
+ })
63
+
64
+ afterAll(async () => {
65
+ await network.close()
66
+ })
67
+
68
+ describe('not found anchor', () => {
69
+ it('returns not found error', async () => {
70
+ const { data } = await agent.app.bsky.unspecced.getPostThreadV2({
71
+ anchor: 'at://did:plc:123/app.bsky.feed.post/456',
72
+ })
73
+ const { thread: t } = data
74
+
75
+ expect(t).toEqual([
76
+ expect.objectContaining({
77
+ depth: 0,
78
+ value: {
79
+ $type: 'app.bsky.unspecced.getPostThreadV2#threadItemNotFound',
80
+ },
81
+ }),
82
+ ])
83
+ })
84
+ })
85
+
86
+ describe('simple thread', () => {
87
+ let seed: Awaited<ReturnType<typeof seeds.simple>>
88
+
89
+ beforeAll(async () => {
90
+ seed = await seeds.simple(sc)
91
+ await network.processAll()
92
+ })
93
+
94
+ it('returns thread anchored on root', async () => {
95
+ const { data } = await agent.app.bsky.unspecced.getPostThreadV2(
96
+ { anchor: seed.root.ref.uriStr },
97
+ {
98
+ headers: await network.serviceHeaders(
99
+ seed.users.op.did,
100
+ ids.AppBskyUnspeccedGetPostThreadV2,
101
+ ),
102
+ },
103
+ )
104
+ const { thread: t, hasHiddenReplies } = data
105
+
106
+ assertPosts(t)
107
+ expect(hasHiddenReplies).toBe(false)
108
+ expect(t).toEqual([
109
+ expect.objectContaining({ depth: 0, uri: seed.root.ref.uriStr }),
110
+ expect.objectContaining({ depth: 1, uri: seed.r['0'].ref.uriStr }),
111
+ expect.objectContaining({ depth: 2, uri: seed.r['0.0'].ref.uriStr }),
112
+ expect.objectContaining({ depth: 1, uri: seed.r['1'].ref.uriStr }),
113
+ expect.objectContaining({ depth: 1, uri: seed.r['2'].ref.uriStr }),
114
+ expect.objectContaining({ depth: 2, uri: seed.r['2.0'].ref.uriStr }),
115
+ expect.objectContaining({ depth: 1, uri: seed.r['3'].ref.uriStr }),
116
+ ])
117
+ expect(forSnapshot(data)).toMatchSnapshot()
118
+ })
119
+
120
+ it('returns thread anchored on r 0', async () => {
121
+ const { data } = await agent.app.bsky.unspecced.getPostThreadV2(
122
+ { anchor: seed.r['0'].ref.uriStr },
123
+ {
124
+ headers: await network.serviceHeaders(
125
+ seed.users.op.did,
126
+ ids.AppBskyUnspeccedGetPostThreadV2,
127
+ ),
128
+ },
129
+ )
130
+ const { thread: t, hasHiddenReplies } = data
131
+
132
+ assertPosts(t)
133
+ expect(hasHiddenReplies).toBe(false)
134
+ expect(t).toEqual([
135
+ expect.objectContaining({ depth: -1, uri: seed.root.ref.uriStr }),
136
+ expect.objectContaining({ depth: 0, uri: seed.r['0'].ref.uriStr }),
137
+ expect.objectContaining({ depth: 1, uri: seed.r['0.0'].ref.uriStr }),
138
+ ])
139
+ expect(forSnapshot(data)).toMatchSnapshot()
140
+ })
141
+
142
+ it('returns thread anchored on r 0.0', async () => {
143
+ const { data } = await agent.app.bsky.unspecced.getPostThreadV2(
144
+ { anchor: seed.r['0.0'].ref.uriStr },
145
+ {
146
+ headers: await network.serviceHeaders(
147
+ seed.users.op.did,
148
+ ids.AppBskyUnspeccedGetPostThreadV2,
149
+ ),
150
+ },
151
+ )
152
+ const { thread: t, hasHiddenReplies } = data
153
+
154
+ assertPosts(t)
155
+ expect(hasHiddenReplies).toBe(false)
156
+ expect(t).toEqual([
157
+ expect.objectContaining({ depth: -2, uri: seed.root.ref.uriStr }),
158
+ expect.objectContaining({ depth: -1, uri: seed.r['0'].ref.uriStr }),
159
+ expect.objectContaining({ depth: 0, uri: seed.r['0.0'].ref.uriStr }),
160
+ ])
161
+ expect(forSnapshot(data)).toMatchSnapshot()
162
+ })
163
+
164
+ it('returns thread anchored on 1', async () => {
165
+ const { data } = await agent.app.bsky.unspecced.getPostThreadV2(
166
+ { anchor: seed.r['1'].ref.uriStr },
167
+ {
168
+ headers: await network.serviceHeaders(
169
+ seed.users.op.did,
170
+ ids.AppBskyUnspeccedGetPostThreadV2,
171
+ ),
172
+ },
173
+ )
174
+ const { thread: t, hasHiddenReplies } = data
175
+
176
+ assertPosts(t)
177
+ expect(hasHiddenReplies).toBe(false)
178
+ expect(t).toEqual([
179
+ expect.objectContaining({ depth: -1, uri: seed.root.ref.uriStr }),
180
+ expect.objectContaining({ depth: 0, uri: seed.r['1'].ref.uriStr }),
181
+ ])
182
+ expect(forSnapshot(data)).toMatchSnapshot()
183
+ })
184
+
185
+ it('returns thread anchored on 2', async () => {
186
+ const { data } = await agent.app.bsky.unspecced.getPostThreadV2(
187
+ { anchor: seed.r['2'].ref.uriStr },
188
+ {
189
+ headers: await network.serviceHeaders(
190
+ seed.users.op.did,
191
+ ids.AppBskyUnspeccedGetPostThreadV2,
192
+ ),
193
+ },
194
+ )
195
+ const { thread: t, hasHiddenReplies } = data
196
+
197
+ assertPosts(t)
198
+ expect(hasHiddenReplies).toBe(false)
199
+ expect(t).toEqual([
200
+ expect.objectContaining({ depth: -1, uri: seed.root.ref.uriStr }),
201
+ expect.objectContaining({ depth: 0, uri: seed.r['2'].ref.uriStr }),
202
+ expect.objectContaining({ depth: 1, uri: seed.r['2.0'].ref.uriStr }),
203
+ ])
204
+ expect(forSnapshot(data)).toMatchSnapshot()
205
+ })
206
+
207
+ it('returns thread anchored on 2.0', async () => {
208
+ const { data } = await agent.app.bsky.unspecced.getPostThreadV2(
209
+ { anchor: seed.r['2.0'].ref.uriStr },
210
+ {
211
+ headers: await network.serviceHeaders(
212
+ seed.users.op.did,
213
+ ids.AppBskyUnspeccedGetPostThreadV2,
214
+ ),
215
+ },
216
+ )
217
+ const { thread: t, hasHiddenReplies } = data
218
+
219
+ assertPosts(t)
220
+ expect(hasHiddenReplies).toBe(false)
221
+ expect(t).toEqual([
222
+ expect.objectContaining({ depth: -2, uri: seed.root.ref.uriStr }),
223
+ expect.objectContaining({ depth: -1, uri: seed.r['2'].ref.uriStr }),
224
+ expect.objectContaining({ depth: 0, uri: seed.r['2.0'].ref.uriStr }),
225
+ ])
226
+ expect(forSnapshot(data)).toMatchSnapshot()
227
+ })
228
+
229
+ it('returns thread anchored on 3', async () => {
230
+ const { data } = await agent.app.bsky.unspecced.getPostThreadV2(
231
+ { anchor: seed.r['3'].ref.uriStr },
232
+ {
233
+ headers: await network.serviceHeaders(
234
+ seed.users.op.did,
235
+ ids.AppBskyUnspeccedGetPostThreadV2,
236
+ ),
237
+ },
238
+ )
239
+ const { thread: t, hasHiddenReplies } = data
240
+
241
+ assertPosts(t)
242
+ expect(hasHiddenReplies).toBe(false)
243
+ expect(t).toEqual([
244
+ expect.objectContaining({ depth: -1, uri: seed.root.ref.uriStr }),
245
+ expect.objectContaining({ depth: 0, uri: seed.r['3'].ref.uriStr }),
246
+ ])
247
+ expect(forSnapshot(data)).toMatchSnapshot()
248
+ })
249
+ })
250
+
251
+ describe('long thread', () => {
252
+ let seed: Awaited<ReturnType<typeof seeds.long>>
253
+
254
+ beforeAll(async () => {
255
+ seed = await seeds.long(sc)
256
+ await network.processAll()
257
+ })
258
+
259
+ describe('calculating depth', () => {
260
+ type Case = {
261
+ postKey: string
262
+ }
263
+
264
+ const cases: Case[] = [
265
+ { postKey: 'root' },
266
+ { postKey: '0' },
267
+ { postKey: '0.0' },
268
+ { postKey: '0.0.0' },
269
+ { postKey: '0.0.0.0' },
270
+ { postKey: '0.0.0.0.0' },
271
+ { postKey: '0.0.1' },
272
+ { postKey: '1' },
273
+ { postKey: '2' },
274
+ { postKey: '3' },
275
+ { postKey: '4' },
276
+ { postKey: '4.0' },
277
+ { postKey: '4.0.0' },
278
+ { postKey: '4.0.0.0' },
279
+ { postKey: '4.0.0.0.0' },
280
+ { postKey: '5' },
281
+ { postKey: '6' },
282
+ { postKey: '7' },
283
+ ]
284
+
285
+ it.each(cases)(
286
+ 'calculates the depths anchored at $postKey',
287
+ async ({ postKey }) => {
288
+ const post = postKey === 'root' ? seed.root : seed.r[postKey]
289
+ const { data } = await agent.app.bsky.unspecced.getPostThreadV2(
290
+ { anchor: post.ref.uriStr },
291
+ {
292
+ headers: await network.serviceHeaders(
293
+ seed.users.op.did,
294
+ ids.AppBskyUnspeccedGetPostThreadV2,
295
+ ),
296
+ },
297
+ )
298
+ const { thread: t, hasHiddenReplies } = data
299
+
300
+ assertPosts(t)
301
+ expect(hasHiddenReplies).toBe(false)
302
+ const anchorIndex = t.findIndex((i) => i.uri === post.ref.uriStr)
303
+ const anchorPost = t[anchorIndex]
304
+
305
+ const parents = t.slice(0, anchorIndex)
306
+ const children = t.slice(anchorIndex + 1, t.length)
307
+
308
+ parents.forEach((parent) => {
309
+ expect(parent.depth).toBeLessThan(0)
310
+ })
311
+ expect(anchorPost.depth).toEqual(0)
312
+ children.forEach((child) => {
313
+ expect(child.depth).toBeGreaterThan(0)
314
+ })
315
+ },
316
+ )
317
+ })
318
+ })
319
+
320
+ describe('deep thread', () => {
321
+ let seed: Awaited<ReturnType<typeof seeds.deep>>
322
+
323
+ beforeAll(async () => {
324
+ seed = await seeds.deep(sc)
325
+ await network.processAll()
326
+ })
327
+
328
+ describe('above', () => {
329
+ it('returns the ancestors above if true (default)', async () => {
330
+ const { data } = await agent.app.bsky.unspecced.getPostThreadV2(
331
+ {
332
+ anchor: seed.r['0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0'].ref.uriStr,
333
+ },
334
+ {
335
+ headers: await network.serviceHeaders(
336
+ seed.users.op.did,
337
+ ids.AppBskyUnspeccedGetPostThreadV2,
338
+ ),
339
+ },
340
+ )
341
+ const { thread: t, hasHiddenReplies } = data
342
+
343
+ assertPosts(t)
344
+ expect(hasHiddenReplies).toBe(false)
345
+ expect(t).toHaveLength(16) // anchor + 15 ancestors, as limited by `maxThreadParents`.
346
+
347
+ const first = t.at(0)
348
+ expect(first!.uri).toBe(seed.r['0.0.0'].ref.uriStr)
349
+ expect(first!.value.moreParents).toBe(true)
350
+
351
+ const second = t.at(1)
352
+ expect(second!.uri).toBe(seed.r['0.0.0.0'].ref.uriStr)
353
+ expect(second!.value.moreParents).toBe(false)
354
+
355
+ const last = t.at(-1)
356
+ expect(last!.uri).toBe(
357
+ seed.r['0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0'].ref.uriStr,
358
+ )
359
+ expect(last!.value.moreParents).toBe(false)
360
+ })
361
+
362
+ it(`does not return ancestors if false`, async () => {
363
+ const { data } = await agent.app.bsky.unspecced.getPostThreadV2(
364
+ {
365
+ anchor: seed.r['0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0'].ref.uriStr,
366
+ above: false,
367
+ },
368
+ {
369
+ headers: await network.serviceHeaders(
370
+ seed.users.op.did,
371
+ ids.AppBskyUnspeccedGetPostThreadV2,
372
+ ),
373
+ },
374
+ )
375
+ const { thread: t, hasHiddenReplies } = data
376
+
377
+ assertPosts(t)
378
+ expect(hasHiddenReplies).toBe(false)
379
+ expect(t).toHaveLength(1)
380
+
381
+ const first = t.at(0)
382
+ expect(first!.uri).toBe(
383
+ seed.r['0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0'].ref.uriStr,
384
+ )
385
+ })
386
+ })
387
+
388
+ describe('below', () => {
389
+ it('limits to the below count', async () => {
390
+ const { data } = await agent.app.bsky.unspecced.getPostThreadV2(
391
+ {
392
+ anchor: seed.root.ref.uriStr,
393
+ below: 10,
394
+ },
395
+ {
396
+ headers: await network.serviceHeaders(
397
+ seed.users.op.did,
398
+ ids.AppBskyUnspeccedGetPostThreadV2,
399
+ ),
400
+ },
401
+ )
402
+ const { thread: t, hasHiddenReplies } = data
403
+
404
+ assertPosts(t)
405
+ expect(hasHiddenReplies).toBe(false)
406
+ expect(t).toHaveLength(11)
407
+ const first = t.at(0)
408
+ expect(first!.uri).toBe(seed.root.ref.uriStr)
409
+ })
410
+
411
+ it(`does not fulfill the below count if there are not enough items in the thread`, async () => {
412
+ const { data } = await agent.app.bsky.unspecced.getPostThreadV2(
413
+ {
414
+ anchor: seed.r['0.0.0.0.0.0.0.0.0.0.0.0.0.0.0'].ref.uriStr,
415
+ above: false,
416
+ below: 10,
417
+ },
418
+ {
419
+ headers: await network.serviceHeaders(
420
+ seed.users.op.did,
421
+ ids.AppBskyUnspeccedGetPostThreadV2,
422
+ ),
423
+ },
424
+ )
425
+ const { thread: t, hasHiddenReplies } = data
426
+
427
+ assertPosts(t)
428
+ expect(hasHiddenReplies).toBe(false)
429
+ expect(t).toHaveLength(4)
430
+
431
+ const first = t.at(0)
432
+ expect(first!.uri).toBe(
433
+ seed.r['0.0.0.0.0.0.0.0.0.0.0.0.0.0.0'].ref.uriStr,
434
+ )
435
+ })
436
+ })
437
+ })
438
+
439
+ describe('branching factor', () => {
440
+ let seed: Awaited<ReturnType<typeof seeds.branchingFactor>>
441
+
442
+ beforeAll(async () => {
443
+ seed = await seeds.branchingFactor(sc)
444
+ await network.processAll()
445
+ })
446
+
447
+ type Case =
448
+ | {
449
+ branchingFactor: number
450
+ sort: QueryParamsThread['sort']
451
+ postKeys: string[]
452
+ }
453
+ | {
454
+ branchingFactor: number
455
+ sort: QueryParamsThread['sort']
456
+ // For higher branching factors it gets too verbose to write all posts.
457
+ length: number
458
+ }
459
+ const cases: Case[] = [
460
+ {
461
+ branchingFactor: 1,
462
+ sort: 'oldest',
463
+ postKeys: [
464
+ 'root',
465
+ '0',
466
+ '0.0',
467
+ '0.0.0',
468
+ '1',
469
+ '1.0',
470
+ '1.0.0',
471
+ '2',
472
+ '2.0',
473
+ '2.0.0',
474
+ '3',
475
+ '3.0',
476
+ '3.0.0',
477
+ ],
478
+ },
479
+ {
480
+ branchingFactor: 1,
481
+ sort: 'newest',
482
+ postKeys: [
483
+ 'root',
484
+ '3',
485
+ '3.3',
486
+ '3.3.3',
487
+ '2',
488
+ '2.3',
489
+ '2.3.3',
490
+ '1',
491
+ '1.3',
492
+ '1.3.3',
493
+ '0',
494
+ '0.3',
495
+ '0.3.3',
496
+ ],
497
+ },
498
+ {
499
+ branchingFactor: 2,
500
+ sort: 'oldest',
501
+ postKeys: [
502
+ 'root',
503
+ '0',
504
+ '0.0',
505
+ '0.0.0',
506
+ '0.0.1',
507
+ '0.1',
508
+ '0.1.0',
509
+ '0.1.1',
510
+ '1',
511
+ '1.0',
512
+ '1.0.0',
513
+ '1.1',
514
+ '1.1.0',
515
+ '1.1.1',
516
+ '2',
517
+ '2.0',
518
+ '2.0.0',
519
+ '2.0.1',
520
+ '2.1',
521
+ '2.1.0',
522
+ '2.1.1',
523
+ '3',
524
+ '3.0',
525
+ '3.0.0',
526
+ '3.0.1',
527
+ '3.1',
528
+ '3.1.0',
529
+ '3.1.1',
530
+ ],
531
+ },
532
+ {
533
+ branchingFactor: 2,
534
+ sort: 'newest',
535
+ postKeys: [
536
+ 'root',
537
+ '3',
538
+ '3.3',
539
+ '3.3.3',
540
+ '3.3.2',
541
+ '3.2',
542
+ '3.2.3',
543
+ '3.2.2',
544
+ '2',
545
+ '2.3',
546
+ '2.3.3',
547
+ '2.3.2',
548
+ '2.2',
549
+ '2.2.3',
550
+ '2.2.2',
551
+ '1',
552
+ '1.3',
553
+ '1.3.3',
554
+ '1.3.2',
555
+ '1.2',
556
+ '1.2.3',
557
+ '1.2.2',
558
+ '0',
559
+ '0.3',
560
+ '0.3.3',
561
+ '0.3.2',
562
+ '0.2',
563
+ '0.2.3',
564
+ '0.2.2',
565
+ ],
566
+ },
567
+ {
568
+ branchingFactor: 3,
569
+ sort: 'newest',
570
+ length: 53,
571
+ },
572
+ {
573
+ branchingFactor: 4,
574
+ sort: 'newest',
575
+ length: 82,
576
+ },
577
+ {
578
+ branchingFactor: 5,
579
+ sort: 'newest',
580
+ // The seeds have 1 post with 5 replies, so it is +1 compared to branchingFactor 4.
581
+ length: 83,
582
+ },
583
+ ]
584
+
585
+ it.each(cases)(
586
+ 'returns all top-level replies and limits nested to branching factor of $branchingFactor when sorting by $sort',
587
+ async (args) => {
588
+ const { data } = await agent.app.bsky.unspecced.getPostThreadV2(
589
+ {
590
+ anchor: seed.root.ref.uriStr,
591
+ sort: 'sort' in args ? args.sort : undefined,
592
+ branchingFactor: args.branchingFactor,
593
+ },
594
+ {
595
+ headers: await network.serviceHeaders(
596
+ seed.users.op.did,
597
+ ids.AppBskyUnspeccedGetPostThreadV2,
598
+ ),
599
+ },
600
+ )
601
+ const { thread: t, hasHiddenReplies } = data
602
+
603
+ assertPosts(t)
604
+ expect(hasHiddenReplies).toBe(false)
605
+ if ('length' in args) {
606
+ expect(data.thread).toHaveLength(args.length)
607
+ } else {
608
+ const tUris = t.map((i) => i.uri)
609
+ const postUris = args.postKeys.map((k) =>
610
+ k === 'root' ? seed.root.ref.uriStr : seed.r[k].ref.uriStr,
611
+ )
612
+ expect(tUris).toEqual(postUris)
613
+ }
614
+ },
615
+ )
616
+ })
617
+
618
+ describe('annotate more replies', () => {
619
+ let seed: Awaited<ReturnType<typeof seeds.annotateMoreReplies>>
620
+
621
+ beforeAll(async () => {
622
+ seed = await seeds.annotateMoreReplies(sc)
623
+ await network.processAll()
624
+ })
625
+
626
+ it('annotates correctly both in cases of trimmed replies by depth and by branching factor reached', async () => {
627
+ const { data } = await agent.app.bsky.unspecced.getPostThreadV2(
628
+ {
629
+ anchor: seed.root.ref.uriStr,
630
+ below: 4,
631
+ branchingFactor: 2,
632
+ },
633
+ {
634
+ headers: await network.serviceHeaders(
635
+ seed.users.op.did,
636
+ ids.AppBskyUnspeccedGetPostThreadV2,
637
+ ),
638
+ },
639
+ )
640
+ const { thread: t, hasHiddenReplies } = data
641
+
642
+ assertPosts(t)
643
+ expect(hasHiddenReplies).toBe(false)
644
+ expect(t).toEqual([
645
+ expect.objectContaining({
646
+ uri: seed.root.ref.uriStr,
647
+ value: expect.objectContaining(props({ opThread: true })),
648
+ }),
649
+ expect.objectContaining({
650
+ uri: seed.r['0'].ref.uriStr,
651
+ value: expect.objectContaining(props()),
652
+ }),
653
+ expect.objectContaining({
654
+ uri: seed.r['0.0'].ref.uriStr,
655
+ value: expect.objectContaining(props()),
656
+ }),
657
+ expect.objectContaining({
658
+ uri: seed.r['0.0.0'].ref.uriStr,
659
+ value: expect.objectContaining(props()),
660
+ }),
661
+ expect.objectContaining({
662
+ uri: seed.r['0.0.0.0'].ref.uriStr,
663
+ value: expect.objectContaining(props({ moreReplies: 5 })),
664
+ }),
665
+ expect.objectContaining({
666
+ uri: seed.r['0.1'].ref.uriStr,
667
+ value: expect.objectContaining(props()),
668
+ }),
669
+ expect.objectContaining({
670
+ uri: seed.r['0.1.0'].ref.uriStr,
671
+ value: expect.objectContaining(props()),
672
+ }),
673
+ expect.objectContaining({
674
+ uri: seed.r['0.1.0.0'].ref.uriStr,
675
+ value: expect.objectContaining(props()),
676
+ }),
677
+ expect.objectContaining({
678
+ uri: seed.r['1'].ref.uriStr,
679
+ value: expect.objectContaining(props({ moreReplies: 1 })),
680
+ }),
681
+ expect.objectContaining({
682
+ uri: seed.r['1.0'].ref.uriStr,
683
+ value: expect.objectContaining(props({ moreReplies: 3 })),
684
+ }),
685
+ expect.objectContaining({
686
+ uri: seed.r['1.0.0'].ref.uriStr,
687
+ value: expect.objectContaining(props()),
688
+ }),
689
+ expect.objectContaining({
690
+ uri: seed.r['1.0.1'].ref.uriStr,
691
+ value: expect.objectContaining(props()),
692
+ }),
693
+ expect.objectContaining({
694
+ uri: seed.r['1.1'].ref.uriStr,
695
+ value: expect.objectContaining(props()),
696
+ }),
697
+ expect.objectContaining({
698
+ uri: seed.r['1.1.0'].ref.uriStr,
699
+ value: expect.objectContaining(props()),
700
+ }),
701
+ expect.objectContaining({
702
+ uri: seed.r['1.1.1'].ref.uriStr,
703
+ value: expect.objectContaining(props()),
704
+ }),
705
+ expect.objectContaining({
706
+ uri: seed.r['2'].ref.uriStr,
707
+ value: expect.objectContaining(props()),
708
+ }),
709
+ ])
710
+ })
711
+ })
712
+
713
+ describe(`annotate OP thread`, () => {
714
+ let seed: Awaited<ReturnType<typeof seeds.annotateOP>>
715
+
716
+ beforeAll(async () => {
717
+ seed = await seeds.annotateOP(sc)
718
+ await network.processAll()
719
+ })
720
+
721
+ type Case = {
722
+ postKey: string
723
+ length: number
724
+ opThreadPostKeys: string[]
725
+ }
726
+
727
+ const cases: Case[] = [
728
+ {
729
+ postKey: 'root',
730
+ length: 9,
731
+ opThreadPostKeys: ['root', '0', '0.0', '0.0.0', '2'],
732
+ },
733
+ {
734
+ postKey: '0',
735
+ length: 4,
736
+ opThreadPostKeys: ['root', '0', '0.0', '0.0.0'],
737
+ },
738
+ {
739
+ postKey: '0.0',
740
+ length: 4,
741
+ opThreadPostKeys: ['root', '0', '0.0', '0.0.0'],
742
+ },
743
+ {
744
+ postKey: '0.0.0',
745
+ length: 4,
746
+ opThreadPostKeys: ['root', '0', '0.0', '0.0.0'],
747
+ },
748
+ {
749
+ postKey: '1',
750
+ length: 3,
751
+ opThreadPostKeys: ['root'],
752
+ },
753
+ {
754
+ postKey: '1.0',
755
+ length: 3,
756
+ opThreadPostKeys: ['root'],
757
+ },
758
+ {
759
+ postKey: '2',
760
+ length: 4,
761
+ opThreadPostKeys: ['root', '2'],
762
+ },
763
+ {
764
+ postKey: '2.0',
765
+ length: 4,
766
+ opThreadPostKeys: ['root', '2'],
767
+ },
768
+ {
769
+ postKey: '2.0.0',
770
+ length: 4,
771
+ opThreadPostKeys: ['root', '2'],
772
+ },
773
+ ]
774
+
775
+ it.each(cases)(
776
+ `annotates OP threads correctly anchored at $postKey`,
777
+ async ({ postKey, length, opThreadPostKeys: opThreadPosts }) => {
778
+ const post = postKey === 'root' ? seed.root : seed.r[postKey]
779
+ const { data } = await agent.app.bsky.unspecced.getPostThreadV2(
780
+ { anchor: post.ref.uriStr },
781
+ {
782
+ headers: await network.serviceHeaders(
783
+ seed.users.op.did,
784
+ ids.AppBskyUnspeccedGetPostThreadV2,
785
+ ),
786
+ },
787
+ )
788
+ const { thread: t, hasHiddenReplies } = data
789
+
790
+ assertPosts(t)
791
+ expect(hasHiddenReplies).toBe(false)
792
+ const opThreadPostsUris = new Set(
793
+ opThreadPosts.map((k) =>
794
+ k === 'root' ? seed.root.ref.uriStr : seed.r[k].ref.uriStr,
795
+ ),
796
+ )
797
+
798
+ expect(t).toHaveLength(length)
799
+ t.forEach((i) => {
800
+ expect(i.value.opThread).toBe(opThreadPostsUris.has(i.uri))
801
+ })
802
+ },
803
+ )
804
+ })
805
+
806
+ describe('bumping and sorting', () => {
807
+ describe('sorting', () => {
808
+ let seed: Awaited<ReturnType<typeof seeds.sort>>
809
+
810
+ beforeAll(async () => {
811
+ seed = await seeds.sort(sc)
812
+ await network.processAll()
813
+ })
814
+
815
+ type Case = {
816
+ sort: QueryParamsThread['sort']
817
+ postKeys: string[]
818
+ }
819
+
820
+ const cases: Case[] = [
821
+ {
822
+ sort: 'newest',
823
+ postKeys: [
824
+ 'root',
825
+ '2',
826
+ '2.2',
827
+ '2.1',
828
+ '2.0',
829
+ '1',
830
+ '1.2',
831
+ '1.1',
832
+ '1.0',
833
+ '0',
834
+ '0.2',
835
+ '0.1',
836
+ '0.0',
837
+ ],
838
+ },
839
+ {
840
+ sort: 'oldest',
841
+ postKeys: [
842
+ 'root',
843
+ '0',
844
+ '0.0',
845
+ '0.1',
846
+ '0.2',
847
+ '1',
848
+ '1.0',
849
+ '1.1',
850
+ '1.2',
851
+ '2',
852
+ '2.0',
853
+ '2.1',
854
+ '2.2',
855
+ ],
856
+ },
857
+ {
858
+ sort: 'top',
859
+ postKeys: [
860
+ 'root',
861
+ '1',
862
+ '1.1',
863
+ '1.0',
864
+ '1.2',
865
+ '2',
866
+ '2.0',
867
+ '2.1',
868
+ '2.2',
869
+ '0',
870
+ '0.2',
871
+ '0.1',
872
+ '0.0',
873
+ ],
874
+ },
875
+ ]
876
+
877
+ it.each(cases)(
878
+ 'sorts by $sort in all levels',
879
+ async ({ sort: sort, postKeys }) => {
880
+ const { data } = await agent.app.bsky.unspecced.getPostThreadV2(
881
+ {
882
+ anchor: seed.root.ref.uriStr,
883
+ sort,
884
+ },
885
+ {
886
+ headers: await network.serviceHeaders(
887
+ seed.users.op.did,
888
+ ids.AppBskyUnspeccedGetPostThreadV2,
889
+ ),
890
+ },
891
+ )
892
+ const { thread: t, hasHiddenReplies } = data
893
+
894
+ assertPosts(t)
895
+ expect(hasHiddenReplies).toBe(false)
896
+ const tUris = t.map((i) => i.uri)
897
+ const postUris = postKeys.map((k) =>
898
+ k === 'root' ? seed.root.ref.uriStr : seed.r[k].ref.uriStr,
899
+ )
900
+ expect(tUris).toEqual(postUris)
901
+ },
902
+ )
903
+ })
904
+
905
+ describe('bumping', () => {
906
+ describe('sorting within bumped post groups', () => {
907
+ let seed: Awaited<ReturnType<typeof seeds.bumpGroupSorting>>
908
+
909
+ beforeAll(async () => {
910
+ seed = await seeds.bumpGroupSorting(sc)
911
+ await network.processAll()
912
+ })
913
+
914
+ type Case = {
915
+ sort: QueryParamsThread['sort']
916
+ postKeys: string[]
917
+ }
918
+
919
+ const cases: Case[] = [
920
+ {
921
+ sort: 'newest',
922
+ postKeys: ['root', '5', '3', '1', '7', '4', '0', '6', '2'],
923
+ },
924
+ {
925
+ sort: 'oldest',
926
+ postKeys: ['root', '1', '3', '5', '0', '4', '7', '2', '6'],
927
+ },
928
+ ]
929
+
930
+ it.each(cases)(
931
+ 'sorts by $sort inside each bumped group',
932
+ async ({ sort: sort, postKeys }) => {
933
+ const { data } = await agent.app.bsky.unspecced.getPostThreadV2(
934
+ {
935
+ anchor: seed.root.ref.uriStr,
936
+ sort,
937
+ },
938
+ {
939
+ headers: await network.serviceHeaders(
940
+ seed.users.viewer.did,
941
+ ids.AppBskyUnspeccedGetPostThreadV2,
942
+ ),
943
+ },
944
+ )
945
+ const { thread: t, hasHiddenReplies } = data
946
+
947
+ assertPosts(t)
948
+ expect(hasHiddenReplies).toBe(false)
949
+ const tUris = t.map((i) => i.uri)
950
+ const postUris = postKeys.map((k) =>
951
+ k === 'root' ? seed.root.ref.uriStr : seed.r[k].ref.uriStr,
952
+ )
953
+ expect(tUris).toEqual(postUris)
954
+ },
955
+ )
956
+ })
957
+
958
+ describe('OP and viewer', () => {
959
+ let seed: Awaited<ReturnType<typeof seeds.bumpOpAndViewer>>
960
+
961
+ beforeAll(async () => {
962
+ seed = await seeds.bumpOpAndViewer(sc)
963
+ await network.processAll()
964
+ })
965
+
966
+ type Case = {
967
+ sort: QueryParamsThread['sort']
968
+ postKeys: string[]
969
+ }
970
+
971
+ const cases: Case[] = [
972
+ {
973
+ sort: 'newest',
974
+ postKeys: [
975
+ 'root',
976
+ '3', // op
977
+ '3.2', // op
978
+ '3.0', // viewer
979
+ '3.4',
980
+ '3.3',
981
+ '3.1',
982
+ '4', // viewer
983
+ '4.2', // op
984
+ '4.3', // viewer
985
+ '4.4',
986
+ '4.1',
987
+ '4.0',
988
+ '2',
989
+ '2.2', // op
990
+ '2.0', // viewer
991
+ '2.4',
992
+ '2.3',
993
+ '2.1',
994
+ '1',
995
+ '1.2', // op
996
+ '1.3', // viewer
997
+ '1.4',
998
+ '1.1',
999
+ '1.0',
1000
+ '0',
1001
+ '0.4', // op
1002
+ '0.3', // viewer
1003
+ '0.2',
1004
+ '0.1',
1005
+ '0.0',
1006
+ ],
1007
+ },
1008
+ {
1009
+ sort: 'oldest',
1010
+ postKeys: [
1011
+ 'root',
1012
+ '3', // op
1013
+ '3.2', // op
1014
+ '3.0', // viewer
1015
+ '3.1',
1016
+ '3.3',
1017
+ '3.4',
1018
+ '4', // viewer
1019
+ '4.2', // op
1020
+ '4.3', // viewer
1021
+ '4.0',
1022
+ '4.1',
1023
+ '4.4',
1024
+ '0',
1025
+ '0.4', // op
1026
+ '0.3', // viewer
1027
+ '0.0',
1028
+ '0.1',
1029
+ '0.2',
1030
+ '1',
1031
+ '1.2', // op
1032
+ '1.3', // viewer
1033
+ '1.0',
1034
+ '1.1',
1035
+ '1.4',
1036
+ '2',
1037
+ '2.2', // op
1038
+ '2.0', // viewer
1039
+ '2.1',
1040
+ '2.3',
1041
+ '2.4',
1042
+ ],
1043
+ },
1044
+ {
1045
+ sort: 'top',
1046
+ postKeys: [
1047
+ 'root',
1048
+ '3', // op
1049
+ '3.2', // op
1050
+ '3.0', // viewer
1051
+ '3.4',
1052
+ '3.3',
1053
+ '3.1',
1054
+ '4', // viewer
1055
+ '4.2', // op
1056
+ '4.3', // viewer
1057
+ '4.1',
1058
+ '4.0',
1059
+ '4.4',
1060
+ '1',
1061
+ '1.2', // op
1062
+ '1.3', // viewer
1063
+ '1.1',
1064
+ '1.0',
1065
+ '1.4',
1066
+ '2',
1067
+ '2.2', // op
1068
+ '2.0', // viewer
1069
+ '2.1',
1070
+ '2.4',
1071
+ '2.3',
1072
+ '0',
1073
+ '0.4', // op
1074
+ '0.3', // viewer
1075
+ '0.2',
1076
+ '0.1',
1077
+ '0.0',
1078
+ ],
1079
+ },
1080
+ ]
1081
+
1082
+ it.each(cases)(
1083
+ 'bumps up OP and viewer and sorts by $sort in all levels',
1084
+ async ({ sort: sort, postKeys }) => {
1085
+ const { data } = await agent.app.bsky.unspecced.getPostThreadV2(
1086
+ {
1087
+ anchor: seed.root.ref.uriStr,
1088
+ sort,
1089
+ },
1090
+ {
1091
+ headers: await network.serviceHeaders(
1092
+ seed.users.viewer.did,
1093
+ ids.AppBskyUnspeccedGetPostThreadV2,
1094
+ ),
1095
+ },
1096
+ )
1097
+ const { thread: t, hasHiddenReplies } = data
1098
+
1099
+ assertPosts(t)
1100
+ expect(hasHiddenReplies).toBe(false)
1101
+ const tUris = t.map((i) => i.uri)
1102
+ const postUris = postKeys.map((k) =>
1103
+ k === 'root' ? seed.root.ref.uriStr : seed.r[k].ref.uriStr,
1104
+ )
1105
+ expect(tUris).toEqual(postUris)
1106
+ },
1107
+ )
1108
+ })
1109
+
1110
+ describe('followers', () => {
1111
+ let seed: Awaited<ReturnType<typeof seeds.bumpFollows>>
1112
+
1113
+ beforeAll(async () => {
1114
+ seed = await seeds.bumpFollows(sc)
1115
+ await network.processAll()
1116
+ })
1117
+
1118
+ const threadForPostAndViewer = async (
1119
+ post: string,
1120
+ viewer: string,
1121
+ prioritizeFollowedUsers: boolean = false,
1122
+ ) => {
1123
+ const { data } = await agent.app.bsky.unspecced.getPostThreadV2(
1124
+ {
1125
+ anchor: post,
1126
+ sort: 'newest',
1127
+ prioritizeFollowedUsers,
1128
+ },
1129
+ {
1130
+ headers: await network.serviceHeaders(
1131
+ viewer,
1132
+ ids.AppBskyUnspeccedGetPostThreadV2,
1133
+ ),
1134
+ },
1135
+ )
1136
+ const { thread: t, hasHiddenReplies } = data
1137
+
1138
+ assertPosts(t)
1139
+ expect(hasHiddenReplies).toBe(false)
1140
+ return t
1141
+ }
1142
+
1143
+ it('bumps up followed users if option is set', async () => {
1144
+ const prioritizeFollowedUsers = true
1145
+
1146
+ const t1 = await threadForPostAndViewer(
1147
+ seed.root.ref.uriStr,
1148
+ seed.users.viewerF.did,
1149
+ prioritizeFollowedUsers,
1150
+ )
1151
+ expect(t1).toEqual([
1152
+ expect.objectContaining({ uri: seed.root.ref.uriStr }), // root
1153
+ expect.objectContaining({ uri: seed.r['3'].ref.uriStr }), // op reply
1154
+ expect.objectContaining({ uri: seed.r['4'].ref.uriStr }), // viewer reply
1155
+ expect.objectContaining({ uri: seed.r['1'].ref.uriStr }), // newest followed reply
1156
+ expect.objectContaining({ uri: seed.r['0'].ref.uriStr }), // oldest followed reply
1157
+ expect.objectContaining({ uri: seed.r['5'].ref.uriStr }), // newest non-followed reply
1158
+ expect.objectContaining({ uri: seed.r['2'].ref.uriStr }), // oldest non-followed reply
1159
+ ])
1160
+
1161
+ const t2 = await threadForPostAndViewer(
1162
+ seed.root.ref.uriStr,
1163
+ seed.users.viewerNoF.did,
1164
+ prioritizeFollowedUsers,
1165
+ )
1166
+ expect(t2).toEqual([
1167
+ expect.objectContaining({ uri: seed.root.ref.uriStr }), // root
1168
+ expect.objectContaining({ uri: seed.r['3'].ref.uriStr }), // op reply
1169
+ expect.objectContaining({ uri: seed.r['5'].ref.uriStr }), // viewer reply
1170
+ // newest to oldest
1171
+ expect.objectContaining({ uri: seed.r['4'].ref.uriStr }),
1172
+ expect.objectContaining({ uri: seed.r['2'].ref.uriStr }),
1173
+ expect.objectContaining({ uri: seed.r['1'].ref.uriStr }),
1174
+ expect.objectContaining({ uri: seed.r['0'].ref.uriStr }),
1175
+ ])
1176
+ })
1177
+
1178
+ it('does not prioritize followed users if option is not set', async () => {
1179
+ const t1 = await threadForPostAndViewer(
1180
+ seed.root.ref.uriStr,
1181
+ seed.users.viewerF.did,
1182
+ )
1183
+ expect(t1).toHaveLength(7)
1184
+ expect(t1[0].uri).toBe(seed.root.ref.uriStr) // root
1185
+ expect(t1[1].uri).toBe(seed.r['3'].ref.uriStr) // op reply
1186
+ expect(t1[2].uri).toBe(seed.r['4'].ref.uriStr) // viewer reply
1187
+ // newest to oldest
1188
+ expect(t1[3].uri).toBe(seed.r['5'].ref.uriStr)
1189
+ expect(t1[4].uri).toBe(seed.r['2'].ref.uriStr)
1190
+ expect(t1[5].uri).toBe(seed.r['1'].ref.uriStr)
1191
+ expect(t1[6].uri).toBe(seed.r['0'].ref.uriStr)
1192
+
1193
+ const t2 = await threadForPostAndViewer(
1194
+ seed.root.ref.uriStr,
1195
+ seed.users.viewerNoF.did,
1196
+ )
1197
+ expect(t2).toHaveLength(7)
1198
+ expect(t2[0].uri).toBe(seed.root.ref.uriStr) // root
1199
+ expect(t2[1].uri).toBe(seed.r['3'].ref.uriStr) // op reply
1200
+ expect(t2[2].uri).toBe(seed.r['5'].ref.uriStr) // viewer reply
1201
+ // newest to oldest
1202
+ expect(t2[3].uri).toBe(seed.r['4'].ref.uriStr)
1203
+ expect(t2[4].uri).toBe(seed.r['2'].ref.uriStr)
1204
+ expect(t2[5].uri).toBe(seed.r['1'].ref.uriStr)
1205
+ expect(t2[6].uri).toBe(seed.r['0'].ref.uriStr)
1206
+ })
1207
+ })
1208
+ })
1209
+ })
1210
+
1211
+ describe(`blocks, deletions, no-unauthenticated`, () => {
1212
+ let seed: Awaited<ReturnType<typeof seeds.blockDeletionAuth>>
1213
+
1214
+ beforeAll(async () => {
1215
+ seed = await seeds.blockDeletionAuth(sc, labelerDid)
1216
+ await network.processAll()
1217
+ })
1218
+
1219
+ describe(`1p blocks`, () => {
1220
+ it(`blocked reply is omitted from replies`, async () => {
1221
+ const { data } = await agent.app.bsky.unspecced.getPostThreadV2(
1222
+ { anchor: seed.root.ref.uriStr },
1223
+ {
1224
+ headers: await network.serviceHeaders(
1225
+ // Use `blocked`, who was blocked by `blocker`, author of '0'.
1226
+ seed.users.blocked.did,
1227
+ ids.AppBskyUnspeccedGetPostThreadV2,
1228
+ ),
1229
+ },
1230
+ )
1231
+ const { thread: t, hasHiddenReplies } = data
1232
+
1233
+ assertPosts(t)
1234
+ expect(hasHiddenReplies).toBe(false)
1235
+ expect(t).toEqual([
1236
+ expect.objectContaining({ uri: seed.root.ref.uriStr }),
1237
+ expect.objectContaining({ uri: seed.r['3'].ref.uriStr }),
1238
+ expect.objectContaining({ uri: seed.r['3.0'].ref.uriStr }),
1239
+ expect.objectContaining({ uri: seed.r['3.0.0'].ref.uriStr }),
1240
+ ])
1241
+ })
1242
+
1243
+ it(`blocked anchor returns lone blocked view`, async () => {
1244
+ const { data } = await agent.app.bsky.unspecced.getPostThreadV2(
1245
+ { anchor: seed.r['0'].ref.uriStr },
1246
+ {
1247
+ headers: await network.serviceHeaders(
1248
+ // Use `blocked`, who was blocked by `blocker`, author of '0'.
1249
+ seed.users.blocked.did,
1250
+ ids.AppBskyUnspeccedGetPostThreadV2,
1251
+ ),
1252
+ },
1253
+ )
1254
+ const { thread: t, hasHiddenReplies } = data
1255
+
1256
+ expect(hasHiddenReplies).toBe(false)
1257
+ expect(t).toEqual([
1258
+ expect.objectContaining({
1259
+ uri: seed.r['0'].ref.uriStr,
1260
+ depth: 0,
1261
+ value: expect.objectContaining({
1262
+ $type: 'app.bsky.unspecced.getPostThreadV2#threadItemBlocked',
1263
+ }),
1264
+ }),
1265
+ ])
1266
+ })
1267
+
1268
+ it(`blocked parent is replaced by blocked view`, async () => {
1269
+ const { data } = await agent.app.bsky.unspecced.getPostThreadV2(
1270
+ { anchor: seed.r['0.0'].ref.uriStr },
1271
+ {
1272
+ headers: await network.serviceHeaders(
1273
+ // Use `blocked`, who was blocked by `blocker`, author of '0'.
1274
+ seed.users.blocked.did,
1275
+ ids.AppBskyUnspeccedGetPostThreadV2,
1276
+ ),
1277
+ },
1278
+ )
1279
+ const { thread: t, hasHiddenReplies } = data
1280
+
1281
+ expect(hasHiddenReplies).toBe(false)
1282
+ expect(t).toEqual([
1283
+ expect.objectContaining({
1284
+ uri: seed.r['0'].ref.uriStr,
1285
+ depth: -1,
1286
+ value: expect.objectContaining({
1287
+ $type: 'app.bsky.unspecced.getPostThreadV2#threadItemBlocked',
1288
+ }),
1289
+ }),
1290
+ expect.objectContaining({
1291
+ uri: seed.r['0.0'].ref.uriStr,
1292
+ depth: 0,
1293
+ value: expect.objectContaining({
1294
+ $type: 'app.bsky.unspecced.getPostThreadV2#threadItemPost',
1295
+ }),
1296
+ }),
1297
+ ])
1298
+ })
1299
+ })
1300
+
1301
+ describe(`3p blocks`, () => {
1302
+ it(`blocked reply is omitted from replies`, async () => {
1303
+ const { data } = await agent.app.bsky.unspecced.getPostThreadV2(
1304
+ { anchor: seed.root.ref.uriStr },
1305
+ {
1306
+ headers: await network.serviceHeaders(
1307
+ // Use `alice` who is a 3rd party between `op` and `opBlocked`.
1308
+ seed.users.alice.did,
1309
+ ids.AppBskyUnspeccedGetPostThreadV2,
1310
+ ),
1311
+ },
1312
+ )
1313
+ const { thread: t, hasHiddenReplies } = data
1314
+
1315
+ expect(hasHiddenReplies).toBe(false)
1316
+ assertPosts(t)
1317
+ expect(t).toEqual([
1318
+ expect.objectContaining({ uri: seed.root.ref.uriStr }),
1319
+ expect.objectContaining({ uri: seed.r['0'].ref.uriStr }),
1320
+ expect.objectContaining({ uri: seed.r['0.0'].ref.uriStr }),
1321
+ expect.objectContaining({ uri: seed.r['3'].ref.uriStr }),
1322
+ expect.objectContaining({ uri: seed.r['3.0'].ref.uriStr }),
1323
+ expect.objectContaining({ uri: seed.r['3.0.0'].ref.uriStr }),
1324
+ ])
1325
+ })
1326
+
1327
+ it(`blocked anchor returns post with blocked parent and non-blocked descendants`, async () => {
1328
+ const { data } = await agent.app.bsky.unspecced.getPostThreadV2(
1329
+ { anchor: seed.r['1'].ref.uriStr },
1330
+ {
1331
+ headers: await network.serviceHeaders(
1332
+ // Use `alice` who is a 3rd party between `op` and `opBlocked`.
1333
+ seed.users.alice.did,
1334
+ ids.AppBskyUnspeccedGetPostThreadV2,
1335
+ ),
1336
+ },
1337
+ )
1338
+ const { thread: t, hasHiddenReplies } = data
1339
+
1340
+ expect(hasHiddenReplies).toBe(false)
1341
+ expect(t).toEqual([
1342
+ expect.objectContaining({
1343
+ uri: seed.root.ref.uriStr,
1344
+ depth: -1,
1345
+ value: expect.objectContaining({
1346
+ $type: 'app.bsky.unspecced.getPostThreadV2#threadItemBlocked',
1347
+ }),
1348
+ }),
1349
+ expect.objectContaining({
1350
+ uri: seed.r['1'].ref.uriStr,
1351
+ depth: 0,
1352
+ value: expect.objectContaining({
1353
+ $type: 'app.bsky.unspecced.getPostThreadV2#threadItemPost',
1354
+ }),
1355
+ }),
1356
+ // 1.0 is blocked, but 1.1 is not
1357
+ expect.objectContaining({
1358
+ uri: seed.r['1.1'].ref.uriStr,
1359
+ depth: 1,
1360
+ value: expect.objectContaining({
1361
+ $type: 'app.bsky.unspecced.getPostThreadV2#threadItemPost',
1362
+ }),
1363
+ }),
1364
+ ])
1365
+ })
1366
+
1367
+ it(`blocked parent is replaced by blocked view`, async () => {
1368
+ const { data } = await agent.app.bsky.unspecced.getPostThreadV2(
1369
+ { anchor: seed.r['1.0'].ref.uriStr },
1370
+ {
1371
+ headers: await network.serviceHeaders(
1372
+ // Use `alice` who is a 3rd party between `op` and `opBlocked`.
1373
+ seed.users.alice.did,
1374
+ ids.AppBskyUnspeccedGetPostThreadV2,
1375
+ ),
1376
+ },
1377
+ )
1378
+ const { thread: t, hasHiddenReplies } = data
1379
+
1380
+ expect(hasHiddenReplies).toBe(false)
1381
+ expect(t).toEqual([
1382
+ expect.objectContaining({
1383
+ uri: seed.r['1'].ref.uriStr,
1384
+ depth: -1,
1385
+ value: expect.objectContaining({
1386
+ $type: 'app.bsky.unspecced.getPostThreadV2#threadItemBlocked',
1387
+ }),
1388
+ }),
1389
+ expect.objectContaining({
1390
+ uri: seed.r['1.0'].ref.uriStr,
1391
+ depth: 0,
1392
+ value: expect.objectContaining({
1393
+ $type: 'app.bsky.unspecced.getPostThreadV2#threadItemPost',
1394
+ }),
1395
+ }),
1396
+ ])
1397
+ })
1398
+
1399
+ it(`blocked root is replaced by blocked view`, async () => {
1400
+ const { data } = await agent.app.bsky.unspecced.getPostThreadV2(
1401
+ { anchor: seed.r['1.1'].ref.uriStr },
1402
+ {
1403
+ headers: await network.serviceHeaders(
1404
+ // Use `alice` who is a 3rd party between `op` and `opBlocked`.
1405
+ seed.users.alice.did,
1406
+ ids.AppBskyUnspeccedGetPostThreadV2,
1407
+ ),
1408
+ },
1409
+ )
1410
+ const { thread: t, hasHiddenReplies } = data
1411
+
1412
+ expect(hasHiddenReplies).toBe(false)
1413
+ expect(t).toEqual([
1414
+ expect.objectContaining({
1415
+ uri: seed.root.ref.uriStr,
1416
+ depth: -2,
1417
+ value: expect.objectContaining({
1418
+ $type: 'app.bsky.unspecced.getPostThreadV2#threadItemBlocked',
1419
+ }),
1420
+ }),
1421
+ expect.objectContaining({
1422
+ uri: seed.r['1'].ref.uriStr,
1423
+ depth: -1,
1424
+ value: expect.objectContaining({
1425
+ $type: 'app.bsky.unspecced.getPostThreadV2#threadItemPost',
1426
+ }),
1427
+ }),
1428
+ expect.objectContaining({
1429
+ uri: seed.r['1.1'].ref.uriStr,
1430
+ depth: 0,
1431
+ value: expect.objectContaining({
1432
+ $type: 'app.bsky.unspecced.getPostThreadV2#threadItemPost',
1433
+ }),
1434
+ }),
1435
+ ])
1436
+ })
1437
+ })
1438
+
1439
+ describe(`deleted posts`, () => {
1440
+ it(`deleted reply is omitted from replies`, async () => {
1441
+ const { data } = await agent.app.bsky.unspecced.getPostThreadV2(
1442
+ { anchor: seed.root.ref.uriStr },
1443
+ {
1444
+ headers: await network.serviceHeaders(
1445
+ seed.users.op.did,
1446
+ ids.AppBskyUnspeccedGetPostThreadV2,
1447
+ ),
1448
+ },
1449
+ )
1450
+ const { thread: t, hasHiddenReplies } = data
1451
+
1452
+ expect(hasHiddenReplies).toBe(false)
1453
+ assertPosts(t)
1454
+ expect(t).toEqual([
1455
+ expect.objectContaining({ uri: seed.root.ref.uriStr }),
1456
+ expect.objectContaining({ uri: seed.r['0'].ref.uriStr }),
1457
+ expect.objectContaining({ uri: seed.r['0.0'].ref.uriStr }),
1458
+ expect.objectContaining({ uri: seed.r['3'].ref.uriStr }),
1459
+ expect.objectContaining({ uri: seed.r['3.0'].ref.uriStr }),
1460
+ expect.objectContaining({ uri: seed.r['3.0.0'].ref.uriStr }),
1461
+ ])
1462
+ })
1463
+
1464
+ it(`deleted parent is replaced by not found view`, async () => {
1465
+ const { data } = await agent.app.bsky.unspecced.getPostThreadV2(
1466
+ { anchor: seed.r['2.0'].ref.uriStr },
1467
+ {
1468
+ headers: await network.serviceHeaders(
1469
+ seed.users.op.did,
1470
+ ids.AppBskyUnspeccedGetPostThreadV2,
1471
+ ),
1472
+ },
1473
+ )
1474
+ const { thread: t, hasHiddenReplies } = data
1475
+
1476
+ expect(hasHiddenReplies).toBe(false)
1477
+ expect(t).toEqual([
1478
+ expect.objectContaining({
1479
+ uri: seed.r['2'].ref.uriStr,
1480
+ depth: -1,
1481
+ value: expect.objectContaining({
1482
+ $type: 'app.bsky.unspecced.getPostThreadV2#threadItemNotFound',
1483
+ }),
1484
+ }),
1485
+ expect.objectContaining({
1486
+ uri: seed.r['2.0'].ref.uriStr,
1487
+ depth: 0,
1488
+ value: expect.objectContaining({
1489
+ $type: 'app.bsky.unspecced.getPostThreadV2#threadItemPost',
1490
+ }),
1491
+ }),
1492
+ ])
1493
+ })
1494
+ })
1495
+
1496
+ describe('no-unauthenticated', () => {
1497
+ it(`no-unauthenticated reply is omitted from replies`, async () => {
1498
+ const { data } = await agent.app.bsky.unspecced.getPostThreadV2(
1499
+ { anchor: seed.root.ref.uriStr },
1500
+ {
1501
+ headers: {
1502
+ 'atproto-accept-labelers': `${labelerDid}`,
1503
+ },
1504
+ },
1505
+ )
1506
+ const { thread: t, hasHiddenReplies } = data
1507
+
1508
+ expect(hasHiddenReplies).toBe(false)
1509
+ expect(t).toEqual([
1510
+ expect.objectContaining({
1511
+ uri: seed.root.ref.uriStr,
1512
+ depth: 0,
1513
+ value: expect.objectContaining({
1514
+ $type: 'app.bsky.unspecced.getPostThreadV2#threadItemPost',
1515
+ }),
1516
+ }),
1517
+ expect.objectContaining({
1518
+ uri: seed.r['0'].ref.uriStr,
1519
+ depth: 1,
1520
+ value: expect.objectContaining({
1521
+ $type: 'app.bsky.unspecced.getPostThreadV2#threadItemPost',
1522
+ }),
1523
+ }),
1524
+ expect.objectContaining({
1525
+ uri: seed.r['0.0'].ref.uriStr,
1526
+ depth: 2,
1527
+ value: expect.objectContaining({
1528
+ $type: 'app.bsky.unspecced.getPostThreadV2#threadItemPost',
1529
+ }),
1530
+ }),
1531
+ ])
1532
+ })
1533
+
1534
+ it(`no-unauthenticated anchor returns no-unauthenticated view without breaking the parent chain`, async () => {
1535
+ const { data } = await agent.app.bsky.unspecced.getPostThreadV2(
1536
+ { anchor: seed.r['3'].ref.uriStr },
1537
+ {
1538
+ headers: {
1539
+ 'atproto-accept-labelers': `${labelerDid}`,
1540
+ },
1541
+ },
1542
+ )
1543
+ const { thread: t, hasHiddenReplies } = data
1544
+
1545
+ expect(hasHiddenReplies).toBe(false)
1546
+ expect(t).toEqual([
1547
+ expect.objectContaining({
1548
+ uri: seed.root.ref.uriStr,
1549
+ depth: -1,
1550
+ value: expect.objectContaining({
1551
+ $type: 'app.bsky.unspecced.getPostThreadV2#threadItemPost',
1552
+ }),
1553
+ }),
1554
+ expect.objectContaining({
1555
+ uri: seed.r['3'].ref.uriStr,
1556
+ depth: 0,
1557
+ value: expect.objectContaining({
1558
+ $type:
1559
+ 'app.bsky.unspecced.getPostThreadV2#threadItemNoUnauthenticated',
1560
+ }),
1561
+ }),
1562
+ ])
1563
+ })
1564
+
1565
+ it(`no-unauthenticated parent is replaced by no-unauthenticated view without breaking the parent chain`, async () => {
1566
+ const { data } = await agent.app.bsky.unspecced.getPostThreadV2(
1567
+ { anchor: seed.r['3.0.0'].ref.uriStr },
1568
+ {
1569
+ headers: {
1570
+ 'atproto-accept-labelers': `${labelerDid}`,
1571
+ },
1572
+ },
1573
+ )
1574
+ const { thread: t, hasHiddenReplies } = data
1575
+
1576
+ expect(hasHiddenReplies).toBe(false)
1577
+ expect(t).toEqual([
1578
+ expect.objectContaining({
1579
+ uri: seed.root.ref.uriStr,
1580
+ depth: -3,
1581
+ value: expect.objectContaining({
1582
+ $type: 'app.bsky.unspecced.getPostThreadV2#threadItemPost',
1583
+ }),
1584
+ }),
1585
+ expect.objectContaining({
1586
+ uri: seed.r['3'].ref.uriStr,
1587
+ depth: -2,
1588
+ value: expect.objectContaining({
1589
+ $type:
1590
+ 'app.bsky.unspecced.getPostThreadV2#threadItemNoUnauthenticated',
1591
+ }),
1592
+ }),
1593
+ expect.objectContaining({
1594
+ uri: seed.r['3.0'].ref.uriStr,
1595
+ depth: -1,
1596
+ value: expect.objectContaining({
1597
+ $type:
1598
+ 'app.bsky.unspecced.getPostThreadV2#threadItemNoUnauthenticated',
1599
+ }),
1600
+ }),
1601
+ expect.objectContaining({
1602
+ uri: seed.r['3.0.0'].ref.uriStr,
1603
+ depth: 0,
1604
+ value: expect.objectContaining({
1605
+ $type: 'app.bsky.unspecced.getPostThreadV2#threadItemPost',
1606
+ }),
1607
+ }),
1608
+ ])
1609
+ })
1610
+ })
1611
+ })
1612
+
1613
+ describe(`mutes`, () => {
1614
+ let seed: Awaited<ReturnType<typeof seeds.mutes>>
1615
+
1616
+ beforeAll(async () => {
1617
+ seed = await seeds.mutes(sc)
1618
+ await network.processAll()
1619
+ })
1620
+
1621
+ describe('omitting muted replies', () => {
1622
+ it(`muted reply is omitted in top-level replies and in nested replies`, async () => {
1623
+ const { data } = await agent.app.bsky.unspecced.getPostThreadV2(
1624
+ { anchor: seed.root.ref.uriStr },
1625
+ {
1626
+ headers: await network.serviceHeaders(
1627
+ // Fetching as `op` mutes `opMuted`.
1628
+ seed.users.op.did,
1629
+ ids.AppBskyUnspeccedGetPostThreadV2,
1630
+ ),
1631
+ },
1632
+ )
1633
+ const { thread: t, hasHiddenReplies } = data
1634
+
1635
+ expect(hasHiddenReplies).toBe(true)
1636
+ assertPosts(t)
1637
+ expect(t).toEqual([
1638
+ expect.objectContaining({
1639
+ uri: seed.root.ref.uriStr,
1640
+ value: expect.objectContaining(props({ opThread: true })),
1641
+ }),
1642
+ expect.objectContaining({
1643
+ uri: seed.r['1'].ref.uriStr,
1644
+ value: expect.objectContaining(props()),
1645
+ }),
1646
+ // 1.0 is a nested muted reply, so it is omitted.
1647
+ expect.objectContaining({
1648
+ uri: seed.r['1.1'].ref.uriStr,
1649
+ value: expect.objectContaining(props()),
1650
+ }),
1651
+ ])
1652
+ })
1653
+
1654
+ it(`top-level muted replies are returned when fetching hidden, sorted by newest`, async () => {
1655
+ const { data } = await agent.app.bsky.unspecced.getPostThreadHiddenV2(
1656
+ { anchor: seed.root.ref.uriStr },
1657
+ {
1658
+ headers: await network.serviceHeaders(
1659
+ // Fetching as `op` mutes `opMuted`.
1660
+ seed.users.op.did,
1661
+ ids.AppBskyUnspeccedGetPostThreadHiddenV2,
1662
+ ),
1663
+ },
1664
+ )
1665
+ const { thread: t } = data
1666
+
1667
+ assertHiddenPosts(t)
1668
+ expect(t).toEqual([
1669
+ expect.objectContaining({
1670
+ uri: seed.r['0'].ref.uriStr,
1671
+ value: expect.objectContaining(
1672
+ propsHidden({ mutedByViewer: true }),
1673
+ ),
1674
+ }),
1675
+ // No nested replies for hidden.
1676
+ ])
1677
+ })
1678
+ })
1679
+
1680
+ describe('OP mutes', () => {
1681
+ it(`mutes by OP don't mute for 3p`, async () => {
1682
+ const { data } = await agent.app.bsky.unspecced.getPostThreadV2(
1683
+ { anchor: seed.root.ref.uriStr },
1684
+ {
1685
+ headers: await network.serviceHeaders(
1686
+ // Fetching as `muter` mutes `muted`.
1687
+ seed.users.muter.did,
1688
+ ids.AppBskyUnspeccedGetPostThreadV2,
1689
+ ),
1690
+ },
1691
+ )
1692
+ const { thread: t, hasHiddenReplies } = data
1693
+
1694
+ expect(hasHiddenReplies).toBe(true)
1695
+ assertPosts(t)
1696
+ expect(t).toEqual([
1697
+ expect.objectContaining({
1698
+ uri: seed.root.ref.uriStr,
1699
+ value: expect.objectContaining(props({ opThread: true })),
1700
+ }),
1701
+ expect.objectContaining({
1702
+ uri: seed.r['0'].ref.uriStr,
1703
+ value: expect.objectContaining(props()),
1704
+ }),
1705
+ expect.objectContaining({
1706
+ uri: seed.r['0.0'].ref.uriStr,
1707
+ value: expect.objectContaining(props()),
1708
+ }),
1709
+ // 0.1 is a nested muted reply, so it is omitted.
1710
+ ])
1711
+ })
1712
+
1713
+ it(`fetches hidden replies includes own mutes, not OP mutes, sorted by newest`, async () => {
1714
+ const { data } = await agent.app.bsky.unspecced.getPostThreadHiddenV2(
1715
+ { anchor: seed.root.ref.uriStr },
1716
+ {
1717
+ headers: await network.serviceHeaders(
1718
+ // Fetching as `muter` mutes `muted`.
1719
+ seed.users.muter.did,
1720
+ ids.AppBskyUnspeccedGetPostThreadHiddenV2,
1721
+ ),
1722
+ },
1723
+ )
1724
+ const { thread: t } = data
1725
+
1726
+ assertHiddenPosts(t)
1727
+ expect(t).toEqual([
1728
+ expect.objectContaining({
1729
+ uri: seed.r['1'].ref.uriStr,
1730
+ value: expect.objectContaining(
1731
+ propsHidden({ mutedByViewer: true }),
1732
+ ),
1733
+ }),
1734
+ // No nested replies for hidden.
1735
+ ])
1736
+ })
1737
+
1738
+ it(`mutes by OP don't affect the muted user`, async () => {
1739
+ const { data } = await agent.app.bsky.unspecced.getPostThreadV2(
1740
+ { anchor: seed.root.ref.uriStr },
1741
+ {
1742
+ headers: await network.serviceHeaders(
1743
+ seed.users.opMuted.did,
1744
+ ids.AppBskyUnspeccedGetPostThreadV2,
1745
+ ),
1746
+ },
1747
+ )
1748
+ const { thread: t, hasHiddenReplies } = data
1749
+
1750
+ expect(hasHiddenReplies).toBe(false)
1751
+ assertPosts(t)
1752
+ // No muted posts by `opMuted`, gets the full thread.
1753
+ expect(t.length).toBe(1 + Object.keys(seed.r).length) // root + replies
1754
+ })
1755
+ })
1756
+ })
1757
+
1758
+ describe(`threadgated`, () => {
1759
+ let seed: Awaited<ReturnType<typeof seeds.threadgated>>
1760
+
1761
+ beforeAll(async () => {
1762
+ seed = await seeds.threadgated(sc)
1763
+ await network.processAll()
1764
+ })
1765
+
1766
+ it(`threadgated reply is omitted in top-level replies and in nested replies`, async () => {
1767
+ const { data } = await agent.app.bsky.unspecced.getPostThreadV2(
1768
+ { anchor: seed.root.ref.uriStr },
1769
+ {
1770
+ headers: await network.serviceHeaders(
1771
+ seed.users.op.did,
1772
+ ids.AppBskyUnspeccedGetPostThreadV2,
1773
+ ),
1774
+ },
1775
+ )
1776
+ const { thread: t, hasHiddenReplies } = data
1777
+
1778
+ expect(hasHiddenReplies).toBe(true)
1779
+ assertPosts(t)
1780
+ expect(t).toEqual([
1781
+ expect.objectContaining({
1782
+ uri: seed.root.ref.uriStr,
1783
+ value: expect.objectContaining(props({ opThread: true })),
1784
+ }),
1785
+ expect.objectContaining({
1786
+ uri: seed.r['2'].ref.uriStr,
1787
+ value: expect.objectContaining(props()),
1788
+ }),
1789
+ // OP reply bumped up.
1790
+ expect.objectContaining({
1791
+ uri: seed.r['2.2'].ref.uriStr,
1792
+ value: expect.objectContaining(props()),
1793
+ }),
1794
+ expect.objectContaining({
1795
+ uri: seed.r['2.0'].ref.uriStr,
1796
+ value: expect.objectContaining(props()),
1797
+ }),
1798
+ // 2.1 is a nested hidden reply, so it is omitted.
1799
+ ])
1800
+ })
1801
+
1802
+ it(`top-level threadgated replies are returned to OP when fetching hidden, sorted by newest`, async () => {
1803
+ const { data } = await agent.app.bsky.unspecced.getPostThreadHiddenV2(
1804
+ { anchor: seed.root.ref.uriStr },
1805
+ {
1806
+ headers: await network.serviceHeaders(
1807
+ seed.users.op.did,
1808
+ ids.AppBskyUnspeccedGetPostThreadHiddenV2,
1809
+ ),
1810
+ },
1811
+ )
1812
+ const { thread: t } = data
1813
+
1814
+ assertHiddenPosts(t)
1815
+ expect(t).toEqual([
1816
+ expect.objectContaining({
1817
+ uri: seed.r['1'].ref.uriStr,
1818
+ value: expect.objectContaining(
1819
+ propsHidden({ hiddenByThreadgate: true }),
1820
+ ),
1821
+ }),
1822
+ // No nested replies for hidden.
1823
+
1824
+ // Mutes come after hidden.
1825
+ expect.objectContaining({
1826
+ uri: seed.r['0'].ref.uriStr,
1827
+ value: expect.objectContaining(propsHidden({ mutedByViewer: true })),
1828
+ }),
1829
+ ])
1830
+ })
1831
+
1832
+ it(`author of hidden reply does not see it as hidden`, async () => {
1833
+ const { data } = await agent.app.bsky.unspecced.getPostThreadV2(
1834
+ { anchor: seed.root.ref.uriStr },
1835
+ {
1836
+ headers: await network.serviceHeaders(
1837
+ // `alice` does not get its own reply as hidden.
1838
+ seed.users.alice.did,
1839
+ ids.AppBskyUnspeccedGetPostThreadV2,
1840
+ ),
1841
+ },
1842
+ )
1843
+ const { thread: t, hasHiddenReplies } = data
1844
+
1845
+ expect(hasHiddenReplies).toBe(false)
1846
+ assertPosts(t)
1847
+ expect(t).toEqual([
1848
+ expect.objectContaining({
1849
+ uri: seed.root.ref.uriStr,
1850
+ value: expect.objectContaining(props({ opThread: true })),
1851
+ }),
1852
+
1853
+ // alice does not see its own reply as hidden.
1854
+ expect.objectContaining({
1855
+ uri: seed.r['1'].ref.uriStr,
1856
+ value: expect.objectContaining(props()),
1857
+ }),
1858
+ // OP reply bumped up.
1859
+ expect.objectContaining({
1860
+ uri: seed.r['1.2'].ref.uriStr,
1861
+ value: expect.objectContaining(props()),
1862
+ }),
1863
+ expect.objectContaining({
1864
+ uri: seed.r['1.0'].ref.uriStr,
1865
+ value: expect.objectContaining(props()),
1866
+ }),
1867
+ expect.objectContaining({
1868
+ uri: seed.r['1.1'].ref.uriStr,
1869
+ value: expect.objectContaining(props()),
1870
+ }),
1871
+
1872
+ // `opMuted` is not muted by `alice`.
1873
+ expect.objectContaining({
1874
+ uri: seed.r['0'].ref.uriStr,
1875
+ value: expect.objectContaining(props()),
1876
+ }),
1877
+
1878
+ expect.objectContaining({
1879
+ uri: seed.r['2'].ref.uriStr,
1880
+ value: expect.objectContaining(props()),
1881
+ }),
1882
+ // OP reply bumped up.
1883
+ expect.objectContaining({
1884
+ uri: seed.r['2.2'].ref.uriStr,
1885
+ value: expect.objectContaining(props()),
1886
+ }),
1887
+ expect.objectContaining({
1888
+ uri: seed.r['2.0'].ref.uriStr,
1889
+ value: expect.objectContaining(props()),
1890
+ }),
1891
+ // 2.1 is a nested hidden reply, so it is omitted.
1892
+ ])
1893
+ })
1894
+
1895
+ it(`other viewers are affected by threadgate-hidden replies by OP`, async () => {
1896
+ const { data } = await agent.app.bsky.unspecced.getPostThreadV2(
1897
+ { anchor: seed.root.ref.uriStr },
1898
+ {
1899
+ headers: await network.serviceHeaders(
1900
+ // `viewer` also gets the replies as hidden.
1901
+ seed.users.viewer.did,
1902
+ ids.AppBskyUnspeccedGetPostThreadV2,
1903
+ ),
1904
+ },
1905
+ )
1906
+ const { thread: t, hasHiddenReplies } = data
1907
+
1908
+ expect(hasHiddenReplies).toBe(true)
1909
+ assertPosts(t)
1910
+ expect(t).toEqual([
1911
+ expect.objectContaining({
1912
+ uri: seed.root.ref.uriStr,
1913
+ value: expect.objectContaining(props({ opThread: true })),
1914
+ }),
1915
+ // `opMuted` doesn't see itself as muted, just `op` does.
1916
+ expect.objectContaining({
1917
+ uri: seed.r['0'].ref.uriStr,
1918
+ value: expect.objectContaining(props()),
1919
+ }),
1920
+
1921
+ expect.objectContaining({
1922
+ uri: seed.r['2'].ref.uriStr,
1923
+ value: expect.objectContaining(props()),
1924
+ }),
1925
+ // OP reply bumped up.
1926
+ expect.objectContaining({
1927
+ uri: seed.r['2.2'].ref.uriStr,
1928
+ value: expect.objectContaining(props()),
1929
+ }),
1930
+ expect.objectContaining({
1931
+ uri: seed.r['2.0'].ref.uriStr,
1932
+ value: expect.objectContaining(props()),
1933
+ }),
1934
+ // 2.1 is a nested hidden reply, so it is omitted.
1935
+ ])
1936
+ })
1937
+
1938
+ it(`top-level threadgated replies are returned to other viewers when fetching hidden, sorted by newest`, async () => {
1939
+ const { data } = await agent.app.bsky.unspecced.getPostThreadHiddenV2(
1940
+ { anchor: seed.root.ref.uriStr },
1941
+ {
1942
+ headers: await network.serviceHeaders(
1943
+ // `viewer` also gets the replies as hidden.
1944
+ seed.users.viewer.did,
1945
+ ids.AppBskyUnspeccedGetPostThreadHiddenV2,
1946
+ ),
1947
+ },
1948
+ )
1949
+ const { thread: t } = data
1950
+
1951
+ assertHiddenPosts(t)
1952
+ expect(t).toEqual([
1953
+ expect.objectContaining({
1954
+ uri: seed.r['1'].ref.uriStr,
1955
+ value: expect.objectContaining(
1956
+ propsHidden({ hiddenByThreadgate: true }),
1957
+ ),
1958
+ }),
1959
+ // No nested replies for hidden.
1960
+ ])
1961
+ })
1962
+ })
1963
+
1964
+ describe('tags', () => {
1965
+ let seed: Awaited<ReturnType<typeof seeds.tags>>
1966
+
1967
+ beforeAll(async () => {
1968
+ seed = await seeds.tags(sc)
1969
+ await network.processAll()
1970
+ })
1971
+
1972
+ describe('when prioritizing followed users', () => {
1973
+ const prioritizeFollowedUsers = true
1974
+
1975
+ it('considers tags for bumping down and hiding', async () => {
1976
+ const { data } = await agent.app.bsky.unspecced.getPostThreadV2(
1977
+ {
1978
+ anchor: seed.root.ref.uriStr,
1979
+ sort: 'newest',
1980
+ prioritizeFollowedUsers,
1981
+ },
1982
+ {
1983
+ headers: await network.serviceHeaders(
1984
+ seed.users.viewer.did,
1985
+ ids.AppBskyUnspeccedGetPostThreadV2,
1986
+ ),
1987
+ },
1988
+ )
1989
+ const { thread: t, hasHiddenReplies } = data
1990
+
1991
+ expect(hasHiddenReplies).toBe(true)
1992
+ assertPosts(t)
1993
+ expect(t).toEqual([
1994
+ expect.objectContaining({ uri: seed.root.ref.uriStr }),
1995
+ // OP (down overridden).
1996
+ expect.objectContaining({ uri: seed.r['3'].ref.uriStr }),
1997
+ // Viewer (hide overridden).
1998
+ expect.objectContaining({ uri: seed.r['4'].ref.uriStr }),
1999
+ // Following (hide overridden).
2000
+ expect.objectContaining({ uri: seed.r['5'].ref.uriStr }),
2001
+ // Fot following.
2002
+ expect.objectContaining({ uri: seed.r['0'].ref.uriStr }),
2003
+ expect.objectContaining({ uri: seed.r['0.0'].ref.uriStr }),
2004
+ expect.objectContaining({ uri: seed.r['0.1'].ref.uriStr }),
2005
+ // Down.
2006
+ expect.objectContaining({ uri: seed.r['1'].ref.uriStr }),
2007
+ expect.objectContaining({ uri: seed.r['1.0'].ref.uriStr }),
2008
+ expect.objectContaining({ uri: seed.r['1.1'].ref.uriStr }),
2009
+ ])
2010
+ })
2011
+
2012
+ it('finds the hidden by tag', async () => {
2013
+ const { data } = await agent.app.bsky.unspecced.getPostThreadHiddenV2(
2014
+ {
2015
+ anchor: seed.root.ref.uriStr,
2016
+ prioritizeFollowedUsers,
2017
+ },
2018
+ {
2019
+ headers: await network.serviceHeaders(
2020
+ seed.users.viewer.did,
2021
+ ids.AppBskyUnspeccedGetPostThreadHiddenV2,
2022
+ ),
2023
+ },
2024
+ )
2025
+ const { thread: t } = data
2026
+
2027
+ assertHiddenPosts(t)
2028
+ expect(t).toEqual([
2029
+ // Hide.
2030
+ expect.objectContaining({ uri: seed.r['2'].ref.uriStr }),
2031
+ ])
2032
+ })
2033
+ })
2034
+
2035
+ describe('when not prioritizing followed users', () => {
2036
+ const prioritizeFollowedUsers = false
2037
+
2038
+ it('considers tags for bumping down and hiding', async () => {
2039
+ const { data } = await agent.app.bsky.unspecced.getPostThreadV2(
2040
+ {
2041
+ anchor: seed.root.ref.uriStr,
2042
+ sort: 'newest',
2043
+ prioritizeFollowedUsers,
2044
+ },
2045
+ {
2046
+ headers: await network.serviceHeaders(
2047
+ seed.users.viewer.did,
2048
+ ids.AppBskyUnspeccedGetPostThreadV2,
2049
+ ),
2050
+ },
2051
+ )
2052
+ const { thread: t, hasHiddenReplies } = data
2053
+
2054
+ expect(hasHiddenReplies).toBe(true)
2055
+ assertPosts(t)
2056
+ expect(t).toEqual([
2057
+ expect.objectContaining({ uri: seed.root.ref.uriStr }),
2058
+ // OP (down overridden).
2059
+ expect.objectContaining({ uri: seed.r['3'].ref.uriStr }),
2060
+ // Viewer (hide overriden).
2061
+ expect.objectContaining({ uri: seed.r['4'].ref.uriStr }),
2062
+ // Following was hidden because not prioritizing.
2063
+ // Not following.
2064
+ expect.objectContaining({ uri: seed.r['0'].ref.uriStr }),
2065
+ expect.objectContaining({ uri: seed.r['0.0'].ref.uriStr }),
2066
+ expect.objectContaining({ uri: seed.r['0.1'].ref.uriStr }),
2067
+ // Down.
2068
+ expect.objectContaining({ uri: seed.r['1'].ref.uriStr }),
2069
+ expect.objectContaining({ uri: seed.r['1.0'].ref.uriStr }),
2070
+ expect.objectContaining({ uri: seed.r['1.1'].ref.uriStr }),
2071
+ ])
2072
+ })
2073
+
2074
+ it('finds the hidden by tag', async () => {
2075
+ const { data } = await agent.app.bsky.unspecced.getPostThreadHiddenV2(
2076
+ {
2077
+ anchor: seed.root.ref.uriStr,
2078
+ prioritizeFollowedUsers,
2079
+ },
2080
+ {
2081
+ headers: await network.serviceHeaders(
2082
+ seed.users.viewer.did,
2083
+ ids.AppBskyUnspeccedGetPostThreadHiddenV2,
2084
+ ),
2085
+ },
2086
+ )
2087
+ const { thread: t } = data
2088
+
2089
+ assertHiddenPosts(t)
2090
+ expect(t).toEqual([
2091
+ // Following (hide).
2092
+ expect.objectContaining({ uri: seed.r['5'].ref.uriStr }),
2093
+ // Hide.
2094
+ expect.objectContaining({ uri: seed.r['2'].ref.uriStr }),
2095
+ ])
2096
+ })
2097
+ })
2098
+ })
2099
+ })
2100
+
2101
+ function assertPosts(
2102
+ t: OutputSchemaThread['thread'],
2103
+ ): asserts t is ThreadItemValuePost[] {
2104
+ t.forEach((i) => {
2105
+ assert(
2106
+ AppBskyUnspeccedGetPostThreadV2.isThreadItemPost(i.value),
2107
+ `Expected thread item to have a post as value`,
2108
+ )
2109
+ })
2110
+ }
2111
+
2112
+ function assertHiddenPosts(
2113
+ t: OutputSchemaHiddenThread['thread'],
2114
+ ): asserts t is ThreadHiddenItem[] {
2115
+ t.forEach((i) => {
2116
+ assert(
2117
+ AppBskyUnspeccedGetPostThreadHiddenV2.isThreadHiddenItemPost(i.value),
2118
+ `Expected thread item to have a hidden post as value`,
2119
+ )
2120
+ })
2121
+ }