[SDK] Remove @atproto/api (#11386)
Co-authored-by: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
@@ -1,27 +1,26 @@
|
||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||
import {type AppBskyUnspeccedGetPostThreadV2} from '@atproto/api'
|
||||
|
||||
/**
|
||||
* See the `below` param on {@link AppBskyUnspeccedGetPostThreadV2.QueryParams}
|
||||
* See the `below` param on {@link app.bsky.unspecced.getPostThreadV2.$Params}
|
||||
*/
|
||||
export const LINEAR_VIEW_BELOW = 10
|
||||
|
||||
/**
|
||||
* See the `branchingFactor` param on {@link AppBskyUnspeccedGetPostThreadV2.QueryParams}
|
||||
* See the `branchingFactor` param on {@link app.bsky.unspecced.getPostThreadV2.$Params}
|
||||
*/
|
||||
export const LINEAR_VIEW_BF = 1
|
||||
|
||||
/**
|
||||
* See the `below` param on {@link AppBskyUnspeccedGetPostThreadV2.QueryParams}
|
||||
* See the `below` param on {@link app.bsky.unspecced.getPostThreadV2.$Params}
|
||||
*/
|
||||
export const TREE_VIEW_BELOW = 4
|
||||
|
||||
/**
|
||||
* See the `branchingFactor` param on {@link AppBskyUnspeccedGetPostThreadV2.QueryParams}
|
||||
* See the `branchingFactor` param on {@link app.bsky.unspecced.getPostThreadV2.$Params}
|
||||
*/
|
||||
export const TREE_VIEW_BF = undefined
|
||||
|
||||
/**
|
||||
* See the `below` param on {@link AppBskyUnspeccedGetPostThreadV2.QueryParams}
|
||||
* See the `below` param on {@link app.bsky.unspecced.getPostThreadV2.$Params}
|
||||
*/
|
||||
export const TREE_VIEW_BELOW_DESKTOP = 6
|
||||
|
||||
@@ -1,13 +1,6 @@
|
||||
import {useCallback} from 'react'
|
||||
import {
|
||||
type $Typed,
|
||||
type AppBskyActorDefs,
|
||||
type AppBskyFeedDefs,
|
||||
AppBskyUnspeccedDefs,
|
||||
type AppBskyUnspeccedGetPostThreadOtherV2,
|
||||
type AppBskyUnspeccedGetPostThreadV2,
|
||||
AtUri,
|
||||
} from '@atproto/api'
|
||||
import {type $Typed} from '@atproto/lex'
|
||||
import {AtUri} from '@atproto/syntax'
|
||||
import {type QueryClient, useQueryClient} from '@tanstack/react-query'
|
||||
|
||||
import {
|
||||
@@ -36,6 +29,8 @@ import {
|
||||
embedViewRecordToPostView,
|
||||
getEmbeddedPost,
|
||||
} from '#/state/queries/util'
|
||||
import {app} from '#/lexicons'
|
||||
import * as bsky from '#/types/bsky'
|
||||
|
||||
export function createCacheMutator({
|
||||
queryClient,
|
||||
@@ -51,18 +46,18 @@ export function createCacheMutator({
|
||||
return {
|
||||
insertReplies(
|
||||
parentUri: string,
|
||||
replies: AppBskyUnspeccedGetPostThreadV2.ThreadItem[],
|
||||
replies: app.bsky.unspecced.getPostThreadV2.ThreadItem[],
|
||||
) {
|
||||
/*
|
||||
* Main thread query mutator.
|
||||
*/
|
||||
queryClient.setQueryData<AppBskyUnspeccedGetPostThreadV2.OutputSchema>(
|
||||
queryClient.setQueryData<app.bsky.unspecced.getPostThreadV2.$OutputBody>(
|
||||
postThreadQueryKey,
|
||||
data => {
|
||||
if (!data) return
|
||||
return {
|
||||
...data,
|
||||
thread: mutator<AppBskyUnspeccedGetPostThreadV2.ThreadItem>([
|
||||
thread: mutator<app.bsky.unspecced.getPostThreadV2.ThreadItem>([
|
||||
...data.thread,
|
||||
]),
|
||||
}
|
||||
@@ -72,15 +67,15 @@ export function createCacheMutator({
|
||||
/*
|
||||
* Additional replies query mutator.
|
||||
*/
|
||||
queryClient.setQueryData<AppBskyUnspeccedGetPostThreadOtherV2.OutputSchema>(
|
||||
queryClient.setQueryData<app.bsky.unspecced.getPostThreadOtherV2.$OutputBody>(
|
||||
postThreadOtherQueryKey,
|
||||
data => {
|
||||
if (!data) return
|
||||
return {
|
||||
...data,
|
||||
thread: mutator<AppBskyUnspeccedGetPostThreadOtherV2.ThreadItem>([
|
||||
...data.thread,
|
||||
]),
|
||||
thread: mutator<app.bsky.unspecced.getPostThreadOtherV2.ThreadItem>(
|
||||
[...data.thread],
|
||||
),
|
||||
}
|
||||
},
|
||||
)
|
||||
@@ -89,7 +84,10 @@ export function createCacheMutator({
|
||||
for (let i = 0; i < thread.length; i++) {
|
||||
const parent = thread[i]
|
||||
|
||||
if (!AppBskyUnspeccedDefs.isThreadItemPost(parent.value)) continue
|
||||
if (
|
||||
!bsky.isType(app.bsky.unspecced.defs.threadItemPost, parent.value)
|
||||
)
|
||||
continue
|
||||
if (parent.uri !== parentUri) continue
|
||||
|
||||
/*
|
||||
@@ -124,7 +122,8 @@ export function createCacheMutator({
|
||||
const isParentRoot = parent.depth === 0
|
||||
const isParentBelowRoot = parent.depth > 0
|
||||
const optimisticReply = replies.at(0)
|
||||
const opIsReplier = AppBskyUnspeccedDefs.isThreadItemPost(
|
||||
const opIsReplier = bsky.isType(
|
||||
app.bsky.unspecced.defs.threadItemPost,
|
||||
optimisticReply?.value,
|
||||
)
|
||||
? opDid === optimisticReply.value.post.author.did
|
||||
@@ -172,8 +171,8 @@ export function createCacheMutator({
|
||||
* Unused atm, post shadow does the trick, but it would be nice to clean up
|
||||
* the whole sub-tree on deletes.
|
||||
*/
|
||||
deletePost(post: AppBskyUnspeccedGetPostThreadV2.ThreadItem) {
|
||||
queryClient.setQueryData<AppBskyUnspeccedGetPostThreadV2.OutputSchema>(
|
||||
deletePost(post: app.bsky.unspecced.getPostThreadV2.ThreadItem) {
|
||||
queryClient.setQueryData<app.bsky.unspecced.getPostThreadV2.$OutputBody>(
|
||||
postThreadQueryKey,
|
||||
queryData => {
|
||||
if (!queryData) return
|
||||
@@ -182,7 +181,10 @@ export function createCacheMutator({
|
||||
|
||||
for (let i = 0; i < thread.length; i++) {
|
||||
const existingPost = thread[i]
|
||||
if (!AppBskyUnspeccedDefs.isThreadItemPost(post.value)) continue
|
||||
if (
|
||||
!bsky.isType(app.bsky.unspecced.defs.threadItemPost, post.value)
|
||||
)
|
||||
continue
|
||||
|
||||
if (existingPost.uri === post.uri) {
|
||||
const branch = getBranch(thread, i, existingPost.depth)
|
||||
@@ -204,7 +206,7 @@ export function createCacheMutator({
|
||||
export function getThreadPlaceholder(
|
||||
queryClient: QueryClient,
|
||||
uri: string,
|
||||
): $Typed<AppBskyUnspeccedGetPostThreadV2.ThreadItem> | void {
|
||||
): $Typed<app.bsky.unspecced.getPostThreadV2.ThreadItem> | void {
|
||||
let partial
|
||||
for (let item of getThreadPlaceholderCandidates(queryClient, uri)) {
|
||||
/*
|
||||
@@ -231,8 +233,8 @@ export function* getThreadPlaceholderCandidates(
|
||||
uri: string,
|
||||
): Generator<
|
||||
$Typed<
|
||||
Omit<AppBskyUnspeccedGetPostThreadV2.ThreadItem, 'value'> & {
|
||||
value: $Typed<AppBskyUnspeccedDefs.ThreadItemPost>
|
||||
Omit<app.bsky.unspecced.getPostThreadV2.ThreadItem, 'value'> & {
|
||||
value: $Typed<app.bsky.unspecced.defs.ThreadItemPost>
|
||||
}
|
||||
>,
|
||||
void
|
||||
@@ -276,10 +278,10 @@ export function* getThreadPlaceholderCandidates(
|
||||
export function* findAllPostsInQueryData(
|
||||
queryClient: QueryClient,
|
||||
uri: string,
|
||||
): Generator<AppBskyFeedDefs.PostView, void> {
|
||||
): Generator<app.bsky.feed.defs.PostView, void> {
|
||||
const atUri = new AtUri(uri)
|
||||
const queryDatas =
|
||||
queryClient.getQueriesData<AppBskyUnspeccedGetPostThreadV2.OutputSchema>({
|
||||
queryClient.getQueriesData<app.bsky.unspecced.getPostThreadV2.$OutputBody>({
|
||||
queryKey: [postThreadQueryKeyRoot],
|
||||
})
|
||||
|
||||
@@ -289,7 +291,7 @@ export function* findAllPostsInQueryData(
|
||||
const {thread} = queryData
|
||||
|
||||
for (const item of thread) {
|
||||
if (AppBskyUnspeccedDefs.isThreadItemPost(item.value)) {
|
||||
if (bsky.isType(app.bsky.unspecced.defs.threadItemPost, item.value)) {
|
||||
if (didOrHandleUriMatches(atUri, item.value.post)) {
|
||||
yield item.value.post
|
||||
}
|
||||
@@ -306,9 +308,9 @@ export function* findAllPostsInQueryData(
|
||||
export function* findAllProfilesInQueryData(
|
||||
queryClient: QueryClient,
|
||||
did: string,
|
||||
): Generator<AppBskyActorDefs.ProfileViewBasic, void> {
|
||||
): Generator<app.bsky.actor.defs.ProfileViewBasic, void> {
|
||||
const queryDatas =
|
||||
queryClient.getQueriesData<AppBskyUnspeccedGetPostThreadV2.OutputSchema>({
|
||||
queryClient.getQueriesData<app.bsky.unspecced.getPostThreadV2.$OutputBody>({
|
||||
queryKey: [postThreadQueryKeyRoot],
|
||||
})
|
||||
|
||||
@@ -318,7 +320,7 @@ export function* findAllProfilesInQueryData(
|
||||
const {thread} = queryData
|
||||
|
||||
for (const item of thread) {
|
||||
if (AppBskyUnspeccedDefs.isThreadItemPost(item.value)) {
|
||||
if (bsky.isType(app.bsky.unspecced.defs.threadItemPost, item.value)) {
|
||||
if (item.value.post.author.did === did) {
|
||||
yield item.value.post.author
|
||||
}
|
||||
@@ -337,14 +339,15 @@ export function useUpdatePostThreadThreadgateQueryCache() {
|
||||
const context = usePostThreadContext()
|
||||
|
||||
return useCallback(
|
||||
(threadgate: AppBskyFeedDefs.ThreadgateView) => {
|
||||
(threadgate: app.bsky.feed.defs.ThreadgateView) => {
|
||||
if (!context) return
|
||||
|
||||
function mutator<T>(thread: ApiThreadItem[]): T[] {
|
||||
for (let i = 0; i < thread.length; i++) {
|
||||
const item = thread[i]
|
||||
|
||||
if (!AppBskyUnspeccedDefs.isThreadItemPost(item.value)) continue
|
||||
if (!bsky.isType(app.bsky.unspecced.defs.threadItemPost, item.value))
|
||||
continue
|
||||
|
||||
if (item.depth === 0) {
|
||||
thread.splice(i, 1, {
|
||||
@@ -363,13 +366,13 @@ export function useUpdatePostThreadThreadgateQueryCache() {
|
||||
return thread as T[]
|
||||
}
|
||||
|
||||
qc.setQueryData<AppBskyUnspeccedGetPostThreadV2.OutputSchema>(
|
||||
qc.setQueryData<app.bsky.unspecced.getPostThreadV2.$OutputBody>(
|
||||
context.postThreadQueryKey,
|
||||
data => {
|
||||
if (!data) return
|
||||
return {
|
||||
...data,
|
||||
thread: mutator<AppBskyUnspeccedGetPostThreadV2.ThreadItem>([
|
||||
thread: mutator<app.bsky.unspecced.getPostThreadV2.ThreadItem>([
|
||||
...data.thread,
|
||||
]),
|
||||
}
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
import {AppBskyUnspeccedDefs} from '@atproto/api'
|
||||
import {type ModerationOpts} from '@bsky.app/sdk/moderation'
|
||||
|
||||
import {
|
||||
@@ -15,6 +14,8 @@ import {
|
||||
storeTraversalMetadata,
|
||||
} from '#/state/queries/usePostThread/utils'
|
||||
import * as views from '#/state/queries/usePostThread/views'
|
||||
import {app} from '#/lexicons'
|
||||
import * as bsky from '#/types/bsky'
|
||||
|
||||
export function sortAndAnnotateThreadItems(
|
||||
thread: ApiThreadItem[],
|
||||
@@ -46,7 +47,7 @@ export function sortAndAnnotateThreadItems(
|
||||
let parentMetadata: TraversalMetadata | undefined
|
||||
let metadata: TraversalMetadata | undefined
|
||||
|
||||
if (AppBskyUnspeccedDefs.isThreadItemPost(item.value)) {
|
||||
if (bsky.isType(app.bsky.unspecced.defs.threadItemPost, item.value)) {
|
||||
parentMetadata = metadatas.get(
|
||||
getPostRecord(item.value.post).reply?.parent?.uri || '',
|
||||
)
|
||||
@@ -65,13 +66,24 @@ export function sortAndAnnotateThreadItems(
|
||||
* _up_ from there.
|
||||
*/
|
||||
} else if (item.depth === 0) {
|
||||
if (AppBskyUnspeccedDefs.isThreadItemNoUnauthenticated(item.value)) {
|
||||
if (
|
||||
bsky.isType(
|
||||
app.bsky.unspecced.defs.threadItemNoUnauthenticated,
|
||||
item.value,
|
||||
)
|
||||
) {
|
||||
threadItems.push(views.threadPostNoUnauthenticated(item))
|
||||
} else if (AppBskyUnspeccedDefs.isThreadItemNotFound(item.value)) {
|
||||
} else if (
|
||||
bsky.isType(app.bsky.unspecced.defs.threadItemNotFound, item.value)
|
||||
) {
|
||||
threadItems.push(views.threadPostNotFound(item))
|
||||
} else if (AppBskyUnspeccedDefs.isThreadItemBlocked(item.value)) {
|
||||
} else if (
|
||||
bsky.isType(app.bsky.unspecced.defs.threadItemBlocked, item.value)
|
||||
) {
|
||||
threadItems.push(views.threadPostBlocked(item))
|
||||
} else if (AppBskyUnspeccedDefs.isThreadItemPost(item.value)) {
|
||||
} else if (
|
||||
bsky.isType(app.bsky.unspecced.defs.threadItemPost, item.value)
|
||||
) {
|
||||
const post = views.threadPost({
|
||||
uri: item.uri,
|
||||
depth: item.depth,
|
||||
@@ -85,7 +97,10 @@ export function sortAndAnnotateThreadItems(
|
||||
const parent = thread[pi]
|
||||
|
||||
if (
|
||||
AppBskyUnspeccedDefs.isThreadItemNoUnauthenticated(parent.value)
|
||||
bsky.isType(
|
||||
app.bsky.unspecced.defs.threadItemNoUnauthenticated,
|
||||
parent.value,
|
||||
)
|
||||
) {
|
||||
const post = views.threadPostNoUnauthenticated(parent)
|
||||
post.ui = getThreadPostNoUnauthenticatedUI({
|
||||
@@ -97,13 +112,22 @@ export function sortAndAnnotateThreadItems(
|
||||
threadItems.unshift(post)
|
||||
// for now, break parent traversal at first no-unauthed
|
||||
break parentTraversal
|
||||
} else if (AppBskyUnspeccedDefs.isThreadItemNotFound(parent.value)) {
|
||||
} else if (
|
||||
bsky.isType(
|
||||
app.bsky.unspecced.defs.threadItemNotFound,
|
||||
parent.value,
|
||||
)
|
||||
) {
|
||||
threadItems.unshift(views.threadPostNotFound(parent))
|
||||
break parentTraversal
|
||||
} else if (AppBskyUnspeccedDefs.isThreadItemBlocked(parent.value)) {
|
||||
} else if (
|
||||
bsky.isType(app.bsky.unspecced.defs.threadItemBlocked, parent.value)
|
||||
) {
|
||||
threadItems.unshift(views.threadPostBlocked(parent))
|
||||
break parentTraversal
|
||||
} else if (AppBskyUnspeccedDefs.isThreadItemPost(parent.value)) {
|
||||
} else if (
|
||||
bsky.isType(app.bsky.unspecced.defs.threadItemPost, parent.value)
|
||||
) {
|
||||
threadItems.unshift(
|
||||
views.threadPost({
|
||||
uri: parent.uri,
|
||||
@@ -123,16 +147,21 @@ export function sortAndAnnotateThreadItems(
|
||||
* we could.
|
||||
*/
|
||||
const shouldBreak =
|
||||
AppBskyUnspeccedDefs.isThreadItemNoUnauthenticated(item.value) ||
|
||||
AppBskyUnspeccedDefs.isThreadItemNotFound(item.value) ||
|
||||
AppBskyUnspeccedDefs.isThreadItemBlocked(item.value)
|
||||
bsky.isType(
|
||||
app.bsky.unspecced.defs.threadItemNoUnauthenticated,
|
||||
item.value,
|
||||
) ||
|
||||
bsky.isType(app.bsky.unspecced.defs.threadItemNotFound, item.value) ||
|
||||
bsky.isType(app.bsky.unspecced.defs.threadItemBlocked, item.value)
|
||||
|
||||
if (shouldBreak) {
|
||||
const branch = getBranch(thread, i, item.depth)
|
||||
// could insert tombstone
|
||||
i = branch.end
|
||||
continue traversal
|
||||
} else if (AppBskyUnspeccedDefs.isThreadItemPost(item.value)) {
|
||||
} else if (
|
||||
bsky.isType(app.bsky.unspecced.defs.threadItemPost, item.value)
|
||||
) {
|
||||
if (parentMetadata) {
|
||||
/*
|
||||
* Set this value before incrementing the `repliesSeenCounter` later
|
||||
@@ -180,7 +209,9 @@ export function sortAndAnnotateThreadItems(
|
||||
for (let ci = startIndex; ci <= branch.end; ci++) {
|
||||
const child = thread[ci]
|
||||
|
||||
if (AppBskyUnspeccedDefs.isThreadItemPost(child.value)) {
|
||||
if (
|
||||
bsky.isType(app.bsky.unspecced.defs.threadItemPost, child.value)
|
||||
) {
|
||||
const childParentMetadata = metadatas.get(
|
||||
getPostRecord(child.value.post).reply?.parent?.uri || '',
|
||||
)
|
||||
|
||||
@@ -1,16 +1,10 @@
|
||||
import {
|
||||
type AppBskyFeedDefs,
|
||||
type AppBskyFeedPost,
|
||||
type AppBskyFeedThreadgate,
|
||||
type AppBskyUnspeccedDefs,
|
||||
type AppBskyUnspeccedGetPostThreadOtherV2,
|
||||
type AppBskyUnspeccedGetPostThreadV2,
|
||||
} from '@atproto/api'
|
||||
import {type ModerationDecision} from '@bsky.app/sdk/moderation'
|
||||
|
||||
import {type app} from '#/lexicons'
|
||||
|
||||
export type ApiThreadItem =
|
||||
| AppBskyUnspeccedGetPostThreadV2.ThreadItem
|
||||
| AppBskyUnspeccedGetPostThreadOtherV2.ThreadItem
|
||||
| app.bsky.unspecced.getPostThreadV2.ThreadItem
|
||||
| app.bsky.unspecced.getPostThreadOtherV2.ThreadItem
|
||||
|
||||
export const postThreadQueryKeyRoot = 'post-thread-v2' as const
|
||||
|
||||
@@ -18,13 +12,13 @@ export const createPostThreadQueryKey = (props: PostThreadParams) =>
|
||||
[postThreadQueryKeyRoot, props] as const
|
||||
|
||||
export const createPostThreadOtherQueryKey = (
|
||||
props: Omit<AppBskyUnspeccedGetPostThreadOtherV2.QueryParams, 'anchor'> & {
|
||||
props: Omit<app.bsky.unspecced.getPostThreadOtherV2.$Params, 'anchor'> & {
|
||||
anchor?: string
|
||||
},
|
||||
) => [postThreadQueryKeyRoot, 'other', props] as const
|
||||
|
||||
export type PostThreadParams = Pick<
|
||||
AppBskyUnspeccedGetPostThreadV2.QueryParams,
|
||||
app.bsky.unspecced.getPostThreadV2.$Params,
|
||||
'sort'
|
||||
> & {
|
||||
anchor?: string
|
||||
@@ -33,9 +27,9 @@ export type PostThreadParams = Pick<
|
||||
|
||||
export type UsePostThreadQueryResult = {
|
||||
hasOtherReplies: boolean
|
||||
thread: AppBskyUnspeccedGetPostThreadV2.ThreadItem[]
|
||||
threadgate?: Omit<AppBskyFeedDefs.ThreadgateView, 'record'> & {
|
||||
record: AppBskyFeedThreadgate.Record
|
||||
thread: app.bsky.unspecced.getPostThreadV2.ThreadItem[]
|
||||
threadgate?: Omit<app.bsky.feed.defs.ThreadgateView, 'record'> & {
|
||||
record: app.bsky.feed.threadgate.Main
|
||||
}
|
||||
}
|
||||
|
||||
@@ -45,9 +39,9 @@ export type ThreadItem =
|
||||
key: string
|
||||
uri: string
|
||||
depth: number
|
||||
value: Omit<AppBskyUnspeccedDefs.ThreadItemPost, 'post'> & {
|
||||
post: Omit<AppBskyFeedDefs.PostView, 'record'> & {
|
||||
record: AppBskyFeedPost.Record
|
||||
value: Omit<app.bsky.unspecced.defs.ThreadItemPost, 'post'> & {
|
||||
post: Omit<app.bsky.feed.defs.PostView, 'record'> & {
|
||||
record: app.bsky.feed.post.Main
|
||||
}
|
||||
}
|
||||
isBlurred: boolean
|
||||
@@ -67,7 +61,7 @@ export type ThreadItem =
|
||||
key: string
|
||||
uri: string
|
||||
depth: number
|
||||
value: AppBskyUnspeccedDefs.ThreadItemNoUnauthenticated
|
||||
value: app.bsky.unspecced.defs.ThreadItemNoUnauthenticated
|
||||
ui: {
|
||||
showParentReplyLine: boolean
|
||||
showChildReplyLine: boolean
|
||||
@@ -78,14 +72,14 @@ export type ThreadItem =
|
||||
key: string
|
||||
uri: string
|
||||
depth: number
|
||||
value: AppBskyUnspeccedDefs.ThreadItemNotFound
|
||||
value: app.bsky.unspecced.defs.ThreadItemNotFound
|
||||
}
|
||||
| {
|
||||
type: 'threadPostBlocked'
|
||||
key: string
|
||||
uri: string
|
||||
depth: number
|
||||
value: AppBskyUnspeccedDefs.ThreadItemBlocked
|
||||
value: app.bsky.unspecced.defs.ThreadItemBlocked
|
||||
}
|
||||
| {
|
||||
type: 'replyComposer'
|
||||
|
||||
@@ -1,38 +1,24 @@
|
||||
import {
|
||||
type AppBskyFeedDefs,
|
||||
AppBskyFeedPost,
|
||||
AppBskyFeedThreadgate,
|
||||
AppBskyUnspeccedDefs,
|
||||
type AppBskyUnspeccedGetPostThreadV2,
|
||||
AtUri,
|
||||
} from '@atproto/api'
|
||||
import {AtUri} from '@atproto/syntax'
|
||||
|
||||
import {
|
||||
type ApiThreadItem,
|
||||
type ThreadItem,
|
||||
type TraversalMetadata,
|
||||
} from '#/state/queries/usePostThread/types'
|
||||
import {app} from '#/lexicons'
|
||||
import {isDevMode} from '#/storage/hooks/dev-mode'
|
||||
import * as bsky from '#/types/bsky'
|
||||
|
||||
export function getThreadgateRecord(
|
||||
view: AppBskyUnspeccedGetPostThreadV2.OutputSchema['threadgate'],
|
||||
view: app.bsky.unspecced.getPostThreadV2.$OutputBody['threadgate'],
|
||||
) {
|
||||
return bsky.dangerousIsType<AppBskyFeedThreadgate.Record>(
|
||||
view?.record,
|
||||
AppBskyFeedThreadgate.isRecord,
|
||||
)
|
||||
return bsky.isType(app.bsky.feed.threadgate, view?.record)
|
||||
? view?.record
|
||||
: undefined
|
||||
}
|
||||
|
||||
export function getRootPostAtUri(post: AppBskyFeedDefs.PostView) {
|
||||
if (
|
||||
bsky.dangerousIsType<AppBskyFeedPost.Record>(
|
||||
post.record,
|
||||
AppBskyFeedPost.isRecord,
|
||||
)
|
||||
) {
|
||||
export function getRootPostAtUri(post: app.bsky.feed.defs.PostView) {
|
||||
if (bsky.isType(app.bsky.feed.post, post.record)) {
|
||||
/**
|
||||
* If the record has no `reply` field, it is a root post.
|
||||
*/
|
||||
@@ -45,8 +31,8 @@ export function getRootPostAtUri(post: AppBskyFeedDefs.PostView) {
|
||||
}
|
||||
}
|
||||
|
||||
export function getPostRecord(post: AppBskyFeedDefs.PostView) {
|
||||
return post.record as AppBskyFeedPost.Record
|
||||
export function getPostRecord(post: app.bsky.feed.defs.PostView) {
|
||||
return post.record as app.bsky.feed.post.Main
|
||||
}
|
||||
|
||||
export function getTraversalMetadata({
|
||||
@@ -60,7 +46,7 @@ export function getTraversalMetadata({
|
||||
nextItem?: ApiThreadItem
|
||||
parentMetadata?: TraversalMetadata
|
||||
}): TraversalMetadata {
|
||||
if (!AppBskyUnspeccedDefs.isThreadItemPost(item.value)) {
|
||||
if (!bsky.isType(app.bsky.unspecced.defs.threadItemPost, item.value)) {
|
||||
throw new Error(`Expected thread item to be a post`)
|
||||
}
|
||||
const repliesCount = item.value.post.replyCount || 0
|
||||
|
||||
@@ -1,20 +1,14 @@
|
||||
import {
|
||||
type $Typed,
|
||||
type AppBskyFeedDefs,
|
||||
type AppBskyFeedPost,
|
||||
type AppBskyUnspeccedDefs,
|
||||
type AppBskyUnspeccedGetPostThreadV2,
|
||||
AtUri,
|
||||
} from '@atproto/api'
|
||||
import {type ModerationOpts} from '@bsky.app/sdk/moderation'
|
||||
import {type $Typed} from '@atproto/lex'
|
||||
import {AtUri} from '@atproto/syntax'
|
||||
import {moderatePost, type ModerationOpts} from '@bsky.app/sdk/moderation'
|
||||
|
||||
import {moderatePost} from '#/lib/moderation/subjects'
|
||||
import {makeProfileLink} from '#/lib/routes/links'
|
||||
import {
|
||||
type ApiThreadItem,
|
||||
type ThreadItem,
|
||||
type TraversalMetadata,
|
||||
} from '#/state/queries/usePostThread/types'
|
||||
import {type app} from '#/lexicons'
|
||||
|
||||
export function threadPostNoUnauthenticated({
|
||||
uri,
|
||||
@@ -26,7 +20,7 @@ export function threadPostNoUnauthenticated({
|
||||
key: uri,
|
||||
uri,
|
||||
depth,
|
||||
value: value as AppBskyUnspeccedDefs.ThreadItemNoUnauthenticated,
|
||||
value: value as app.bsky.unspecced.defs.ThreadItemNoUnauthenticated,
|
||||
// @ts-ignore populated by the traversal
|
||||
ui: {},
|
||||
}
|
||||
@@ -42,7 +36,7 @@ export function threadPostNotFound({
|
||||
key: uri,
|
||||
uri,
|
||||
depth,
|
||||
value: value as AppBskyUnspeccedDefs.ThreadItemNotFound,
|
||||
value: value as app.bsky.unspecced.defs.ThreadItemNotFound,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -56,7 +50,7 @@ export function threadPostBlocked({
|
||||
key: uri,
|
||||
uri,
|
||||
depth,
|
||||
value: value as AppBskyUnspeccedDefs.ThreadItemBlocked,
|
||||
value: value as app.bsky.unspecced.defs.ThreadItemBlocked,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -69,7 +63,7 @@ export function threadPost({
|
||||
}: {
|
||||
uri: string
|
||||
depth: number
|
||||
value: $Typed<AppBskyUnspeccedDefs.ThreadItemPost>
|
||||
value: $Typed<app.bsky.unspecced.defs.ThreadItemPost>
|
||||
moderationOpts: ModerationOpts
|
||||
threadgateHiddenReplies: Set<string>
|
||||
}): Extract<ThreadItem, {type: 'threadPost'}> {
|
||||
@@ -91,8 +85,8 @@ export function threadPost({
|
||||
* Do not spread anything here, load bearing for post shadow strict
|
||||
* equality reference checks.
|
||||
*/
|
||||
post: value.post as Omit<AppBskyFeedDefs.PostView, 'record'> & {
|
||||
record: AppBskyFeedPost.Record
|
||||
post: value.post as Omit<app.bsky.feed.defs.PostView, 'record'> & {
|
||||
record: app.bsky.feed.post.Main
|
||||
},
|
||||
},
|
||||
isBlurred,
|
||||
@@ -161,10 +155,10 @@ export function skeleton({
|
||||
}
|
||||
|
||||
export function postViewToThreadPlaceholder(
|
||||
post: AppBskyFeedDefs.PostView,
|
||||
post: app.bsky.feed.defs.PostView,
|
||||
): $Typed<
|
||||
Omit<AppBskyUnspeccedGetPostThreadV2.ThreadItem, 'value'> & {
|
||||
value: $Typed<AppBskyUnspeccedDefs.ThreadItemPost>
|
||||
Omit<app.bsky.unspecced.getPostThreadV2.ThreadItem, 'value'> & {
|
||||
value: $Typed<app.bsky.unspecced.defs.ThreadItemPost>
|
||||
}
|
||||
> {
|
||||
return {
|
||||
|
||||
Reference in New Issue
Block a user