Thread through threadgate record, validate approach

This commit is contained in:
Eric Bailey
2024-08-05 09:55:59 -05:00
parent 380c4dbf24
commit 571d00cf41
5 changed files with 64 additions and 3 deletions
+31 -1
View File
@@ -1,4 +1,9 @@
import {AppBskyFeedDefs, AppBskyFeedThreadgate, AtUri} from '@atproto/api'
import {
AppBskyFeedDefs,
AppBskyFeedThreadgate,
AtUri,
BskyAgent,
} from '@atproto/api'
import {useQuery} from '@tanstack/react-query'
import {useAgent} from '#/state/session'
@@ -78,3 +83,28 @@ export function useThreadgateRecordQuery({
},
})
}
export function createThreadgate({
agent,
postUri,
threadgate,
}: {
agent: BskyAgent
postUri: string
threadgate: Partial<AppBskyFeedThreadgate.Record>
}) {
const urip = new AtUri(postUri)
const record = {
...threadgate,
post: postUri,
createdAt: new Date().toISOString(),
}
return agent.api.app.bsky.feed.threadgate.create(
{
repo: urip.host,
rkey: urip.rkey,
},
record,
)
}