Return ThreadgateView on response from getPostThread ()

* Return `ThreadgateView` on response from `getPostThread`

* Changeset

* Format

* Add to test

* Clean up logic

* Use suggestion from Dan
This commit is contained in:
Eric Bailey 2024-08-22 17:00:01 -05:00 committed by GitHub
parent d9ffa3c460
commit a8e1f9000d
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
12 changed files with 51 additions and 8 deletions
.changeset
lexicons/app/bsky/feed
packages
api/src/client
lexicons.ts
types/app/bsky/feed
bsky
src
api/app/bsky/feed
lexicon
lexicons.ts
types/app/bsky/feed
tests/views
ozone/src/lexicon
lexicons.ts
types/app/bsky/feed
pds/src/lexicon
lexicons.ts
types/app/bsky/feed

@ -0,0 +1,6 @@
---
"@atproto/bsky": patch
"@atproto/api": patch
---
Add `threadgate: ThreadgateView` to response from `getPostThread`

@ -43,6 +43,10 @@
"app.bsky.feed.defs#notFoundPost",
"app.bsky.feed.defs#blockedPost"
]
},
"threadgate": {
"type": "ref",
"ref": "app.bsky.feed.defs#threadgateView"
}
}
}

@ -6251,6 +6251,10 @@ export const schemaDict = {
'lex:app.bsky.feed.defs#blockedPost',
],
},
threadgate: {
type: 'ref',
ref: 'lex:app.bsky.feed.defs#threadgateView',
},
},
},
},

@ -25,6 +25,7 @@ export interface OutputSchema {
| AppBskyFeedDefs.NotFoundPost
| AppBskyFeedDefs.BlockedPost
| { $type: string; [k: string]: unknown }
threadgate?: AppBskyFeedDefs.ThreadgateView
[k: string]: unknown
}

@ -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,
@ -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(
@ -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 = {

@ -6251,6 +6251,10 @@ export const schemaDict = {
'lex:app.bsky.feed.defs#blockedPost',
],
},
threadgate: {
type: 'ref',
ref: 'lex:app.bsky.feed.defs#threadgateView',
},
},
},
},

@ -26,6 +26,7 @@ export interface OutputSchema {
| AppBskyFeedDefs.NotFoundPost
| AppBskyFeedDefs.BlockedPost
| { $type: string; [k: string]: unknown }
threadgate?: AppBskyFeedDefs.ThreadgateView
[k: string]: unknown
}

@ -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 },
{
@ -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)
})

@ -6251,6 +6251,10 @@ export const schemaDict = {
'lex:app.bsky.feed.defs#blockedPost',
],
},
threadgate: {
type: 'ref',
ref: 'lex:app.bsky.feed.defs#threadgateView',
},
},
},
},

@ -26,6 +26,7 @@ export interface OutputSchema {
| AppBskyFeedDefs.NotFoundPost
| AppBskyFeedDefs.BlockedPost
| { $type: string; [k: string]: unknown }
threadgate?: AppBskyFeedDefs.ThreadgateView
[k: string]: unknown
}

@ -6251,6 +6251,10 @@ export const schemaDict = {
'lex:app.bsky.feed.defs#blockedPost',
],
},
threadgate: {
type: 'ref',
ref: 'lex:app.bsky.feed.defs#threadgateView',
},
},
},
},

@ -26,6 +26,7 @@ export interface OutputSchema {
| AppBskyFeedDefs.NotFoundPost
| AppBskyFeedDefs.BlockedPost
| { $type: string; [k: string]: unknown }
threadgate?: AppBskyFeedDefs.ThreadgateView
[k: string]: unknown
}