Skip to content

Commit

Permalink
Handle missing creator on lists and feed generators (#1906)
Browse files Browse the repository at this point in the history
handle missing creator on lists and feed generators
  • Loading branch information
dholms authored Nov 30, 2023
1 parent 4a5b658 commit 401538a
Show file tree
Hide file tree
Showing 12 changed files with 53 additions and 16 deletions.
3 changes: 2 additions & 1 deletion packages/bsky/src/api/app/bsky/feed/getActorFeeds.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { InvalidRequestError } from '@atproto/xrpc-server'
import { mapDefined } from '@atproto/common'
import { Server } from '../../../../lexicon'
import AppContext from '../../../../context'
import { TimeCidKeyset, paginate } from '../../../../db/pagination'
Expand Down Expand Up @@ -42,7 +43,7 @@ export default function (server: Server, ctx: AppContext) {
throw new InvalidRequestError(`Actor not found: ${actor}`)
}

const feeds = feedsRes.map((row) => {
const feeds = mapDefined(feedsRes, (row) => {
const feed = {
...row,
viewer: viewer ? { like: row.viewerLike } : undefined,
Expand Down
3 changes: 3 additions & 0 deletions packages/bsky/src/api/app/bsky/feed/getFeedGenerator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,9 @@ export default function (server: Server, ctx: AppContext) {
feedInfo,
profiles,
)
if (!feedView) {
throw new InvalidRequestError('could not find feed')
}

return {
encoding: 'application/json',
Expand Down
3 changes: 2 additions & 1 deletion packages/bsky/src/api/app/bsky/feed/getFeedGenerators.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { mapDefined } from '@atproto/common'
import { Server } from '../../../../lexicon'
import AppContext from '../../../../context'
import { FeedGenInfo, FeedService } from '../../../../services/feed'
Expand Down Expand Up @@ -60,7 +61,7 @@ const hydration = async (state: SkeletonState, ctx: Context) => {

const presentation = (state: HydrationState, ctx: Context) => {
const { feedService } = ctx
const feeds = state.generators.map((gen) =>
const feeds = mapDefined(state.generators, (gen) =>
feedService.views.formatFeedGeneratorView(gen, state.profiles),
)
return { feeds }
Expand Down
3 changes: 2 additions & 1 deletion packages/bsky/src/api/app/bsky/feed/getSuggestedFeeds.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { mapDefined } from '@atproto/common'
import { Server } from '../../../../lexicon'
import AppContext from '../../../../context'

Expand All @@ -23,7 +24,7 @@ export default function (server: Server, ctx: AppContext) {
const creators = genList.map((gen) => gen.creator)
const profiles = await actorService.views.profilesBasic(creators, viewer)

const feedViews = genList.map((gen) =>
const feedViews = mapDefined(genList, (gen) =>
feedService.views.formatFeedGeneratorView(gen, profiles),
)

Expand Down
3 changes: 3 additions & 0 deletions packages/bsky/src/api/app/bsky/graph/getList.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,9 @@ const presentation = (state: HydrationState, ctx: Context) => {
throw new InvalidRequestError(`Actor not found: ${list.handle}`)
}
const listView = graphService.formatListView(list, actors)
if (!listView) {
throw new InvalidRequestError('List not found')
}
const items = mapDefined(listItems, (item) => {
const subject = actors[item.did]
if (!subject) return
Expand Down
3 changes: 2 additions & 1 deletion packages/bsky/src/api/app/bsky/graph/getListBlocks.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { mapDefined } from '@atproto/common'
import { Server } from '../../../../lexicon'
import { QueryParams } from '../../../../lexicon/types/app/bsky/graph/getListBlocks'
import { paginate, TimeCidKeyset } from '../../../../db/pagination'
Expand Down Expand Up @@ -89,7 +90,7 @@ const presentation = (state: HydrationState, ctx: Context) => {
profileState,
params.viewer,
)
const lists = listInfos.map((list) =>
const lists = mapDefined(listInfos, (list) =>
graphService.formatListView(list, actors),
)
return { lists, cursor }
Expand Down
3 changes: 2 additions & 1 deletion packages/bsky/src/api/app/bsky/graph/getListMutes.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { mapDefined } from '@atproto/common'
import { Server } from '../../../../lexicon'
import { paginate, TimeCidKeyset } from '../../../../db/pagination'
import AppContext from '../../../../context'
Expand Down Expand Up @@ -34,7 +35,7 @@ export default function (server: Server, ctx: AppContext) {
const actorService = ctx.services.actor(db)
const profiles = await actorService.views.profiles(listsRes, requester)

const lists = listsRes.map((row) =>
const lists = mapDefined(listsRes, (row) =>
graphService.formatListView(row, profiles),
)

Expand Down
3 changes: 2 additions & 1 deletion packages/bsky/src/api/app/bsky/graph/getLists.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { mapDefined } from '@atproto/common'
import { InvalidRequestError } from '@atproto/xrpc-server'
import { Server } from '../../../../lexicon'
import { paginate, TimeCidKeyset } from '../../../../db/pagination'
Expand Down Expand Up @@ -39,7 +40,7 @@ export default function (server: Server, ctx: AppContext) {
throw new InvalidRequestError(`Actor not found: ${actor}`)
}

const lists = listsRes.map((row) =>
const lists = mapDefined(listsRes, (row) =>
graphService.formatListView(row, profiles),
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,9 @@ export default function (server: Server, ctx: AppContext) {
const gen = genInfos[row.uri]
if (!gen) continue
const view = feedService.views.formatFeedGeneratorView(gen, profiles)
genViews.push(view)
if (view) {
genViews.push(view)
}
}

return {
Expand Down
24 changes: 18 additions & 6 deletions packages/bsky/src/services/feed/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -411,14 +411,26 @@ export class FeedService {
for (const uri of nestedUris) {
const collection = new AtUri(uri).collection
if (collection === ids.AppBskyFeedGenerator && feedGenInfos[uri]) {
recordEmbedViews[uri] = {
$type: 'app.bsky.feed.defs#generatorView',
...this.views.formatFeedGeneratorView(feedGenInfos[uri], actorInfos),
const genView = this.views.formatFeedGeneratorView(
feedGenInfos[uri],
actorInfos,
)
if (genView) {
recordEmbedViews[uri] = {
$type: 'app.bsky.feed.defs#generatorView',
...genView,
}
}
} else if (collection === ids.AppBskyGraphList && listViews[uri]) {
recordEmbedViews[uri] = {
$type: 'app.bsky.graph.defs#listView',
...this.services.graph.formatListView(listViews[uri], actorInfos),
const listView = this.services.graph.formatListView(
listViews[uri],
actorInfos,
)
if (listView) {
recordEmbedViews[uri] = {
$type: 'app.bsky.graph.defs#listView',
...listView,
}
}
} else if (collection === ids.AppBskyFeedPost && feedState.posts[uri]) {
const formatted = this.views.formatPostView(
Expand Down
5 changes: 4 additions & 1 deletion packages/bsky/src/services/feed/views.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,11 @@ export class FeedViews {
formatFeedGeneratorView(
info: FeedGenInfo,
profiles: ActorInfoMap,
): GeneratorView {
): GeneratorView | undefined {
const profile = profiles[info.creator]
if (!profile) {
return undefined
}
return {
uri: info.uri,
cid: info.cid,
Expand Down
12 changes: 10 additions & 2 deletions packages/bsky/src/services/graph/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ import { ImageUriBuilder } from '../../image/uri'
import { valuesList } from '../../db/util'
import { ListInfo } from './types'
import { ActorInfoMap } from '../actor'
import {
ListView,
ListViewBasic,
} from '../../lexicon/types/app/bsky/graph/defs'

export * from './types'

Expand Down Expand Up @@ -235,18 +239,22 @@ export class GraphService {
)
}

formatListView(list: ListInfo, profiles: ActorInfoMap) {
formatListView(list: ListInfo, profiles: ActorInfoMap): ListView | undefined {
if (!profiles[list.creator]) {
return undefined
}
return {
...this.formatListViewBasic(list),
creator: profiles[list.creator],
description: list.description ?? undefined,
descriptionFacets: list.descriptionFacets
? JSON.parse(list.descriptionFacets)
: undefined,
indexedAt: list.sortAt,
}
}

formatListViewBasic(list: ListInfo) {
formatListViewBasic(list: ListInfo): ListViewBasic {
return {
uri: list.uri,
cid: list.cid,
Expand Down

0 comments on commit 401538a

Please sign in to comment.