From d703bc36e6637750ec20df4c8d0c015c7bbd04aa Mon Sep 17 00:00:00 2001 From: devin ivy Date: Mon, 25 Sep 2023 10:27:48 +0200 Subject: [PATCH] Clear follow viewer state when blocking (#1659) * clear follow viewer state when blocking * tidy --- packages/bsky/src/services/actor/views.ts | 20 +++++++++++++---- .../__snapshots__/block-lists.test.ts.snap | 1 - packages/bsky/tests/views/blocks.test.ts | 22 +++++++++++++++++-- .../tests/views/suggested-follows.test.ts | 2 +- .../proxied/__snapshots__/views.test.ts.snap | 10 +++------ 5 files changed, 40 insertions(+), 15 deletions(-) diff --git a/packages/bsky/src/services/actor/views.ts b/packages/bsky/src/services/actor/views.ts index 80652599f80..ec39805c76d 100644 --- a/packages/bsky/src/services/actor/views.ts +++ b/packages/bsky/src/services/actor/views.ts @@ -194,8 +194,14 @@ export class ActorViews { mutedByList, blockedBy: !!bam.blockedBy([viewer, did]), blocking: bam.blocking([viewer, did]) ?? undefined, - following: prof?.viewerFollowing || undefined, - followedBy: prof?.viewerFollowedBy || undefined, + following: + prof?.viewerFollowing && !bam.block([viewer, did]) + ? prof.viewerFollowing + : undefined, + followedBy: + prof?.viewerFollowedBy && !bam.block([viewer, did]) + ? prof.viewerFollowedBy + : undefined, } : undefined, labels: [...actorLabels, ...selfLabels], @@ -314,8 +320,14 @@ export class ActorViews { mutedByList, blockedBy: !!bam.blockedBy([viewer, did]), blocking: bam.blocking([viewer, did]) ?? undefined, - following: prof?.viewerFollowing || undefined, - followedBy: prof?.viewerFollowedBy || undefined, + following: + prof?.viewerFollowing && !bam.block([viewer, did]) + ? prof.viewerFollowing + : undefined, + followedBy: + prof?.viewerFollowedBy && !bam.block([viewer, did]) + ? prof.viewerFollowedBy + : undefined, } : undefined, labels: [...actorLabels, ...selfLabels], 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 009095947c2..364ad4b7d63 100644 --- a/packages/bsky/tests/views/__snapshots__/block-lists.test.ts.snap +++ b/packages/bsky/tests/views/__snapshots__/block-lists.test.ts.snap @@ -512,7 +512,6 @@ Object { "viewer": Object { "blockedBy": false, "blocking": "record(0)", - "following": "record(4)", "muted": false, }, }, diff --git a/packages/bsky/tests/views/blocks.test.ts b/packages/bsky/tests/views/blocks.test.ts index 30b46e78ab5..0109b93f82a 100644 --- a/packages/bsky/tests/views/blocks.test.ts +++ b/packages/bsky/tests/views/blocks.test.ts @@ -191,17 +191,35 @@ describe('pds views with blocking', () => { { actor: dan }, { headers: await network.serviceHeaders(carol) }, ) - expect(resCarol.data.viewer?.blocking).toBeUndefined + expect(resCarol.data.viewer?.blocking).toBeUndefined() expect(resCarol.data.viewer?.blockedBy).toBe(true) const resDan = await agent.api.app.bsky.actor.getProfile( { actor: carol }, { headers: await network.serviceHeaders(dan) }, ) - expect(resDan.data.viewer?.blocking).toBeDefined + expect(resDan.data.viewer?.blocking).toBeDefined() expect(resDan.data.viewer?.blockedBy).toBe(false) }) + it('unsets viewer follow state when blocked', async () => { + // there are follows between carol and dan + const { data: profile } = await agent.api.app.bsky.actor.getProfile( + { actor: carol }, + { headers: await network.serviceHeaders(dan) }, + ) + expect(profile.viewer?.following).toBeUndefined() + expect(profile.viewer?.followedBy).toBeUndefined() + const { data: result } = await agent.api.app.bsky.graph.getBlocks( + {}, + { headers: await network.serviceHeaders(dan) }, + ) + const blocked = result.blocks.find((block) => block.did === carol) + expect(blocked).toBeDefined() + expect(blocked?.viewer?.following).toBeUndefined() + expect(blocked?.viewer?.followedBy).toBeUndefined() + }) + it('returns block status on getProfiles', async () => { const resCarol = await agent.api.app.bsky.actor.getProfiles( { actors: [alice, dan] }, diff --git a/packages/bsky/tests/views/suggested-follows.test.ts b/packages/bsky/tests/views/suggested-follows.test.ts index 6a2f3ebe1d7..1d8cb5a91ba 100644 --- a/packages/bsky/tests/views/suggested-follows.test.ts +++ b/packages/bsky/tests/views/suggested-follows.test.ts @@ -11,7 +11,7 @@ describe('suggested follows', () => { beforeAll(async () => { network = await TestNetwork.create({ - dbPostgresSchema: 'bsky_views_suggestions', + dbPostgresSchema: 'bsky_views_suggested_follows', }) agent = network.bsky.getClient() pdsAgent = network.pds.getClient() diff --git a/packages/pds/tests/proxied/__snapshots__/views.test.ts.snap b/packages/pds/tests/proxied/__snapshots__/views.test.ts.snap index d6707292de4..994589ff0b2 100644 --- a/packages/pds/tests/proxied/__snapshots__/views.test.ts.snap +++ b/packages/pds/tests/proxied/__snapshots__/views.test.ts.snap @@ -2959,8 +2959,6 @@ Object { "viewer": Object { "blockedBy": false, "blocking": "record(0)", - "followedBy": "record(2)", - "following": "record(1)", "muted": false, }, }, @@ -2977,7 +2975,7 @@ Object { "cts": "1970-01-01T00:00:00.000Z", "neg": false, "src": "user(1)", - "uri": "record(6)", + "uri": "record(2)", "val": "self-label-a", }, Object { @@ -2985,15 +2983,13 @@ Object { "cts": "1970-01-01T00:00:00.000Z", "neg": false, "src": "user(1)", - "uri": "record(6)", + "uri": "record(2)", "val": "self-label-b", }, ], "viewer": Object { "blockedBy": false, - "blocking": "record(3)", - "followedBy": "record(5)", - "following": "record(4)", + "blocking": "record(1)", "muted": false, }, },