Split up thread post components
This commit is contained in:
@@ -1051,4 +1051,8 @@ export const atoms = {
|
|||||||
transform: [],
|
transform: [],
|
||||||
},
|
},
|
||||||
}) as {transform: Exclude<ViewStyle['transform'], string | undefined>},
|
}) as {transform: Exclude<ViewStyle['transform'], string | undefined>},
|
||||||
|
|
||||||
|
pointer: web({
|
||||||
|
cursor: 'pointer',
|
||||||
|
}),
|
||||||
} as const
|
} as const
|
||||||
|
|||||||
@@ -1,9 +1,10 @@
|
|||||||
import {View} from 'react-native'
|
import {View} from 'react-native'
|
||||||
import {msg, Trans, Plural} from '@lingui/macro'
|
import {msg, Plural,Trans} from '@lingui/macro'
|
||||||
import {useLingui} from '@lingui/react'
|
import {useLingui} from '@lingui/react'
|
||||||
|
|
||||||
import {makeProfileLink} from '#/lib/routes/links'
|
import {makeProfileLink} from '#/lib/routes/links'
|
||||||
import {type Slice, PostThreadParams} from '#/state/queries/usePostThread'
|
import {type PostThreadParams,type Slice} from '#/state/queries/usePostThread'
|
||||||
|
import {TREE_INDENT} from '#/screens/PostThread/const'
|
||||||
import {atoms as a, useTheme} from '#/alf'
|
import {atoms as a, useTheme} from '#/alf'
|
||||||
import {CirclePlus_Stroke2_Corner0_Rounded as CirclePlus} from '#/components/icons/CirclePlus'
|
import {CirclePlus_Stroke2_Corner0_Rounded as CirclePlus} from '#/components/icons/CirclePlus'
|
||||||
import {Link} from '#/components/Link'
|
import {Link} from '#/components/Link'
|
||||||
@@ -26,11 +27,10 @@ export function ReadMore({
|
|||||||
<View
|
<View
|
||||||
key={`${item.key}-padding-${n}`}
|
key={`${item.key}-padding-${n}`}
|
||||||
style={[
|
style={[
|
||||||
a.ml_sm,
|
|
||||||
t.atoms.border_contrast_low,
|
t.atoms.border_contrast_low,
|
||||||
{
|
{
|
||||||
borderLeftWidth: 2,
|
borderRightWidth: 2,
|
||||||
paddingLeft: a.pl_sm.paddingLeft - 2, // minus border
|
width: TREE_INDENT,
|
||||||
},
|
},
|
||||||
]}
|
]}
|
||||||
/>
|
/>
|
||||||
@@ -45,22 +45,21 @@ export function ReadMore({
|
|||||||
) : null
|
) : null
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<View style={[a.flex_row, a.px_sm]}>
|
<View style={[a.flex_row]}>
|
||||||
{treeIndents}
|
{treeIndents}
|
||||||
<View style={[a.ml_sm]}>
|
<View
|
||||||
<View
|
style={[
|
||||||
style={[
|
t.atoms.border_contrast_low,
|
||||||
t.atoms.border_contrast_low,
|
{
|
||||||
{
|
marginLeft: isTreeView ? TREE_INDENT - 2 : TREE_INDENT,
|
||||||
borderLeftWidth: 2,
|
borderLeftWidth: 2,
|
||||||
borderBottomWidth: 2,
|
borderBottomWidth: 2,
|
||||||
borderBottomLeftRadius: a.rounded_sm.borderRadius,
|
borderBottomLeftRadius: a.rounded_sm.borderRadius,
|
||||||
height: 12,
|
height: 12,
|
||||||
width: isTreeView ? a.pl_sm.paddingLeft * 2 : 42 / 2 + 10,
|
width: isTreeView ? TREE_INDENT : 42 / 2 + 10,
|
||||||
},
|
},
|
||||||
]}
|
]}
|
||||||
/>
|
/>
|
||||||
</View>
|
|
||||||
<Link
|
<Link
|
||||||
label={_(msg`Read more replies`)}
|
label={_(msg`Read more replies`)}
|
||||||
to={makeProfileLink(
|
to={makeProfileLink(
|
||||||
|
|||||||
@@ -0,0 +1,576 @@
|
|||||||
|
import React, {useMemo} from 'react'
|
||||||
|
import {type GestureResponderEvent, Text as RNText, View} from 'react-native'
|
||||||
|
import {
|
||||||
|
type AppBskyFeedDefs,
|
||||||
|
AppBskyFeedPost,
|
||||||
|
type AppBskyFeedThreadgate,
|
||||||
|
AtUri,
|
||||||
|
RichText as RichTextAPI,
|
||||||
|
} from '@atproto/api'
|
||||||
|
import {msg, Plural, Trans} from '@lingui/macro'
|
||||||
|
import {useLingui} from '@lingui/react'
|
||||||
|
|
||||||
|
import {useActorStatus} from '#/lib/actor-status'
|
||||||
|
import {useOpenComposer} from '#/lib/hooks/useOpenComposer'
|
||||||
|
import {useOpenLink} from '#/lib/hooks/useOpenLink'
|
||||||
|
import {usePalette} from '#/lib/hooks/usePalette'
|
||||||
|
import {makeProfileLink} from '#/lib/routes/links'
|
||||||
|
import {sanitizeDisplayName} from '#/lib/strings/display-names'
|
||||||
|
import {sanitizeHandle} from '#/lib/strings/handles'
|
||||||
|
import {niceDate} from '#/lib/strings/time'
|
||||||
|
import {s} from '#/lib/styles'
|
||||||
|
import {getTranslatorLink, isPostInLanguage} from '#/locale/helpers'
|
||||||
|
import {logger} from '#/logger'
|
||||||
|
import {
|
||||||
|
POST_TOMBSTONE,
|
||||||
|
type Shadow,
|
||||||
|
usePostShadow,
|
||||||
|
} from '#/state/cache/post-shadow'
|
||||||
|
import {useProfileShadow} from '#/state/cache/profile-shadow'
|
||||||
|
import {useLanguagePrefs} from '#/state/preferences'
|
||||||
|
import {type Slice} from '#/state/queries/usePostThread/types'
|
||||||
|
import {useSession} from '#/state/session'
|
||||||
|
import {type OnPostSuccessData} from '#/state/shell/composer'
|
||||||
|
import {useMergedThreadgateHiddenReplies} from '#/state/threadgate-hidden-replies'
|
||||||
|
import {PostThreadFollowBtn} from '#/view/com/post-thread/PostThreadFollowBtn'
|
||||||
|
import {Link} from '#/view/com/util/Link'
|
||||||
|
import {formatCount} from '#/view/com/util/numeric/format'
|
||||||
|
import {PostCtrls} from '#/view/com/util/post-ctrls/PostCtrls'
|
||||||
|
import {PostEmbeds, PostEmbedViewContext} from '#/view/com/util/post-embeds'
|
||||||
|
import {PreviewableUserAvatar} from '#/view/com/util/UserAvatar'
|
||||||
|
import {atoms as a, useTheme} from '#/alf'
|
||||||
|
import {colors} from '#/components/Admonition'
|
||||||
|
import {Button} from '#/components/Button'
|
||||||
|
import {CalendarClock_Stroke2_Corner0_Rounded as CalendarClockIcon} from '#/components/icons/CalendarClock'
|
||||||
|
import {Trash_Stroke2_Corner0_Rounded as TrashIcon} from '#/components/icons/Trash'
|
||||||
|
import {InlineLinkText} from '#/components/Link'
|
||||||
|
import {ContentHider} from '#/components/moderation/ContentHider'
|
||||||
|
import {LabelsOnMyPost} from '#/components/moderation/LabelsOnMe'
|
||||||
|
import {PostAlerts} from '#/components/moderation/PostAlerts'
|
||||||
|
import {type AppModerationCause} from '#/components/Pills'
|
||||||
|
import * as Prompt from '#/components/Prompt'
|
||||||
|
import {RichText} from '#/components/RichText'
|
||||||
|
import {Text} from '#/components/Typography'
|
||||||
|
import {VerificationCheckButton} from '#/components/verification/VerificationCheckButton'
|
||||||
|
import {WhoCanReply} from '#/components/WhoCanReply'
|
||||||
|
import * as bsky from '#/types/bsky'
|
||||||
|
|
||||||
|
export function ThreadAnchor({
|
||||||
|
item,
|
||||||
|
onPostSuccess,
|
||||||
|
threadgateRecord,
|
||||||
|
}: {
|
||||||
|
item: Extract<Slice, {type: 'threadPost'}>
|
||||||
|
onPostSuccess?: (data: OnPostSuccessData) => void
|
||||||
|
threadgateRecord?: AppBskyFeedThreadgate.Record
|
||||||
|
}) {
|
||||||
|
const postShadow = usePostShadow(item.value.post)
|
||||||
|
|
||||||
|
if (postShadow === POST_TOMBSTONE) {
|
||||||
|
return <PostThreadItemDeleted />
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<PostThreadItemLoaded
|
||||||
|
// Safeguard from clobbering per-post state below:
|
||||||
|
key={postShadow.uri}
|
||||||
|
item={item}
|
||||||
|
postShadow={postShadow}
|
||||||
|
onPostSuccess={onPostSuccess}
|
||||||
|
threadgateRecord={threadgateRecord}
|
||||||
|
/>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
function PostThreadItemDeleted({hideTopBorder}: {hideTopBorder?: boolean}) {
|
||||||
|
const t = useTheme()
|
||||||
|
return (
|
||||||
|
<View
|
||||||
|
style={[
|
||||||
|
t.atoms.bg,
|
||||||
|
t.atoms.border_contrast_low,
|
||||||
|
a.p_xl,
|
||||||
|
a.pl_lg,
|
||||||
|
a.flex_row,
|
||||||
|
a.gap_md,
|
||||||
|
!hideTopBorder && a.border_t,
|
||||||
|
]}>
|
||||||
|
<TrashIcon style={[t.atoms.text]} />
|
||||||
|
<Text style={[t.atoms.text_contrast_medium, a.mt_2xs]}>
|
||||||
|
<Trans>This post has been deleted.</Trans>
|
||||||
|
</Text>
|
||||||
|
</View>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
let PostThreadItemLoaded = ({
|
||||||
|
item,
|
||||||
|
postShadow,
|
||||||
|
onPostSuccess,
|
||||||
|
threadgateRecord,
|
||||||
|
}: {
|
||||||
|
item: Extract<Slice, {type: 'threadPost'}>
|
||||||
|
postShadow: Shadow<AppBskyFeedDefs.PostView>
|
||||||
|
onPostSuccess?: (data: OnPostSuccessData) => void
|
||||||
|
threadgateRecord?: AppBskyFeedThreadgate.Record
|
||||||
|
}): React.ReactNode => {
|
||||||
|
const t = useTheme()
|
||||||
|
const {_, i18n} = useLingui()
|
||||||
|
const {openComposer} = useOpenComposer()
|
||||||
|
const {currentAccount} = useSession()
|
||||||
|
|
||||||
|
const post = item.value.post
|
||||||
|
const record = item.value.post.record
|
||||||
|
const moderation = item.moderation
|
||||||
|
const authorShadow = useProfileShadow(post.author)
|
||||||
|
const {isActive: live} = useActorStatus(post.author)
|
||||||
|
const richText = useMemo(
|
||||||
|
() =>
|
||||||
|
new RichTextAPI({
|
||||||
|
text: record.text,
|
||||||
|
facets: record.facets,
|
||||||
|
}),
|
||||||
|
[record],
|
||||||
|
)
|
||||||
|
|
||||||
|
// TODO
|
||||||
|
const pal = usePalette('default')
|
||||||
|
const threadRootUri = record.reply?.root?.uri || post.uri
|
||||||
|
const isThreadRoot = threadRootUri === post.uri
|
||||||
|
const authorHref = makeProfileLink(post.author)
|
||||||
|
const authorTitle = post.author.handle
|
||||||
|
const isThreadAuthor = getThreadAuthor(post, record) === currentAccount?.did
|
||||||
|
|
||||||
|
const likesHref = React.useMemo(() => {
|
||||||
|
const urip = new AtUri(post.uri)
|
||||||
|
return makeProfileLink(post.author, 'post', urip.rkey, 'liked-by')
|
||||||
|
}, [post.uri, post.author])
|
||||||
|
const repostsHref = React.useMemo(() => {
|
||||||
|
const urip = new AtUri(post.uri)
|
||||||
|
return makeProfileLink(post.author, 'post', urip.rkey, 'reposted-by')
|
||||||
|
}, [post.uri, post.author])
|
||||||
|
const quotesHref = React.useMemo(() => {
|
||||||
|
const urip = new AtUri(post.uri)
|
||||||
|
return makeProfileLink(post.author, 'post', urip.rkey, 'quotes')
|
||||||
|
}, [post.uri, post.author])
|
||||||
|
|
||||||
|
const threadgateHiddenReplies = useMergedThreadgateHiddenReplies({
|
||||||
|
threadgateRecord,
|
||||||
|
})
|
||||||
|
const additionalPostAlerts: AppModerationCause[] = React.useMemo(() => {
|
||||||
|
const isPostHiddenByThreadgate = threadgateHiddenReplies.has(post.uri)
|
||||||
|
const isControlledByViewer =
|
||||||
|
new AtUri(threadRootUri).host === currentAccount?.did
|
||||||
|
return isControlledByViewer && isPostHiddenByThreadgate
|
||||||
|
? [
|
||||||
|
{
|
||||||
|
type: 'reply-hidden',
|
||||||
|
source: {type: 'user', did: currentAccount?.did},
|
||||||
|
priority: 6,
|
||||||
|
},
|
||||||
|
]
|
||||||
|
: []
|
||||||
|
}, [post, currentAccount?.did, threadgateHiddenReplies, threadRootUri])
|
||||||
|
const onlyFollowersCanReply = !!threadgateRecord?.allow?.find(
|
||||||
|
rule => rule.$type === 'app.bsky.feed.threadgate#followerRule',
|
||||||
|
)
|
||||||
|
const showFollowButton =
|
||||||
|
currentAccount?.did !== post.author.did && !onlyFollowersCanReply
|
||||||
|
|
||||||
|
const onPressReply = React.useCallback(() => {
|
||||||
|
openComposer({
|
||||||
|
replyTo: {
|
||||||
|
uri: post.uri,
|
||||||
|
cid: post.cid,
|
||||||
|
text: record.text,
|
||||||
|
author: post.author,
|
||||||
|
embed: post.embed,
|
||||||
|
moderation,
|
||||||
|
},
|
||||||
|
onPostSuccess: onPostSuccess,
|
||||||
|
})
|
||||||
|
}, [openComposer, post, record, onPostSuccess, moderation])
|
||||||
|
|
||||||
|
return (
|
||||||
|
<>
|
||||||
|
{!isThreadRoot && (
|
||||||
|
<View
|
||||||
|
style={[a.pl_lg, a.flex_row, a.pb_xs, {height: a.pt_lg.paddingTop}]}>
|
||||||
|
<View style={{width: 42}}>
|
||||||
|
<View
|
||||||
|
style={[
|
||||||
|
{
|
||||||
|
width: 2,
|
||||||
|
marginLeft: 'auto',
|
||||||
|
marginRight: 'auto',
|
||||||
|
flexGrow: 1,
|
||||||
|
backgroundColor: pal.colors.replyLine,
|
||||||
|
},
|
||||||
|
]}
|
||||||
|
/>
|
||||||
|
</View>
|
||||||
|
</View>
|
||||||
|
)}
|
||||||
|
|
||||||
|
<View
|
||||||
|
testID={`postThreadItem-by-${post.author.handle}`}
|
||||||
|
style={[
|
||||||
|
a.px_lg,
|
||||||
|
t.atoms.border_contrast_low,
|
||||||
|
isThreadRoot && [a.pt_lg],
|
||||||
|
]}>
|
||||||
|
<View style={[a.flex_row, a.gap_md, a.pb_md]}>
|
||||||
|
<PreviewableUserAvatar
|
||||||
|
size={42}
|
||||||
|
profile={post.author}
|
||||||
|
moderation={moderation.ui('avatar')}
|
||||||
|
type={post.author.associated?.labeler ? 'labeler' : 'user'}
|
||||||
|
live={live}
|
||||||
|
/>
|
||||||
|
<View style={[a.flex_1]}>
|
||||||
|
<View style={[a.flex_row, a.align_center]}>
|
||||||
|
<Link
|
||||||
|
style={[a.flex_shrink]}
|
||||||
|
href={authorHref}
|
||||||
|
title={authorTitle}>
|
||||||
|
<Text
|
||||||
|
emoji
|
||||||
|
style={[a.text_lg, a.font_bold, a.leading_snug, a.self_start]}
|
||||||
|
numberOfLines={1}>
|
||||||
|
{sanitizeDisplayName(
|
||||||
|
post.author.displayName ||
|
||||||
|
sanitizeHandle(post.author.handle),
|
||||||
|
moderation.ui('displayName'),
|
||||||
|
)}
|
||||||
|
</Text>
|
||||||
|
</Link>
|
||||||
|
|
||||||
|
<View style={[{paddingLeft: 3, top: -1}]}>
|
||||||
|
<VerificationCheckButton profile={authorShadow} size="md" />
|
||||||
|
</View>
|
||||||
|
</View>
|
||||||
|
<Link style={s.flex1} href={authorHref} title={authorTitle}>
|
||||||
|
<Text
|
||||||
|
emoji
|
||||||
|
style={[
|
||||||
|
a.text_md,
|
||||||
|
a.leading_snug,
|
||||||
|
t.atoms.text_contrast_medium,
|
||||||
|
]}
|
||||||
|
numberOfLines={1}>
|
||||||
|
{sanitizeHandle(post.author.handle, '@')}
|
||||||
|
</Text>
|
||||||
|
</Link>
|
||||||
|
</View>
|
||||||
|
{showFollowButton && (
|
||||||
|
<View>
|
||||||
|
<PostThreadFollowBtn did={post.author.did} />
|
||||||
|
</View>
|
||||||
|
)}
|
||||||
|
</View>
|
||||||
|
<View style={[a.pb_sm]}>
|
||||||
|
<LabelsOnMyPost post={post} style={[a.pb_sm]} />
|
||||||
|
<ContentHider
|
||||||
|
modui={moderation.ui('contentView')}
|
||||||
|
ignoreMute
|
||||||
|
childContainerStyle={[a.pt_sm]}>
|
||||||
|
<PostAlerts
|
||||||
|
modui={moderation.ui('contentView')}
|
||||||
|
size="lg"
|
||||||
|
includeMute
|
||||||
|
style={[a.pb_sm]}
|
||||||
|
additionalCauses={additionalPostAlerts}
|
||||||
|
/>
|
||||||
|
{richText?.text ? (
|
||||||
|
<RichText
|
||||||
|
enableTags
|
||||||
|
selectable
|
||||||
|
value={richText}
|
||||||
|
style={[a.flex_1, a.text_xl]}
|
||||||
|
authorHandle={post.author.handle}
|
||||||
|
shouldProxyLinks={true}
|
||||||
|
/>
|
||||||
|
) : undefined}
|
||||||
|
{post.embed && (
|
||||||
|
<View style={[a.py_xs]}>
|
||||||
|
<PostEmbeds
|
||||||
|
embed={post.embed}
|
||||||
|
moderation={moderation}
|
||||||
|
viewContext={PostEmbedViewContext.ThreadHighlighted}
|
||||||
|
/>
|
||||||
|
</View>
|
||||||
|
)}
|
||||||
|
</ContentHider>
|
||||||
|
<ExpandedPostDetails
|
||||||
|
post={item.value.post}
|
||||||
|
isThreadAuthor={isThreadAuthor}
|
||||||
|
/>
|
||||||
|
{post.repostCount !== 0 ||
|
||||||
|
post.likeCount !== 0 ||
|
||||||
|
post.quoteCount !== 0 ? (
|
||||||
|
// Show this section unless we're *sure* it has no engagement.
|
||||||
|
<View
|
||||||
|
style={[
|
||||||
|
a.flex_row,
|
||||||
|
a.align_center,
|
||||||
|
a.gap_lg,
|
||||||
|
a.border_t,
|
||||||
|
a.border_b,
|
||||||
|
a.mt_md,
|
||||||
|
a.py_md,
|
||||||
|
t.atoms.border_contrast_low,
|
||||||
|
]}>
|
||||||
|
{post.repostCount != null && post.repostCount !== 0 ? (
|
||||||
|
<Link href={repostsHref} title={_(msg`Reposts of this post`)}>
|
||||||
|
<Text
|
||||||
|
testID="repostCount-expanded"
|
||||||
|
style={[a.text_md, t.atoms.text_contrast_medium]}>
|
||||||
|
<Text style={[a.text_md, a.font_bold, t.atoms.text]}>
|
||||||
|
{formatCount(i18n, post.repostCount)}
|
||||||
|
</Text>{' '}
|
||||||
|
<Plural
|
||||||
|
value={post.repostCount}
|
||||||
|
one="repost"
|
||||||
|
other="reposts"
|
||||||
|
/>
|
||||||
|
</Text>
|
||||||
|
</Link>
|
||||||
|
) : null}
|
||||||
|
{post.quoteCount != null &&
|
||||||
|
post.quoteCount !== 0 &&
|
||||||
|
!post.viewer?.embeddingDisabled ? (
|
||||||
|
<Link href={quotesHref} title={_(msg`Quotes of this post`)}>
|
||||||
|
<Text
|
||||||
|
testID="quoteCount-expanded"
|
||||||
|
style={[a.text_md, t.atoms.text_contrast_medium]}>
|
||||||
|
<Text style={[a.text_md, a.font_bold, t.atoms.text]}>
|
||||||
|
{formatCount(i18n, post.quoteCount)}
|
||||||
|
</Text>{' '}
|
||||||
|
<Plural
|
||||||
|
value={post.quoteCount}
|
||||||
|
one="quote"
|
||||||
|
other="quotes"
|
||||||
|
/>
|
||||||
|
</Text>
|
||||||
|
</Link>
|
||||||
|
) : null}
|
||||||
|
{post.likeCount != null && post.likeCount !== 0 ? (
|
||||||
|
<Link href={likesHref} title={_(msg`Likes on this post`)}>
|
||||||
|
<Text
|
||||||
|
testID="likeCount-expanded"
|
||||||
|
style={[a.text_md, t.atoms.text_contrast_medium]}>
|
||||||
|
<Text style={[a.text_md, a.font_bold, t.atoms.text]}>
|
||||||
|
{formatCount(i18n, post.likeCount)}
|
||||||
|
</Text>{' '}
|
||||||
|
<Plural value={post.likeCount} one="like" other="likes" />
|
||||||
|
</Text>
|
||||||
|
</Link>
|
||||||
|
) : null}
|
||||||
|
</View>
|
||||||
|
) : null}
|
||||||
|
<View
|
||||||
|
style={[
|
||||||
|
a.pt_sm,
|
||||||
|
a.pb_2xs,
|
||||||
|
{
|
||||||
|
marginLeft: -5,
|
||||||
|
},
|
||||||
|
]}>
|
||||||
|
<PostCtrls
|
||||||
|
big
|
||||||
|
post={postShadow}
|
||||||
|
record={record}
|
||||||
|
richText={richText}
|
||||||
|
onPressReply={onPressReply}
|
||||||
|
logContext="PostThreadItem"
|
||||||
|
threadgateRecord={threadgateRecord}
|
||||||
|
/>
|
||||||
|
</View>
|
||||||
|
</View>
|
||||||
|
</View>
|
||||||
|
</>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
function ExpandedPostDetails({
|
||||||
|
post,
|
||||||
|
isThreadAuthor,
|
||||||
|
}: {
|
||||||
|
post: Extract<Slice, {type: 'threadPost'}>['value']['post']
|
||||||
|
isThreadAuthor: boolean
|
||||||
|
}) {
|
||||||
|
const t = useTheme()
|
||||||
|
const pal = usePalette('default')
|
||||||
|
const {_, i18n} = useLingui()
|
||||||
|
const openLink = useOpenLink()
|
||||||
|
const langPrefs = useLanguagePrefs()
|
||||||
|
|
||||||
|
const translatorUrl = getTranslatorLink(
|
||||||
|
post.record?.text || '',
|
||||||
|
langPrefs.primaryLanguage,
|
||||||
|
)
|
||||||
|
const needsTranslation = useMemo(
|
||||||
|
() =>
|
||||||
|
Boolean(
|
||||||
|
langPrefs.primaryLanguage &&
|
||||||
|
!isPostInLanguage(post, [langPrefs.primaryLanguage]),
|
||||||
|
),
|
||||||
|
[post, langPrefs.primaryLanguage],
|
||||||
|
)
|
||||||
|
|
||||||
|
const onTranslatePress = React.useCallback(
|
||||||
|
(e: GestureResponderEvent) => {
|
||||||
|
e.preventDefault()
|
||||||
|
openLink(translatorUrl, true)
|
||||||
|
|
||||||
|
if (
|
||||||
|
bsky.dangerousIsType<AppBskyFeedPost.Record>(
|
||||||
|
post.record,
|
||||||
|
AppBskyFeedPost.isRecord,
|
||||||
|
)
|
||||||
|
) {
|
||||||
|
logger.metric('translate', {
|
||||||
|
sourceLanguages: post.record.langs ?? [],
|
||||||
|
targetLanguage: langPrefs.primaryLanguage,
|
||||||
|
textLength: post.record.text.length,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
return false
|
||||||
|
},
|
||||||
|
[openLink, translatorUrl, langPrefs, post],
|
||||||
|
)
|
||||||
|
|
||||||
|
return (
|
||||||
|
<View style={[a.gap_md, a.pt_md, a.align_start]}>
|
||||||
|
<BackdatedPostIndicator post={post} />
|
||||||
|
<View style={[a.flex_row, a.align_center, a.flex_wrap, a.gap_sm]}>
|
||||||
|
<Text style={[a.text_sm, t.atoms.text_contrast_medium]}>
|
||||||
|
{niceDate(i18n, post.indexedAt)}
|
||||||
|
</Text>
|
||||||
|
<WhoCanReply post={post} isThreadAuthor={isThreadAuthor} />
|
||||||
|
{needsTranslation && (
|
||||||
|
<>
|
||||||
|
<Text style={[a.text_sm, t.atoms.text_contrast_medium]}>
|
||||||
|
·
|
||||||
|
</Text>
|
||||||
|
|
||||||
|
<InlineLinkText
|
||||||
|
to={translatorUrl}
|
||||||
|
label={_(msg`Translate`)}
|
||||||
|
style={[a.text_sm, pal.link]}
|
||||||
|
onPress={onTranslatePress}>
|
||||||
|
<Trans>Translate</Trans>
|
||||||
|
</InlineLinkText>
|
||||||
|
</>
|
||||||
|
)}
|
||||||
|
</View>
|
||||||
|
</View>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
function BackdatedPostIndicator({post}: {post: AppBskyFeedDefs.PostView}) {
|
||||||
|
const t = useTheme()
|
||||||
|
const {_, i18n} = useLingui()
|
||||||
|
const control = Prompt.usePromptControl()
|
||||||
|
|
||||||
|
const indexedAt = new Date(post.indexedAt)
|
||||||
|
const createdAt = bsky.dangerousIsType<AppBskyFeedPost.Record>(
|
||||||
|
post.record,
|
||||||
|
AppBskyFeedPost.isRecord,
|
||||||
|
)
|
||||||
|
? new Date(post.record.createdAt)
|
||||||
|
: new Date(post.indexedAt)
|
||||||
|
|
||||||
|
// backdated if createdAt is 24 hours or more before indexedAt
|
||||||
|
const isBackdated =
|
||||||
|
indexedAt.getTime() - createdAt.getTime() > 24 * 60 * 60 * 1000
|
||||||
|
|
||||||
|
if (!isBackdated) return null
|
||||||
|
|
||||||
|
const orange = t.name === 'light' ? colors.warning.dark : colors.warning.light
|
||||||
|
|
||||||
|
return (
|
||||||
|
<>
|
||||||
|
<Button
|
||||||
|
label={_(msg`Archived post`)}
|
||||||
|
accessibilityHint={_(
|
||||||
|
msg`Shows information about when this post was created`,
|
||||||
|
)}
|
||||||
|
onPress={e => {
|
||||||
|
e.preventDefault()
|
||||||
|
e.stopPropagation()
|
||||||
|
control.open()
|
||||||
|
}}>
|
||||||
|
{({hovered, pressed}) => (
|
||||||
|
<View
|
||||||
|
style={[
|
||||||
|
a.flex_row,
|
||||||
|
a.align_center,
|
||||||
|
a.rounded_full,
|
||||||
|
t.atoms.bg_contrast_25,
|
||||||
|
(hovered || pressed) && t.atoms.bg_contrast_50,
|
||||||
|
{
|
||||||
|
gap: 3,
|
||||||
|
paddingHorizontal: 6,
|
||||||
|
paddingVertical: 3,
|
||||||
|
},
|
||||||
|
]}>
|
||||||
|
<CalendarClockIcon fill={orange} size="sm" aria-hidden />
|
||||||
|
<Text
|
||||||
|
style={[
|
||||||
|
a.text_xs,
|
||||||
|
a.font_bold,
|
||||||
|
a.leading_tight,
|
||||||
|
t.atoms.text_contrast_medium,
|
||||||
|
]}>
|
||||||
|
<Trans>Archived from {niceDate(i18n, createdAt)}</Trans>
|
||||||
|
</Text>
|
||||||
|
</View>
|
||||||
|
)}
|
||||||
|
</Button>
|
||||||
|
|
||||||
|
<Prompt.Outer control={control}>
|
||||||
|
<Prompt.TitleText>
|
||||||
|
<Trans>Archived post</Trans>
|
||||||
|
</Prompt.TitleText>
|
||||||
|
<Prompt.DescriptionText>
|
||||||
|
<Trans>
|
||||||
|
This post claims to have been created on{' '}
|
||||||
|
<RNText style={[a.font_bold]}>{niceDate(i18n, createdAt)}</RNText>,
|
||||||
|
but was first seen by Bluesky on{' '}
|
||||||
|
<RNText style={[a.font_bold]}>{niceDate(i18n, indexedAt)}</RNText>.
|
||||||
|
</Trans>
|
||||||
|
</Prompt.DescriptionText>
|
||||||
|
<Text
|
||||||
|
style={[
|
||||||
|
a.text_md,
|
||||||
|
a.leading_snug,
|
||||||
|
t.atoms.text_contrast_high,
|
||||||
|
a.pb_xl,
|
||||||
|
]}>
|
||||||
|
<Trans>
|
||||||
|
Bluesky cannot confirm the authenticity of the claimed date.
|
||||||
|
</Trans>
|
||||||
|
</Text>
|
||||||
|
<Prompt.Actions>
|
||||||
|
<Prompt.Action cta={_(msg`Okay`)} onPress={() => {}} />
|
||||||
|
</Prompt.Actions>
|
||||||
|
</Prompt.Outer>
|
||||||
|
</>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
function getThreadAuthor(
|
||||||
|
post: AppBskyFeedDefs.PostView,
|
||||||
|
record: AppBskyFeedPost.Record,
|
||||||
|
): string {
|
||||||
|
if (!record.reply) {
|
||||||
|
return post.author.did
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
return new AtUri(record.reply.root.uri).host
|
||||||
|
} catch {
|
||||||
|
return ''
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,329 @@
|
|||||||
|
import React, {memo, useMemo} from 'react'
|
||||||
|
import {View} from 'react-native'
|
||||||
|
import {
|
||||||
|
type AppBskyFeedDefs,
|
||||||
|
type AppBskyFeedThreadgate,
|
||||||
|
AtUri,
|
||||||
|
RichText as RichTextAPI,
|
||||||
|
} from '@atproto/api'
|
||||||
|
import {msg, Trans} from '@lingui/macro'
|
||||||
|
import {useLingui} from '@lingui/react'
|
||||||
|
|
||||||
|
import {useActorStatus} from '#/lib/actor-status'
|
||||||
|
import {MAX_POST_LINES} from '#/lib/constants'
|
||||||
|
import {useOpenComposer} from '#/lib/hooks/useOpenComposer'
|
||||||
|
import {usePalette} from '#/lib/hooks/usePalette'
|
||||||
|
import {makeProfileLink} from '#/lib/routes/links'
|
||||||
|
import {countLines} from '#/lib/strings/helpers'
|
||||||
|
import {
|
||||||
|
POST_TOMBSTONE,
|
||||||
|
type Shadow,
|
||||||
|
usePostShadow,
|
||||||
|
} from '#/state/cache/post-shadow'
|
||||||
|
import {type Slice} from '#/state/queries/usePostThread/types'
|
||||||
|
import {useSession} from '#/state/session'
|
||||||
|
import {type OnPostSuccessData} from '#/state/shell/composer'
|
||||||
|
import {useMergedThreadgateHiddenReplies} from '#/state/threadgate-hidden-replies'
|
||||||
|
import {TextLink} from '#/view/com/util/Link'
|
||||||
|
import {PostCtrls} from '#/view/com/util/post-ctrls/PostCtrls'
|
||||||
|
import {PostEmbeds, PostEmbedViewContext} from '#/view/com/util/post-embeds'
|
||||||
|
import {PostMeta} from '#/view/com/util/PostMeta'
|
||||||
|
import {PreviewableUserAvatar} from '#/view/com/util/UserAvatar'
|
||||||
|
import {atoms as a, useTheme} from '#/alf'
|
||||||
|
import {useInteractionState} from '#/components/hooks/useInteractionState'
|
||||||
|
import {Trash_Stroke2_Corner0_Rounded as TrashIcon} from '#/components/icons/Trash'
|
||||||
|
import {LabelsOnMyPost} from '#/components/moderation/LabelsOnMe'
|
||||||
|
import {PostAlerts} from '#/components/moderation/PostAlerts'
|
||||||
|
import {PostHider} from '#/components/moderation/PostHider'
|
||||||
|
import {type AppModerationCause} from '#/components/Pills'
|
||||||
|
import {RichText} from '#/components/RichText'
|
||||||
|
import {SubtleWebHover} from '#/components/SubtleWebHover'
|
||||||
|
import {Text} from '#/components/Typography'
|
||||||
|
|
||||||
|
export function ThreadPost({
|
||||||
|
item,
|
||||||
|
overrides,
|
||||||
|
onPostSuccess,
|
||||||
|
threadgateRecord,
|
||||||
|
}: {
|
||||||
|
item: Extract<Slice, {type: 'threadPost'}>
|
||||||
|
overrides?: {
|
||||||
|
moderation?: boolean
|
||||||
|
topBorder?: boolean
|
||||||
|
}
|
||||||
|
onPostSuccess?: (data: OnPostSuccessData) => void
|
||||||
|
threadgateRecord?: AppBskyFeedThreadgate.Record
|
||||||
|
}) {
|
||||||
|
const postShadow = usePostShadow(item.value.post)
|
||||||
|
|
||||||
|
if (postShadow === POST_TOMBSTONE) {
|
||||||
|
return <PostThreadItemDeleted />
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<PostThreadItemLoaded
|
||||||
|
// Safeguard from clobbering per-post state below:
|
||||||
|
key={postShadow.uri}
|
||||||
|
item={item}
|
||||||
|
postShadow={postShadow}
|
||||||
|
threadgateRecord={threadgateRecord}
|
||||||
|
overrides={overrides}
|
||||||
|
onPostSuccess={onPostSuccess}
|
||||||
|
/>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
function PostThreadItemDeleted({hideTopBorder}: {hideTopBorder?: boolean}) {
|
||||||
|
const t = useTheme()
|
||||||
|
return (
|
||||||
|
<View
|
||||||
|
style={[
|
||||||
|
t.atoms.bg,
|
||||||
|
t.atoms.border_contrast_low,
|
||||||
|
a.p_xl,
|
||||||
|
a.pl_lg,
|
||||||
|
a.flex_row,
|
||||||
|
a.gap_md,
|
||||||
|
!hideTopBorder && a.border_t,
|
||||||
|
]}>
|
||||||
|
<TrashIcon style={[t.atoms.text]} />
|
||||||
|
<Text style={[t.atoms.text_contrast_medium, a.mt_2xs]}>
|
||||||
|
<Trans>This post has been deleted.</Trans>
|
||||||
|
</Text>
|
||||||
|
</View>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
let PostThreadItemLoaded = ({
|
||||||
|
item,
|
||||||
|
postShadow,
|
||||||
|
overrides,
|
||||||
|
onPostSuccess,
|
||||||
|
threadgateRecord,
|
||||||
|
}: {
|
||||||
|
item: Extract<Slice, {type: 'threadPost'}>
|
||||||
|
postShadow: Shadow<AppBskyFeedDefs.PostView>
|
||||||
|
overrides?: {
|
||||||
|
moderation?: boolean
|
||||||
|
topBorder?: boolean
|
||||||
|
}
|
||||||
|
onPostSuccess?: (data: OnPostSuccessData) => void
|
||||||
|
threadgateRecord?: AppBskyFeedThreadgate.Record
|
||||||
|
}): React.ReactNode => {
|
||||||
|
const t = useTheme()
|
||||||
|
const pal = usePalette('default')
|
||||||
|
const {_} = useLingui()
|
||||||
|
const {openComposer} = useOpenComposer()
|
||||||
|
const {currentAccount} = useSession()
|
||||||
|
|
||||||
|
const post = item.value.post
|
||||||
|
const record = item.value.post.record
|
||||||
|
const moderation = item.moderation
|
||||||
|
const richText = useMemo(
|
||||||
|
() =>
|
||||||
|
new RichTextAPI({
|
||||||
|
text: record.text,
|
||||||
|
facets: record.facets,
|
||||||
|
}),
|
||||||
|
[record],
|
||||||
|
)
|
||||||
|
const [limitLines, setLimitLines] = React.useState(
|
||||||
|
() => countLines(richText?.text) >= MAX_POST_LINES,
|
||||||
|
)
|
||||||
|
const threadRootUri = record.reply?.root?.uri || post.uri
|
||||||
|
const postHref = React.useMemo(() => {
|
||||||
|
const urip = new AtUri(post.uri)
|
||||||
|
return makeProfileLink(post.author, 'post', urip.rkey)
|
||||||
|
}, [post.uri, post.author])
|
||||||
|
const threadgateHiddenReplies = useMergedThreadgateHiddenReplies({
|
||||||
|
threadgateRecord,
|
||||||
|
})
|
||||||
|
const additionalPostAlerts: AppModerationCause[] = React.useMemo(() => {
|
||||||
|
const isPostHiddenByThreadgate = threadgateHiddenReplies.has(post.uri)
|
||||||
|
const isControlledByViewer =
|
||||||
|
new AtUri(threadRootUri).host === currentAccount?.did
|
||||||
|
return isControlledByViewer && isPostHiddenByThreadgate
|
||||||
|
? [
|
||||||
|
{
|
||||||
|
type: 'reply-hidden',
|
||||||
|
source: {type: 'user', did: currentAccount?.did},
|
||||||
|
priority: 6,
|
||||||
|
},
|
||||||
|
]
|
||||||
|
: []
|
||||||
|
}, [post, currentAccount?.did, threadgateHiddenReplies, threadRootUri])
|
||||||
|
|
||||||
|
const onPressReply = React.useCallback(() => {
|
||||||
|
openComposer({
|
||||||
|
replyTo: {
|
||||||
|
uri: post.uri,
|
||||||
|
cid: post.cid,
|
||||||
|
text: record.text,
|
||||||
|
author: post.author,
|
||||||
|
embed: post.embed,
|
||||||
|
moderation,
|
||||||
|
},
|
||||||
|
onPostSuccess: onPostSuccess,
|
||||||
|
})
|
||||||
|
}, [openComposer, post, record, onPostSuccess, moderation])
|
||||||
|
|
||||||
|
const onPressShowMore = React.useCallback(() => {
|
||||||
|
setLimitLines(false)
|
||||||
|
}, [setLimitLines])
|
||||||
|
|
||||||
|
const {isActive: live} = useActorStatus(post.author)
|
||||||
|
|
||||||
|
const showTopBorder =
|
||||||
|
!item.ui.showParentReplyLine && overrides?.topBorder !== true
|
||||||
|
|
||||||
|
return (
|
||||||
|
<SubtleHover>
|
||||||
|
<View
|
||||||
|
style={[
|
||||||
|
a.px_sm,
|
||||||
|
a.pointer,
|
||||||
|
showTopBorder && [a.border_t, t.atoms.border_contrast_low],
|
||||||
|
]}>
|
||||||
|
<PostHider
|
||||||
|
testID={`postThreadItem-by-${post.author.handle}`}
|
||||||
|
href={postHref}
|
||||||
|
disabled={overrides?.moderation === true}
|
||||||
|
modui={moderation.ui('contentList')}
|
||||||
|
iconSize={42}
|
||||||
|
iconStyles={{marginLeft: 2, marginRight: 2}}
|
||||||
|
profile={post.author}
|
||||||
|
interpretFilterAsBlur>
|
||||||
|
<View
|
||||||
|
style={{
|
||||||
|
flexDirection: 'row',
|
||||||
|
gap: 10,
|
||||||
|
paddingLeft: 8,
|
||||||
|
height: 16,
|
||||||
|
}}>
|
||||||
|
<View style={{width: 42}}>
|
||||||
|
{item.ui.showParentReplyLine && (
|
||||||
|
<View
|
||||||
|
style={[
|
||||||
|
{
|
||||||
|
width: 2,
|
||||||
|
marginLeft: 'auto',
|
||||||
|
marginRight: 'auto',
|
||||||
|
flexGrow: 1,
|
||||||
|
backgroundColor: pal.colors.replyLine,
|
||||||
|
marginBottom: 4,
|
||||||
|
},
|
||||||
|
]}
|
||||||
|
/>
|
||||||
|
)}
|
||||||
|
</View>
|
||||||
|
</View>
|
||||||
|
|
||||||
|
<View
|
||||||
|
style={[
|
||||||
|
a.flex_row,
|
||||||
|
a.px_sm,
|
||||||
|
a.gap_md,
|
||||||
|
{
|
||||||
|
paddingBottom: item.ui.showChildReplyLine ? 0 : 8,
|
||||||
|
},
|
||||||
|
]}>
|
||||||
|
{/* If we are in threaded mode, the avatar is rendered in PostMeta */}
|
||||||
|
<View>
|
||||||
|
<PreviewableUserAvatar
|
||||||
|
size={42}
|
||||||
|
profile={post.author}
|
||||||
|
moderation={moderation.ui('avatar')}
|
||||||
|
type={post.author.associated?.labeler ? 'labeler' : 'user'}
|
||||||
|
live={live}
|
||||||
|
/>
|
||||||
|
|
||||||
|
{item.ui.showChildReplyLine && (
|
||||||
|
<View
|
||||||
|
style={[
|
||||||
|
{
|
||||||
|
width: 2,
|
||||||
|
marginLeft: 'auto',
|
||||||
|
marginRight: 'auto',
|
||||||
|
flexGrow: 1,
|
||||||
|
backgroundColor: pal.colors.replyLine,
|
||||||
|
marginTop: 4,
|
||||||
|
},
|
||||||
|
]}
|
||||||
|
/>
|
||||||
|
)}
|
||||||
|
</View>
|
||||||
|
|
||||||
|
<View style={[a.flex_1]}>
|
||||||
|
<PostMeta
|
||||||
|
author={post.author}
|
||||||
|
moderation={moderation}
|
||||||
|
timestamp={post.indexedAt}
|
||||||
|
postHref={postHref}
|
||||||
|
avatarSize={24}
|
||||||
|
style={[a.pb_xs]}
|
||||||
|
/>
|
||||||
|
<LabelsOnMyPost post={post} style={[a.pb_xs]} />
|
||||||
|
<PostAlerts
|
||||||
|
modui={moderation.ui('contentList')}
|
||||||
|
style={[a.pb_2xs]}
|
||||||
|
additionalCauses={additionalPostAlerts}
|
||||||
|
/>
|
||||||
|
{richText?.text ? (
|
||||||
|
<View style={[a.pb_2xs, a.pr_sm]}>
|
||||||
|
<RichText
|
||||||
|
enableTags
|
||||||
|
value={richText}
|
||||||
|
style={[a.flex_1, a.text_md]}
|
||||||
|
numberOfLines={limitLines ? MAX_POST_LINES : undefined}
|
||||||
|
authorHandle={post.author.handle}
|
||||||
|
shouldProxyLinks={true}
|
||||||
|
/>
|
||||||
|
</View>
|
||||||
|
) : undefined}
|
||||||
|
{limitLines ? (
|
||||||
|
<TextLink
|
||||||
|
text={_(msg`Show More`)}
|
||||||
|
style={pal.link}
|
||||||
|
onPress={onPressShowMore}
|
||||||
|
href="#"
|
||||||
|
/>
|
||||||
|
) : undefined}
|
||||||
|
{post.embed && (
|
||||||
|
<View style={[a.pb_xs]}>
|
||||||
|
<PostEmbeds
|
||||||
|
embed={post.embed}
|
||||||
|
moderation={moderation}
|
||||||
|
viewContext={PostEmbedViewContext.Feed}
|
||||||
|
/>
|
||||||
|
</View>
|
||||||
|
)}
|
||||||
|
<PostCtrls
|
||||||
|
post={postShadow}
|
||||||
|
record={record}
|
||||||
|
richText={richText}
|
||||||
|
onPressReply={onPressReply}
|
||||||
|
logContext="PostThreadItem"
|
||||||
|
threadgateRecord={threadgateRecord}
|
||||||
|
/>
|
||||||
|
</View>
|
||||||
|
</View>
|
||||||
|
</PostHider>
|
||||||
|
</View>
|
||||||
|
</SubtleHover>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
PostThreadItemLoaded = memo(PostThreadItemLoaded)
|
||||||
|
|
||||||
|
function SubtleHover({children}: {children: React.ReactNode}) {
|
||||||
|
const {
|
||||||
|
state: hover,
|
||||||
|
onIn: onHoverIn,
|
||||||
|
onOut: onHoverOut,
|
||||||
|
} = useInteractionState()
|
||||||
|
return (
|
||||||
|
<View onPointerEnter={onHoverIn} onPointerLeave={onHoverOut}>
|
||||||
|
<SubtleWebHover hover={hover} />
|
||||||
|
{children}
|
||||||
|
</View>
|
||||||
|
)
|
||||||
|
}
|
||||||
@@ -0,0 +1,283 @@
|
|||||||
|
import React, {memo, useMemo} from 'react'
|
||||||
|
import {View} from 'react-native'
|
||||||
|
import {
|
||||||
|
type AppBskyFeedDefs,
|
||||||
|
type AppBskyFeedThreadgate,
|
||||||
|
AtUri,
|
||||||
|
RichText as RichTextAPI,
|
||||||
|
} from '@atproto/api'
|
||||||
|
import {msg, Trans} from '@lingui/macro'
|
||||||
|
import {useLingui} from '@lingui/react'
|
||||||
|
|
||||||
|
import {MAX_POST_LINES} from '#/lib/constants'
|
||||||
|
import {useOpenComposer} from '#/lib/hooks/useOpenComposer'
|
||||||
|
import {usePalette} from '#/lib/hooks/usePalette'
|
||||||
|
import {makeProfileLink} from '#/lib/routes/links'
|
||||||
|
import {countLines} from '#/lib/strings/helpers'
|
||||||
|
import {
|
||||||
|
POST_TOMBSTONE,
|
||||||
|
type Shadow,
|
||||||
|
usePostShadow,
|
||||||
|
} from '#/state/cache/post-shadow'
|
||||||
|
import {type Slice} from '#/state/queries/usePostThread/types'
|
||||||
|
import {useSession} from '#/state/session'
|
||||||
|
import {type OnPostSuccessData} from '#/state/shell/composer'
|
||||||
|
import {useMergedThreadgateHiddenReplies} from '#/state/threadgate-hidden-replies'
|
||||||
|
import {TextLink} from '#/view/com/util/Link'
|
||||||
|
import {PostCtrls} from '#/view/com/util/post-ctrls/PostCtrls'
|
||||||
|
import {PostEmbeds, PostEmbedViewContext} from '#/view/com/util/post-embeds'
|
||||||
|
import {PostMeta} from '#/view/com/util/PostMeta'
|
||||||
|
import {TREE_INDENT} from '#/screens/PostThread/const'
|
||||||
|
import {atoms as a, useTheme} from '#/alf'
|
||||||
|
import {useInteractionState} from '#/components/hooks/useInteractionState'
|
||||||
|
import {Trash_Stroke2_Corner0_Rounded as TrashIcon} from '#/components/icons/Trash'
|
||||||
|
import {LabelsOnMyPost} from '#/components/moderation/LabelsOnMe'
|
||||||
|
import {PostAlerts} from '#/components/moderation/PostAlerts'
|
||||||
|
import {PostHider} from '#/components/moderation/PostHider'
|
||||||
|
import {type AppModerationCause} from '#/components/Pills'
|
||||||
|
import {RichText} from '#/components/RichText'
|
||||||
|
import {SubtleWebHover} from '#/components/SubtleWebHover'
|
||||||
|
import {Text} from '#/components/Typography'
|
||||||
|
|
||||||
|
export function ThreadReply({
|
||||||
|
item,
|
||||||
|
overrides,
|
||||||
|
onPostSuccess,
|
||||||
|
threadgateRecord,
|
||||||
|
}: {
|
||||||
|
item: Extract<Slice, {type: 'threadPost'}>
|
||||||
|
overrides?: {
|
||||||
|
moderation?: boolean
|
||||||
|
topBorder?: boolean
|
||||||
|
}
|
||||||
|
onPostSuccess?: (data: OnPostSuccessData) => void
|
||||||
|
threadgateRecord?: AppBskyFeedThreadgate.Record
|
||||||
|
}) {
|
||||||
|
const postShadow = usePostShadow(item.value.post)
|
||||||
|
|
||||||
|
if (postShadow === POST_TOMBSTONE) {
|
||||||
|
return <PostThreadItemDeleted />
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<PostThreadItemLoaded
|
||||||
|
// Safeguard from clobbering per-post state below:
|
||||||
|
key={postShadow.uri}
|
||||||
|
item={item}
|
||||||
|
postShadow={postShadow}
|
||||||
|
threadgateRecord={threadgateRecord}
|
||||||
|
overrides={overrides}
|
||||||
|
onPostSuccess={onPostSuccess}
|
||||||
|
/>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
function PostThreadItemDeleted({hideTopBorder}: {hideTopBorder?: boolean}) {
|
||||||
|
const t = useTheme()
|
||||||
|
return (
|
||||||
|
<View
|
||||||
|
style={[
|
||||||
|
t.atoms.bg,
|
||||||
|
t.atoms.border_contrast_low,
|
||||||
|
a.p_xl,
|
||||||
|
a.pl_lg,
|
||||||
|
a.flex_row,
|
||||||
|
a.gap_md,
|
||||||
|
!hideTopBorder && a.border_t,
|
||||||
|
]}>
|
||||||
|
<TrashIcon style={[t.atoms.text]} />
|
||||||
|
<Text style={[t.atoms.text_contrast_medium, a.mt_2xs]}>
|
||||||
|
<Trans>This post has been deleted.</Trans>
|
||||||
|
</Text>
|
||||||
|
</View>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
let PostThreadItemLoaded = ({
|
||||||
|
item,
|
||||||
|
postShadow,
|
||||||
|
overrides,
|
||||||
|
onPostSuccess,
|
||||||
|
threadgateRecord,
|
||||||
|
}: {
|
||||||
|
item: Extract<Slice, {type: 'threadPost'}>
|
||||||
|
postShadow: Shadow<AppBskyFeedDefs.PostView>
|
||||||
|
overrides?: {
|
||||||
|
moderation?: boolean
|
||||||
|
topBorder?: boolean
|
||||||
|
}
|
||||||
|
onPostSuccess?: (data: OnPostSuccessData) => void
|
||||||
|
threadgateRecord?: AppBskyFeedThreadgate.Record
|
||||||
|
}): React.ReactNode => {
|
||||||
|
const t = useTheme()
|
||||||
|
const pal = usePalette('default')
|
||||||
|
const {_} = useLingui()
|
||||||
|
const {openComposer} = useOpenComposer()
|
||||||
|
const {currentAccount} = useSession()
|
||||||
|
|
||||||
|
const post = item.value.post
|
||||||
|
const record = item.value.post.record
|
||||||
|
const moderation = item.moderation
|
||||||
|
const richText = useMemo(
|
||||||
|
() =>
|
||||||
|
new RichTextAPI({
|
||||||
|
text: record.text,
|
||||||
|
facets: record.facets,
|
||||||
|
}),
|
||||||
|
[record],
|
||||||
|
)
|
||||||
|
const [limitLines, setLimitLines] = React.useState(
|
||||||
|
() => countLines(richText?.text) >= MAX_POST_LINES,
|
||||||
|
)
|
||||||
|
const threadRootUri = record.reply?.root?.uri || post.uri
|
||||||
|
const postHref = React.useMemo(() => {
|
||||||
|
const urip = new AtUri(post.uri)
|
||||||
|
return makeProfileLink(post.author, 'post', urip.rkey)
|
||||||
|
}, [post.uri, post.author])
|
||||||
|
const threadgateHiddenReplies = useMergedThreadgateHiddenReplies({
|
||||||
|
threadgateRecord,
|
||||||
|
})
|
||||||
|
const additionalPostAlerts: AppModerationCause[] = React.useMemo(() => {
|
||||||
|
const isPostHiddenByThreadgate = threadgateHiddenReplies.has(post.uri)
|
||||||
|
const isControlledByViewer =
|
||||||
|
new AtUri(threadRootUri).host === currentAccount?.did
|
||||||
|
return isControlledByViewer && isPostHiddenByThreadgate
|
||||||
|
? [
|
||||||
|
{
|
||||||
|
type: 'reply-hidden',
|
||||||
|
source: {type: 'user', did: currentAccount?.did},
|
||||||
|
priority: 6,
|
||||||
|
},
|
||||||
|
]
|
||||||
|
: []
|
||||||
|
}, [post, currentAccount?.did, threadgateHiddenReplies, threadRootUri])
|
||||||
|
|
||||||
|
const onPressReply = React.useCallback(() => {
|
||||||
|
openComposer({
|
||||||
|
replyTo: {
|
||||||
|
uri: post.uri,
|
||||||
|
cid: post.cid,
|
||||||
|
text: record.text,
|
||||||
|
author: post.author,
|
||||||
|
embed: post.embed,
|
||||||
|
moderation,
|
||||||
|
},
|
||||||
|
onPostSuccess: onPostSuccess,
|
||||||
|
})
|
||||||
|
}, [openComposer, post, record, onPostSuccess, moderation])
|
||||||
|
|
||||||
|
const onPressShowMore = React.useCallback(() => {
|
||||||
|
setLimitLines(false)
|
||||||
|
}, [setLimitLines])
|
||||||
|
|
||||||
|
return (
|
||||||
|
<View
|
||||||
|
style={[
|
||||||
|
a.flex_row,
|
||||||
|
item.depth === 1 && [a.border_t, t.atoms.border_contrast_low],
|
||||||
|
]}>
|
||||||
|
{Array.from(Array(item.depth - 1)).map((_, n: number) => (
|
||||||
|
<View
|
||||||
|
key={`${post.uri}-padding-${n}`}
|
||||||
|
style={[
|
||||||
|
t.atoms.border_contrast_low,
|
||||||
|
{
|
||||||
|
borderRightWidth: 2,
|
||||||
|
width: TREE_INDENT,
|
||||||
|
},
|
||||||
|
]}
|
||||||
|
/>
|
||||||
|
))}
|
||||||
|
<View style={a.flex_1}>
|
||||||
|
<SubtleHover>
|
||||||
|
<View style={[a.px_lg, a.py_sm, item.depth === 1 && [a.pt_lg]]}>
|
||||||
|
<PostHider
|
||||||
|
testID={`postThreadItem-by-${post.author.handle}`}
|
||||||
|
href={postHref}
|
||||||
|
disabled={overrides?.moderation === true}
|
||||||
|
modui={moderation.ui('contentList')}
|
||||||
|
iconSize={42}
|
||||||
|
iconStyles={{marginLeft: 2, marginRight: 2}}
|
||||||
|
profile={post.author}
|
||||||
|
interpretFilterAsBlur>
|
||||||
|
<View style={[a.flex_row, a.gap_md]}>
|
||||||
|
<View style={[a.flex_1]}>
|
||||||
|
<PostMeta
|
||||||
|
author={post.author}
|
||||||
|
moderation={moderation}
|
||||||
|
timestamp={post.indexedAt}
|
||||||
|
postHref={postHref}
|
||||||
|
avatarSize={24}
|
||||||
|
style={[a.pb_xs]}
|
||||||
|
showAvatar
|
||||||
|
/>
|
||||||
|
<LabelsOnMyPost post={post} style={[a.pb_xs]} />
|
||||||
|
<PostAlerts
|
||||||
|
modui={moderation.ui('contentList')}
|
||||||
|
style={[a.pb_2xs]}
|
||||||
|
additionalCauses={additionalPostAlerts}
|
||||||
|
/>
|
||||||
|
{richText?.text ? (
|
||||||
|
<View style={[a.pb_2xs, a.pr_sm]}>
|
||||||
|
<RichText
|
||||||
|
enableTags
|
||||||
|
value={richText}
|
||||||
|
style={[a.flex_1, a.text_md]}
|
||||||
|
numberOfLines={limitLines ? MAX_POST_LINES : undefined}
|
||||||
|
authorHandle={post.author.handle}
|
||||||
|
shouldProxyLinks={true}
|
||||||
|
/>
|
||||||
|
</View>
|
||||||
|
) : undefined}
|
||||||
|
{limitLines ? (
|
||||||
|
<TextLink
|
||||||
|
text={_(msg`Show More`)}
|
||||||
|
style={pal.link}
|
||||||
|
onPress={onPressShowMore}
|
||||||
|
href="#"
|
||||||
|
/>
|
||||||
|
) : undefined}
|
||||||
|
{post.embed && (
|
||||||
|
<View style={[a.pb_xs]}>
|
||||||
|
<PostEmbeds
|
||||||
|
embed={post.embed}
|
||||||
|
moderation={moderation}
|
||||||
|
viewContext={PostEmbedViewContext.Feed}
|
||||||
|
/>
|
||||||
|
</View>
|
||||||
|
)}
|
||||||
|
<PostCtrls
|
||||||
|
post={postShadow}
|
||||||
|
record={record}
|
||||||
|
richText={richText}
|
||||||
|
onPressReply={onPressReply}
|
||||||
|
logContext="PostThreadItem"
|
||||||
|
threadgateRecord={threadgateRecord}
|
||||||
|
/>
|
||||||
|
</View>
|
||||||
|
</View>
|
||||||
|
</PostHider>
|
||||||
|
</View>
|
||||||
|
</SubtleHover>
|
||||||
|
</View>
|
||||||
|
</View>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
PostThreadItemLoaded = memo(PostThreadItemLoaded)
|
||||||
|
|
||||||
|
function SubtleHover({children}: {children: React.ReactNode}) {
|
||||||
|
const {
|
||||||
|
state: hover,
|
||||||
|
onIn: onHoverIn,
|
||||||
|
onOut: onHoverOut,
|
||||||
|
} = useInteractionState()
|
||||||
|
return (
|
||||||
|
<View
|
||||||
|
onPointerEnter={onHoverIn}
|
||||||
|
onPointerLeave={onHoverOut}
|
||||||
|
style={a.pointer}>
|
||||||
|
<SubtleWebHover hover={hover} />
|
||||||
|
{children}
|
||||||
|
</View>
|
||||||
|
)
|
||||||
|
}
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
export const TREE_INDENT = 16
|
||||||
@@ -16,11 +16,14 @@ import {
|
|||||||
} from '#/state/queries/usePostThread'
|
} from '#/state/queries/usePostThread'
|
||||||
import {type OnPostSuccessData} from '#/state/shell/composer'
|
import {type OnPostSuccessData} from '#/state/shell/composer'
|
||||||
import {PostThreadComposePrompt} from '#/view/com/post-thread/PostThreadComposePrompt'
|
import {PostThreadComposePrompt} from '#/view/com/post-thread/PostThreadComposePrompt'
|
||||||
import {PostThreadItem} from '#/view/com/post-thread/PostThreadItem'
|
// import {PostThreadItem} from '#/view/com/post-thread/PostThreadItem'
|
||||||
import {PostThreadShowHiddenReplies} from '#/view/com/post-thread/PostThreadShowHiddenReplies'
|
import {PostThreadShowHiddenReplies} from '#/view/com/post-thread/PostThreadShowHiddenReplies'
|
||||||
import {List, type ListMethods} from '#/view/com/util/List'
|
import {List, type ListMethods} from '#/view/com/util/List'
|
||||||
import {HeaderDropdown} from '#/screens/PostThread/components/HeaderDropdown'
|
import {HeaderDropdown} from '#/screens/PostThread/components/HeaderDropdown'
|
||||||
import {ReadMore} from '#/screens/PostThread/components/ReadMore'
|
import {ReadMore} from '#/screens/PostThread/components/ReadMore'
|
||||||
|
import {ThreadAnchor} from '#/screens/PostThread/components/ThreadAnchor'
|
||||||
|
import {ThreadPost} from '#/screens/PostThread/components/ThreadPost'
|
||||||
|
import {ThreadReply} from '#/screens/PostThread/components/ThreadReply'
|
||||||
import {atoms as a, useBreakpoints, useTheme, web} from '#/alf'
|
import {atoms as a, useBreakpoints, useTheme, web} from '#/alf'
|
||||||
import * as Layout from '#/components/Layout'
|
import * as Layout from '#/components/Layout'
|
||||||
import {ListFooter} from '#/components/Lists'
|
import {ListFooter} from '#/components/Lists'
|
||||||
@@ -142,33 +145,58 @@ export function Inner({uri}: {uri: string | undefined}) {
|
|||||||
|
|
||||||
const renderItem = ({item, index}: {item: Slice; index: number}) => {
|
const renderItem = ({item, index}: {item: Slice; index: number}) => {
|
||||||
if (item.type === 'threadPost') {
|
if (item.type === 'threadPost') {
|
||||||
return (
|
if (item.depth < 0) {
|
||||||
<View
|
return (
|
||||||
ref={item.ui.isAnchor ? anchorRef : undefined}
|
<ThreadPost
|
||||||
onLayout={deferParents ? () => setDeferParents(false) : undefined}>
|
item={item}
|
||||||
<PostThreadItem
|
|
||||||
post={item.value.post}
|
|
||||||
record={item.value.post.record}
|
|
||||||
threadgateRecord={data?.threadgate?.record ?? undefined}
|
threadgateRecord={data?.threadgate?.record ?? undefined}
|
||||||
moderation={item.moderation}
|
overrides={{
|
||||||
treeView={treeViewEnabled}
|
topBorder: index === 0, // && !item.isParentLoading, // TODO
|
||||||
depth={item.depth}
|
}}
|
||||||
// TODO
|
|
||||||
// prevPost={prev}
|
|
||||||
// nextPost={next}
|
|
||||||
isHighlightedPost={item.ui.isAnchor}
|
|
||||||
hasMore={false} // TODO need to replace this entirely
|
|
||||||
showChildReplyLine={item.ui.showChildReplyLine}
|
|
||||||
showParentReplyLine={item.ui.showParentReplyLine}
|
|
||||||
hasPrecedingItem={item.ui.showParentReplyLine} // !!hasUnrevealedParents // TODO
|
|
||||||
overrideBlur={
|
|
||||||
shownHiddenReplyKinds.has(HiddenReplyKind.Muted) && item.depth > 0
|
|
||||||
}
|
|
||||||
onPostSuccess={optimisticOnPostReply}
|
onPostSuccess={optimisticOnPostReply}
|
||||||
hideTopBorder={index === 0} // && !item.isParentLoading} // TODO
|
|
||||||
/>
|
/>
|
||||||
</View>
|
)
|
||||||
)
|
} else if (item.depth === 0) {
|
||||||
|
return (
|
||||||
|
<View
|
||||||
|
ref={item.ui.isAnchor ? anchorRef : undefined}
|
||||||
|
onLayout={deferParents ? () => setDeferParents(false) : undefined}>
|
||||||
|
<ThreadAnchor
|
||||||
|
item={item}
|
||||||
|
threadgateRecord={data?.threadgate?.record ?? undefined}
|
||||||
|
onPostSuccess={optimisticOnPostReply}
|
||||||
|
/>
|
||||||
|
</View>
|
||||||
|
)
|
||||||
|
} else {
|
||||||
|
if (treeViewEnabled) {
|
||||||
|
return (
|
||||||
|
<ThreadReply
|
||||||
|
item={item}
|
||||||
|
threadgateRecord={data?.threadgate?.record ?? undefined}
|
||||||
|
overrides={{
|
||||||
|
moderation:
|
||||||
|
shownHiddenReplyKinds.has(HiddenReplyKind.Muted) &&
|
||||||
|
item.depth > 0,
|
||||||
|
}}
|
||||||
|
onPostSuccess={optimisticOnPostReply}
|
||||||
|
/>
|
||||||
|
)
|
||||||
|
} else {
|
||||||
|
return (
|
||||||
|
<ThreadPost
|
||||||
|
item={item}
|
||||||
|
threadgateRecord={data?.threadgate?.record ?? undefined}
|
||||||
|
overrides={{
|
||||||
|
moderation:
|
||||||
|
shownHiddenReplyKinds.has(HiddenReplyKind.Muted) &&
|
||||||
|
item.depth > 0,
|
||||||
|
}}
|
||||||
|
onPostSuccess={optimisticOnPostReply}
|
||||||
|
/>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
} else if (item.type === 'readMore') {
|
} else if (item.type === 'readMore') {
|
||||||
return <ReadMore item={item} view={treeViewEnabled ? 'tree' : 'linear'} />
|
return <ReadMore item={item} view={treeViewEnabled ? 'tree' : 'linear'} />
|
||||||
} else if (item.type === 'threadPostBlocked') {
|
} else if (item.type === 'threadPostBlocked') {
|
||||||
|
|||||||
Reference in New Issue
Block a user