mirror of
https://github.com/tooot-app/app
synced 2025-06-05 22:19:13 +02:00
@ -1,5 +1,6 @@
|
||||
import analytics from '@components/analytics'
|
||||
import { displayMessage } from '@components/Message'
|
||||
import { useRelationshipQuery } from '@utils/queryHooks/relationship'
|
||||
import {
|
||||
MutationVarsTimelineUpdateAccountProperty,
|
||||
QueryKeyTimeline,
|
||||
@ -8,13 +9,13 @@ import {
|
||||
import { getInstanceAccount } from '@utils/slices/instancesSlice'
|
||||
import { useTheme } from '@utils/styles/ThemeManager'
|
||||
import { useTranslation } from 'react-i18next'
|
||||
import { Platform } from 'react-native'
|
||||
import { ContextMenuAction } from 'react-native-context-menu-view'
|
||||
import { useQueryClient } from 'react-query'
|
||||
import { useSelector } from 'react-redux'
|
||||
|
||||
export interface Props {
|
||||
actions: ContextMenuAction[]
|
||||
type: 'status' | 'account' // Do not need to fetch relationship in timeline
|
||||
queryKey?: QueryKeyTimeline
|
||||
rootQueryKey?: QueryKeyTimeline
|
||||
id: Mastodon.Account['id']
|
||||
@ -22,6 +23,7 @@ export interface Props {
|
||||
|
||||
const contextMenuAccount = ({
|
||||
actions,
|
||||
type,
|
||||
queryKey,
|
||||
rootQueryKey,
|
||||
id: accountId
|
||||
@ -32,12 +34,17 @@ const contextMenuAccount = ({
|
||||
const queryClient = useQueryClient()
|
||||
const mutateion = useTimelineMutation({
|
||||
onSuccess: (_, params) => {
|
||||
queryClient.refetchQueries(['Relationship', { id: accountId }])
|
||||
const theParams = params as MutationVarsTimelineUpdateAccountProperty
|
||||
displayMessage({
|
||||
theme,
|
||||
type: 'success',
|
||||
message: t('common:message.success.message', {
|
||||
function: t(`account.${theParams.payload.property}.action`)
|
||||
function: t(`account.${theParams.payload.property}.action`, {
|
||||
...(typeof theParams.payload.currentValue === 'boolean' && {
|
||||
context: theParams.payload.currentValue.toString()
|
||||
})
|
||||
})
|
||||
})
|
||||
})
|
||||
},
|
||||
@ -47,7 +54,11 @@ const contextMenuAccount = ({
|
||||
theme,
|
||||
type: 'error',
|
||||
message: t('common:message.error.message', {
|
||||
function: t(`account.${theParams.payload.property}.action`)
|
||||
function: t(`account.${theParams.payload.property}.action`, {
|
||||
...(typeof theParams.payload.currentValue === 'boolean' && {
|
||||
context: theParams.payload.currentValue.toString()
|
||||
})
|
||||
})
|
||||
}),
|
||||
...(err.status &&
|
||||
typeof err.status === 'number' &&
|
||||
@ -70,93 +81,70 @@ const contextMenuAccount = ({
|
||||
)
|
||||
const ownAccount = instanceAccount?.id === accountId
|
||||
|
||||
const { data: relationship } = useRelationshipQuery({
|
||||
id: accountId,
|
||||
options: { enabled: type === 'account' }
|
||||
})
|
||||
|
||||
if (!ownAccount) {
|
||||
switch (Platform.OS) {
|
||||
case 'ios':
|
||||
actions.push({
|
||||
id: 'account',
|
||||
title: t('account.title'),
|
||||
inlineChildren: true,
|
||||
actions: [
|
||||
{
|
||||
id: 'account-mute',
|
||||
title: t('account.mute.action'),
|
||||
systemIcon: 'eye.slash'
|
||||
},
|
||||
{
|
||||
id: 'account-block',
|
||||
title: t('account.block.action'),
|
||||
systemIcon: 'xmark.circle',
|
||||
destructive: true
|
||||
},
|
||||
{
|
||||
id: 'account-reports',
|
||||
title: t('account.reports.action'),
|
||||
systemIcon: 'flag',
|
||||
destructive: true
|
||||
}
|
||||
]
|
||||
})
|
||||
break
|
||||
default:
|
||||
actions.push(
|
||||
{
|
||||
id: 'account-mute',
|
||||
title: t('account.mute.action'),
|
||||
systemIcon: 'eye.slash'
|
||||
},
|
||||
{
|
||||
id: 'account-block',
|
||||
title: t('account.block.action'),
|
||||
systemIcon: 'xmark.circle',
|
||||
destructive: true
|
||||
},
|
||||
{
|
||||
id: 'account-reports',
|
||||
title: t('account.reports.action'),
|
||||
systemIcon: 'flag',
|
||||
destructive: true
|
||||
}
|
||||
)
|
||||
break
|
||||
}
|
||||
actions.push(
|
||||
{
|
||||
id: 'account-mute',
|
||||
title: t('account.mute.action', {
|
||||
context: (relationship?.muting || false).toString()
|
||||
}),
|
||||
systemIcon: 'eye.slash'
|
||||
},
|
||||
{
|
||||
id: 'account-block',
|
||||
title: t('account.block.action', {
|
||||
context: (relationship?.blocking || false).toString()
|
||||
}),
|
||||
systemIcon: 'xmark.circle',
|
||||
destructive: true
|
||||
},
|
||||
{
|
||||
id: 'account-reports',
|
||||
title: t('account.reports.action'),
|
||||
systemIcon: 'flag',
|
||||
destructive: true
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
return (id: string) => {
|
||||
switch (id) {
|
||||
case 'account-mute':
|
||||
analytics('timeline_shared_headeractions_account_mute_press', {
|
||||
page: queryKey && queryKey[1].page
|
||||
})
|
||||
mutateion.mutate({
|
||||
type: 'updateAccountProperty',
|
||||
queryKey,
|
||||
id: accountId,
|
||||
payload: { property: 'mute' }
|
||||
})
|
||||
break
|
||||
case 'account-block':
|
||||
analytics('timeline_shared_headeractions_account_block_press', {
|
||||
page: queryKey && queryKey[1].page
|
||||
})
|
||||
mutateion.mutate({
|
||||
type: 'updateAccountProperty',
|
||||
queryKey,
|
||||
id: accountId,
|
||||
payload: { property: 'block' }
|
||||
})
|
||||
break
|
||||
case 'account-report':
|
||||
analytics('timeline_shared_headeractions_account_reports_press', {
|
||||
page: queryKey && queryKey[1].page
|
||||
})
|
||||
mutateion.mutate({
|
||||
type: 'updateAccountProperty',
|
||||
queryKey,
|
||||
id: accountId,
|
||||
payload: { property: 'reports' }
|
||||
})
|
||||
break
|
||||
return (index: number) => {
|
||||
if (actions[index].id === 'account-mute') {
|
||||
analytics('timeline_shared_headeractions_account_mute_press', {
|
||||
page: queryKey && queryKey[1].page
|
||||
})
|
||||
mutateion.mutate({
|
||||
type: 'updateAccountProperty',
|
||||
queryKey,
|
||||
id: accountId,
|
||||
payload: { property: 'mute', currentValue: relationship?.muting }
|
||||
})
|
||||
}
|
||||
if (actions[index].id === 'account-block') {
|
||||
analytics('timeline_shared_headeractions_account_block_press', {
|
||||
page: queryKey && queryKey[1].page
|
||||
})
|
||||
mutateion.mutate({
|
||||
type: 'updateAccountProperty',
|
||||
queryKey,
|
||||
id: accountId,
|
||||
payload: { property: 'block', currentValue: relationship?.blocking }
|
||||
})
|
||||
}
|
||||
if (actions[index].id === 'account-report') {
|
||||
analytics('timeline_shared_headeractions_account_reports_press', {
|
||||
page: queryKey && queryKey[1].page
|
||||
})
|
||||
mutateion.mutate({
|
||||
type: 'updateAccountProperty',
|
||||
queryKey,
|
||||
id: accountId,
|
||||
payload: { property: 'reports' }
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user