2021-01-24 02:25:43 +01:00
|
|
|
import analytics from '@components/analytics'
|
2021-01-03 02:00:26 +01:00
|
|
|
import Icon from '@components/Icon'
|
2021-02-28 22:49:55 +01:00
|
|
|
import { displayMessage } from '@components/Message'
|
2021-01-24 02:25:43 +01:00
|
|
|
import { ParseEmojis } from '@components/Parse'
|
2022-05-07 00:52:32 +02:00
|
|
|
import CustomText from '@components/Text'
|
2021-01-11 21:36:57 +01:00
|
|
|
import {
|
|
|
|
QueryKeyTimeline,
|
|
|
|
useTimelineMutation
|
|
|
|
} from '@utils/queryHooks/timeline'
|
2020-12-13 14:04:25 +01:00
|
|
|
import { StyleConstants } from '@utils/styles/constants'
|
|
|
|
import { useTheme } from '@utils/styles/ThemeManager'
|
2021-01-01 16:48:16 +01:00
|
|
|
import React, { useCallback, useMemo } from 'react'
|
2021-01-04 10:50:24 +01:00
|
|
|
import { useTranslation } from 'react-i18next'
|
2022-05-07 00:52:32 +02:00
|
|
|
import { Pressable, View } from 'react-native'
|
2021-01-11 21:36:57 +01:00
|
|
|
import { useQueryClient } from 'react-query'
|
2021-01-01 23:10:47 +01:00
|
|
|
import HeaderSharedCreated from './HeaderShared/Created'
|
2021-01-11 21:36:57 +01:00
|
|
|
import HeaderSharedMuted from './HeaderShared/Muted'
|
2020-11-22 00:46:23 +01:00
|
|
|
|
2022-04-30 21:29:08 +02:00
|
|
|
const Names = ({ accounts }: { accounts: Mastodon.Account[] }) => {
|
|
|
|
const { t } = useTranslation('componentTimeline')
|
|
|
|
const { colors } = useTheme()
|
2021-01-24 02:25:43 +01:00
|
|
|
|
2022-04-30 21:29:08 +02:00
|
|
|
return (
|
2022-05-07 00:52:32 +02:00
|
|
|
<CustomText
|
2022-04-30 21:29:08 +02:00
|
|
|
numberOfLines={1}
|
|
|
|
style={{ ...StyleConstants.FontStyle.M, color: colors.secondary }}
|
|
|
|
>
|
2022-05-07 00:52:32 +02:00
|
|
|
<CustomText>{t('shared.header.conversation.withAccounts')}</CustomText>
|
2022-04-30 21:29:08 +02:00
|
|
|
{accounts.map((account, index) => (
|
2022-05-07 00:52:32 +02:00
|
|
|
<CustomText key={account.id} numberOfLines={1}>
|
2022-04-30 21:29:08 +02:00
|
|
|
{index !== 0 ? t('common:separator') : undefined}
|
|
|
|
<ParseEmojis
|
|
|
|
content={account.display_name || account.username}
|
|
|
|
emojis={account.emojis}
|
|
|
|
fontBold
|
|
|
|
/>
|
2022-05-07 00:52:32 +02:00
|
|
|
</CustomText>
|
2022-04-30 21:29:08 +02:00
|
|
|
))}
|
2022-05-07 00:52:32 +02:00
|
|
|
</CustomText>
|
2022-04-30 21:29:08 +02:00
|
|
|
)
|
|
|
|
}
|
2021-01-24 02:25:43 +01:00
|
|
|
|
2020-11-22 00:46:23 +01:00
|
|
|
export interface Props {
|
2021-01-07 19:13:09 +01:00
|
|
|
queryKey: QueryKeyTimeline
|
2020-12-27 16:25:29 +01:00
|
|
|
conversation: Mastodon.Conversation
|
2020-11-22 00:46:23 +01:00
|
|
|
}
|
|
|
|
|
2022-04-30 21:29:08 +02:00
|
|
|
const HeaderConversation = ({ queryKey, conversation }: Props) => {
|
|
|
|
const { colors, theme } = useTheme()
|
|
|
|
const { t } = useTranslation('componentTimeline')
|
2021-01-04 10:50:24 +01:00
|
|
|
|
2022-04-30 21:29:08 +02:00
|
|
|
const queryClient = useQueryClient()
|
|
|
|
const mutation = useTimelineMutation({
|
|
|
|
onMutate: true,
|
|
|
|
onError: (err: any, _, oldData) => {
|
|
|
|
displayMessage({
|
|
|
|
theme,
|
|
|
|
type: 'error',
|
|
|
|
message: t('common:message.error.message', {
|
|
|
|
function: t(`shared.header.conversation.delete.function`)
|
|
|
|
}),
|
|
|
|
...(err.status &&
|
|
|
|
typeof err.status === 'number' &&
|
|
|
|
err.data &&
|
|
|
|
err.data.error &&
|
|
|
|
typeof err.data.error === 'string' && {
|
|
|
|
description: err.data.error
|
|
|
|
})
|
2021-02-27 16:33:54 +01:00
|
|
|
})
|
2022-04-30 21:29:08 +02:00
|
|
|
queryClient.setQueryData(queryKey, oldData)
|
|
|
|
}
|
|
|
|
})
|
2020-12-13 01:24:25 +01:00
|
|
|
|
2022-04-30 21:29:08 +02:00
|
|
|
const actionOnPress = useCallback(() => {
|
|
|
|
analytics('timeline_conversation_delete_press')
|
|
|
|
mutation.mutate({
|
|
|
|
type: 'deleteItem',
|
|
|
|
source: 'conversations',
|
|
|
|
queryKey,
|
|
|
|
id: conversation.id
|
|
|
|
})
|
|
|
|
}, [])
|
2020-12-13 01:24:25 +01:00
|
|
|
|
2022-04-30 21:29:08 +02:00
|
|
|
const actionChildren = useMemo(
|
|
|
|
() => (
|
|
|
|
<Icon
|
|
|
|
name='Trash'
|
|
|
|
color={colors.secondary}
|
|
|
|
size={StyleConstants.Font.Size.L}
|
|
|
|
/>
|
|
|
|
),
|
|
|
|
[]
|
|
|
|
)
|
2020-12-13 01:24:25 +01:00
|
|
|
|
2022-04-30 21:29:08 +02:00
|
|
|
return (
|
|
|
|
<View style={{ flex: 1, flexDirection: 'row' }}>
|
|
|
|
<View style={{ flex: 3 }}>
|
|
|
|
<Names accounts={conversation.accounts} />
|
|
|
|
<View
|
|
|
|
style={{
|
|
|
|
flexDirection: 'row',
|
|
|
|
alignItems: 'center',
|
|
|
|
marginTop: StyleConstants.Spacing.XS,
|
|
|
|
marginBottom: StyleConstants.Spacing.S
|
|
|
|
}}
|
|
|
|
>
|
|
|
|
{conversation.last_status?.created_at ? (
|
|
|
|
<HeaderSharedCreated
|
|
|
|
created_at={conversation.last_status?.created_at}
|
|
|
|
edited_at={conversation.last_status?.edited_at}
|
|
|
|
/>
|
|
|
|
) : null}
|
|
|
|
<HeaderSharedMuted muted={conversation.last_status?.muted} />
|
|
|
|
</View>
|
2021-02-27 16:33:54 +01:00
|
|
|
</View>
|
2020-11-22 00:46:23 +01:00
|
|
|
|
2022-04-30 21:29:08 +02:00
|
|
|
<Pressable
|
|
|
|
style={{ flex: 1, flexDirection: 'row', justifyContent: 'center' }}
|
|
|
|
onPress={actionOnPress}
|
|
|
|
children={actionChildren}
|
|
|
|
/>
|
|
|
|
</View>
|
|
|
|
)
|
|
|
|
}
|
2020-11-22 00:46:23 +01:00
|
|
|
|
|
|
|
export default HeaderConversation
|