2022-12-03 01:08:38 +01:00
|
|
|
import menuInstance from '@components/contextMenu/instance'
|
|
|
|
import menuShare from '@components/contextMenu/share'
|
|
|
|
import menuStatus from '@components/contextMenu/status'
|
2021-02-08 23:47:20 +01:00
|
|
|
import TimelineActioned from '@components/Timeline/Shared/Actioned'
|
|
|
|
import TimelineActions from '@components/Timeline/Shared/Actions'
|
|
|
|
import TimelineAttachment from '@components/Timeline/Shared/Attachment'
|
|
|
|
import TimelineAvatar from '@components/Timeline/Shared/Avatar'
|
|
|
|
import TimelineCard from '@components/Timeline/Shared/Card'
|
|
|
|
import TimelineContent from '@components/Timeline/Shared/Content'
|
|
|
|
import TimelineHeaderDefault from '@components/Timeline/Shared/HeaderDefault'
|
|
|
|
import TimelinePoll from '@components/Timeline/Shared/Poll'
|
2020-12-30 14:33:33 +01:00
|
|
|
import { useNavigation } from '@react-navigation/native'
|
2021-01-24 02:25:43 +01:00
|
|
|
import { StackNavigationProp } from '@react-navigation/stack'
|
2022-12-28 23:41:36 +01:00
|
|
|
import { featureCheck } from '@utils/helpers/featureCheck'
|
2023-02-07 15:06:04 +01:00
|
|
|
import { checkIsMyAccount } from '@utils/helpers/isMyAccount'
|
2022-12-28 23:41:36 +01:00
|
|
|
import removeHTML from '@utils/helpers/removeHTML'
|
2022-04-29 23:57:18 +02:00
|
|
|
import { TabLocalStackParamList } from '@utils/navigation/navigators'
|
2022-12-28 23:41:36 +01:00
|
|
|
import { usePreferencesQuery } from '@utils/queryHooks/preferences'
|
2021-01-07 19:13:09 +01:00
|
|
|
import { QueryKeyTimeline } from '@utils/queryHooks/timeline'
|
2020-12-13 14:04:25 +01:00
|
|
|
import { StyleConstants } from '@utils/styles/constants'
|
2021-02-08 23:47:20 +01:00
|
|
|
import { useTheme } from '@utils/styles/ThemeManager'
|
2022-12-25 17:40:53 +01:00
|
|
|
import React, { Fragment, useRef, useState } from 'react'
|
2022-11-29 23:44:11 +01:00
|
|
|
import { Pressable, StyleProp, View, ViewStyle } from 'react-native'
|
2022-12-03 01:08:38 +01:00
|
|
|
import * as ContextMenu from 'zeego/context-menu'
|
2022-12-03 20:47:11 +01:00
|
|
|
import StatusContext from './Shared/Context'
|
2022-04-29 23:57:18 +02:00
|
|
|
import TimelineFeedback from './Shared/Feedback'
|
2022-12-18 17:25:18 +01:00
|
|
|
import TimelineFiltered, { FilteredProps, shouldFilter } from './Shared/Filtered'
|
2021-03-14 01:35:38 +01:00
|
|
|
import TimelineFullConversation from './Shared/FullConversation'
|
2022-12-03 01:08:38 +01:00
|
|
|
import TimelineHeaderAndroid from './Shared/HeaderAndroid'
|
2021-05-19 20:40:16 +02:00
|
|
|
import TimelineTranslate from './Shared/Translate'
|
2020-10-29 14:52:28 +01:00
|
|
|
|
2020-10-31 21:04:46 +01:00
|
|
|
export interface Props {
|
2021-03-09 10:35:53 +01:00
|
|
|
item: Mastodon.Status & { _pinned?: boolean } // For account page, internal property
|
2021-01-07 19:13:09 +01:00
|
|
|
queryKey?: QueryKeyTimeline
|
2020-12-12 22:19:18 +01:00
|
|
|
highlighted?: boolean
|
2023-01-29 19:27:15 +01:00
|
|
|
suppressSpoiler?: boolean // Same content as the main thread, can be dimmed
|
2021-01-04 18:29:02 +01:00
|
|
|
disableDetails?: boolean
|
|
|
|
disableOnPress?: boolean
|
2022-12-16 00:21:53 +01:00
|
|
|
isConversation?: boolean
|
2023-01-15 19:59:48 +01:00
|
|
|
noBackground?: boolean
|
2020-10-31 21:04:46 +01:00
|
|
|
}
|
|
|
|
|
2020-11-23 00:07:32 +01:00
|
|
|
// When the poll is long
|
2022-06-01 00:33:59 +02:00
|
|
|
const TimelineDefault: React.FC<Props> = ({
|
|
|
|
item,
|
|
|
|
queryKey,
|
|
|
|
highlighted = false,
|
2023-01-29 19:27:15 +01:00
|
|
|
suppressSpoiler = false,
|
2022-06-01 00:33:59 +02:00
|
|
|
disableDetails = false,
|
2022-12-16 00:21:53 +01:00
|
|
|
disableOnPress = false,
|
2023-01-15 19:59:48 +01:00
|
|
|
isConversation = false,
|
|
|
|
noBackground = false
|
2022-06-01 00:33:59 +02:00
|
|
|
}) => {
|
2022-12-18 17:25:18 +01:00
|
|
|
const status = item.reblog ? item.reblog : item
|
|
|
|
const rawContent = useRef<string[]>([])
|
2022-12-31 02:06:19 +01:00
|
|
|
if (highlighted || isConversation) {
|
2022-12-18 17:25:18 +01:00
|
|
|
rawContent.current = [
|
|
|
|
removeHTML(status.content),
|
|
|
|
status.spoiler_text ? removeHTML(status.spoiler_text) : ''
|
|
|
|
].filter(c => c.length)
|
|
|
|
}
|
|
|
|
|
2022-06-01 00:33:59 +02:00
|
|
|
const { colors } = useTheme()
|
2022-10-27 23:05:00 +02:00
|
|
|
const navigation = useNavigation<StackNavigationProp<TabLocalStackParamList>>()
|
2020-10-29 14:52:28 +01:00
|
|
|
|
2022-12-28 23:41:36 +01:00
|
|
|
const { data: preferences } = usePreferencesQuery()
|
2021-05-30 23:39:07 +02:00
|
|
|
|
2023-02-07 15:06:04 +01:00
|
|
|
const isMyAccount = checkIsMyAccount(status.account.id)
|
2022-12-03 20:47:11 +01:00
|
|
|
const [spoilerExpanded, setSpoilerExpanded] = useState(
|
2022-12-28 23:41:36 +01:00
|
|
|
preferences?.['reading:expand:spoilers'] || false
|
2022-12-03 20:47:11 +01:00
|
|
|
)
|
|
|
|
const spoilerHidden = status.spoiler_text?.length
|
2022-12-28 23:41:36 +01:00
|
|
|
? !preferences?.['reading:expand:spoilers'] && !spoilerExpanded
|
2022-12-03 20:47:11 +01:00
|
|
|
: false
|
2022-12-17 23:21:56 +01:00
|
|
|
const detectedLanguage = useRef<string>(status.language || '')
|
2022-12-31 02:06:19 +01:00
|
|
|
const excludeMentions = useRef<Mastodon.Mention[]>([])
|
2022-08-09 00:44:56 +02:00
|
|
|
|
2022-11-12 17:52:50 +01:00
|
|
|
const mainStyle: StyleProp<ViewStyle> = {
|
2022-12-11 12:16:12 +01:00
|
|
|
flex: 1,
|
2022-12-11 14:08:27 +01:00
|
|
|
padding: disableDetails
|
|
|
|
? StyleConstants.Spacing.Global.PagePadding / 1.5
|
|
|
|
: StyleConstants.Spacing.Global.PagePadding,
|
2023-01-15 19:59:48 +01:00
|
|
|
backgroundColor: noBackground ? undefined : colors.backgroundDefault,
|
2022-12-16 00:21:53 +01:00
|
|
|
paddingBottom: disableDetails ? StyleConstants.Spacing.Global.PagePadding / 1.5 : 0
|
2022-11-12 17:52:50 +01:00
|
|
|
}
|
|
|
|
const main = () => (
|
|
|
|
<>
|
|
|
|
{item.reblog ? (
|
2023-01-01 18:37:05 +01:00
|
|
|
<TimelineActioned action='reblog' rootStatus={item} />
|
2022-11-12 17:52:50 +01:00
|
|
|
) : item._pinned ? (
|
2023-01-01 18:37:05 +01:00
|
|
|
<TimelineActioned action='pinned' rootStatus={item} />
|
2022-11-12 17:52:50 +01:00
|
|
|
) : null}
|
|
|
|
|
2022-12-11 14:08:27 +01:00
|
|
|
<View
|
|
|
|
style={{
|
|
|
|
flex: 1,
|
|
|
|
flexDirection: 'row',
|
|
|
|
...(disableDetails && { alignItems: 'flex-start', overflow: 'hidden' })
|
|
|
|
}}
|
|
|
|
>
|
2022-12-03 20:47:11 +01:00
|
|
|
<TimelineAvatar />
|
|
|
|
<TimelineHeaderDefault />
|
2022-11-12 17:52:50 +01:00
|
|
|
</View>
|
|
|
|
|
|
|
|
<View
|
2022-04-30 21:59:13 +02:00
|
|
|
style={{
|
2022-11-12 17:52:50 +01:00
|
|
|
paddingTop: highlighted ? StyleConstants.Spacing.S : 0,
|
2022-12-11 14:08:27 +01:00
|
|
|
paddingLeft: highlighted
|
|
|
|
? 0
|
2022-12-18 23:15:58 +01:00
|
|
|
: (disableDetails || isConversation
|
|
|
|
? StyleConstants.Avatar.XS
|
|
|
|
: StyleConstants.Avatar.M) + StyleConstants.Spacing.S,
|
2022-12-11 14:08:27 +01:00
|
|
|
...(disableDetails && { marginTop: -StyleConstants.Spacing.S })
|
2020-12-13 23:02:54 +01:00
|
|
|
}}
|
2020-12-12 22:19:18 +01:00
|
|
|
>
|
2022-12-03 20:47:11 +01:00
|
|
|
<TimelineContent setSpoilerExpanded={setSpoilerExpanded} />
|
|
|
|
<TimelinePoll />
|
|
|
|
<TimelineAttachment />
|
|
|
|
<TimelineCard />
|
|
|
|
<TimelineFullConversation />
|
|
|
|
<TimelineTranslate />
|
|
|
|
<TimelineFeedback />
|
2022-11-12 17:52:50 +01:00
|
|
|
|
2022-12-18 23:15:58 +01:00
|
|
|
<TimelineActions />
|
|
|
|
</View>
|
2022-11-12 17:52:50 +01:00
|
|
|
</>
|
|
|
|
)
|
|
|
|
|
2022-12-03 01:08:38 +01:00
|
|
|
const mShare = menuShare({
|
2022-12-03 20:47:11 +01:00
|
|
|
visibility: status.visibility,
|
2022-12-03 01:08:38 +01:00
|
|
|
type: 'status',
|
2022-12-03 20:47:11 +01:00
|
|
|
url: status.url || status.uri,
|
2022-12-18 17:25:18 +01:00
|
|
|
rawContent
|
2022-12-03 01:08:38 +01:00
|
|
|
})
|
2023-01-04 22:39:29 +01:00
|
|
|
const mStatus = menuStatus({ status, queryKey })
|
|
|
|
const mInstance = menuInstance({ status, queryKey })
|
2022-12-03 20:47:11 +01:00
|
|
|
|
2023-02-07 15:06:04 +01:00
|
|
|
if (!isMyAccount) {
|
2022-12-18 17:25:18 +01:00
|
|
|
let filterResults: FilteredProps['filterResults'] = []
|
|
|
|
const [filterRevealed, setFilterRevealed] = useState(false)
|
2022-12-28 23:41:36 +01:00
|
|
|
const hasFilterServerSide = featureCheck('filter_server_side')
|
2022-12-18 17:25:18 +01:00
|
|
|
if (hasFilterServerSide) {
|
|
|
|
if (status.filtered?.length) {
|
|
|
|
filterResults = status.filtered?.map(filter => filter.filter)
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (queryKey) {
|
|
|
|
const checkFilter = shouldFilter({ queryKey, status })
|
|
|
|
if (checkFilter?.length) {
|
|
|
|
filterResults = checkFilter
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (queryKey && !highlighted && filterResults?.length && !filterRevealed) {
|
|
|
|
return !filterResults.filter(result => result.filter_action === 'hide').length ? (
|
|
|
|
<Pressable onPress={() => setFilterRevealed(!filterRevealed)}>
|
|
|
|
<TimelineFiltered filterResults={filterResults} />
|
|
|
|
</Pressable>
|
|
|
|
) : null
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-12-03 20:47:11 +01:00
|
|
|
return (
|
|
|
|
<StatusContext.Provider
|
|
|
|
value={{
|
|
|
|
queryKey,
|
|
|
|
status,
|
2023-02-07 15:06:04 +01:00
|
|
|
isMyAccount,
|
2022-12-03 20:47:11 +01:00
|
|
|
spoilerHidden,
|
2022-12-18 17:25:18 +01:00
|
|
|
rawContent,
|
2022-12-17 23:21:56 +01:00
|
|
|
detectedLanguage,
|
2022-12-31 02:06:19 +01:00
|
|
|
excludeMentions,
|
2022-12-03 20:47:11 +01:00
|
|
|
highlighted,
|
2023-01-29 19:27:15 +01:00
|
|
|
suppressSpoiler,
|
2022-12-11 01:46:14 +01:00
|
|
|
inThread: queryKey?.[1].page === 'Toot',
|
2022-12-03 20:47:11 +01:00
|
|
|
disableDetails,
|
2022-12-16 00:21:53 +01:00
|
|
|
disableOnPress,
|
2022-12-31 15:53:02 +01:00
|
|
|
isConversation,
|
2023-01-02 23:18:22 +01:00
|
|
|
isRemote: item._remote
|
2022-12-03 20:47:11 +01:00
|
|
|
}}
|
|
|
|
>
|
|
|
|
{disableOnPress ? (
|
|
|
|
<View style={mainStyle}>{main()}</View>
|
|
|
|
) : (
|
|
|
|
<>
|
|
|
|
<ContextMenu.Root>
|
|
|
|
<ContextMenu.Trigger>
|
|
|
|
<Pressable
|
|
|
|
accessible={highlighted ? false : true}
|
|
|
|
style={mainStyle}
|
|
|
|
disabled={highlighted}
|
2023-01-04 22:39:29 +01:00
|
|
|
onPress={() => navigation.push('Tab-Shared-Toot', { toot: status })}
|
2022-12-03 20:47:11 +01:00
|
|
|
onLongPress={() => {}}
|
|
|
|
children={main()}
|
|
|
|
/>
|
|
|
|
</ContextMenu.Trigger>
|
|
|
|
|
|
|
|
<ContextMenu.Content>
|
2023-01-08 16:59:35 +01:00
|
|
|
{[mShare, mStatus, mInstance].map((menu, i) => (
|
2022-12-25 17:40:53 +01:00
|
|
|
<Fragment key={i}>
|
2023-01-08 16:59:35 +01:00
|
|
|
{menu.map((group, index) => (
|
2022-12-24 01:59:18 +01:00
|
|
|
<ContextMenu.Group key={index}>
|
2023-01-08 16:59:35 +01:00
|
|
|
{group.map(item => {
|
|
|
|
switch (item.type) {
|
|
|
|
case 'item':
|
|
|
|
return (
|
|
|
|
<ContextMenu.Item key={item.key} {...item.props}>
|
|
|
|
<ContextMenu.ItemTitle children={item.title} />
|
|
|
|
{item.icon ? (
|
|
|
|
<ContextMenu.ItemIcon ios={{ name: item.icon }} />
|
|
|
|
) : null}
|
|
|
|
</ContextMenu.Item>
|
|
|
|
)
|
|
|
|
case 'sub':
|
|
|
|
return (
|
|
|
|
// @ts-ignore
|
|
|
|
<ContextMenu.Sub key={item.key}>
|
|
|
|
<ContextMenu.SubTrigger
|
|
|
|
key={item.trigger.key}
|
|
|
|
{...item.trigger.props}
|
|
|
|
>
|
|
|
|
<ContextMenu.ItemTitle children={item.trigger.title} />
|
|
|
|
{item.trigger.icon ? (
|
|
|
|
<ContextMenu.ItemIcon ios={{ name: item.trigger.icon }} />
|
|
|
|
) : null}
|
|
|
|
</ContextMenu.SubTrigger>
|
|
|
|
<ContextMenu.SubContent>
|
|
|
|
{item.items.map(sub => (
|
|
|
|
<ContextMenu.Item key={sub.key} {...sub.props}>
|
|
|
|
<ContextMenu.ItemTitle children={sub.title} />
|
|
|
|
{sub.icon ? (
|
|
|
|
<ContextMenu.ItemIcon ios={{ name: sub.icon }} />
|
|
|
|
) : null}
|
|
|
|
</ContextMenu.Item>
|
|
|
|
))}
|
|
|
|
</ContextMenu.SubContent>
|
|
|
|
</ContextMenu.Sub>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
})}
|
2022-12-24 01:59:18 +01:00
|
|
|
</ContextMenu.Group>
|
2022-12-03 20:47:11 +01:00
|
|
|
))}
|
2022-12-25 17:40:53 +01:00
|
|
|
</Fragment>
|
2022-12-03 01:08:38 +01:00
|
|
|
))}
|
2022-12-03 20:47:11 +01:00
|
|
|
</ContextMenu.Content>
|
|
|
|
</ContextMenu.Root>
|
|
|
|
<TimelineHeaderAndroid />
|
|
|
|
</>
|
|
|
|
)}
|
|
|
|
</StatusContext.Provider>
|
2022-06-01 00:33:59 +02:00
|
|
|
)
|
|
|
|
}
|
2020-10-29 14:52:28 +01:00
|
|
|
|
2023-02-25 00:34:37 +01:00
|
|
|
export default React.memo(TimelineDefault)
|