forked from
jollywhoppers.com/witchsky.app
Bluesky app fork with some witchin' additions 馃挮
1import {StyleSheet, View} from 'react-native'
2import {AppBskyFeedDefs, type ModerationDecision} from '@atproto/api'
3import {msg, Trans} from '@lingui/macro'
4import {useLingui} from '@lingui/react'
5
6import {isReasonFeedSource, type ReasonFeedSource} from '#/lib/api/feed/types'
7import {createSanitizedDisplayName} from '#/lib/moderation/create-sanitized-display-name'
8import {makeProfileLink} from '#/lib/routes/links'
9import {useSession} from '#/state/session'
10import {atoms as a, useTheme} from '#/alf'
11import {Pin_Stroke2_Corner0_Rounded as PinIcon} from '#/components/icons/Pin'
12import {Repost_Stroke2_Corner3_Rounded as RepostIcon} from '#/components/icons/Repost'
13import {Link} from '#/components/Link'
14import {ProfileHoverCard} from '#/components/ProfileHoverCard'
15import {Text} from '#/components/Typography'
16import {FeedNameText} from '../util/FeedInfoText'
17
18export function PostFeedReason({
19 reason,
20 moderation,
21 onOpenReposter,
22}: {
23 reason:
24 | ReasonFeedSource
25 | AppBskyFeedDefs.ReasonRepost
26 | AppBskyFeedDefs.ReasonPin
27 | {[k: string]: unknown; $type: string}
28 moderation?: ModerationDecision
29 onOpenReposter?: () => void
30}) {
31 const t = useTheme()
32 const {_} = useLingui()
33
34 const {currentAccount} = useSession()
35
36 if (isReasonFeedSource(reason)) {
37 return (
38 <Link label={_(msg`Go to feed`)} to={reason.href}>
39 <Text
40 style={[
41 t.atoms.text_contrast_medium,
42 a.font_medium,
43 a.leading_snug,
44 a.leading_snug,
45 ]}
46 numberOfLines={1}>
47 <Trans context="from-feed">
48 From{' '}
49 <FeedNameText
50 uri={reason.uri}
51 href={reason.href}
52 style={[
53 t.atoms.text_contrast_medium,
54 a.font_medium,
55 a.leading_snug,
56 ]}
57 numberOfLines={1}
58 />
59 </Trans>
60 </Text>
61 </Link>
62 )
63 }
64
65 if (AppBskyFeedDefs.isReasonRepost(reason)) {
66 const isOwner = reason.by.did === currentAccount?.did
67 const reposter = createSanitizedDisplayName(
68 reason.by,
69 false,
70 moderation?.ui('displayName'),
71 )
72 return (
73 <Link
74 style={styles.includeReason}
75 to={makeProfileLink(reason.by)}
76 label={
77 isOwner ? _(msg`Reskeeted by you`) : _(msg`Reskeeted by ${reposter}`)
78 }
79 onPress={onOpenReposter}>
80 <RepostIcon
81 style={[t.atoms.text_contrast_medium, {marginRight: 3}]}
82 width={13}
83 height={13}
84 />
85 <ProfileHoverCard did={reason.by.did}>
86 <Text
87 style={[
88 t.atoms.text_contrast_medium,
89 a.font_medium,
90 a.leading_snug,
91 ]}
92 numberOfLines={1}>
93 {isOwner ? (
94 <Trans>Reskeeted by you</Trans>
95 ) : (
96 <Trans>Reskeeted by {reposter}</Trans>
97 )}
98 </Text>
99 </ProfileHoverCard>
100 </Link>
101 )
102 }
103
104 if (AppBskyFeedDefs.isReasonPin(reason)) {
105 return (
106 <View style={styles.includeReason}>
107 <PinIcon
108 style={[t.atoms.text_contrast_medium, {marginRight: 3}]}
109 width={13}
110 height={13}
111 />
112 <Text
113 style={[t.atoms.text_contrast_medium, a.font_medium, a.leading_snug]}
114 numberOfLines={1}>
115 <Trans>Pinned</Trans>
116 </Text>
117 </View>
118 )
119 }
120}
121
122const styles = StyleSheet.create({
123 includeReason: {
124 flexDirection: 'row',
125 alignItems: 'center',
126 marginBottom: 2,
127 marginLeft: -16,
128 },
129})