From 43e1b247187c4439d55f674f5939fbe9c5df517d Mon Sep 17 00:00:00 2001 From: Devin Ivy Date: Tue, 12 Mar 2024 16:17:02 -0400 Subject: [PATCH 1/4] lexicon: add labels to feedgen and list views --- lexicons/app/bsky/feed/defs.json | 4 ++++ lexicons/app/bsky/graph/defs.json | 8 +++++++ packages/api/src/client/lexicons.ts | 21 +++++++++++++++++++ .../src/client/types/app/bsky/feed/defs.ts | 1 + .../src/client/types/app/bsky/graph/defs.ts | 3 +++ packages/bsky/src/lexicon/lexicons.ts | 21 +++++++++++++++++++ .../src/lexicon/types/app/bsky/feed/defs.ts | 1 + .../src/lexicon/types/app/bsky/graph/defs.ts | 3 +++ packages/ozone/src/lexicon/lexicons.ts | 21 +++++++++++++++++++ .../src/lexicon/types/app/bsky/feed/defs.ts | 1 + .../src/lexicon/types/app/bsky/graph/defs.ts | 3 +++ packages/pds/src/lexicon/lexicons.ts | 21 +++++++++++++++++++ .../src/lexicon/types/app/bsky/feed/defs.ts | 1 + .../src/lexicon/types/app/bsky/graph/defs.ts | 3 +++ 14 files changed, 112 insertions(+) diff --git a/lexicons/app/bsky/feed/defs.json b/lexicons/app/bsky/feed/defs.json index 7f121e88403..7c40ef3962f 100644 --- a/lexicons/app/bsky/feed/defs.json +++ b/lexicons/app/bsky/feed/defs.json @@ -137,6 +137,10 @@ }, "avatar": { "type": "string" }, "likeCount": { "type": "integer", "minimum": 0 }, + "labels": { + "type": "array", + "items": { "type": "ref", "ref": "com.atproto.label.defs#label" } + }, "viewer": { "type": "ref", "ref": "#generatorViewerState" }, "indexedAt": { "type": "string", "format": "datetime" } } diff --git a/lexicons/app/bsky/graph/defs.json b/lexicons/app/bsky/graph/defs.json index 737d984d08b..be718f20a16 100644 --- a/lexicons/app/bsky/graph/defs.json +++ b/lexicons/app/bsky/graph/defs.json @@ -11,6 +11,10 @@ "name": { "type": "string", "maxLength": 64, "minLength": 1 }, "purpose": { "type": "ref", "ref": "#listPurpose" }, "avatar": { "type": "string" }, + "labels": { + "type": "array", + "items": { "type": "ref", "ref": "com.atproto.label.defs#label" } + }, "viewer": { "type": "ref", "ref": "#listViewerState" }, "indexedAt": { "type": "string", "format": "datetime" } } @@ -34,6 +38,10 @@ "items": { "type": "ref", "ref": "app.bsky.richtext.facet" } }, "avatar": { "type": "string" }, + "labels": { + "type": "array", + "items": { "type": "ref", "ref": "com.atproto.label.defs#label" } + }, "viewer": { "type": "ref", "ref": "#listViewerState" }, "indexedAt": { "type": "string", "format": "datetime" } } diff --git a/packages/api/src/client/lexicons.ts b/packages/api/src/client/lexicons.ts index e9a585f5a21..1c9d18c1f17 100644 --- a/packages/api/src/client/lexicons.ts +++ b/packages/api/src/client/lexicons.ts @@ -6322,6 +6322,13 @@ export const schemaDict = { type: 'integer', minimum: 0, }, + labels: { + type: 'array', + items: { + type: 'ref', + ref: 'lex:com.atproto.label.defs#label', + }, + }, viewer: { type: 'ref', ref: 'lex:app.bsky.feed.defs#generatorViewerState', @@ -7626,6 +7633,13 @@ export const schemaDict = { avatar: { type: 'string', }, + labels: { + type: 'array', + items: { + type: 'ref', + ref: 'lex:com.atproto.label.defs#label', + }, + }, viewer: { type: 'ref', ref: 'lex:app.bsky.graph.defs#listViewerState', @@ -7676,6 +7690,13 @@ export const schemaDict = { avatar: { type: 'string', }, + labels: { + type: 'array', + items: { + type: 'ref', + ref: 'lex:com.atproto.label.defs#label', + }, + }, viewer: { type: 'ref', ref: 'lex:app.bsky.graph.defs#listViewerState', diff --git a/packages/api/src/client/types/app/bsky/feed/defs.ts b/packages/api/src/client/types/app/bsky/feed/defs.ts index 949b8fb975e..856d5356086 100644 --- a/packages/api/src/client/types/app/bsky/feed/defs.ts +++ b/packages/api/src/client/types/app/bsky/feed/defs.ts @@ -219,6 +219,7 @@ export interface GeneratorView { descriptionFacets?: AppBskyRichtextFacet.Main[] avatar?: string likeCount?: number + labels?: ComAtprotoLabelDefs.Label[] viewer?: GeneratorViewerState indexedAt: string [k: string]: unknown diff --git a/packages/api/src/client/types/app/bsky/graph/defs.ts b/packages/api/src/client/types/app/bsky/graph/defs.ts index 0580b9bb158..78d3ac24d62 100644 --- a/packages/api/src/client/types/app/bsky/graph/defs.ts +++ b/packages/api/src/client/types/app/bsky/graph/defs.ts @@ -5,6 +5,7 @@ import { ValidationResult, BlobRef } from '@atproto/lexicon' import { isObj, hasProp } from '../../../../util' import { lexicons } from '../../../../lexicons' import { CID } from 'multiformats/cid' +import * as ComAtprotoLabelDefs from '../../../com/atproto/label/defs' import * as AppBskyActorDefs from '../actor/defs' import * as AppBskyRichtextFacet from '../richtext/facet' @@ -14,6 +15,7 @@ export interface ListViewBasic { name: string purpose: ListPurpose avatar?: string + labels?: ComAtprotoLabelDefs.Label[] viewer?: ListViewerState indexedAt?: string [k: string]: unknown @@ -40,6 +42,7 @@ export interface ListView { description?: string descriptionFacets?: AppBskyRichtextFacet.Main[] avatar?: string + labels?: ComAtprotoLabelDefs.Label[] viewer?: ListViewerState indexedAt: string [k: string]: unknown diff --git a/packages/bsky/src/lexicon/lexicons.ts b/packages/bsky/src/lexicon/lexicons.ts index e9a585f5a21..1c9d18c1f17 100644 --- a/packages/bsky/src/lexicon/lexicons.ts +++ b/packages/bsky/src/lexicon/lexicons.ts @@ -6322,6 +6322,13 @@ export const schemaDict = { type: 'integer', minimum: 0, }, + labels: { + type: 'array', + items: { + type: 'ref', + ref: 'lex:com.atproto.label.defs#label', + }, + }, viewer: { type: 'ref', ref: 'lex:app.bsky.feed.defs#generatorViewerState', @@ -7626,6 +7633,13 @@ export const schemaDict = { avatar: { type: 'string', }, + labels: { + type: 'array', + items: { + type: 'ref', + ref: 'lex:com.atproto.label.defs#label', + }, + }, viewer: { type: 'ref', ref: 'lex:app.bsky.graph.defs#listViewerState', @@ -7676,6 +7690,13 @@ export const schemaDict = { avatar: { type: 'string', }, + labels: { + type: 'array', + items: { + type: 'ref', + ref: 'lex:com.atproto.label.defs#label', + }, + }, viewer: { type: 'ref', ref: 'lex:app.bsky.graph.defs#listViewerState', diff --git a/packages/bsky/src/lexicon/types/app/bsky/feed/defs.ts b/packages/bsky/src/lexicon/types/app/bsky/feed/defs.ts index 261d8a622ec..8c99f64f32e 100644 --- a/packages/bsky/src/lexicon/types/app/bsky/feed/defs.ts +++ b/packages/bsky/src/lexicon/types/app/bsky/feed/defs.ts @@ -219,6 +219,7 @@ export interface GeneratorView { descriptionFacets?: AppBskyRichtextFacet.Main[] avatar?: string likeCount?: number + labels?: ComAtprotoLabelDefs.Label[] viewer?: GeneratorViewerState indexedAt: string [k: string]: unknown diff --git a/packages/bsky/src/lexicon/types/app/bsky/graph/defs.ts b/packages/bsky/src/lexicon/types/app/bsky/graph/defs.ts index 31791dd3647..0ce8a364a8e 100644 --- a/packages/bsky/src/lexicon/types/app/bsky/graph/defs.ts +++ b/packages/bsky/src/lexicon/types/app/bsky/graph/defs.ts @@ -5,6 +5,7 @@ import { ValidationResult, BlobRef } from '@atproto/lexicon' import { lexicons } from '../../../../lexicons' import { isObj, hasProp } from '../../../../util' import { CID } from 'multiformats/cid' +import * as ComAtprotoLabelDefs from '../../../com/atproto/label/defs' import * as AppBskyActorDefs from '../actor/defs' import * as AppBskyRichtextFacet from '../richtext/facet' @@ -14,6 +15,7 @@ export interface ListViewBasic { name: string purpose: ListPurpose avatar?: string + labels?: ComAtprotoLabelDefs.Label[] viewer?: ListViewerState indexedAt?: string [k: string]: unknown @@ -40,6 +42,7 @@ export interface ListView { description?: string descriptionFacets?: AppBskyRichtextFacet.Main[] avatar?: string + labels?: ComAtprotoLabelDefs.Label[] viewer?: ListViewerState indexedAt: string [k: string]: unknown diff --git a/packages/ozone/src/lexicon/lexicons.ts b/packages/ozone/src/lexicon/lexicons.ts index e9a585f5a21..1c9d18c1f17 100644 --- a/packages/ozone/src/lexicon/lexicons.ts +++ b/packages/ozone/src/lexicon/lexicons.ts @@ -6322,6 +6322,13 @@ export const schemaDict = { type: 'integer', minimum: 0, }, + labels: { + type: 'array', + items: { + type: 'ref', + ref: 'lex:com.atproto.label.defs#label', + }, + }, viewer: { type: 'ref', ref: 'lex:app.bsky.feed.defs#generatorViewerState', @@ -7626,6 +7633,13 @@ export const schemaDict = { avatar: { type: 'string', }, + labels: { + type: 'array', + items: { + type: 'ref', + ref: 'lex:com.atproto.label.defs#label', + }, + }, viewer: { type: 'ref', ref: 'lex:app.bsky.graph.defs#listViewerState', @@ -7676,6 +7690,13 @@ export const schemaDict = { avatar: { type: 'string', }, + labels: { + type: 'array', + items: { + type: 'ref', + ref: 'lex:com.atproto.label.defs#label', + }, + }, viewer: { type: 'ref', ref: 'lex:app.bsky.graph.defs#listViewerState', diff --git a/packages/ozone/src/lexicon/types/app/bsky/feed/defs.ts b/packages/ozone/src/lexicon/types/app/bsky/feed/defs.ts index 261d8a622ec..8c99f64f32e 100644 --- a/packages/ozone/src/lexicon/types/app/bsky/feed/defs.ts +++ b/packages/ozone/src/lexicon/types/app/bsky/feed/defs.ts @@ -219,6 +219,7 @@ export interface GeneratorView { descriptionFacets?: AppBskyRichtextFacet.Main[] avatar?: string likeCount?: number + labels?: ComAtprotoLabelDefs.Label[] viewer?: GeneratorViewerState indexedAt: string [k: string]: unknown diff --git a/packages/ozone/src/lexicon/types/app/bsky/graph/defs.ts b/packages/ozone/src/lexicon/types/app/bsky/graph/defs.ts index 31791dd3647..0ce8a364a8e 100644 --- a/packages/ozone/src/lexicon/types/app/bsky/graph/defs.ts +++ b/packages/ozone/src/lexicon/types/app/bsky/graph/defs.ts @@ -5,6 +5,7 @@ import { ValidationResult, BlobRef } from '@atproto/lexicon' import { lexicons } from '../../../../lexicons' import { isObj, hasProp } from '../../../../util' import { CID } from 'multiformats/cid' +import * as ComAtprotoLabelDefs from '../../../com/atproto/label/defs' import * as AppBskyActorDefs from '../actor/defs' import * as AppBskyRichtextFacet from '../richtext/facet' @@ -14,6 +15,7 @@ export interface ListViewBasic { name: string purpose: ListPurpose avatar?: string + labels?: ComAtprotoLabelDefs.Label[] viewer?: ListViewerState indexedAt?: string [k: string]: unknown @@ -40,6 +42,7 @@ export interface ListView { description?: string descriptionFacets?: AppBskyRichtextFacet.Main[] avatar?: string + labels?: ComAtprotoLabelDefs.Label[] viewer?: ListViewerState indexedAt: string [k: string]: unknown diff --git a/packages/pds/src/lexicon/lexicons.ts b/packages/pds/src/lexicon/lexicons.ts index e9a585f5a21..1c9d18c1f17 100644 --- a/packages/pds/src/lexicon/lexicons.ts +++ b/packages/pds/src/lexicon/lexicons.ts @@ -6322,6 +6322,13 @@ export const schemaDict = { type: 'integer', minimum: 0, }, + labels: { + type: 'array', + items: { + type: 'ref', + ref: 'lex:com.atproto.label.defs#label', + }, + }, viewer: { type: 'ref', ref: 'lex:app.bsky.feed.defs#generatorViewerState', @@ -7626,6 +7633,13 @@ export const schemaDict = { avatar: { type: 'string', }, + labels: { + type: 'array', + items: { + type: 'ref', + ref: 'lex:com.atproto.label.defs#label', + }, + }, viewer: { type: 'ref', ref: 'lex:app.bsky.graph.defs#listViewerState', @@ -7676,6 +7690,13 @@ export const schemaDict = { avatar: { type: 'string', }, + labels: { + type: 'array', + items: { + type: 'ref', + ref: 'lex:com.atproto.label.defs#label', + }, + }, viewer: { type: 'ref', ref: 'lex:app.bsky.graph.defs#listViewerState', diff --git a/packages/pds/src/lexicon/types/app/bsky/feed/defs.ts b/packages/pds/src/lexicon/types/app/bsky/feed/defs.ts index 261d8a622ec..8c99f64f32e 100644 --- a/packages/pds/src/lexicon/types/app/bsky/feed/defs.ts +++ b/packages/pds/src/lexicon/types/app/bsky/feed/defs.ts @@ -219,6 +219,7 @@ export interface GeneratorView { descriptionFacets?: AppBskyRichtextFacet.Main[] avatar?: string likeCount?: number + labels?: ComAtprotoLabelDefs.Label[] viewer?: GeneratorViewerState indexedAt: string [k: string]: unknown diff --git a/packages/pds/src/lexicon/types/app/bsky/graph/defs.ts b/packages/pds/src/lexicon/types/app/bsky/graph/defs.ts index 31791dd3647..0ce8a364a8e 100644 --- a/packages/pds/src/lexicon/types/app/bsky/graph/defs.ts +++ b/packages/pds/src/lexicon/types/app/bsky/graph/defs.ts @@ -5,6 +5,7 @@ import { ValidationResult, BlobRef } from '@atproto/lexicon' import { lexicons } from '../../../../lexicons' import { isObj, hasProp } from '../../../../util' import { CID } from 'multiformats/cid' +import * as ComAtprotoLabelDefs from '../../../com/atproto/label/defs' import * as AppBskyActorDefs from '../actor/defs' import * as AppBskyRichtextFacet from '../richtext/facet' @@ -14,6 +15,7 @@ export interface ListViewBasic { name: string purpose: ListPurpose avatar?: string + labels?: ComAtprotoLabelDefs.Label[] viewer?: ListViewerState indexedAt?: string [k: string]: unknown @@ -40,6 +42,7 @@ export interface ListView { description?: string descriptionFacets?: AppBskyRichtextFacet.Main[] avatar?: string + labels?: ComAtprotoLabelDefs.Label[] viewer?: ListViewerState indexedAt: string [k: string]: unknown From 79f6ce8287c6f492a6461a93dacd461e2eddf064 Mon Sep 17 00:00:00 2001 From: Devin Ivy Date: Tue, 12 Mar 2024 16:19:20 -0400 Subject: [PATCH 2/4] appview: hydrate labels onto lists, feedgens --- packages/bsky/src/hydration/hydrator.ts | 9 ++++++--- packages/bsky/src/views/index.ts | 4 ++++ 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/packages/bsky/src/hydration/hydrator.ts b/packages/bsky/src/hydration/hydrator.ts index 402e4985b5e..9181032b7da 100644 --- a/packages/bsky/src/hydration/hydrator.ts +++ b/packages/bsky/src/hydration/hydrator.ts @@ -194,11 +194,12 @@ export class Hydrator { uris: string[], ctx: HydrateCtx, ): Promise { - const [lists, listViewers] = await Promise.all([ + const [lists, listViewers, labels] = await Promise.all([ this.graph.getLists(uris), ctx.viewer ? this.graph.getListViewerStates(uris, ctx.viewer) : undefined, + this.label.getLabelsForSubjects(uris, ctx.labelers), ]) - return { lists, listViewers, ctx } + return { lists, listViewers, labels, ctx } } // app.bsky.graph.defs#listItemView @@ -430,7 +431,7 @@ export class Hydrator { uris: string[], // @TODO any way to get refs here? ctx: HydrateCtx, ): Promise { - const [feedgens, feedgenAggs, feedgenViewers, profileState] = + const [feedgens, feedgenAggs, feedgenViewers, profileState, labels] = await Promise.all([ this.feed.getFeedGens(uris), this.feed.getFeedGenAggregates(uris.map((uri) => ({ uri }))), @@ -438,11 +439,13 @@ export class Hydrator { ? this.feed.getFeedGenViewerStates(uris, ctx.viewer) : undefined, this.hydrateProfiles(uris.map(didFromUri), ctx), + this.label.getLabelsForSubjects(uris, ctx.labelers), ]) return mergeStates(profileState, { feedgens, feedgenAggs, feedgenViewers, + labels, ctx, }) } diff --git a/packages/bsky/src/views/index.ts b/packages/bsky/src/views/index.ts index 4c573d6ace6..29a5238d383 100644 --- a/packages/bsky/src/views/index.ts +++ b/packages/bsky/src/views/index.ts @@ -223,6 +223,7 @@ export class Views { return undefined } const listViewer = state.listViewers?.get(uri) + const labels = state.labels?.get(uri) ?? [] const creator = new AtUri(uri).hostname return { uri, @@ -237,6 +238,7 @@ export class Views { ) : undefined, indexedAt: list.sortedAt.toISOString(), + labels, viewer: listViewer ? { muted: !!listViewer.viewerMuted, @@ -347,6 +349,7 @@ export class Views { if (!creator) return const viewer = state.feedgenViewers?.get(uri) const aggs = state.feedgenAggs?.get(uri) + const labels = state.labels?.get(uri) ?? [] return { uri, @@ -364,6 +367,7 @@ export class Views { ) : undefined, likeCount: aggs?.likes, + labels, viewer: viewer ? { like: viewer.like, From 9c843bbacd8081a36981ae9fec7820428a07e039 Mon Sep 17 00:00:00 2001 From: Devin Ivy Date: Tue, 12 Mar 2024 16:33:48 -0400 Subject: [PATCH 3/4] test hydration of labels on lists and feedgens --- .../feed-generation.test.ts.snap | 12 +++ packages/bsky/tests/label-hydration.test.ts | 101 +++++++++++++----- .../__snapshots__/block-lists.test.ts.snap | 7 ++ .../__snapshots__/mute-lists.test.ts.snap | 10 ++ .../__snapshots__/threadgating.test.ts.snap | 2 + 5 files changed, 103 insertions(+), 29 deletions(-) diff --git a/packages/bsky/tests/__snapshots__/feed-generation.test.ts.snap b/packages/bsky/tests/__snapshots__/feed-generation.test.ts.snap index 8aea15ddfc8..d4844cbfad5 100644 --- a/packages/bsky/tests/__snapshots__/feed-generation.test.ts.snap +++ b/packages/bsky/tests/__snapshots__/feed-generation.test.ts.snap @@ -99,6 +99,7 @@ Object { "did": "user(2)", "displayName": "All", "indexedAt": "1970-01-01T00:00:00.000Z", + "labels": Array [], "likeCount": 2, "uri": "record(1)", "viewer": Object { @@ -168,6 +169,7 @@ Array [ "did": "user(0)", "displayName": "Odd", "indexedAt": "1970-01-01T00:00:00.000Z", + "labels": Array [], "likeCount": 0, "uri": "record(0)", "viewer": Object {}, @@ -210,6 +212,7 @@ Array [ "did": "user(0)", "displayName": "Needs Auth", "indexedAt": "1970-01-01T00:00:00.000Z", + "labels": Array [], "likeCount": 0, "uri": "record(4)", "viewer": Object {}, @@ -252,6 +255,7 @@ Array [ "did": "user(0)", "displayName": "Bad Pagination", "indexedAt": "1970-01-01T00:00:00.000Z", + "labels": Array [], "likeCount": 0, "uri": "record(5)", "viewer": Object {}, @@ -294,6 +298,7 @@ Array [ "did": "user(0)", "displayName": "Even", "indexedAt": "1970-01-01T00:00:00.000Z", + "labels": Array [], "likeCount": 0, "uri": "record(6)", "viewer": Object {}, @@ -336,6 +341,7 @@ Array [ "did": "user(0)", "displayName": "All", "indexedAt": "1970-01-01T00:00:00.000Z", + "labels": Array [], "likeCount": 2, "uri": "record(7)", "viewer": Object { @@ -1493,6 +1499,7 @@ Object { "did": "user(0)", "displayName": "All", "indexedAt": "1970-01-01T00:00:00.000Z", + "labels": Array [], "likeCount": 2, "uri": "record(0)", "viewer": Object { @@ -1543,6 +1550,7 @@ Object { "did": "user(0)", "displayName": "Even", "indexedAt": "1970-01-01T00:00:00.000Z", + "labels": Array [], "likeCount": 0, "uri": "record(0)", "viewer": Object {}, @@ -1585,6 +1593,7 @@ Object { "did": "user(0)", "displayName": "All", "indexedAt": "1970-01-01T00:00:00.000Z", + "labels": Array [], "likeCount": 2, "uri": "record(4)", "viewer": Object { @@ -1637,6 +1646,7 @@ Object { "did": "user(0)", "displayName": "All", "indexedAt": "1970-01-01T00:00:00.000Z", + "labels": Array [], "likeCount": 2, "uri": "record(0)", "viewer": Object { @@ -1681,6 +1691,7 @@ Object { "did": "user(0)", "displayName": "Even", "indexedAt": "1970-01-01T00:00:00.000Z", + "labels": Array [], "likeCount": 0, "uri": "record(5)", "viewer": Object {}, @@ -1723,6 +1734,7 @@ Object { "did": "user(0)", "displayName": "Bad Pagination", "indexedAt": "1970-01-01T00:00:00.000Z", + "labels": Array [], "likeCount": 0, "uri": "record(6)", "viewer": Object {}, diff --git a/packages/bsky/tests/label-hydration.test.ts b/packages/bsky/tests/label-hydration.test.ts index ab672619f86..a7fe678581c 100644 --- a/packages/bsky/tests/label-hydration.test.ts +++ b/packages/bsky/tests/label-hydration.test.ts @@ -22,35 +22,14 @@ describe('label hydration', () => { bob = sc.dids.bob carol = sc.dids.carol labelerDid = network.bsky.ctx.cfg.labelsFromIssuerDids[0] - await network.bsky.db.db - .insertInto('label') - .values([ - { - src: alice, - uri: carol, - cid: '', - val: 'spam', - neg: false, - cts: new Date().toISOString(), - }, - { - src: bob, - uri: carol, - cid: '', - val: 'impersonation', - neg: false, - cts: new Date().toISOString(), - }, - { - src: labelerDid, - uri: carol, - cid: '', - val: 'misleading', - neg: false, - cts: new Date().toISOString(), - }, - ]) - .execute() + await createLabel({ src: alice, uri: carol, cid: '', val: 'spam' }) + await createLabel({ src: bob, uri: carol, cid: '', val: 'impersonation' }) + await createLabel({ + src: labelerDid, + uri: carol, + cid: '', + val: 'misleading', + }) await network.processAll() }) @@ -97,4 +76,68 @@ describe('label hydration', () => { expect(res.data.labels?.[0].src).toBe(labelerDid) expect(res.data.labels?.[0].val).toBe('misleading') }) + + it('hydrates labels onto list views.', async () => { + const list = await pdsAgent.api.app.bsky.graph.list.create( + { repo: alice }, + { + name: "alice's modlist", + purpose: 'app.bsky.graph.defs#modlist', + createdAt: new Date().toISOString(), + }, + sc.getHeaders(alice), + ) + await network.processAll() + await createLabel({ uri: list.uri, cid: list.cid, val: 'spam' }) + const res = await pdsAgent.api.app.bsky.graph.getList( + { list: list.uri }, + { headers: sc.getHeaders(alice) }, + ) + const [label, ...others] = res.data.list.labels ?? [] + expect(label?.src).toBe(labelerDid) + expect(label?.val).toBe('spam') + expect(others.length).toBe(0) + }) + + it('hydrates labels onto feed generator views.', async () => { + const feedgen = await pdsAgent.api.app.bsky.feed.generator.create( + { repo: alice }, + { + displayName: "alice's feedgen", + did: alice, + createdAt: new Date().toISOString(), + }, + sc.getHeaders(alice), + ) + await network.processAll() + await createLabel({ uri: feedgen.uri, cid: feedgen.cid, val: 'spam' }) + const res = await pdsAgent.api.app.bsky.feed.getFeedGenerators( + { feeds: [feedgen.uri] }, + { headers: sc.getHeaders(alice) }, + ) + expect(res.data.feeds.length).toBe(1) + const [label, ...others] = res.data.feeds[0].labels ?? [] + expect(label?.src).toBe(labelerDid) + expect(label?.val).toBe('spam') + expect(others.length).toBe(0) + }) + + const createLabel = async (opts: { + src?: string + uri: string + cid: string + val: string + }) => { + await network.bsky.db.db + .insertInto('label') + .values({ + uri: opts.uri, + cid: opts.cid, + val: opts.val, + cts: new Date().toISOString(), + neg: false, + src: opts.src ?? 'did:example:labeler', + }) + .execute() + } }) diff --git a/packages/bsky/tests/views/__snapshots__/block-lists.test.ts.snap b/packages/bsky/tests/views/__snapshots__/block-lists.test.ts.snap index c5ff586f5c2..0130e6eae31 100644 --- a/packages/bsky/tests/views/__snapshots__/block-lists.test.ts.snap +++ b/packages/bsky/tests/views/__snapshots__/block-lists.test.ts.snap @@ -325,6 +325,7 @@ Object { }, "description": "blah blah", "indexedAt": "1970-01-01T00:00:00.000Z", + "labels": Array [], "name": "new list", "purpose": "app.bsky.graph.defs#modlist", "uri": "record(0)", @@ -369,6 +370,7 @@ Object { }, "description": "big list of blocks", "indexedAt": "1970-01-01T00:00:00.000Z", + "labels": Array [], "name": "alice blocks", "purpose": "app.bsky.graph.defs#modlist", "uri": "record(4)", @@ -420,6 +422,7 @@ Object { }, "description": "blah blah", "indexedAt": "1970-01-01T00:00:00.000Z", + "labels": Array [], "name": "new list", "purpose": "app.bsky.graph.defs#modlist", "uri": "record(0)", @@ -463,6 +466,7 @@ Object { }, "description": "big list of blocks", "indexedAt": "1970-01-01T00:00:00.000Z", + "labels": Array [], "name": "alice blocks", "purpose": "app.bsky.graph.defs#modlist", "uri": "record(3)", @@ -503,6 +507,7 @@ Object { "avatar": "https://bsky.public.url/img/avatar/plain/user(0)/cids(1)@jpeg", "cid": "cids(0)", "indexedAt": "1970-01-01T00:00:00.000Z", + "labels": Array [], "name": "alice blocks", "purpose": "app.bsky.graph.defs#modlist", "uri": "record(0)", @@ -532,6 +537,7 @@ Object { "avatar": "https://bsky.public.url/img/avatar/plain/user(0)/cids(1)@jpeg", "cid": "cids(0)", "indexedAt": "1970-01-01T00:00:00.000Z", + "labels": Array [], "name": "alice blocks", "purpose": "app.bsky.graph.defs#modlist", "uri": "record(0)", @@ -582,6 +588,7 @@ Object { }, "description": "big list of blocks", "indexedAt": "1970-01-01T00:00:00.000Z", + "labels": Array [], "name": "alice blocks", "purpose": "app.bsky.graph.defs#modlist", "uri": "record(0)", diff --git a/packages/bsky/tests/views/__snapshots__/mute-lists.test.ts.snap b/packages/bsky/tests/views/__snapshots__/mute-lists.test.ts.snap index 4cd94ec2efc..f3f0fc1d06c 100644 --- a/packages/bsky/tests/views/__snapshots__/mute-lists.test.ts.snap +++ b/packages/bsky/tests/views/__snapshots__/mute-lists.test.ts.snap @@ -68,6 +68,7 @@ Object { }, "description": "new descript", "indexedAt": "1970-01-01T00:00:00.000Z", + "labels": Array [], "name": "updated alice mutes", "purpose": "app.bsky.graph.defs#modlist", "uri": "record(2)", @@ -165,6 +166,7 @@ Object { "avatar": "https://bsky.public.url/img/avatar/plain/user(1)/cids(1)@jpeg", "cid": "cids(4)", "indexedAt": "1970-01-01T00:00:00.000Z", + "labels": Array [], "name": "alice mutes", "purpose": "app.bsky.graph.defs#modlist", "uri": "record(6)", @@ -216,6 +218,7 @@ Object { "avatar": "https://bsky.public.url/img/avatar/plain/user(1)/cids(1)@jpeg", "cid": "cids(4)", "indexedAt": "1970-01-01T00:00:00.000Z", + "labels": Array [], "name": "alice mutes", "purpose": "app.bsky.graph.defs#modlist", "uri": "record(6)", @@ -336,6 +339,7 @@ Object { }, "description": "blah blah", "indexedAt": "1970-01-01T00:00:00.000Z", + "labels": Array [], "name": "new list", "purpose": "app.bsky.graph.defs#modlist", "uri": "record(0)", @@ -379,6 +383,7 @@ Object { }, "description": "big list of mutes", "indexedAt": "1970-01-01T00:00:00.000Z", + "labels": Array [], "name": "alice mutes", "purpose": "app.bsky.graph.defs#modlist", "uri": "record(3)", @@ -429,6 +434,7 @@ Object { }, "description": "blah blah", "indexedAt": "1970-01-01T00:00:00.000Z", + "labels": Array [], "name": "new list", "purpose": "app.bsky.graph.defs#modlist", "uri": "record(0)", @@ -472,6 +478,7 @@ Object { }, "description": "big list of mutes", "indexedAt": "1970-01-01T00:00:00.000Z", + "labels": Array [], "name": "alice mutes", "purpose": "app.bsky.graph.defs#modlist", "uri": "record(3)", @@ -512,6 +519,7 @@ Object { "avatar": "https://bsky.public.url/img/avatar/plain/user(0)/cids(1)@jpeg", "cid": "cids(0)", "indexedAt": "1970-01-01T00:00:00.000Z", + "labels": Array [], "name": "alice mutes", "purpose": "app.bsky.graph.defs#modlist", "uri": "record(0)", @@ -540,6 +548,7 @@ Object { "avatar": "https://bsky.public.url/img/avatar/plain/user(0)/cids(1)@jpeg", "cid": "cids(0)", "indexedAt": "1970-01-01T00:00:00.000Z", + "labels": Array [], "name": "alice mutes", "purpose": "app.bsky.graph.defs#modlist", "uri": "record(0)", @@ -588,6 +597,7 @@ Object { }, "description": "big list of mutes", "indexedAt": "1970-01-01T00:00:00.000Z", + "labels": Array [], "name": "alice mutes", "purpose": "app.bsky.graph.defs#modlist", "uri": "record(0)", diff --git a/packages/bsky/tests/views/__snapshots__/threadgating.test.ts.snap b/packages/bsky/tests/views/__snapshots__/threadgating.test.ts.snap index 1545c19e9f4..9c460569d89 100644 --- a/packages/bsky/tests/views/__snapshots__/threadgating.test.ts.snap +++ b/packages/bsky/tests/views/__snapshots__/threadgating.test.ts.snap @@ -41,6 +41,7 @@ Object { Object { "cid": "cids(1)", "indexedAt": "1970-01-01T00:00:00.000Z", + "labels": Array [], "name": "list a", "purpose": "app.bsky.graph.defs#modlist", "uri": "record(2)", @@ -51,6 +52,7 @@ Object { Object { "cid": "cids(2)", "indexedAt": "1970-01-01T00:00:00.000Z", + "labels": Array [], "name": "list b", "purpose": "app.bsky.graph.defs#modlist", "uri": "record(3)", From 6c425ca9cd8c05a986d85ede6253e2da3ee14dc9 Mon Sep 17 00:00:00 2001 From: Devin Ivy Date: Tue, 12 Mar 2024 16:40:17 -0400 Subject: [PATCH 4/4] update pds snap --- packages/pds/tests/proxied/__snapshots__/views.test.ts.snap | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/packages/pds/tests/proxied/__snapshots__/views.test.ts.snap b/packages/pds/tests/proxied/__snapshots__/views.test.ts.snap index 5daad7572b3..275cdea90b9 100644 --- a/packages/pds/tests/proxied/__snapshots__/views.test.ts.snap +++ b/packages/pds/tests/proxied/__snapshots__/views.test.ts.snap @@ -554,6 +554,7 @@ Object { "did": "user(0)", "displayName": "MyFeed", "indexedAt": "1970-01-01T00:00:00.000Z", + "labels": Array [], "likeCount": 0, "uri": "record(0)", "viewer": Object {}, @@ -599,6 +600,7 @@ Object { "did": "user(0)", "displayName": "MyFeed", "indexedAt": "1970-01-01T00:00:00.000Z", + "labels": Array [], "likeCount": 0, "uri": "record(0)", "viewer": Object {}, @@ -3309,6 +3311,7 @@ Object { }, "description": "bob's list of mutes", "indexedAt": "1970-01-01T00:00:00.000Z", + "labels": Array [], "name": "bob mutes", "purpose": "app.bsky.graph.defs#modlist", "uri": "record(0)", @@ -3340,6 +3343,7 @@ Object { }, "description": "bob's list of mutes", "indexedAt": "1970-01-01T00:00:00.000Z", + "labels": Array [], "name": "bob mutes", "purpose": "app.bsky.graph.defs#modlist", "uri": "record(0)", @@ -3375,6 +3379,7 @@ Object { }, "description": "a second list", "indexedAt": "1970-01-01T00:00:00.000Z", + "labels": Array [], "name": "another list", "purpose": "app.bsky.graph.defs#modlist", "uri": "record(0)", @@ -3401,6 +3406,7 @@ Object { }, "description": "bob's list of mutes", "indexedAt": "1970-01-01T00:00:00.000Z", + "labels": Array [], "name": "bob mutes", "purpose": "app.bsky.graph.defs#modlist", "uri": "record(3)",