Skip to content

Commit 2121225

Browse files
committed
fix tests & better hydration
1 parent 91efd64 commit 2121225

File tree

4 files changed

+25
-19
lines changed

4 files changed

+25
-19
lines changed

packages/bsky/src/hydration/hydrator.ts

+1-10
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import { ids } from '../lexicon/lexicons'
77
import { isMain as isEmbedRecord } from '../lexicon/types/app/bsky/embed/record'
88
import { isMain as isEmbedRecordWithMedia } from '../lexicon/types/app/bsky/embed/recordWithMedia'
99
import { isListRule } from '../lexicon/types/app/bsky/feed/threadgate'
10-
import type { Label } from '../lexicon/types/com/atproto/label/defs'
1110
import {
1211
ActorHydrator,
1312
ProfileAggs,
@@ -762,16 +761,8 @@ const actionTakedownLabels = <T>(
762761
labels: Labels,
763762
) => {
764763
for (const key of keys) {
765-
const subjectLabels = labels.get(key)
766-
if (!subjectLabels) continue
767-
if (includesTakedownLabel(subjectLabels)) {
764+
if (labels.get(key)?.isTakendown) {
768765
hydrationMap.set(key, null)
769766
}
770767
}
771768
}
772-
773-
const includesTakedownLabel = (labels: Label[]) => {
774-
return labels.some((l) => l.val === TAKEDOWN_LABEL)
775-
}
776-
777-
const TAKEDOWN_LABEL = '!takedown'

packages/bsky/src/hydration/label.ts

+22-8
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,12 @@ import { HydrationMap, parseJsonBytes } from './util'
44

55
export type { Label } from '../lexicon/types/com/atproto/label/defs'
66

7-
export type Labels = HydrationMap<Label[]>
7+
export type SubjectLabels = {
8+
isTakendown: boolean
9+
labels: Label[]
10+
}
11+
12+
export type Labels = HydrationMap<SubjectLabels>
813

914
export class LabelHydrator {
1015
constructor(
@@ -19,18 +24,27 @@ export class LabelHydrator {
1924
issuers = ([] as string[])
2025
.concat(issuers ?? [])
2126
.concat(this.opts?.labelsFromIssuerDids ?? [])
22-
if (!subjects.length || !issuers.length) return new HydrationMap<Label[]>()
27+
if (!subjects.length || !issuers.length)
28+
return new HydrationMap<SubjectLabels>()
2329
const res = await this.dataplane.getLabels({ subjects, issuers })
2430
return res.labels.reduce((acc, cur) => {
2531
const label = parseJsonBytes(cur) as Label | undefined
2632
if (!label || label.neg) return acc
27-
const entry = acc.get(label.uri)
28-
if (entry) {
29-
entry.push(label)
30-
} else {
31-
acc.set(label.uri, [label])
33+
let entry = acc.get(label.uri)
34+
if (!entry) {
35+
entry = {
36+
isTakendown: false,
37+
labels: [],
38+
}
39+
acc.set(label.uri, entry)
40+
}
41+
entry.labels.push(label)
42+
if (TAKEDOWN_LABELS.includes(label.val) && !label.neg) {
43+
entry.isTakendown = true
3244
}
3345
return acc
34-
}, new HydrationMap<Label[]>())
46+
}, new HydrationMap<SubjectLabels>())
3547
}
3648
}
49+
50+
const TAKEDOWN_LABELS = ['!takedown', '!suspend']

packages/bsky/tests/views/takedown-labels.test.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ describe('bsky takedown labels', () => {
2222

2323
const addTakedownLabels = async (subjects: string[]) => {
2424
if (subjects.length === 0) return
25-
const src = network.bsky.ctx.cfg.modServiceDid
25+
const src = network.ozone.ctx.cfg.service.did
2626
const cts = new Date().toISOString()
2727
const labels = subjects.map((uri) => ({
2828
src,

packages/dev-env/src/network.ts

+1
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ export class TestNetwork extends TestNetworkNoAppView {
6060
dbPostgresUrl,
6161
redisHost,
6262
modServiceDid: ozoneDid,
63+
labelsFromIssuerDids: [ozoneDid],
6364
...params.bsky,
6465
})
6566

0 commit comments

Comments
 (0)