Skip to content

Commit

Permalink
Appview: remove replies to blocked posts from feeds (#2430)
Browse files Browse the repository at this point in the history
appview: remove replies to blocked posts from feeds
  • Loading branch information
devinivy authored Apr 19, 2024
1 parent 1faf634 commit b079506
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 5 deletions.
3 changes: 2 additions & 1 deletion packages/bsky/src/api/app/bsky/feed/getFeed.ts
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,8 @@ const noBlocksOrMutes = (inputs: RulesFnInput<Context, Params, Skeleton>) => {
!bam.authorBlocked &&
!bam.authorMuted &&
!bam.originatorBlocked &&
!bam.originatorMuted
!bam.originatorMuted &&
!bam.parentAuthorBlocked
)
})
return skeleton
Expand Down
3 changes: 2 additions & 1 deletion packages/bsky/src/api/app/bsky/feed/getListFeed.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,8 @@ const noBlocksOrMutes = (inputs: {
!bam.authorBlocked &&
!bam.authorMuted &&
!bam.originatorBlocked &&
!bam.originatorMuted
!bam.originatorMuted &&
!bam.parentAuthorBlocked
)
})
return skeleton
Expand Down
3 changes: 2 additions & 1 deletion packages/bsky/src/api/app/bsky/feed/getTimeline.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,8 @@ const noBlocksOrMutes = (inputs: {
!bam.authorBlocked &&
!bam.authorMuted &&
!bam.originatorBlocked &&
!bam.originatorMuted
!bam.originatorMuted &&
!bam.parentAuthorBlocked
)
})
return skeleton
Expand Down
7 changes: 7 additions & 0 deletions packages/bsky/src/views/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -334,16 +334,23 @@ export class Views {
originatorBlocked: boolean
authorMuted: boolean
authorBlocked: boolean
parentAuthorBlocked: boolean
} {
const authorDid = creatorFromUri(item.post.uri)
const originatorDid = item.repost
? creatorFromUri(item.repost.uri)
: authorDid
const post = state.posts?.get(item.post.uri)
const parentUri = post?.record.reply?.parent.uri
const parentAuthorDid = parentUri && creatorFromUri(parentUri)
return {
originatorMuted: this.viewerMuteExists(originatorDid, state),
originatorBlocked: this.viewerBlockExists(originatorDid, state),
authorMuted: this.viewerMuteExists(authorDid, state),
authorBlocked: this.viewerBlockExists(authorDid, state),
parentAuthorBlocked: parentAuthorDid
? this.viewerBlockExists(parentAuthorDid, state)
: false,
}
}

Expand Down
14 changes: 12 additions & 2 deletions packages/bsky/tests/views/blocks.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -160,16 +160,26 @@ describe('pds views with blocking', () => {
{ limit: 100 },
{ headers: await network.serviceHeaders(carol) },
)

// dan's posts don't appear, nor alice's reply to dan.
expect(
resCarol.data.feed.some((post) => post.post.author.did === dan),
resCarol.data.feed.some(
(post) =>
post.post.author.did === dan ||
post.reply?.parent.author?.['did'] === dan,
),
).toBeFalsy()

const resDan = await agent.api.app.bsky.feed.getTimeline(
{ limit: 100 },
{ headers: await network.serviceHeaders(dan) },
)
expect(
resDan.data.feed.some((post) => post.post.author.did === carol),
resDan.data.feed.some(
(post) =>
post.post.author.did === carol ||
post.reply?.parent.author?.['did'] === carol,
),
).toBeFalsy()
})

Expand Down

0 comments on commit b079506

Please sign in to comment.