Skip to content

Commit

Permalink
Appview: labels on feed gens and list views (#2298)
Browse files Browse the repository at this point in the history
* lexicon: add labels to feedgen and list views

* appview: hydrate labels onto lists, feedgens

* test hydration of labels on lists and feedgens

* update pds snap
  • Loading branch information
devinivy authored Mar 12, 2024
1 parent 40a3537 commit 8dd67f5
Show file tree
Hide file tree
Showing 22 changed files with 231 additions and 32 deletions.
4 changes: 4 additions & 0 deletions lexicons/app/bsky/feed/defs.json
Original file line number Diff line number Diff line change
Expand Up @@ -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" }
}
Expand Down
8 changes: 8 additions & 0 deletions lexicons/app/bsky/graph/defs.json
Original file line number Diff line number Diff line change
Expand Up @@ -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" }
}
Expand All @@ -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" }
}
Expand Down
21 changes: 21 additions & 0 deletions packages/api/src/client/lexicons.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down Expand Up @@ -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',
Expand Down Expand Up @@ -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',
Expand Down
1 change: 1 addition & 0 deletions packages/api/src/client/types/app/bsky/feed/defs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,7 @@ export interface GeneratorView {
descriptionFacets?: AppBskyRichtextFacet.Main[]
avatar?: string
likeCount?: number
labels?: ComAtprotoLabelDefs.Label[]
viewer?: GeneratorViewerState
indexedAt: string
[k: string]: unknown
Expand Down
3 changes: 3 additions & 0 deletions packages/api/src/client/types/app/bsky/graph/defs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'

Expand All @@ -14,6 +15,7 @@ export interface ListViewBasic {
name: string
purpose: ListPurpose
avatar?: string
labels?: ComAtprotoLabelDefs.Label[]
viewer?: ListViewerState
indexedAt?: string
[k: string]: unknown
Expand All @@ -40,6 +42,7 @@ export interface ListView {
description?: string
descriptionFacets?: AppBskyRichtextFacet.Main[]
avatar?: string
labels?: ComAtprotoLabelDefs.Label[]
viewer?: ListViewerState
indexedAt: string
[k: string]: unknown
Expand Down
9 changes: 6 additions & 3 deletions packages/bsky/src/hydration/hydrator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -194,11 +194,12 @@ export class Hydrator {
uris: string[],
ctx: HydrateCtx,
): Promise<HydrationState> {
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
Expand Down Expand Up @@ -430,19 +431,21 @@ export class Hydrator {
uris: string[], // @TODO any way to get refs here?
ctx: HydrateCtx,
): Promise<HydrationState> {
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 }))),
ctx.viewer
? 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,
})
}
Expand Down
21 changes: 21 additions & 0 deletions packages/bsky/src/lexicon/lexicons.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down Expand Up @@ -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',
Expand Down Expand Up @@ -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',
Expand Down
1 change: 1 addition & 0 deletions packages/bsky/src/lexicon/types/app/bsky/feed/defs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,7 @@ export interface GeneratorView {
descriptionFacets?: AppBskyRichtextFacet.Main[]
avatar?: string
likeCount?: number
labels?: ComAtprotoLabelDefs.Label[]
viewer?: GeneratorViewerState
indexedAt: string
[k: string]: unknown
Expand Down
3 changes: 3 additions & 0 deletions packages/bsky/src/lexicon/types/app/bsky/graph/defs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'

Expand All @@ -14,6 +15,7 @@ export interface ListViewBasic {
name: string
purpose: ListPurpose
avatar?: string
labels?: ComAtprotoLabelDefs.Label[]
viewer?: ListViewerState
indexedAt?: string
[k: string]: unknown
Expand All @@ -40,6 +42,7 @@ export interface ListView {
description?: string
descriptionFacets?: AppBskyRichtextFacet.Main[]
avatar?: string
labels?: ComAtprotoLabelDefs.Label[]
viewer?: ListViewerState
indexedAt: string
[k: string]: unknown
Expand Down
4 changes: 4 additions & 0 deletions packages/bsky/src/views/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -237,6 +238,7 @@ export class Views {
)
: undefined,
indexedAt: list.sortedAt.toISOString(),
labels,
viewer: listViewer
? {
muted: !!listViewer.viewerMuted,
Expand Down Expand Up @@ -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,
Expand All @@ -364,6 +367,7 @@ export class Views {
)
: undefined,
likeCount: aggs?.likes,
labels,
viewer: viewer
? {
like: viewer.like,
Expand Down
12 changes: 12 additions & 0 deletions packages/bsky/tests/__snapshots__/feed-generation.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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 {},
Expand Down Expand Up @@ -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 {},
Expand Down Expand Up @@ -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 {},
Expand Down Expand Up @@ -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 {},
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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 {},
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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 {},
Expand Down Expand Up @@ -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 {},
Expand Down
Loading

0 comments on commit 8dd67f5

Please sign in to comment.