2021-01-04 10:50:24 +01:00
|
|
|
import Button from '@components/Button'
|
|
|
|
import { RelationshipOutgoing } from '@components/Relationship'
|
2020-12-27 16:25:29 +01:00
|
|
|
import { useNavigation } from '@react-navigation/native'
|
2021-01-11 21:36:57 +01:00
|
|
|
import { useRelationshipQuery } from '@utils/queryHooks/relationship'
|
2021-12-15 23:22:47 +01:00
|
|
|
import { getInstanceAccount } from '@utils/slices/instancesSlice'
|
2021-01-04 10:50:24 +01:00
|
|
|
import { StyleConstants } from '@utils/styles/constants'
|
|
|
|
import React from 'react'
|
2021-01-23 02:41:50 +01:00
|
|
|
import { useTranslation } from 'react-i18next'
|
2021-05-09 21:59:03 +02:00
|
|
|
import { StyleSheet, View } from 'react-native'
|
|
|
|
import { useSelector } from 'react-redux'
|
2020-12-27 16:25:29 +01:00
|
|
|
|
|
|
|
export interface Props {
|
|
|
|
account: Mastodon.Account | undefined
|
2021-05-09 21:59:03 +02:00
|
|
|
myInfo?: boolean
|
2021-01-23 02:41:50 +01:00
|
|
|
}
|
|
|
|
|
2021-01-07 19:13:09 +01:00
|
|
|
const Conversation = ({ account }: { account: Mastodon.Account }) => {
|
2021-08-29 15:25:38 +02:00
|
|
|
const navigation = useNavigation<any>()
|
2021-01-11 21:36:57 +01:00
|
|
|
const query = useRelationshipQuery({ id: account.id })
|
2021-01-07 19:13:09 +01:00
|
|
|
|
|
|
|
return query.data && !query.data.blocked_by ? (
|
|
|
|
<Button
|
|
|
|
round
|
|
|
|
type='icon'
|
|
|
|
content='Mail'
|
2021-05-09 21:59:03 +02:00
|
|
|
style={styles.actionLeft}
|
2022-11-29 23:44:11 +01:00
|
|
|
onPress={() =>
|
2021-01-30 01:29:15 +01:00
|
|
|
navigation.navigate('Screen-Compose', {
|
2021-01-07 19:13:09 +01:00
|
|
|
type: 'conversation',
|
2021-01-24 02:25:43 +01:00
|
|
|
accts: [account.acct]
|
2021-01-07 19:13:09 +01:00
|
|
|
})
|
2022-11-29 23:44:11 +01:00
|
|
|
}
|
2021-01-07 19:13:09 +01:00
|
|
|
/>
|
|
|
|
) : null
|
|
|
|
}
|
2020-12-27 16:25:29 +01:00
|
|
|
|
2021-05-09 21:59:03 +02:00
|
|
|
const AccountInformationActions: React.FC<Props> = ({ account, myInfo }) => {
|
2022-11-06 23:39:31 +01:00
|
|
|
if (!account || account.suspended) {
|
2021-07-07 17:19:13 +02:00
|
|
|
return null
|
|
|
|
}
|
|
|
|
|
2021-05-09 21:59:03 +02:00
|
|
|
const { t } = useTranslation('screenTabs')
|
2021-08-29 15:25:38 +02:00
|
|
|
const navigation = useNavigation<any>()
|
2021-05-09 21:59:03 +02:00
|
|
|
|
|
|
|
if (account?.moved) {
|
|
|
|
const accountMoved = account.moved
|
|
|
|
return (
|
|
|
|
<View style={styles.base}>
|
|
|
|
<Button
|
|
|
|
type='text'
|
|
|
|
content={t('shared.account.moved')}
|
2022-11-29 23:44:11 +01:00
|
|
|
onPress={() => navigation.push('Tab-Shared-Account', { account: accountMoved })}
|
2021-05-09 21:59:03 +02:00
|
|
|
/>
|
|
|
|
</View>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
if (myInfo) {
|
|
|
|
return (
|
|
|
|
<View style={styles.base}>
|
|
|
|
<Button
|
|
|
|
type='text'
|
|
|
|
disabled={account === undefined}
|
|
|
|
content={t('me.stacks.profile.name')}
|
|
|
|
onPress={() => navigation.navigate('Tab-Me-Profile')}
|
|
|
|
/>
|
|
|
|
</View>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
const instanceAccount = useSelector(getInstanceAccount, () => true)
|
2022-11-29 23:44:11 +01:00
|
|
|
const ownAccount = account?.id === instanceAccount?.id && account?.acct === instanceAccount?.acct
|
2021-05-09 21:59:03 +02:00
|
|
|
|
|
|
|
if (!ownAccount && account) {
|
|
|
|
return (
|
|
|
|
<View style={styles.base}>
|
2021-01-23 02:41:50 +01:00
|
|
|
<Conversation account={account} />
|
|
|
|
<RelationshipOutgoing id={account.id} />
|
2021-05-09 21:59:03 +02:00
|
|
|
</View>
|
|
|
|
)
|
|
|
|
} else {
|
|
|
|
return null
|
|
|
|
}
|
2020-12-27 16:25:29 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
const styles = StyleSheet.create({
|
2021-05-09 21:59:03 +02:00
|
|
|
base: {
|
|
|
|
alignSelf: 'flex-end',
|
|
|
|
flexDirection: 'row'
|
|
|
|
},
|
|
|
|
actionLeft: { marginRight: StyleConstants.Spacing.S }
|
2020-12-27 16:25:29 +01:00
|
|
|
})
|
|
|
|
|
|
|
|
export default AccountInformationActions
|