Thread through threadgate record, validate approach
This commit is contained in:
@@ -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 {useQuery} from '@tanstack/react-query'
|
||||||
|
|
||||||
import {useAgent} from '#/state/session'
|
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,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|||||||
@@ -119,7 +119,7 @@ export function PostThread({
|
|||||||
const rootPostRecord = thread?.type === 'post' ? thread.record : undefined
|
const rootPostRecord = thread?.type === 'post' ? thread.record : undefined
|
||||||
|
|
||||||
const {data: threadgateRecord} = useThreadgateRecordQuery({
|
const {data: threadgateRecord} = useThreadgateRecordQuery({
|
||||||
postUri: uri,
|
postUri: rootPost?.record?.reply?.root?.uri,
|
||||||
initialData: rootPost?.threadgate?.record as AppBskyFeedThreadgate.Record,
|
initialData: rootPost?.threadgate?.record as AppBskyFeedThreadgate.Record,
|
||||||
})
|
})
|
||||||
|
|
||||||
@@ -572,6 +572,10 @@ function* flattenThreadReplies(
|
|||||||
return HiddenReplyType.Hidden
|
return HiddenReplyType.Hidden
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (threadgateRecord?.hiddenReplies?.includes(node.post.uri)) {
|
||||||
|
return HiddenReplyType.Hidden
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!node.ctx.isHighlightedPost) {
|
if (!node.ctx.isHighlightedPost) {
|
||||||
|
|||||||
@@ -392,6 +392,7 @@ let PostThreadItemLoaded = ({
|
|||||||
richText={richText}
|
richText={richText}
|
||||||
onPressReply={onPressReply}
|
onPressReply={onPressReply}
|
||||||
logContext="PostThreadItem"
|
logContext="PostThreadItem"
|
||||||
|
rootPostUri={rootUri}
|
||||||
/>
|
/>
|
||||||
</View>
|
</View>
|
||||||
</View>
|
</View>
|
||||||
@@ -543,6 +544,7 @@ let PostThreadItemLoaded = ({
|
|||||||
richText={richText}
|
richText={richText}
|
||||||
onPressReply={onPressReply}
|
onPressReply={onPressReply}
|
||||||
logContext="PostThreadItem"
|
logContext="PostThreadItem"
|
||||||
|
rootPostUri={rootUri}
|
||||||
/>
|
/>
|
||||||
</View>
|
</View>
|
||||||
</View>
|
</View>
|
||||||
|
|||||||
@@ -31,7 +31,8 @@ import {
|
|||||||
usePostDeleteMutation,
|
usePostDeleteMutation,
|
||||||
useThreadMuteMutationQueue,
|
useThreadMuteMutationQueue,
|
||||||
} from '#/state/queries/post'
|
} from '#/state/queries/post'
|
||||||
import {useSession} from '#/state/session'
|
import {createThreadgate} from '#/state/queries/threadgate'
|
||||||
|
import {useAgent, useSession} from '#/state/session'
|
||||||
import {getCurrentRoute} from 'lib/routes/helpers'
|
import {getCurrentRoute} from 'lib/routes/helpers'
|
||||||
import {shareUrl} from 'lib/sharing'
|
import {shareUrl} from 'lib/sharing'
|
||||||
import {toShareUrl} from 'lib/strings/url-helpers'
|
import {toShareUrl} from 'lib/strings/url-helpers'
|
||||||
@@ -73,6 +74,7 @@ let PostDropdownBtn = ({
|
|||||||
hitSlop,
|
hitSlop,
|
||||||
size,
|
size,
|
||||||
timestamp,
|
timestamp,
|
||||||
|
rootPostUri,
|
||||||
}: {
|
}: {
|
||||||
testID: string
|
testID: string
|
||||||
post: Shadow<AppBskyFeedDefs.PostView>
|
post: Shadow<AppBskyFeedDefs.PostView>
|
||||||
@@ -83,8 +85,10 @@ let PostDropdownBtn = ({
|
|||||||
hitSlop?: PressableProps['hitSlop']
|
hitSlop?: PressableProps['hitSlop']
|
||||||
size?: 'lg' | 'md' | 'sm'
|
size?: 'lg' | 'md' | 'sm'
|
||||||
timestamp: string
|
timestamp: string
|
||||||
|
rootPostUri?: string
|
||||||
}): React.ReactNode => {
|
}): React.ReactNode => {
|
||||||
const {hasSession, currentAccount} = useSession()
|
const {hasSession, currentAccount} = useSession()
|
||||||
|
const agent = useAgent()
|
||||||
const theme = useTheme()
|
const theme = useTheme()
|
||||||
const alf = useAlf()
|
const alf = useAlf()
|
||||||
const {gtMobile} = useBreakpoints()
|
const {gtMobile} = useBreakpoints()
|
||||||
@@ -393,6 +397,24 @@ let PostDropdownBtn = ({
|
|||||||
<Menu.ItemIcon icon={EyeSlash} position="right" />
|
<Menu.ItemIcon icon={EyeSlash} position="right" />
|
||||||
</Menu.Item>
|
</Menu.Item>
|
||||||
)}
|
)}
|
||||||
|
|
||||||
|
{!isAuthor && !isPostHidden && rootPostUri && (
|
||||||
|
<Menu.Item
|
||||||
|
testID="postDropdownHideBtn"
|
||||||
|
label={_(msg`Hide reply`)}
|
||||||
|
onPress={() => {
|
||||||
|
createThreadgate({
|
||||||
|
agent,
|
||||||
|
postUri: rootPostUri,
|
||||||
|
threadgate: {
|
||||||
|
hiddenReplies: [postUri],
|
||||||
|
},
|
||||||
|
})
|
||||||
|
}}>
|
||||||
|
<Menu.ItemText>{_(msg`Hide reply`)}</Menu.ItemText>
|
||||||
|
<Menu.ItemIcon icon={EyeSlash} position="right" />
|
||||||
|
</Menu.Item>
|
||||||
|
)}
|
||||||
</Menu.Group>
|
</Menu.Group>
|
||||||
</>
|
</>
|
||||||
)}
|
)}
|
||||||
|
|||||||
@@ -59,6 +59,7 @@ let PostCtrls = ({
|
|||||||
style,
|
style,
|
||||||
onPressReply,
|
onPressReply,
|
||||||
logContext,
|
logContext,
|
||||||
|
rootPostUri,
|
||||||
}: {
|
}: {
|
||||||
big?: boolean
|
big?: boolean
|
||||||
post: Shadow<AppBskyFeedDefs.PostView>
|
post: Shadow<AppBskyFeedDefs.PostView>
|
||||||
@@ -68,6 +69,7 @@ let PostCtrls = ({
|
|||||||
style?: StyleProp<ViewStyle>
|
style?: StyleProp<ViewStyle>
|
||||||
onPressReply: () => void
|
onPressReply: () => void
|
||||||
logContext: 'FeedItem' | 'PostThreadItem' | 'Post'
|
logContext: 'FeedItem' | 'PostThreadItem' | 'Post'
|
||||||
|
rootPostUri?: string
|
||||||
}): React.ReactNode => {
|
}): React.ReactNode => {
|
||||||
const t = useTheme()
|
const t = useTheme()
|
||||||
const {_} = useLingui()
|
const {_} = useLingui()
|
||||||
@@ -338,6 +340,7 @@ let PostCtrls = ({
|
|||||||
style={{padding: 5}}
|
style={{padding: 5}}
|
||||||
hitSlop={POST_CTRL_HITSLOP}
|
hitSlop={POST_CTRL_HITSLOP}
|
||||||
timestamp={post.indexedAt}
|
timestamp={post.indexedAt}
|
||||||
|
rootPostUri={rootPostUri}
|
||||||
/>
|
/>
|
||||||
</View>
|
</View>
|
||||||
{gate('debug_show_feedcontext') && feedContext && (
|
{gate('debug_show_feedcontext') && feedContext && (
|
||||||
|
|||||||
Reference in New Issue
Block a user