Prep threadgate shadow hack (#4970)
Co-authored-by: Hailey <me@haileyok.com>
This commit is contained in:
parent
61f0be705d
commit
d5c78b9183
6 changed files with 68 additions and 23 deletions
13
src/state/cache/post-shadow.ts
vendored
13
src/state/cache/post-shadow.ts
vendored
|
@ -21,6 +21,7 @@ export interface PostShadow {
|
|||
repostUri: string | undefined
|
||||
isDeleted: boolean
|
||||
embed: AppBskyEmbedRecord.View | AppBskyEmbedRecordWithMedia.View | undefined
|
||||
threadgateView: AppBskyFeedDefs.ThreadgateView | undefined
|
||||
}
|
||||
|
||||
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({
|
||||
...post,
|
||||
embed: embed || post.embed,
|
||||
|
@ -114,6 +125,8 @@ function mergeShadow(
|
|||
like: 'likeUri' in shadow ? shadow.likeUri : post.viewer?.like,
|
||||
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 {until} from '#/lib/async/until'
|
||||
import {updatePostShadow} from '#/state/cache/post-shadow'
|
||||
import {STALE} from '#/state/queries'
|
||||
import {RQKEY_ROOT as postThreadQueryKeyRoot} from '#/state/queries/post-thread'
|
||||
import {ThreadgateAllowUISetting} from '#/state/queries/threadgate/types'
|
||||
import {
|
||||
createTempThreadgateView,
|
||||
createThreadgateRecord,
|
||||
mergeThreadgateRecords,
|
||||
threadgateAllowUISettingToAllowRecordValue,
|
||||
|
@ -342,17 +344,26 @@ export function useToggleReplyVisibilityMutation() {
|
|||
}
|
||||
})
|
||||
},
|
||||
onSuccess() {
|
||||
onSuccess(_, {postUri, replyUri}) {
|
||||
updatePostShadow(queryClient, postUri, {
|
||||
threadgateView: createTempThreadgateView({
|
||||
postUri,
|
||||
hiddenReplies: [replyUri],
|
||||
}),
|
||||
})
|
||||
queryClient.invalidateQueries({
|
||||
queryKey: [threadgateRecordQueryKeyRoot],
|
||||
})
|
||||
},
|
||||
onError(_, {replyUri, action}) {
|
||||
onError(_, {postUri, replyUri, action}) {
|
||||
if (action === 'hide') {
|
||||
hiddenReplies.removeHiddenReplyUri(replyUri)
|
||||
} else if (action === 'show') {
|
||||
hiddenReplies.addHiddenReplyUri(replyUri)
|
||||
}
|
||||
updatePostShadow(queryClient, postUri, {
|
||||
threadgateView: undefined,
|
||||
})
|
||||
},
|
||||
})
|
||||
}
|
||||
|
|
|
@ -139,3 +139,23 @@ export function createThreadgateRecord(
|
|||
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,
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue