From 94a59e52cb493136b086f56fd7cb392a1e56d1bf Mon Sep 17 00:00:00 2001 From: Daniel Holmgren Date: Thu, 8 Feb 2024 16:38:48 -0600 Subject: [PATCH 1/3] Adjust wording for account suspension (#2153) adjust wording for account suspension --- .../bsky/src/api/app/bsky/actor/getProfile.ts | 15 ++++-------- packages/bsky/src/views/index.ts | 7 ------ packages/bsky/tests/views/profile.test.ts | 23 +------------------ 3 files changed, 5 insertions(+), 40 deletions(-) diff --git a/packages/bsky/src/api/app/bsky/actor/getProfile.ts b/packages/bsky/src/api/app/bsky/actor/getProfile.ts index 515093ebf9b..386313aa5cb 100644 --- a/packages/bsky/src/api/app/bsky/actor/getProfile.ts +++ b/packages/bsky/src/api/app/bsky/actor/getProfile.ts @@ -69,17 +69,10 @@ const presentation = (input: { !params.canViewTakedowns && ctx.views.actorIsTakendown(skeleton.did, hydration) ) { - if (ctx.views.actorIsSuspended(skeleton.did, hydration)) { - throw new InvalidRequestError( - 'Account has been temporarily suspended', - 'AccountTakedown', - ) - } else { - throw new InvalidRequestError( - 'Account has been taken down', - 'AccountTakedown', - ) - } + throw new InvalidRequestError( + 'Account has been suspended', + 'AccountTakedown', + ) } return profile } diff --git a/packages/bsky/src/views/index.ts b/packages/bsky/src/views/index.ts index 08c58134383..feee19f9adf 100644 --- a/packages/bsky/src/views/index.ts +++ b/packages/bsky/src/views/index.ts @@ -60,13 +60,6 @@ export class Views { return !!state.actors?.get(did)?.takedownRef } - actorIsSuspended(did: string, state: HydrationState): boolean { - return !!state.actors - ?.get(did) - ?.takedownRef?.toLowerCase() - .includes('suspend') - } - viewerBlockExists(did: string, state: HydrationState): boolean { const actor = state.profileViewers?.get(did) if (!actor) return false diff --git a/packages/bsky/tests/views/profile.test.ts b/packages/bsky/tests/views/profile.test.ts index 17d91b5e189..8c83c3e49aa 100644 --- a/packages/bsky/tests/views/profile.test.ts +++ b/packages/bsky/tests/views/profile.test.ts @@ -191,28 +191,7 @@ describe('pds profile views', () => { { headers: await network.serviceHeaders(bob) }, ) - await expect(promise).rejects.toThrow('Account has been taken down') - - // Cleanup - await network.bsky.ctx.dataplane.untakedownActor({ - did: alice, - }) - }) - - // @TODO reimplement suspension? - it.skip('blocked by actor suspension', async () => { - await network.bsky.ctx.dataplane.takedownActor({ - did: alice, - }) - await network.processAll() - const promise = agent.api.app.bsky.actor.getProfile( - { actor: alice }, - { headers: await network.serviceHeaders(bob) }, - ) - - await expect(promise).rejects.toThrow( - 'Account has been temporarily suspended', - ) + await expect(promise).rejects.toThrow('Account has been suspended') // Cleanup await network.bsky.ctx.dataplane.untakedownActor({ From 8497d18d6d1ff38a33e6e2c7f818c96685400ea8 Mon Sep 17 00:00:00 2001 From: devin ivy Date: Tue, 20 Feb 2024 18:26:56 -0500 Subject: [PATCH 2/3] Appview v2: fix not-found and blocked uris in threads (#2201) * fix uris of not-found and blocked posts in threads * update snaps --- packages/bsky/src/views/index.ts | 4 ++-- .../views/__snapshots__/block-lists.test.ts.snap | 8 ++++---- .../tests/views/__snapshots__/blocks.test.ts.snap | 12 ++++++------ .../tests/views/__snapshots__/thread.test.ts.snap | 14 +++++++------- 4 files changed, 19 insertions(+), 19 deletions(-) diff --git a/packages/bsky/src/views/index.ts b/packages/bsky/src/views/index.ts index feee19f9adf..80d1596ade1 100644 --- a/packages/bsky/src/views/index.ts +++ b/packages/bsky/src/views/index.ts @@ -568,10 +568,10 @@ export class Views { return undefined } const post = this.post(uri, state) - if (!postInfo || !post) return this.notFoundPost(parentUri) + if (!postInfo || !post) return this.notFoundPost(uri) if (rootUri !== getRootUri(uri, postInfo)) return // outside thread boundary if (this.viewerBlockExists(post.author.did, state)) { - return this.blockedPost(parentUri, post.author.did, state) + return this.blockedPost(uri, post.author.did, state) } return { $type: 'app.bsky.feed.defs#threadViewPost', diff --git a/packages/bsky/tests/views/__snapshots__/block-lists.test.ts.snap b/packages/bsky/tests/views/__snapshots__/block-lists.test.ts.snap index 408d5576387..c5ff586f5c2 100644 --- a/packages/bsky/tests/views/__snapshots__/block-lists.test.ts.snap +++ b/packages/bsky/tests/views/__snapshots__/block-lists.test.ts.snap @@ -263,11 +263,11 @@ Object { "did": "user(2)", "viewer": Object { "blockedBy": false, - "blocking": "record(5)", + "blocking": "record(6)", }, }, "blocked": true, - "uri": "record(0)", + "uri": "record(5)", }, Object { "$type": "app.bsky.feed.defs#blockedPost", @@ -275,11 +275,11 @@ Object { "did": "user(3)", "viewer": Object { "blockedBy": false, - "blocking": "record(5)", + "blocking": "record(6)", }, }, "blocked": true, - "uri": "record(0)", + "uri": "record(7)", }, ], }, diff --git a/packages/bsky/tests/views/__snapshots__/blocks.test.ts.snap b/packages/bsky/tests/views/__snapshots__/blocks.test.ts.snap index 80632f69479..751dc15b3ac 100644 --- a/packages/bsky/tests/views/__snapshots__/blocks.test.ts.snap +++ b/packages/bsky/tests/views/__snapshots__/blocks.test.ts.snap @@ -263,11 +263,11 @@ Object { "did": "user(2)", "viewer": Object { "blockedBy": false, - "blocking": "record(5)", + "blocking": "record(6)", }, }, "blocked": true, - "uri": "record(0)", + "uri": "record(5)", }, Object { "$type": "app.bsky.feed.defs#threadViewPost", @@ -280,7 +280,7 @@ Object { "labels": Array [], "viewer": Object { "blockedBy": false, - "following": "record(7)", + "following": "record(8)", "muted": false, }, }, @@ -302,7 +302,7 @@ Object { "cts": "1970-01-01T00:00:00.000Z", "neg": false, "src": "did:example:labeler", - "uri": "record(6)", + "uri": "record(7)", "val": "test-label", }, Object { @@ -310,7 +310,7 @@ Object { "cts": "1970-01-01T00:00:00.000Z", "neg": false, "src": "did:example:labeler", - "uri": "record(6)", + "uri": "record(7)", "val": "test-label-2", }, ], @@ -348,7 +348,7 @@ Object { }, "replyCount": 1, "repostCount": 0, - "uri": "record(6)", + "uri": "record(7)", "viewer": Object {}, }, }, diff --git a/packages/bsky/tests/views/__snapshots__/thread.test.ts.snap b/packages/bsky/tests/views/__snapshots__/thread.test.ts.snap index 27016f89097..41a448f63eb 100644 --- a/packages/bsky/tests/views/__snapshots__/thread.test.ts.snap +++ b/packages/bsky/tests/views/__snapshots__/thread.test.ts.snap @@ -1074,7 +1074,7 @@ Object { Object { "$type": "app.bsky.feed.defs#notFoundPost", "notFound": true, - "uri": "record(0)", + "uri": "record(5)", }, Object { "$type": "app.bsky.feed.defs#threadViewPost", @@ -1108,7 +1108,7 @@ Object { "cts": "1970-01-01T00:00:00.000Z", "neg": false, "src": "did:example:labeler", - "uri": "record(5)", + "uri": "record(6)", "val": "test-label", }, Object { @@ -1116,7 +1116,7 @@ Object { "cts": "1970-01-01T00:00:00.000Z", "neg": false, "src": "did:example:labeler", - "uri": "record(5)", + "uri": "record(6)", "val": "test-label-2", }, ], @@ -1154,7 +1154,7 @@ Object { }, "replyCount": 1, "repostCount": 0, - "uri": "record(5)", + "uri": "record(6)", "viewer": Object {}, }, "replies": Array [ @@ -1201,7 +1201,7 @@ Object { "reply": Object { "parent": Object { "cid": "cids(3)", - "uri": "record(5)", + "uri": "record(6)", }, "root": Object { "cid": "cids(0)", @@ -1212,9 +1212,9 @@ Object { }, "replyCount": 0, "repostCount": 2, - "uri": "record(6)", + "uri": "record(7)", "viewer": Object { - "repost": "record(7)", + "repost": "record(8)", }, }, "replies": Array [], From c2a65777d4e9dd0df360f2f3217a41862fefb8ef Mon Sep 17 00:00:00 2001 From: Foysal Ahamed Date: Wed, 21 Feb 2024 00:29:50 +0100 Subject: [PATCH 3/3] :sparkles: Show author feed of takendown author to admins only (#2197) --- .../src/api/app/bsky/feed/getAuthorFeed.ts | 20 ++++++++++++++----- packages/bsky/src/hydration/hydrator.ts | 2 +- packages/bsky/tests/views/author-feed.test.ts | 12 ++++++++--- 3 files changed, 25 insertions(+), 9 deletions(-) diff --git a/packages/bsky/src/api/app/bsky/feed/getAuthorFeed.ts b/packages/bsky/src/api/app/bsky/feed/getAuthorFeed.ts index 15305b00a99..02e2240828f 100644 --- a/packages/bsky/src/api/app/bsky/feed/getAuthorFeed.ts +++ b/packages/bsky/src/api/app/bsky/feed/getAuthorFeed.ts @@ -27,9 +27,12 @@ export default function (server: Server, ctx: AppContext) { server.app.bsky.feed.getAuthorFeed({ auth: ctx.authVerifier.optionalStandardOrRole, handler: async ({ params, auth, res }) => { - const { viewer } = ctx.authVerifier.parseCreds(auth) + const { viewer, canViewTakedowns } = ctx.authVerifier.parseCreds(auth) - const result = await getAuthorFeed({ ...params, viewer }, ctx) + const result = await getAuthorFeed( + { ...params, viewer, includeTakedowns: canViewTakedowns }, + ctx, + ) const repoRev = await ctx.hydrator.actor.getRepoRevSafe(viewer) setRepoRev(res, repoRev) @@ -58,7 +61,10 @@ export const skeleton = async (inputs: { if (!did) { throw new InvalidRequestError('Profile not found') } - const actors = await ctx.hydrator.actor.getActors([did]) + const actors = await ctx.hydrator.actor.getActors( + [did], + params.includeTakedowns, + ) const actor = actors.get(did) if (!actor) { throw new InvalidRequestError('Profile not found') @@ -91,7 +97,11 @@ const hydration = async (inputs: { }): Promise => { const { ctx, params, skeleton } = inputs const [feedPostState, profileViewerState = {}] = await Promise.all([ - ctx.hydrator.hydrateFeedItems(skeleton.items, params.viewer), + ctx.hydrator.hydrateFeedItems( + skeleton.items, + params.viewer, + params.includeTakedowns, + ), params.viewer ? ctx.hydrator.hydrateProfileViewers([skeleton.actor.did], params.viewer) : undefined, @@ -147,7 +157,7 @@ type Context = { dataplane: DataPlaneClient } -type Params = QueryParams & { viewer: string | null } +type Params = QueryParams & { viewer: string | null; includeTakedowns: boolean } type Skeleton = { actor: Actor diff --git a/packages/bsky/src/hydration/hydrator.ts b/packages/bsky/src/hydration/hydrator.ts index d7ead860336..180411237fb 100644 --- a/packages/bsky/src/hydration/hydrator.ts +++ b/packages/bsky/src/hydration/hydrator.ts @@ -361,7 +361,7 @@ export class Hydrator { const repostUris = mapDefined(items, (item) => item.repost?.uri) const [posts, reposts, repostProfileState] = await Promise.all([ this.feed.getPosts(postUris, includeTakedowns), - this.feed.getReposts(repostUris), + this.feed.getReposts(repostUris, includeTakedowns), this.hydrateProfiles( repostUris.map(didFromUri), viewer, diff --git a/packages/bsky/tests/views/author-feed.test.ts b/packages/bsky/tests/views/author-feed.test.ts index b8cea76cb41..3ce69a48286 100644 --- a/packages/bsky/tests/views/author-feed.test.ts +++ b/packages/bsky/tests/views/author-feed.test.ts @@ -138,7 +138,7 @@ describe('pds author feed views', () => { ) }) - it('blocked by actor takedown.', async () => { + it('non-admins blocked by actor takedown.', async () => { const { data: preBlock } = await agent.api.app.bsky.feed.getAuthorFeed( { actor: alice }, { headers: await network.serviceHeaders(carol) }, @@ -150,11 +150,17 @@ describe('pds author feed views', () => { did: alice, }) - const attempt = agent.api.app.bsky.feed.getAuthorFeed( + const attemptAsUser = agent.api.app.bsky.feed.getAuthorFeed( { actor: alice }, { headers: await network.serviceHeaders(carol) }, ) - await expect(attempt).rejects.toThrow('Profile not found') + await expect(attemptAsUser).rejects.toThrow('Profile not found') + + const attemptAsAdmin = await agent.api.app.bsky.feed.getAuthorFeed( + { actor: alice }, + { headers: await network.bsky.adminAuthHeaders() }, + ) + expect(attemptAsAdmin.data.feed.length).toEqual(preBlock.feed.length) // Cleanup await network.bsky.ctx.dataplane.untakedownActor({