Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

exact matches always show profile regardless of block status #2653

Merged
merged 5 commits into from
Aug 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 9 additions & 4 deletions packages/bsky/src/api/app/bsky/actor/searchActorsTypeahead.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,10 +82,15 @@ const hydration = async (
}

const noBlocks = (inputs: RulesFnInput<Context, Params, Skeleton>) => {
const { ctx, skeleton, hydration } = inputs
skeleton.dids = skeleton.dids.filter(
(did) => !ctx.views.viewerBlockExists(did, hydration),
)
const { ctx, skeleton, hydration, params } = inputs
skeleton.dids = skeleton.dids.filter((did) => {
const actor = hydration.actors?.get(did)
if (!actor) return false
// Always display exact matches so that users can find profiles that they have blocked
const term = (params.q ?? params.term ?? '').toLowerCase()
const isExactMatch = actor.handle?.toLowerCase() === term
return isExactMatch || !ctx.views.viewerBlockExists(did, hydration)
})
return skeleton
}

Expand Down
22 changes: 20 additions & 2 deletions packages/bsky/tests/views/block-lists.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -295,21 +295,39 @@ describe('pds views with blocking from block lists', () => {
it('does not return blocked accounts in actor search typeahead', async () => {
const resCarol = await agent.api.app.bsky.actor.searchActorsTypeahead(
{
term: 'dan.test',
term: 'dan.tes',
},
{ headers: await network.serviceHeaders(carol) },
)
expect(resCarol.data.actors.some((actor) => actor.did === dan)).toBeFalsy()

const resDan = await agent.api.app.bsky.actor.searchActorsTypeahead(
{
term: 'carol.test',
term: 'carol.tes',
},
{ headers: await network.serviceHeaders(dan) },
)
expect(resDan.data.actors.some((actor) => actor.did === carol)).toBeFalsy()
})

it('does return blocked accounts in actor search typeahead when term is exact handle', async () => {
const resCarol = await agent.api.app.bsky.actor.searchActorsTypeahead(
{
term: 'dan.test',
},
{ headers: await network.serviceHeaders(carol) },
)
expect(resCarol.data.actors.some((actor) => actor.did === dan)).toBeTruthy()

const resDan = await agent.api.app.bsky.actor.searchActorsTypeahead(
{
term: 'carol.test',
},
{ headers: await network.serviceHeaders(dan) },
)
expect(resDan.data.actors.some((actor) => actor.did === carol)).toBeTruthy()
})

it('does not return blocked accounts in get suggestions', async () => {
// unfollow so they _would_ show up in suggestions if not for block
await sc.unfollow(carol, dan)
Expand Down
22 changes: 20 additions & 2 deletions packages/bsky/tests/views/blocks.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -367,21 +367,39 @@ describe('pds views with blocking', () => {
it('does not return blocked accounts in actor search typeahead', async () => {
const resCarol = await agent.api.app.bsky.actor.searchActorsTypeahead(
{
term: 'dan.test',
term: 'dan.tes',
},
{ headers: await network.serviceHeaders(carol) },
)
expect(resCarol.data.actors.some((actor) => actor.did === dan)).toBeFalsy()

const resDan = await agent.api.app.bsky.actor.searchActorsTypeahead(
{
term: 'carol.test',
term: 'carol.tes',
},
{ headers: await network.serviceHeaders(dan) },
)
expect(resDan.data.actors.some((actor) => actor.did === carol)).toBeFalsy()
})

it('does return blocked accounts in actor search typeahead when term is exact handle', async () => {
const resCarol = await agent.api.app.bsky.actor.searchActorsTypeahead(
{
term: 'dan.test',
},
{ headers: await network.serviceHeaders(carol) },
)
expect(resCarol.data.actors.some((actor) => actor.did === dan)).toBeTruthy()

const resDan = await agent.api.app.bsky.actor.searchActorsTypeahead(
{
term: 'carol.test',
},
{ headers: await network.serviceHeaders(dan) },
)
expect(resDan.data.actors.some((actor) => actor.did === carol)).toBeTruthy()
})

it('does not return blocked accounts in get suggestions', async () => {
// unfollow so they _would_ show up in suggestions if not for block
await sc.unfollow(carol, dan)
Expand Down