Optimistic hidden replies (#4977)
This commit is contained in:
@@ -22,7 +22,7 @@ import {POST_TOMBSTONE, Shadow, usePostShadow} from '#/state/cache/post-shadow'
|
||||
import {useFeedFeedbackContext} from '#/state/feed-feedback'
|
||||
import {useSession} from '#/state/session'
|
||||
import {useComposerControls} from '#/state/shell/composer'
|
||||
import {useThreadgateHiddenReplyUris} from '#/state/threadgate-hidden-replies'
|
||||
import {useMergedThreadgateHiddenReplies} from '#/state/threadgate-hidden-replies'
|
||||
import {isReasonFeedSource, ReasonFeedSource} from 'lib/api/feed/types'
|
||||
import {MAX_POST_LINES} from 'lib/constants'
|
||||
import {usePalette} from 'lib/hooks/usePalette'
|
||||
@@ -227,6 +227,10 @@ let FeedItemInner = ({
|
||||
AppBskyFeedDefs.isReasonRepost(reason) &&
|
||||
reason.by.did === currentAccount?.did
|
||||
|
||||
/**
|
||||
* If `post[0]` in this slice is the actual root post (not an orphan thread),
|
||||
* then we may have a threadgate record to reference
|
||||
*/
|
||||
const threadgateRecord = AppBskyFeedThreadgate.isRecord(
|
||||
rootPost.threadgate?.record,
|
||||
)
|
||||
@@ -422,41 +426,26 @@ let PostContent = ({
|
||||
const [limitLines, setLimitLines] = useState(
|
||||
() => countLines(richText.text) >= MAX_POST_LINES,
|
||||
)
|
||||
const {uris: hiddenReplyUris, recentlyUnhiddenUris} =
|
||||
useThreadgateHiddenReplyUris()
|
||||
const threadgateHiddenReplies = useMergedThreadgateHiddenReplies({
|
||||
threadgateRecord,
|
||||
})
|
||||
const additionalPostAlerts: AppModerationCause[] = React.useMemo(() => {
|
||||
const isPostHiddenByHiddenReplyCache = hiddenReplyUris.has(post.uri)
|
||||
const isPostHiddenByThreadgate =
|
||||
!recentlyUnhiddenUris.has(post.uri) &&
|
||||
!!threadgateRecord?.hiddenReplies?.includes(post.uri)
|
||||
const isHidden = isPostHiddenByHiddenReplyCache || isPostHiddenByThreadgate
|
||||
const isPostHiddenByThreadgate = threadgateHiddenReplies.has(post.uri)
|
||||
const rootPostUri = AppBskyFeedPost.isRecord(post.record)
|
||||
? post.record?.reply?.root?.uri || post.uri
|
||||
: undefined
|
||||
const isControlledByViewer =
|
||||
isPostHiddenByHiddenReplyCache ||
|
||||
(threadgateRecord &&
|
||||
new AtUri(threadgateRecord.post).host === currentAccount?.did)
|
||||
if (!isControlledByViewer) return []
|
||||
const alertSource =
|
||||
threadgateRecord && isPostHiddenByThreadgate
|
||||
? new AtUri(threadgateRecord.post).host
|
||||
: isPostHiddenByHiddenReplyCache
|
||||
? currentAccount?.did
|
||||
: undefined
|
||||
return isHidden && alertSource
|
||||
rootPostUri && new AtUri(rootPostUri).host === currentAccount?.did
|
||||
return isControlledByViewer && isPostHiddenByThreadgate
|
||||
? [
|
||||
{
|
||||
type: 'reply-hidden',
|
||||
source: {type: 'user', did: alertSource},
|
||||
source: {type: 'user', did: currentAccount?.did},
|
||||
priority: 6,
|
||||
},
|
||||
]
|
||||
: []
|
||||
}, [
|
||||
post,
|
||||
hiddenReplyUris,
|
||||
recentlyUnhiddenUris,
|
||||
threadgateRecord,
|
||||
currentAccount?.did,
|
||||
])
|
||||
}, [post, currentAccount?.did, threadgateHiddenReplies])
|
||||
|
||||
const onPressShowMore = React.useCallback(() => {
|
||||
setLimitLines(false)
|
||||
|
||||
Reference in New Issue
Block a user