Skip to content

Commit

Permalink
Return ThreadgateView on response from getPostThread (bluesky-soc…
Browse files Browse the repository at this point in the history
…ial#2737)

* Return `ThreadgateView` on response from `getPostThread`

* Changeset

* Format

* Add to test

* Clean up logic

* Use suggestion from Dan
  • Loading branch information
estrattonbailey authored Aug 22, 2024
1 parent d9ffa3c commit a8e1f90
Show file tree
Hide file tree
Showing 12 changed files with 51 additions and 8 deletions.
6 changes: 6 additions & 0 deletions .changeset/plenty-turtles-shop.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"@atproto/bsky": patch
"@atproto/api": patch
---

Add `threadgate: ThreadgateView` to response from `getPostThread`
4 changes: 4 additions & 0 deletions lexicons/app/bsky/feed/getPostThread.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,10 @@
"app.bsky.feed.defs#notFoundPost",
"app.bsky.feed.defs#blockedPost"
]
},
"threadgate": {
"type": "ref",
"ref": "app.bsky.feed.defs#threadgateView"
}
}
}
Expand Down
4 changes: 4 additions & 0 deletions packages/api/src/client/lexicons.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6251,6 +6251,10 @@ export const schemaDict = {
'lex:app.bsky.feed.defs#blockedPost',
],
},
threadgate: {
type: 'ref',
ref: 'lex:app.bsky.feed.defs#threadgateView',
},
},
},
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ export interface OutputSchema {
| AppBskyFeedDefs.NotFoundPost
| AppBskyFeedDefs.BlockedPost
| { $type: string; [k: string]: unknown }
threadgate?: AppBskyFeedDefs.ThreadgateView
[k: string]: unknown
}

Expand Down
15 changes: 13 additions & 2 deletions packages/bsky/src/api/app/bsky/feed/getPostThread.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
import { InvalidRequestError } from '@atproto/xrpc-server'
import { Server } from '../../../../lexicon'
import { isNotFoundPost } from '../../../../lexicon/types/app/bsky/feed/defs'
import {
isNotFoundPost,
isThreadViewPost,
} from '../../../../lexicon/types/app/bsky/feed/defs'
import { isRecord as isPostRecord } from '../../../../lexicon/types/app/bsky/feed/post'
import {
QueryParams,
OutputSchema,
Expand All @@ -17,6 +21,7 @@ import {
import { HydrateCtx, Hydrator } from '../../../../hydration/hydrator'
import { Views } from '../../../../views'
import { DataPlaneClient, isDataplaneError, Code } from '../../../../data-plane'
import { postUriToThreadgateUri } from '../../../../util/uris'

export default function (server: Server, ctx: AppContext) {
const getPostThread = createPipeline(
Expand Down Expand Up @@ -110,7 +115,13 @@ const presentation = (
// @TODO technically this could be returned as a NotFoundPost based on lexicon
throw new InvalidRequestError(`Post not found: ${params.uri}`, 'NotFound')
}
return { thread }
const rootUri =
hydration.posts?.get(params.uri)?.record.reply?.root.uri ?? params.uri
const threadgate = ctx.views.threadgate(
postUriToThreadgateUri(rootUri),
hydration,
)
return { thread, threadgate }
}

type Context = {
Expand Down
4 changes: 4 additions & 0 deletions packages/bsky/src/lexicon/lexicons.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6251,6 +6251,10 @@ export const schemaDict = {
'lex:app.bsky.feed.defs#blockedPost',
],
},
threadgate: {
type: 'ref',
ref: 'lex:app.bsky.feed.defs#threadgateView',
},
},
},
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ export interface OutputSchema {
| AppBskyFeedDefs.NotFoundPost
| AppBskyFeedDefs.BlockedPost
| { $type: string; [k: string]: unknown }
threadgate?: AppBskyFeedDefs.ThreadgateView
[k: string]: unknown
}

Expand Down
14 changes: 8 additions & 6 deletions packages/bsky/tests/views/threadgating.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,16 +44,17 @@ describe('views with thread gating', () => {

it('applies gate for empty rules.', async () => {
const post = await sc.post(sc.dids.carol, 'empty rules')
await pdsAgent.api.app.bsky.feed.threadgate.create(
{ repo: sc.dids.carol, rkey: post.ref.uri.rkey },
{ post: post.ref.uriStr, createdAt: iso(), allow: [] },
sc.getHeaders(sc.dids.carol),
)
const { uri: threadgateUri } =
await pdsAgent.api.app.bsky.feed.threadgate.create(
{ repo: sc.dids.carol, rkey: post.ref.uri.rkey },
{ post: post.ref.uriStr, createdAt: iso(), allow: [] },
sc.getHeaders(sc.dids.carol),
)
await network.processAll()
await sc.reply(sc.dids.alice, post.ref, post.ref, 'empty rules reply')
await network.processAll()
const {
data: { thread },
data: { thread, threadgate },
} = await agent.api.app.bsky.feed.getPostThread(
{ uri: post.ref.uriStr },
{
Expand All @@ -67,6 +68,7 @@ describe('views with thread gating', () => {
expect(forSnapshot(thread.post.threadgate)).toMatchSnapshot()
expect(thread.post.viewer?.replyDisabled).toBe(true)
expect(thread.replies?.length).toEqual(0)
expect(threadgate?.uri).toEqual(threadgateUri)
await checkReplyDisabled(post.ref.uriStr, sc.dids.alice, true)
})

Expand Down
4 changes: 4 additions & 0 deletions packages/ozone/src/lexicon/lexicons.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6251,6 +6251,10 @@ export const schemaDict = {
'lex:app.bsky.feed.defs#blockedPost',
],
},
threadgate: {
type: 'ref',
ref: 'lex:app.bsky.feed.defs#threadgateView',
},
},
},
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ export interface OutputSchema {
| AppBskyFeedDefs.NotFoundPost
| AppBskyFeedDefs.BlockedPost
| { $type: string; [k: string]: unknown }
threadgate?: AppBskyFeedDefs.ThreadgateView
[k: string]: unknown
}

Expand Down
4 changes: 4 additions & 0 deletions packages/pds/src/lexicon/lexicons.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6251,6 +6251,10 @@ export const schemaDict = {
'lex:app.bsky.feed.defs#blockedPost',
],
},
threadgate: {
type: 'ref',
ref: 'lex:app.bsky.feed.defs#threadgateView',
},
},
},
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ export interface OutputSchema {
| AppBskyFeedDefs.NotFoundPost
| AppBskyFeedDefs.BlockedPost
| { $type: string; [k: string]: unknown }
threadgate?: AppBskyFeedDefs.ThreadgateView
[k: string]: unknown
}

Expand Down

0 comments on commit a8e1f90

Please sign in to comment.