Skip to content

Commit

Permalink
Labeler takedowns (alternate) (#2322)
Browse files Browse the repository at this point in the history
* build hydration ctx in each handler

* test hydration w/ takendown labeler

* tidy

* handle and test labeler takedowns by label

* appview/ozone: fix admin repo search
  • Loading branch information
devinivy authored Mar 15, 2024
1 parent 506614f commit 011aa22
Show file tree
Hide file tree
Showing 38 changed files with 237 additions and 95 deletions.
16 changes: 10 additions & 6 deletions packages/bsky/src/api/app/bsky/actor/getProfile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,11 @@ export default function (server: Server, ctx: AppContext) {
handler: async ({ auth, params, req }) => {
const { viewer, includeTakedowns } = ctx.authVerifier.parseCreds(auth)
const labelers = ctx.reqLabelers(req)
const hydrateCtx = { labelers, viewer, includeTakedowns }
const hydrateCtx = await ctx.hydrator.createContext({
labelers,
viewer,
includeTakedowns,
})

const result = await getProfile({ ...params, hydrateCtx }, ctx)

Expand All @@ -29,7 +33,7 @@ export default function (server: Server, ctx: AppContext) {
body: result,
headers: resHeaders({
repoRev,
labelers,
labelers: hydrateCtx.labelers,
}),
}
},
Expand All @@ -54,10 +58,10 @@ const hydration = async (input: {
skeleton: SkeletonState
}) => {
const { ctx, params, skeleton } = input
return ctx.hydrator.hydrateProfilesDetailed([skeleton.did], {
...params.hydrateCtx,
includeTakedowns: true,
})
return ctx.hydrator.hydrateProfilesDetailed(
[skeleton.did],
params.hydrateCtx.copy({ includeTakedowns: true }),
)
}

const presentation = (input: {
Expand Down
4 changes: 2 additions & 2 deletions packages/bsky/src/api/app/bsky/actor/getProfiles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export default function (server: Server, ctx: AppContext) {
handler: async ({ auth, params, req }) => {
const viewer = auth.credentials.iss
const labelers = ctx.reqLabelers(req)
const hydrateCtx = { viewer, labelers }
const hydrateCtx = await ctx.hydrator.createContext({ viewer, labelers })

const result = await getProfile({ ...params, hydrateCtx }, ctx)

Expand All @@ -29,7 +29,7 @@ export default function (server: Server, ctx: AppContext) {
body: result,
headers: resHeaders({
repoRev,
labelers,
labelers: hydrateCtx.labelers,
}),
}
},
Expand Down
4 changes: 2 additions & 2 deletions packages/bsky/src/api/app/bsky/actor/getSuggestions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,13 @@ export default function (server: Server, ctx: AppContext) {
handler: async ({ params, auth, req }) => {
const viewer = auth.credentials.iss
const labelers = ctx.reqLabelers(req)
const hydrateCtx = { viewer, labelers }
const hydrateCtx = await ctx.hydrator.createContext({ viewer, labelers })
const result = await getSuggestions({ ...params, hydrateCtx }, ctx)

return {
encoding: 'application/json',
body: result,
headers: resHeaders({ labelers }),
headers: resHeaders({ labelers: hydrateCtx.labelers }),
}
},
})
Expand Down
10 changes: 7 additions & 3 deletions packages/bsky/src/api/app/bsky/actor/searchActors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,18 @@ export default function (server: Server, ctx: AppContext) {
server.app.bsky.actor.searchActors({
auth: ctx.authVerifier.standardOptional,
handler: async ({ auth, params, req }) => {
const viewer = auth.credentials.iss
const { viewer, includeTakedowns } = ctx.authVerifier.parseCreds(auth)
const labelers = ctx.reqLabelers(req)
const hydrateCtx = { viewer, labelers }
const hydrateCtx = await ctx.hydrator.createContext({
viewer,
labelers,
includeTakedowns,
})
const results = await searchActors({ ...params, hydrateCtx }, ctx)
return {
encoding: 'application/json',
body: results,
headers: resHeaders({ labelers }),
headers: resHeaders({ labelers: hydrateCtx.labelers }),
}
},
})
Expand Down
4 changes: 2 additions & 2 deletions packages/bsky/src/api/app/bsky/actor/searchActorsTypeahead.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,15 @@ export default function (server: Server, ctx: AppContext) {
handler: async ({ params, auth, req }) => {
const viewer = auth.credentials.iss
const labelers = ctx.reqLabelers(req)
const hydrateCtx = { labelers, viewer }
const hydrateCtx = await ctx.hydrator.createContext({ labelers, viewer })
const results = await searchActorsTypeahead(
{ ...params, hydrateCtx },
ctx,
)
return {
encoding: 'application/json',
body: results,
headers: resHeaders({ labelers }),
headers: resHeaders({ labelers: hydrateCtx.labelers }),
}
},
})
Expand Down
4 changes: 2 additions & 2 deletions packages/bsky/src/api/app/bsky/feed/getActorFeeds.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,12 @@ export default function (server: Server, ctx: AppContext) {
handler: async ({ auth, params, req }) => {
const viewer = auth.credentials.iss
const labelers = ctx.reqLabelers(req)
const hydrateCtx = { labelers, viewer }
const hydrateCtx = await ctx.hydrator.createContext({ labelers, viewer })
const result = await getActorFeeds({ ...params, hydrateCtx }, ctx)
return {
encoding: 'application/json',
body: result,
headers: resHeaders({ labelers }),
headers: resHeaders({ labelers: hydrateCtx.labelers }),
}
},
})
Expand Down
4 changes: 2 additions & 2 deletions packages/bsky/src/api/app/bsky/feed/getActorLikes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export default function (server: Server, ctx: AppContext) {
handler: async ({ params, auth, req }) => {
const viewer = auth.credentials.iss
const labelers = ctx.reqLabelers(req)
const hydrateCtx = { labelers, viewer }
const hydrateCtx = await ctx.hydrator.createContext({ labelers, viewer })

const result = await getActorLikes({ ...params, hydrateCtx }, ctx)

Expand All @@ -39,7 +39,7 @@ export default function (server: Server, ctx: AppContext) {
body: result,
headers: resHeaders({
repoRev,
labelers,
labelers: hydrateCtx.labelers,
}),
}
},
Expand Down
8 changes: 6 additions & 2 deletions packages/bsky/src/api/app/bsky/feed/getAuthorFeed.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,11 @@ export default function (server: Server, ctx: AppContext) {
handler: async ({ params, auth, req }) => {
const { viewer, includeTakedowns } = ctx.authVerifier.parseCreds(auth)
const labelers = ctx.reqLabelers(req)
const hydrateCtx = { labelers, viewer, includeTakedowns }
const hydrateCtx = await ctx.hydrator.createContext({
labelers,
viewer,
includeTakedowns,
})

const result = await getAuthorFeed({ ...params, hydrateCtx }, ctx)

Expand All @@ -41,7 +45,7 @@ export default function (server: Server, ctx: AppContext) {
body: result,
headers: resHeaders({
repoRev,
labelers,
labelers: hydrateCtx.labelers,
}),
}
},
Expand Down
4 changes: 2 additions & 2 deletions packages/bsky/src/api/app/bsky/feed/getFeed.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ export default function (server: Server, ctx: AppContext) {
handler: async ({ params, auth, req }) => {
const viewer = auth.credentials.iss
const labelers = ctx.reqLabelers(req)
const hydrateCtx = { labelers, viewer }
const hydrateCtx = await ctx.hydrator.createContext({ labelers, viewer })
const headers = noUndefinedVals({
authorization: req.headers['authorization'],
'accept-language': req.headers['accept-language'],
Expand All @@ -60,7 +60,7 @@ export default function (server: Server, ctx: AppContext) {
body: result,
headers: {
...(feedResHeaders ?? {}),
...resHeaders({ labelers }),
...resHeaders({ labelers: hydrateCtx.labelers }),
'server-timing': serverTimingHeader([timerSkele, timerHydr]),
},
}
Expand Down
9 changes: 3 additions & 6 deletions packages/bsky/src/api/app/bsky/feed/getFeedGenerator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,8 @@ export default function (server: Server, ctx: AppContext) {
const { feed } = params
const viewer = auth.credentials.iss
const labelers = ctx.reqLabelers(req)

const hydration = await ctx.hydrator.hydrateFeedGens([feed], {
viewer,
labelers,
})
const hydrateCtx = await ctx.hydrator.createContext({ labelers, viewer })
const hydration = await ctx.hydrator.hydrateFeedGens([feed], hydrateCtx)
const feedInfo = hydration.feedgens?.get(feed)
if (!feedInfo) {
throw new InvalidRequestError('could not find feed')
Expand Down Expand Up @@ -64,7 +61,7 @@ export default function (server: Server, ctx: AppContext) {
isOnline: true,
isValid: true,
},
headers: resHeaders({ labelers }),
headers: resHeaders({ labelers: hydrateCtx.labelers }),
}
},
})
Expand Down
4 changes: 2 additions & 2 deletions packages/bsky/src/api/app/bsky/feed/getFeedGenerators.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,12 @@ export default function (server: Server, ctx: AppContext) {
handler: async ({ params, auth, req }) => {
const viewer = auth.credentials.iss
const labelers = ctx.reqLabelers(req)
const hydrateCtx = { labelers, viewer }
const hydrateCtx = await ctx.hydrator.createContext({ labelers, viewer })
const view = await getFeedGenerators({ ...params, hydrateCtx }, ctx)
return {
encoding: 'application/json',
body: view,
headers: resHeaders({ labelers }),
headers: resHeaders({ labelers: hydrateCtx.labelers }),
}
},
})
Expand Down
4 changes: 2 additions & 2 deletions packages/bsky/src/api/app/bsky/feed/getLikes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,13 @@ export default function (server: Server, ctx: AppContext) {
handler: async ({ params, auth, req }) => {
const viewer = auth.credentials.iss
const labelers = ctx.reqLabelers(req)
const hydrateCtx = { labelers, viewer }
const hydrateCtx = await ctx.hydrator.createContext({ labelers, viewer })
const result = await getLikes({ ...params, hydrateCtx }, ctx)

return {
encoding: 'application/json',
body: result,
headers: resHeaders({ labelers }),
headers: resHeaders({ labelers: hydrateCtx.labelers }),
}
},
})
Expand Down
4 changes: 2 additions & 2 deletions packages/bsky/src/api/app/bsky/feed/getListFeed.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export default function (server: Server, ctx: AppContext) {
handler: async ({ params, auth, req }) => {
const viewer = auth.credentials.iss
const labelers = ctx.reqLabelers(req)
const hydrateCtx = { labelers, viewer }
const hydrateCtx = await ctx.hydrator.createContext({ labelers, viewer })

const result = await getListFeed({ ...params, hydrateCtx }, ctx)

Expand All @@ -35,7 +35,7 @@ export default function (server: Server, ctx: AppContext) {
return {
encoding: 'application/json',
body: result,
headers: resHeaders({ labelers, repoRev }),
headers: resHeaders({ labelers: hydrateCtx.labelers, repoRev }),
}
},
})
Expand Down
4 changes: 2 additions & 2 deletions packages/bsky/src/api/app/bsky/feed/getPostThread.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export default function (server: Server, ctx: AppContext) {
handler: async ({ params, auth, req, res }) => {
const { viewer } = ctx.authVerifier.parseCreds(auth)
const labelers = ctx.reqLabelers(req)
const hydrateCtx = { labelers, viewer }
const hydrateCtx = await ctx.hydrator.createContext({ labelers, viewer })

let result: OutputSchema
try {
Expand All @@ -50,7 +50,7 @@ export default function (server: Server, ctx: AppContext) {
body: result,
headers: resHeaders({
repoRev,
labelers,
labelers: hydrateCtx.labelers,
}),
}
},
Expand Down
4 changes: 2 additions & 2 deletions packages/bsky/src/api/app/bsky/feed/getPosts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,14 @@ export default function (server: Server, ctx: AppContext) {
handler: async ({ params, auth, req }) => {
const viewer = auth.credentials.iss
const labelers = ctx.reqLabelers(req)
const hydrateCtx = { labelers, viewer }
const hydrateCtx = await ctx.hydrator.createContext({ labelers, viewer })

const results = await getPosts({ ...params, hydrateCtx }, ctx)

return {
encoding: 'application/json',
body: results,
headers: resHeaders({ labelers }),
headers: resHeaders({ labelers: hydrateCtx.labelers }),
}
},
})
Expand Down
4 changes: 2 additions & 2 deletions packages/bsky/src/api/app/bsky/feed/getRepostedBy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,13 @@ export default function (server: Server, ctx: AppContext) {
handler: async ({ params, auth, req }) => {
const viewer = auth.credentials.iss
const labelers = ctx.reqLabelers(req)
const hydrateCtx = { labelers, viewer }
const hydrateCtx = await ctx.hydrator.createContext({ labelers, viewer })
const result = await getRepostedBy({ ...params, hydrateCtx }, ctx)

return {
encoding: 'application/json',
body: result,
headers: resHeaders({ labelers }),
headers: resHeaders({ labelers: hydrateCtx.labelers }),
}
},
})
Expand Down
8 changes: 3 additions & 5 deletions packages/bsky/src/api/app/bsky/feed/getSuggestedFeeds.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,8 @@ export default function (server: Server, ctx: AppContext) {
cursor: params.cursor,
})
const uris = suggestedRes.uris
const hydration = await ctx.hydrator.hydrateFeedGens(uris, {
labelers,
viewer,
})
const hydrateCtx = await ctx.hydrator.createContext({ labelers, viewer })
const hydration = await ctx.hydrator.hydrateFeedGens(uris, hydrateCtx)
const feedViews = mapDefined(uris, (uri) =>
ctx.views.feedGenerator(uri, hydration),
)
Expand All @@ -32,7 +30,7 @@ export default function (server: Server, ctx: AppContext) {
feeds: feedViews,
cursor: parseString(suggestedRes.cursor),
},
headers: resHeaders({ labelers }),
headers: resHeaders({ labelers: hydrateCtx.labelers }),
}
},
})
Expand Down
9 changes: 6 additions & 3 deletions packages/bsky/src/api/app/bsky/feed/getTimeline.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,16 +26,19 @@ export default function (server: Server, ctx: AppContext) {
handler: async ({ params, auth, req }) => {
const viewer = auth.credentials.iss
const labelers = ctx.reqLabelers(req)
const hydrateCtx = { labelers, viewer }
const hydrateCtx = await ctx.hydrator.createContext({ labelers, viewer })

const result = await getTimeline({ ...params, hydrateCtx }, ctx)
const result = await getTimeline(
{ ...params, hydrateCtx: hydrateCtx.copy({ viewer }) },
ctx,
)

const repoRev = await ctx.hydrator.actor.getRepoRevSafe(viewer)

return {
encoding: 'application/json',
body: result,
headers: resHeaders({ labelers, repoRev }),
headers: resHeaders({ labelers: hydrateCtx.labelers, repoRev }),
}
},
})
Expand Down
4 changes: 2 additions & 2 deletions packages/bsky/src/api/app/bsky/feed/searchPosts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,12 @@ export default function (server: Server, ctx: AppContext) {
handler: async ({ auth, params, req }) => {
const viewer = auth.credentials.iss
const labelers = ctx.reqLabelers(req)
const hydrateCtx = { labelers, viewer }
const hydrateCtx = await ctx.hydrator.createContext({ labelers, viewer })
const results = await searchPosts({ ...params, hydrateCtx }, ctx)
return {
encoding: 'application/json',
body: results,
headers: resHeaders({ labelers }),
headers: resHeaders({ labelers: hydrateCtx.labelers }),
}
},
})
Expand Down
9 changes: 6 additions & 3 deletions packages/bsky/src/api/app/bsky/graph/getBlocks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,15 @@ export default function (server: Server, ctx: AppContext) {
handler: async ({ params, auth, req }) => {
const viewer = auth.credentials.iss
const labelers = ctx.reqLabelers(req)
const hydrateCtx = { labelers, viewer }
const result = await getBlocks({ ...params, hydrateCtx }, ctx)
const hydrateCtx = await ctx.hydrator.createContext({ labelers, viewer })
const result = await getBlocks(
{ ...params, hydrateCtx: hydrateCtx.copy({ viewer }) },
ctx,
)
return {
encoding: 'application/json',
body: result,
headers: resHeaders({ labelers }),
headers: resHeaders({ labelers: hydrateCtx.labelers }),
}
},
})
Expand Down
Loading

0 comments on commit 011aa22

Please sign in to comment.