Skip to content

Commit

Permalink
tidy up includeTakedowns
Browse files Browse the repository at this point in the history
  • Loading branch information
dholms committed Mar 8, 2024
1 parent 3c06cb8 commit 3060b43
Show file tree
Hide file tree
Showing 8 changed files with 60 additions and 109 deletions.
18 changes: 5 additions & 13 deletions packages/bsky/src/api/app/bsky/actor/getProfile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,11 @@ export default function (server: Server, ctx: AppContext) {
server.app.bsky.actor.getProfile({
auth: ctx.authVerifier.optionalStandardOrRole,
handler: async ({ auth, params, req, res }) => {
const { viewer, canViewTakedowns } = ctx.authVerifier.parseCreds(auth)
const { viewer, includeTakedowns } = ctx.authVerifier.parseCreds(auth)
const labelers = ctx.reqLabelers(req)
const hydrateCtx = { labelers, viewer }
const hydrateCtx = { labelers, viewer, includeTakedowns }

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

const repoRev = await ctx.hydrator.actor.getRepoRevSafe(viewer)
setRepoRev(res, repoRev)
Expand Down Expand Up @@ -54,11 +51,7 @@ const hydration = async (input: {
skeleton: SkeletonState
}) => {
const { ctx, params, skeleton } = input
return ctx.hydrator.hydrateProfilesDetailed(
[skeleton.did],
params.hydrateCtx,
true,
)
return ctx.hydrator.hydrateProfilesDetailed([skeleton.did], params.hydrateCtx)
}

const presentation = (input: {
Expand All @@ -72,7 +65,7 @@ const presentation = (input: {
if (!profile) {
throw new InvalidRequestError('Profile not found')
} else if (
!params.canViewTakedowns &&
!params.hydrateCtx.includeTakedowns &&
ctx.views.actorIsTakendown(skeleton.did, hydration)
) {
throw new InvalidRequestError(
Expand All @@ -90,7 +83,6 @@ type Context = {

type Params = QueryParams & {
hydrateCtx: HydrateCtx
canViewTakedowns: boolean
}

type SkeletonState = { did: string }
6 changes: 1 addition & 5 deletions packages/bsky/src/api/app/bsky/actor/getSuggestions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,11 +64,7 @@ const hydration = async (input: {
skeleton: Skeleton
}) => {
const { ctx, params, skeleton } = input
return ctx.hydrator.hydrateProfilesDetailed(
skeleton.dids,
params.hydrateCtx,
true,
)
return ctx.hydrator.hydrateProfilesDetailed(skeleton.dids, params.hydrateCtx)
}

const noBlocksOrMutes = (input: {
Expand Down
18 changes: 5 additions & 13 deletions packages/bsky/src/api/app/bsky/feed/getAuthorFeed.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,11 @@ export default function (server: Server, ctx: AppContext) {
server.app.bsky.feed.getAuthorFeed({
auth: ctx.authVerifier.optionalStandardOrRole,
handler: async ({ params, auth, req, res }) => {
const { viewer, canViewTakedowns } = ctx.authVerifier.parseCreds(auth)
const { viewer, includeTakedowns } = ctx.authVerifier.parseCreds(auth)
const labelers = ctx.reqLabelers(req)
const hydrateCtx = { labelers, viewer }
const hydrateCtx = { labelers, viewer, includeTakedowns }

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

const repoRev = await ctx.hydrator.actor.getRepoRevSafe(viewer)
setRepoRev(res, repoRev)
Expand Down Expand Up @@ -66,7 +63,7 @@ export const skeleton = async (inputs: {
}
const actors = await ctx.hydrator.actor.getActors(
[did],
params.includeTakedowns,
params.hydrateCtx.includeTakedowns,
)
const actor = actors.get(did)
if (!actor) {
Expand Down Expand Up @@ -100,11 +97,7 @@ const hydration = async (inputs: {
}): Promise<HydrationState> => {
const { ctx, params, skeleton } = inputs
const [feedPostState, profileViewerState] = await Promise.all([
ctx.hydrator.hydrateFeedItems(
skeleton.items,
params.hydrateCtx,
params.includeTakedowns,
),
ctx.hydrator.hydrateFeedItems(skeleton.items, params.hydrateCtx),
ctx.hydrator.hydrateProfileViewers([skeleton.actor.did], params.hydrateCtx),
])
return mergeStates(feedPostState, profileViewerState)
Expand Down Expand Up @@ -160,7 +153,6 @@ type Context = {

type Params = QueryParams & {
hydrateCtx: HydrateCtx
includeTakedowns: boolean
}

type Skeleton = {
Expand Down
18 changes: 8 additions & 10 deletions packages/bsky/src/api/app/bsky/graph/getFollowers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,11 @@ export default function (server: Server, ctx: AppContext) {
server.app.bsky.graph.getFollowers({
auth: ctx.authVerifier.optionalStandardOrRole,
handler: async ({ params, auth, req }) => {
const { viewer, canViewTakedowns } = ctx.authVerifier.parseCreds(auth)
const { viewer, includeTakedowns } = ctx.authVerifier.parseCreds(auth)
const labelers = ctx.reqLabelers(req)
const hydrateCtx = { labelers, viewer }
const hydrateCtx = { labelers, viewer, includeTakedowns }

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

return {
encoding: 'application/json',
Expand Down Expand Up @@ -84,7 +81,6 @@ const hydration = async (
const profileState = await ctx.hydrator.hydrateProfiles(
dids,
params.hydrateCtx,
params.canViewTakedowns,
)
return mergeStates(followState, profileState)
}
Expand All @@ -111,13 +107,16 @@ const presentation = (
ctx.views.actorIsTakendown(did, hydration)

const subject = ctx.views.profile(subjectDid, hydration)
if (!subject || (!params.canViewTakedowns && isTakendown(subjectDid))) {
if (
!subject ||
(!params.hydrateCtx.includeTakedowns && isTakendown(subjectDid))
) {
throw new InvalidRequestError(`Actor not found: ${params.actor}`)
}

const followers = mapDefined(followUris, (followUri) => {
const followerDid = didFromUri(followUri)
if (!params.canViewTakedowns && isTakendown(followerDid)) {
if (!params.hydrateCtx.includeTakedowns && isTakendown(followerDid)) {
return
}
return ctx.views.profile(didFromUri(followUri), hydration)
Expand All @@ -133,7 +132,6 @@ type Context = {

type Params = QueryParams & {
hydrateCtx: HydrateCtx
canViewTakedowns: boolean
}

type SkeletonState = {
Expand Down
18 changes: 8 additions & 10 deletions packages/bsky/src/api/app/bsky/graph/getFollows.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,12 @@ export default function (server: Server, ctx: AppContext) {
server.app.bsky.graph.getFollows({
auth: ctx.authVerifier.optionalStandardOrRole,
handler: async ({ params, auth, req }) => {
const { viewer, canViewTakedowns } = ctx.authVerifier.parseCreds(auth)
const { viewer, includeTakedowns } = ctx.authVerifier.parseCreds(auth)
const labelers = ctx.reqLabelers(req)
const hydrateCtx = { labelers, viewer }
const hydrateCtx = { labelers, viewer, includeTakedowns }

// @TODO ensure canViewTakedowns gets threaded through and applied properly
const result = await getFollows(
{ ...params, hydrateCtx, canViewTakedowns },
ctx,
)
const result = await getFollows({ ...params, hydrateCtx }, ctx)

return {
encoding: 'application/json',
Expand Down Expand Up @@ -79,7 +76,6 @@ const hydration = async (
const profileState = await ctx.hydrator.hydrateProfiles(
dids,
params.hydrateCtx,
params.canViewTakedowns,
)
return mergeStates(followState, profileState)
}
Expand Down Expand Up @@ -108,14 +104,17 @@ const presentation = (
ctx.views.actorIsTakendown(did, hydration)

const subject = ctx.views.profile(subjectDid, hydration)
if (!subject || (!params.canViewTakedowns && isTakendown(subjectDid))) {
if (
!subject ||
(!params.hydrateCtx.includeTakedowns && isTakendown(subjectDid))
) {
throw new InvalidRequestError(`Actor not found: ${params.actor}`)
}

const follows = mapDefined(followUris, (followUri) => {
const followDid = hydration.follows?.get(followUri)?.record.subject
if (!followDid) return
if (!params.canViewTakedowns && isTakendown(followDid)) {
if (!params.hydrateCtx.includeTakedowns && isTakendown(followDid)) {
return
}
return ctx.views.profile(followDid, hydration)
Expand All @@ -131,7 +130,6 @@ type Context = {

type Params = QueryParams & {
hydrateCtx: HydrateCtx
canViewTakedowns: boolean
}

type SkeletonState = {
Expand Down
4 changes: 2 additions & 2 deletions packages/bsky/src/auth-verifier.ts
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,7 @@ export class AuthVerifier {
) {
const viewer =
creds.credentials.type === 'standard' ? creds.credentials.iss : null
const canViewTakedowns =
const includeTakedowns =
(creds.credentials.type === 'role' && creds.credentials.admin) ||
creds.credentials.type === 'mod_service' ||
(creds.credentials.type === 'standard' &&
Expand All @@ -269,7 +269,7 @@ export class AuthVerifier {

return {
viewer,
canViewTakedowns,
includeTakedowns,
canPerformTakedown,
}
}
Expand Down
Loading

0 comments on commit 3060b43

Please sign in to comment.