-
Notifications
You must be signed in to change notification settings - Fork 578
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
implement getListMutes and -Blocks w/ dataplane
- Loading branch information
Showing
5 changed files
with
98 additions
and
113 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,51 +1,76 @@ | ||
import { mapDefined } from '@atproto/common' | ||
import { Server } from '../../../../lexicon' | ||
import { paginate, TimeCidKeyset } from '../../../../db/pagination' | ||
import { QueryParams } from '../../../../lexicon/types/app/bsky/graph/getListBlocks' | ||
import AppContext from '../../../../context' | ||
import { | ||
createPipelineNew, | ||
HydrationFnInput, | ||
noRulesNew, | ||
PresentationFnInput, | ||
SkeletonFnInput, | ||
} from '../../../../pipeline' | ||
import { Hydrator } from '../../../../hydration/hydrator' | ||
import { Views } from '../../../../views' | ||
|
||
export default function (server: Server, ctx: AppContext) { | ||
const getListMutes = createPipelineNew( | ||
skeleton, | ||
hydration, | ||
noRulesNew, | ||
presentation, | ||
) | ||
server.app.bsky.graph.getListMutes({ | ||
auth: ctx.authVerifier, | ||
handler: async ({ params, auth }) => { | ||
const { limit, cursor } = params | ||
const requester = auth.credentials.did | ||
const db = ctx.db.getReplica() | ||
const { ref } = db.db.dynamic | ||
const viewer = auth.credentials.did | ||
const result = await getListMutes({ ...params, viewer }, ctx) | ||
return { | ||
encoding: 'application/json', | ||
body: result, | ||
} | ||
}, | ||
}) | ||
} | ||
|
||
const graphService = ctx.services.graph(db) | ||
const skeleton = async ( | ||
input: SkeletonFnInput<Context, Params>, | ||
): Promise<SkeletonState> => { | ||
const { ctx, params } = input | ||
const { listUris, cursor } = | ||
await ctx.hydrator.dataplane.getMutelistSubscriptions({ | ||
actorDid: params.viewer, | ||
cursor: params.cursor, | ||
limit: params.limit, | ||
}) | ||
return { listUris, cursor } | ||
} | ||
|
||
let listsReq = graphService | ||
.getListsQb(requester) | ||
.whereExists( | ||
db.db | ||
.selectFrom('list_mute') | ||
.where('list_mute.mutedByDid', '=', requester) | ||
.whereRef('list_mute.listUri', '=', ref('list.uri')) | ||
.selectAll(), | ||
) | ||
const hydration = async ( | ||
input: HydrationFnInput<Context, Params, SkeletonState>, | ||
) => { | ||
const { ctx, params, skeleton } = input | ||
return await ctx.hydrator.hydrateLists(skeleton.listUris, params.viewer) | ||
} | ||
|
||
const keyset = new TimeCidKeyset(ref('list.createdAt'), ref('list.cid')) | ||
listsReq = paginate(listsReq, { | ||
limit, | ||
cursor, | ||
keyset, | ||
}) | ||
const listsRes = await listsReq.execute() | ||
const presentation = ( | ||
input: PresentationFnInput<Context, Params, SkeletonState>, | ||
) => { | ||
const { ctx, skeleton, hydration } = input | ||
const { listUris, cursor } = skeleton | ||
const lists = mapDefined(listUris, (uri) => ctx.views.list(uri, hydration)) | ||
return { lists, cursor } | ||
} | ||
|
||
const actorService = ctx.services.actor(db) | ||
const profiles = await actorService.views.profiles(listsRes, requester) | ||
type Context = { | ||
hydrator: Hydrator | ||
views: Views | ||
} | ||
|
||
const lists = mapDefined(listsRes, (row) => | ||
graphService.formatListView(row, profiles), | ||
) | ||
type Params = QueryParams & { | ||
viewer: string | ||
} | ||
|
||
return { | ||
encoding: 'application/json', | ||
body: { | ||
lists, | ||
cursor: keyset.packFromResult(listsRes), | ||
}, | ||
} | ||
}, | ||
}) | ||
type SkeletonState = { | ||
listUris: string[] | ||
cursor?: string | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters