parent
61f0be705d
commit
d5c78b9183
|
@ -21,6 +21,7 @@ export interface PostShadow {
|
||||||
repostUri: string | undefined
|
repostUri: string | undefined
|
||||||
isDeleted: boolean
|
isDeleted: boolean
|
||||||
embed: AppBskyEmbedRecord.View | AppBskyEmbedRecordWithMedia.View | undefined
|
embed: AppBskyEmbedRecord.View | AppBskyEmbedRecordWithMedia.View | undefined
|
||||||
|
threadgateView: AppBskyFeedDefs.ThreadgateView | undefined
|
||||||
}
|
}
|
||||||
|
|
||||||
export const POST_TOMBSTONE = Symbol('PostTombstone')
|
export const POST_TOMBSTONE = Symbol('PostTombstone')
|
||||||
|
@ -104,6 +105,16 @@ function mergeShadow(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let threadgateView: typeof post.threadgate
|
||||||
|
if ('threadgateView' in shadow && !post.threadgate) {
|
||||||
|
if (
|
||||||
|
AppBskyFeedDefs.isThreadgateView(shadow.threadgateView) ||
|
||||||
|
shadow.threadgateView === undefined
|
||||||
|
) {
|
||||||
|
threadgateView = shadow.threadgateView
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return castAsShadow({
|
return castAsShadow({
|
||||||
...post,
|
...post,
|
||||||
embed: embed || post.embed,
|
embed: embed || post.embed,
|
||||||
|
@ -114,6 +125,8 @@ function mergeShadow(
|
||||||
like: 'likeUri' in shadow ? shadow.likeUri : post.viewer?.like,
|
like: 'likeUri' in shadow ? shadow.likeUri : post.viewer?.like,
|
||||||
repost: 'repostUri' in shadow ? shadow.repostUri : post.viewer?.repost,
|
repost: 'repostUri' in shadow ? shadow.repostUri : post.viewer?.repost,
|
||||||
},
|
},
|
||||||
|
// always prefer real post data
|
||||||
|
threadgate: post.threadgate || threadgateView,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -9,10 +9,12 @@ import {useMutation, useQuery, useQueryClient} from '@tanstack/react-query'
|
||||||
|
|
||||||
import {networkRetry, retry} from '#/lib/async/retry'
|
import {networkRetry, retry} from '#/lib/async/retry'
|
||||||
import {until} from '#/lib/async/until'
|
import {until} from '#/lib/async/until'
|
||||||
|
import {updatePostShadow} from '#/state/cache/post-shadow'
|
||||||
import {STALE} from '#/state/queries'
|
import {STALE} from '#/state/queries'
|
||||||
import {RQKEY_ROOT as postThreadQueryKeyRoot} from '#/state/queries/post-thread'
|
import {RQKEY_ROOT as postThreadQueryKeyRoot} from '#/state/queries/post-thread'
|
||||||
import {ThreadgateAllowUISetting} from '#/state/queries/threadgate/types'
|
import {ThreadgateAllowUISetting} from '#/state/queries/threadgate/types'
|
||||||
import {
|
import {
|
||||||
|
createTempThreadgateView,
|
||||||
createThreadgateRecord,
|
createThreadgateRecord,
|
||||||
mergeThreadgateRecords,
|
mergeThreadgateRecords,
|
||||||
threadgateAllowUISettingToAllowRecordValue,
|
threadgateAllowUISettingToAllowRecordValue,
|
||||||
|
@ -342,17 +344,26 @@ export function useToggleReplyVisibilityMutation() {
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
onSuccess() {
|
onSuccess(_, {postUri, replyUri}) {
|
||||||
|
updatePostShadow(queryClient, postUri, {
|
||||||
|
threadgateView: createTempThreadgateView({
|
||||||
|
postUri,
|
||||||
|
hiddenReplies: [replyUri],
|
||||||
|
}),
|
||||||
|
})
|
||||||
queryClient.invalidateQueries({
|
queryClient.invalidateQueries({
|
||||||
queryKey: [threadgateRecordQueryKeyRoot],
|
queryKey: [threadgateRecordQueryKeyRoot],
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
onError(_, {replyUri, action}) {
|
onError(_, {postUri, replyUri, action}) {
|
||||||
if (action === 'hide') {
|
if (action === 'hide') {
|
||||||
hiddenReplies.removeHiddenReplyUri(replyUri)
|
hiddenReplies.removeHiddenReplyUri(replyUri)
|
||||||
} else if (action === 'show') {
|
} else if (action === 'show') {
|
||||||
hiddenReplies.addHiddenReplyUri(replyUri)
|
hiddenReplies.addHiddenReplyUri(replyUri)
|
||||||
}
|
}
|
||||||
|
updatePostShadow(queryClient, postUri, {
|
||||||
|
threadgateView: undefined,
|
||||||
|
})
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
|
@ -139,3 +139,23 @@ export function createThreadgateRecord(
|
||||||
hiddenReplies: threadgate.hiddenReplies || [],
|
hiddenReplies: threadgate.hiddenReplies || [],
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function createTempThreadgateView({
|
||||||
|
postUri,
|
||||||
|
hiddenReplies,
|
||||||
|
}: Pick<AppBskyFeedThreadgate.Record, 'hiddenReplies'> & {
|
||||||
|
postUri: string
|
||||||
|
}): AppBskyFeedDefs.ThreadgateView {
|
||||||
|
const record: AppBskyFeedThreadgate.Record = {
|
||||||
|
$type: 'app.bsky.feed.threadgate',
|
||||||
|
post: postUri,
|
||||||
|
allow: undefined,
|
||||||
|
hiddenReplies,
|
||||||
|
createdAt: new Date().toISOString(),
|
||||||
|
}
|
||||||
|
return {
|
||||||
|
$type: 'app.bsky.feed.defs#threadgateView',
|
||||||
|
uri: postUri,
|
||||||
|
record,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -129,17 +129,18 @@ export function PostThread({uri}: {uri: string | undefined}) {
|
||||||
currentAccount &&
|
currentAccount &&
|
||||||
rootPostUri &&
|
rootPostUri &&
|
||||||
currentAccount?.did === new AtUri(rootPostUri).host
|
currentAccount?.did === new AtUri(rootPostUri).host
|
||||||
|
const initialThreadgateRecord = rootPost?.threadgate?.record as
|
||||||
|
| AppBskyFeedThreadgate.Record
|
||||||
|
| undefined
|
||||||
const {data: threadgateRecord} = useThreadgateRecordQuery({
|
const {data: threadgateRecord} = useThreadgateRecordQuery({
|
||||||
/**
|
/**
|
||||||
* If the user is the OP and the root post has a threadgate, we should load
|
* If the user is the OP and the root post has a threadgate, we should load
|
||||||
* the threadgate record. Otherwise, fallback to initialData, which is taken
|
* the threadgate record. Otherwise, fallback to initialData, which is taken
|
||||||
* from the response from `getPostThread`.
|
* from the response from `getPostThread`.
|
||||||
*/
|
*/
|
||||||
enabled: Boolean(isOP && rootPostUri),
|
enabled: Boolean(isOP && rootPostUri && initialThreadgateRecord),
|
||||||
postUri: rootPostUri,
|
postUri: rootPostUri,
|
||||||
initialData: rootPost?.threadgate?.record as
|
initialData: initialThreadgateRecord,
|
||||||
| AppBskyFeedThreadgate.Record
|
|
||||||
| undefined,
|
|
||||||
})
|
})
|
||||||
|
|
||||||
const moderationOpts = useModerationOpts()
|
const moderationOpts = useModerationOpts()
|
||||||
|
|
|
@ -399,22 +399,6 @@ let PostThreadItemLoaded = ({
|
||||||
</Text>
|
</Text>
|
||||||
</Link>
|
</Link>
|
||||||
) : null}
|
) : null}
|
||||||
{post.likeCount != null && post.likeCount !== 0 ? (
|
|
||||||
<Link
|
|
||||||
style={styles.expandedInfoItem}
|
|
||||||
href={likesHref}
|
|
||||||
title={likesTitle}>
|
|
||||||
<Text
|
|
||||||
testID="likeCount-expanded"
|
|
||||||
type="lg"
|
|
||||||
style={pal.textLight}>
|
|
||||||
<Text type="xl-bold" style={pal.text}>
|
|
||||||
{formatCount(post.likeCount)}
|
|
||||||
</Text>{' '}
|
|
||||||
<Plural value={post.likeCount} one="like" other="likes" />
|
|
||||||
</Text>
|
|
||||||
</Link>
|
|
||||||
) : null}
|
|
||||||
{post.quoteCount != null && post.quoteCount !== 0 ? (
|
{post.quoteCount != null && post.quoteCount !== 0 ? (
|
||||||
<Link
|
<Link
|
||||||
style={styles.expandedInfoItem}
|
style={styles.expandedInfoItem}
|
||||||
|
@ -435,6 +419,22 @@ let PostThreadItemLoaded = ({
|
||||||
</Text>
|
</Text>
|
||||||
</Link>
|
</Link>
|
||||||
) : null}
|
) : null}
|
||||||
|
{post.likeCount != null && post.likeCount !== 0 ? (
|
||||||
|
<Link
|
||||||
|
style={styles.expandedInfoItem}
|
||||||
|
href={likesHref}
|
||||||
|
title={likesTitle}>
|
||||||
|
<Text
|
||||||
|
testID="likeCount-expanded"
|
||||||
|
type="lg"
|
||||||
|
style={pal.textLight}>
|
||||||
|
<Text type="xl-bold" style={pal.text}>
|
||||||
|
{formatCount(post.likeCount)}
|
||||||
|
</Text>{' '}
|
||||||
|
<Plural value={post.likeCount} one="like" other="likes" />
|
||||||
|
</Text>
|
||||||
|
</Link>
|
||||||
|
) : null}
|
||||||
</View>
|
</View>
|
||||||
) : null}
|
) : null}
|
||||||
<View style={[s.pl10, s.pr10]}>
|
<View style={[s.pl10, s.pr10]}>
|
||||||
|
|
|
@ -255,7 +255,7 @@ let PostCtrls = ({
|
||||||
<View style={big ? a.align_center : [a.flex_1, a.align_start]}>
|
<View style={big ? a.align_center : [a.flex_1, a.align_start]}>
|
||||||
<RepostButton
|
<RepostButton
|
||||||
isReposted={!!post.viewer?.repost}
|
isReposted={!!post.viewer?.repost}
|
||||||
repostCount={post.repostCount}
|
repostCount={(post.repostCount ?? 0) + (post.quoteCount ?? 0)}
|
||||||
onRepost={onRepost}
|
onRepost={onRepost}
|
||||||
onQuote={onQuote}
|
onQuote={onQuote}
|
||||||
big={big}
|
big={big}
|
||||||
|
|
Loading…
Reference in New Issue