Skip to content

Commit

Permalink
Better handle 3rd party blocks in feeds (#1677)
Browse files Browse the repository at this point in the history
* better handle 3rd party blocks inf eeds

* show anchor post in threads

* test
  • Loading branch information
dholms authored Dec 19, 2023
1 parent 16b31e3 commit aadd35e
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 7 deletions.
7 changes: 4 additions & 3 deletions packages/bsky/src/api/app/bsky/feed/getPostThread.ts
Original file line number Diff line number Diff line change
Expand Up @@ -128,9 +128,10 @@ const composeThread = (
// @TODO re-enable invalidReplyRoot check
// const badReply = !!info?.invalidReplyRoot || !!info?.violatesThreadGate
const badReply = !!info?.violatesThreadGate
const omitBadReply = !isAnchorPost && badReply
const violatesBlock = (post && blocks[post.uri]?.reply) ?? false
const omitBadReply = !isAnchorPost && (badReply || violatesBlock)

if (!post || blocks[post.uri]?.reply || omitBadReply) {
if (!post || omitBadReply) {
return {
$type: 'app.bsky.feed.defs#notFoundPost',
uri: threadData.post.postUri,
Expand All @@ -156,7 +157,7 @@ const composeThread = (
}

let parent
if (threadData.parent && !badReply) {
if (threadData.parent && !badReply && !violatesBlock) {
if (threadData.parent instanceof ParentNotFoundError) {
parent = {
$type: 'app.bsky.feed.defs#notFoundPost',
Expand Down
9 changes: 6 additions & 3 deletions packages/bsky/src/services/feed/views.ts
Original file line number Diff line number Diff line change
Expand Up @@ -132,8 +132,8 @@ export class FeedViews {
lists,
viewer,
)
// skip over not found & blocked posts
if (!post || blocks[post.uri]?.reply) {
// skip over not found post
if (!post) {
continue
}
const feedPost = { post }
Expand All @@ -159,6 +159,7 @@ export class FeedViews {
) {
const replyParent = this.formatMaybePostView(
item.replyParent,
item.uri,
actors,
posts,
threadgates,
Expand All @@ -171,6 +172,7 @@ export class FeedViews {
)
const replyRoot = this.formatMaybePostView(
item.replyRoot,
item.uri,
actors,
posts,
threadgates,
Expand Down Expand Up @@ -291,6 +293,7 @@ export class FeedViews {

formatMaybePostView(
uri: string,
replyUri: string | null,
actors: ActorInfoMap,
posts: PostInfoMap,
threadgates: ThreadgateInfoMap,
Expand Down Expand Up @@ -320,7 +323,7 @@ export class FeedViews {
if (
post.author.viewer?.blockedBy ||
post.author.viewer?.blocking ||
blocks[uri]?.reply
(replyUri !== null && blocks[replyUri]?.reply)
) {
if (!opts?.usePostViewUnion) return
return this.blockedPost(post)
Expand Down
15 changes: 14 additions & 1 deletion packages/bsky/tests/views/blocks.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,18 @@ describe('pds views with blocking', () => {
expect(forSnapshot(thread)).toMatchSnapshot()
})

it('loads blocked reply as anchor with no parent', async () => {
const { data: thread } = await agent.api.app.bsky.feed.getPostThread(
{ depth: 1, uri: carolReplyToDan.ref.uriStr },
{ headers: await network.serviceHeaders(alice) },
)
if (!isThreadViewPost(thread.thread)) {
throw new Error('Expected thread view post')
}
expect(thread.thread.post.uri).toEqual(carolReplyToDan.ref.uriStr)
expect(thread.thread.parent).toBeUndefined()
})

it('blocks thread parent', async () => {
// Parent is a post by dan
const { data: thread } = await agent.api.app.bsky.feed.getPostThread(
Expand Down Expand Up @@ -498,7 +510,8 @@ describe('pds views with blocking', () => {
const replyBlockedPost = timeline.feed.find(
(item) => item.post.uri === replyBlockedUri,
)
expect(replyBlockedPost).toBeUndefined()
assert(replyBlockedPost)
expect(replyBlockedPost.reply?.parent).toBeUndefined()
const embedBlockedPost = timeline.feed.find(
(item) => item.post.uri === embedBlockedUri,
)
Expand Down

0 comments on commit aadd35e

Please sign in to comment.