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,
)
}
+5 -1
View File
@@ -119,7 +119,7 @@ export function PostThread({
const rootPostRecord = thread?.type === 'post' ? thread.record : undefined
const {data: threadgateRecord} = useThreadgateRecordQuery({
postUri: uri,
postUri: rootPost?.record?.reply?.root?.uri,
initialData: rootPost?.threadgate?.record as AppBskyFeedThreadgate.Record,
})
@@ -572,6 +572,10 @@ function* flattenThreadReplies(
return HiddenReplyType.Hidden
}
}
if (threadgateRecord?.hiddenReplies?.includes(node.post.uri)) {
return HiddenReplyType.Hidden
}
}
if (!node.ctx.isHighlightedPost) {
@@ -392,6 +392,7 @@ let PostThreadItemLoaded = ({
richText={richText}
onPressReply={onPressReply}
logContext="PostThreadItem"
rootPostUri={rootUri}
/>
</View>
</View>
@@ -543,6 +544,7 @@ let PostThreadItemLoaded = ({
richText={richText}
onPressReply={onPressReply}
logContext="PostThreadItem"
rootPostUri={rootUri}
/>
</View>
</View>
+23 -1
View File
@@ -31,7 +31,8 @@ import {
usePostDeleteMutation,
useThreadMuteMutationQueue,
} 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 {shareUrl} from 'lib/sharing'
import {toShareUrl} from 'lib/strings/url-helpers'
@@ -73,6 +74,7 @@ let PostDropdownBtn = ({
hitSlop,
size,
timestamp,
rootPostUri,
}: {
testID: string
post: Shadow<AppBskyFeedDefs.PostView>
@@ -83,8 +85,10 @@ let PostDropdownBtn = ({
hitSlop?: PressableProps['hitSlop']
size?: 'lg' | 'md' | 'sm'
timestamp: string
rootPostUri?: string
}): React.ReactNode => {
const {hasSession, currentAccount} = useSession()
const agent = useAgent()
const theme = useTheme()
const alf = useAlf()
const {gtMobile} = useBreakpoints()
@@ -393,6 +397,24 @@ let PostDropdownBtn = ({
<Menu.ItemIcon icon={EyeSlash} position="right" />
</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>
</>
)}
@@ -59,6 +59,7 @@ let PostCtrls = ({
style,
onPressReply,
logContext,
rootPostUri,
}: {
big?: boolean
post: Shadow<AppBskyFeedDefs.PostView>
@@ -68,6 +69,7 @@ let PostCtrls = ({
style?: StyleProp<ViewStyle>
onPressReply: () => void
logContext: 'FeedItem' | 'PostThreadItem' | 'Post'
rootPostUri?: string
}): React.ReactNode => {
const t = useTheme()
const {_} = useLingui()
@@ -338,6 +340,7 @@ let PostCtrls = ({
style={{padding: 5}}
hitSlop={POST_CTRL_HITSLOP}
timestamp={post.indexedAt}
rootPostUri={rootPostUri}
/>
</View>
{gate('debug_show_feedcontext') && feedContext && (