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'
|
2022-12-28 23:41:36 +01:00
|
|
|
import { useQueryClient } from '@tanstack/react-query'
|
2022-12-03 20:47:11 +01:00
|
|
|
import { 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'
|
2022-12-03 20:47:11 +01:00
|
|
|
import React, { useContext } 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'
|
2022-12-03 20:47:11 +01:00
|
|
|
import StatusContext from './Context'
|
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
|
|
|
|
|
|
|
export interface Props {
|
2020-12-27 16:25:29 +01:00
|
|
|
conversation: Mastodon.Conversation
|
2020-11-22 00:46:23 +01:00
|
|
|
}
|
|
|
|
|
2022-12-03 20:47:11 +01:00
|
|
|
const HeaderConversation = ({ conversation }: Props) => {
|
|
|
|
const { queryKey } = useContext(StatusContext)
|
|
|
|
if (!queryKey) return null
|
|
|
|
|
2022-04-30 21:29:08 +02:00
|
|
|
const { colors, theme } = useTheme()
|
2022-12-23 15:53:40 +01:00
|
|
|
const { t } = useTranslation(['common', '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', {
|
2022-12-23 15:53:40 +01:00
|
|
|
function: t(`componentTimeline:shared.header.conversation.delete.function`)
|
2022-04-30 21:29:08 +02:00
|
|
|
}),
|
|
|
|
...(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
|
|
|
return (
|
|
|
|
<View style={{ flex: 1, flexDirection: 'row' }}>
|
|
|
|
<View style={{ flex: 3 }}>
|
2022-12-03 20:47:11 +01:00
|
|
|
<CustomText
|
|
|
|
numberOfLines={1}
|
|
|
|
style={{ ...StyleConstants.FontStyle.M, color: colors.secondary }}
|
|
|
|
>
|
2022-12-23 15:53:40 +01:00
|
|
|
<CustomText>{t('componentTimeline:shared.header.conversation.withAccounts')}</CustomText>
|
2022-12-03 20:47:11 +01:00
|
|
|
{conversation.accounts.map((account, index) => (
|
|
|
|
<CustomText key={account.id} numberOfLines={1}>
|
|
|
|
{index !== 0 ? t('common:separator') : undefined}
|
|
|
|
<ParseEmojis
|
|
|
|
content={account.display_name || account.username}
|
|
|
|
emojis={account.emojis}
|
|
|
|
fontBold
|
|
|
|
/>
|
|
|
|
</CustomText>
|
|
|
|
))}
|
|
|
|
</CustomText>
|
2022-04-30 21:29:08 +02:00
|
|
|
<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' }}
|
2022-11-29 23:44:11 +01:00
|
|
|
onPress={() =>
|
|
|
|
mutation.mutate({
|
|
|
|
type: 'deleteItem',
|
|
|
|
source: 'conversations',
|
|
|
|
queryKey,
|
|
|
|
id: conversation.id
|
|
|
|
})
|
|
|
|
}
|
|
|
|
children={<Icon name='Trash' color={colors.secondary} size={StyleConstants.Font.Size.L} />}
|
2022-04-30 21:29:08 +02:00
|
|
|
/>
|
|
|
|
</View>
|
|
|
|
)
|
|
|
|
}
|
2020-11-22 00:46:23 +01:00
|
|
|
|
|
|
|
export default HeaderConversation
|