From 72549f442223c0c74594e111a9793e39b0c5ea2d Mon Sep 17 00:00:00 2001 From: Matthieu Sieben Date: Fri, 4 Oct 2024 07:18:38 +0200 Subject: [PATCH] Allow using a handle as "actor" param in app.bsky.graph.getLists (#2853) * Allow using a handle as "actor" param in app.bsky.graph.getLists * tests --- .changeset/eleven-walls-cover.md | 5 +++ .../bsky/src/api/app/bsky/graph/getLists.ts | 7 +++- .../views/__snapshots__/lists.test.ts.snap | 33 +++++++++++++++++++ packages/bsky/tests/views/lists.test.ts | 8 +++++ 4 files changed, 52 insertions(+), 1 deletion(-) create mode 100644 .changeset/eleven-walls-cover.md diff --git a/.changeset/eleven-walls-cover.md b/.changeset/eleven-walls-cover.md new file mode 100644 index 00000000000..249dc417699 --- /dev/null +++ b/.changeset/eleven-walls-cover.md @@ -0,0 +1,5 @@ +--- +"@atproto/bsky": patch +--- + +Allow using a handle as "actor" param in app.bsky.graph.getLists diff --git a/packages/bsky/src/api/app/bsky/graph/getLists.ts b/packages/bsky/src/api/app/bsky/graph/getLists.ts index 081c64fbc19..31d241710c2 100644 --- a/packages/bsky/src/api/app/bsky/graph/getLists.ts +++ b/packages/bsky/src/api/app/bsky/graph/getLists.ts @@ -1,4 +1,5 @@ import { mapDefined } from '@atproto/common' +import { InvalidRequestError } from '@atproto/xrpc-server' import { Server } from '../../../../lexicon' import { QueryParams } from '../../../../lexicon/types/app/bsky/graph/getLists' import { REFERENCELIST } from '../../../../lexicon/types/app/bsky/graph/defs' @@ -49,8 +50,12 @@ const skeleton = async ( if (clearlyBadCursor(params.cursor)) { return { listUris: [] } } + + const [did] = await ctx.hydrator.actor.getDids([params.actor]) + if (!did) throw new InvalidRequestError('Profile not found') + const { listUris, cursor } = await ctx.hydrator.dataplane.getActorLists({ - actorDid: params.actor, + actorDid: did, cursor: params.cursor, limit: params.limit, }) diff --git a/packages/bsky/tests/views/__snapshots__/lists.test.ts.snap b/packages/bsky/tests/views/__snapshots__/lists.test.ts.snap index da10fb14752..82842d664ab 100644 --- a/packages/bsky/tests/views/__snapshots__/lists.test.ts.snap +++ b/packages/bsky/tests/views/__snapshots__/lists.test.ts.snap @@ -343,3 +343,36 @@ Array [ }, ] `; + +exports[`bsky actor likes feed views supports using a handle as getList actor param 1`] = ` +Array [ + Object { + "cid": "cids(0)", + "creator": Object { + "did": "user(0)", + "handle": "eve.test", + "labels": Array [], + }, + "indexedAt": "1970-01-01T00:00:00.000Z", + "labels": Array [], + "listItemCount": 0, + "name": "cool curate list", + "purpose": "app.bsky.graph.defs#curatelist", + "uri": "record(0)", + }, + Object { + "cid": "cids(1)", + "creator": Object { + "did": "user(0)", + "handle": "eve.test", + "labels": Array [], + }, + "indexedAt": "1970-01-01T00:00:00.000Z", + "labels": Array [], + "listItemCount": 3, + "name": "blah curate list!", + "purpose": "app.bsky.graph.defs#curatelist", + "uri": "record(1)", + }, +] +`; diff --git a/packages/bsky/tests/views/lists.test.ts b/packages/bsky/tests/views/lists.test.ts index e725050b4a5..15266746d2b 100644 --- a/packages/bsky/tests/views/lists.test.ts +++ b/packages/bsky/tests/views/lists.test.ts @@ -82,6 +82,14 @@ describe('bsky actor likes feed views', () => { expect(forSnapshot(view.data.lists)).toMatchSnapshot() }) + it('supports using a handle as getList actor param', async () => { + const view = await agent.app.bsky.graph.getLists({ + actor: 'eve.test', + }) + expect(view.data.lists.length).toBe(2) + expect(forSnapshot(view.data.lists)).toMatchSnapshot() + }) + it('does not include users with creator block relationship in reference lists for non-creator, in-list viewers', async () => { const curView = await agent.api.app.bsky.graph.getList( {