mirror of
https://github.com/tooot-app/app
synced 2025-04-11 17:11:09 +02:00
Fixed #568
This commit is contained in:
parent
b76d3f50df
commit
fea2e82bdd
2
src/@types/mastodon.d.ts
vendored
2
src/@types/mastodon.d.ts
vendored
@ -406,6 +406,8 @@ declare namespace Mastodon {
|
|||||||
id: string
|
id: string
|
||||||
following: boolean
|
following: boolean
|
||||||
showing_reblogs: boolean
|
showing_reblogs: boolean
|
||||||
|
notifying?: boolean
|
||||||
|
languages?: string[]
|
||||||
followed_by: boolean
|
followed_by: boolean
|
||||||
blocking: boolean
|
blocking: boolean
|
||||||
blocked_by: boolean
|
blocked_by: boolean
|
||||||
|
@ -6,21 +6,24 @@ import {
|
|||||||
useRelationshipMutation,
|
useRelationshipMutation,
|
||||||
useRelationshipQuery
|
useRelationshipQuery
|
||||||
} from '@utils/queryHooks/relationship'
|
} from '@utils/queryHooks/relationship'
|
||||||
import { QueryKeyTimeline } from '@utils/queryHooks/timeline'
|
|
||||||
import { useTheme } from '@utils/styles/ThemeManager'
|
import { useTheme } from '@utils/styles/ThemeManager'
|
||||||
import React from 'react'
|
import React from 'react'
|
||||||
import { useTranslation } from 'react-i18next'
|
import { useTranslation } from 'react-i18next'
|
||||||
import { useQueryClient } from '@tanstack/react-query'
|
import { useQueryClient } from '@tanstack/react-query'
|
||||||
|
import { useSelector } from 'react-redux'
|
||||||
|
import { checkInstanceFeature } from '@utils/slices/instancesSlice'
|
||||||
|
import { StyleConstants } from '@utils/styles/constants'
|
||||||
|
|
||||||
export interface Props {
|
export interface Props {
|
||||||
id: Mastodon.Account['id']
|
id: Mastodon.Account['id']
|
||||||
}
|
}
|
||||||
|
|
||||||
const RelationshipOutgoing = React.memo(
|
const RelationshipOutgoing: React.FC<Props> = ({ id }: Props) => {
|
||||||
({ id }: Props) => {
|
|
||||||
const { theme } = useTheme()
|
const { theme } = useTheme()
|
||||||
const { t } = useTranslation('componentRelationship')
|
const { t } = useTranslation('componentRelationship')
|
||||||
|
|
||||||
|
const canFollowNotify = useSelector(checkInstanceFeature('account_follow_notify'))
|
||||||
|
|
||||||
const query = useRelationshipQuery({ id })
|
const query = useRelationshipQuery({ id })
|
||||||
|
|
||||||
const queryKeyRelationship: QueryKeyRelationship = ['Relationship', { id }]
|
const queryKeyRelationship: QueryKeyRelationship = ['Relationship', { id }]
|
||||||
@ -120,6 +123,27 @@ const RelationshipOutgoing = React.memo(
|
|||||||
}
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
<>
|
||||||
|
{canFollowNotify && query.data?.following ? (
|
||||||
|
<Button
|
||||||
|
type='icon'
|
||||||
|
content={query.data.notifying ? 'BellOff' : 'Bell'}
|
||||||
|
round
|
||||||
|
onPress={() =>
|
||||||
|
mutation.mutate({
|
||||||
|
id,
|
||||||
|
type: 'outgoing',
|
||||||
|
payload: {
|
||||||
|
action: 'follow',
|
||||||
|
state: false,
|
||||||
|
notify: !query.data.notifying
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
loading={query.isLoading || mutation.isLoading}
|
||||||
|
style={{ marginRight: StyleConstants.Spacing.S }}
|
||||||
|
/>
|
||||||
|
) : null}
|
||||||
<Button
|
<Button
|
||||||
type='text'
|
type='text'
|
||||||
content={content}
|
content={content}
|
||||||
@ -127,9 +151,8 @@ const RelationshipOutgoing = React.memo(
|
|||||||
loading={query.isLoading || mutation.isLoading}
|
loading={query.isLoading || mutation.isLoading}
|
||||||
disabled={query.isError || query.data?.blocked_by}
|
disabled={query.isError || query.data?.blocked_by}
|
||||||
/>
|
/>
|
||||||
|
</>
|
||||||
)
|
)
|
||||||
},
|
}
|
||||||
() => true
|
|
||||||
)
|
|
||||||
|
|
||||||
export default RelationshipOutgoing
|
export default RelationshipOutgoing
|
||||||
|
@ -1,4 +1,8 @@
|
|||||||
[
|
[
|
||||||
|
{
|
||||||
|
"feature": "account_follow_notify",
|
||||||
|
"version": 3.3
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"feature": "notification_type_status",
|
"feature": "notification_type_status",
|
||||||
"version": 3.3
|
"version": 3.3
|
||||||
|
@ -8,14 +8,9 @@ import {
|
|||||||
UseQueryOptions
|
UseQueryOptions
|
||||||
} from '@tanstack/react-query'
|
} from '@tanstack/react-query'
|
||||||
|
|
||||||
export type QueryKeyRelationship = [
|
export type QueryKeyRelationship = ['Relationship', { id: Mastodon.Account['id'] }]
|
||||||
'Relationship',
|
|
||||||
{ id: Mastodon.Account['id'] }
|
|
||||||
]
|
|
||||||
|
|
||||||
const queryFunction = async ({
|
const queryFunction = async ({ queryKey }: QueryFunctionContext<QueryKeyRelationship>) => {
|
||||||
queryKey
|
|
||||||
}: QueryFunctionContext<QueryKeyRelationship>) => {
|
|
||||||
const { id } = queryKey[1]
|
const { id } = queryKey[1]
|
||||||
|
|
||||||
const res = await apiInstance<Mastodon.Relationship[]>({
|
const res = await apiInstance<Mastodon.Relationship[]>({
|
||||||
@ -32,11 +27,7 @@ const useRelationshipQuery = ({
|
|||||||
options,
|
options,
|
||||||
...queryKeyParams
|
...queryKeyParams
|
||||||
}: QueryKeyRelationship[1] & {
|
}: QueryKeyRelationship[1] & {
|
||||||
options?: UseQueryOptions<
|
options?: UseQueryOptions<Mastodon.Relationship[], AxiosError, Mastodon.Relationship>
|
||||||
Mastodon.Relationship[],
|
|
||||||
AxiosError,
|
|
||||||
Mastodon.Relationship
|
|
||||||
>
|
|
||||||
}) => {
|
}) => {
|
||||||
const queryKey: QueryKeyRelationship = ['Relationship', { ...queryKeyParams }]
|
const queryKey: QueryKeyRelationship = ['Relationship', { ...queryKeyParams }]
|
||||||
return useQuery(queryKey, queryFunction, {
|
return useQuery(queryKey, queryFunction, {
|
||||||
@ -54,7 +45,20 @@ type MutationVarsRelationship =
|
|||||||
| {
|
| {
|
||||||
id: Mastodon.Account['id']
|
id: Mastodon.Account['id']
|
||||||
type: 'outgoing'
|
type: 'outgoing'
|
||||||
payload: { action: 'follow' | 'block'; state: boolean }
|
payload: {
|
||||||
|
action: 'block'
|
||||||
|
state: boolean
|
||||||
|
notify?: undefined
|
||||||
|
}
|
||||||
|
}
|
||||||
|
| {
|
||||||
|
id: Mastodon.Account['id']
|
||||||
|
type: 'outgoing'
|
||||||
|
payload: {
|
||||||
|
action: 'follow'
|
||||||
|
state: boolean
|
||||||
|
notify?: boolean
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const mutationFunction = async (params: MutationVarsRelationship) => {
|
const mutationFunction = async (params: MutationVarsRelationship) => {
|
||||||
@ -65,21 +69,20 @@ const mutationFunction = async (params: MutationVarsRelationship) => {
|
|||||||
url: `follow_requests/${params.id}/${params.payload.action}`
|
url: `follow_requests/${params.id}/${params.payload.action}`
|
||||||
}).then(res => res.body)
|
}).then(res => res.body)
|
||||||
case 'outgoing':
|
case 'outgoing':
|
||||||
|
const formData = new FormData()
|
||||||
|
typeof params.payload.notify === 'boolean' &&
|
||||||
|
formData.append('notify', params.payload.notify.toString())
|
||||||
|
|
||||||
return apiInstance<Mastodon.Relationship>({
|
return apiInstance<Mastodon.Relationship>({
|
||||||
method: 'post',
|
method: 'post',
|
||||||
url: `accounts/${params.id}/${params.payload.state ? 'un' : ''}${
|
url: `accounts/${params.id}/${params.payload.state ? 'un' : ''}${params.payload.action}`,
|
||||||
params.payload.action
|
body: formData
|
||||||
}`
|
|
||||||
}).then(res => res.body)
|
}).then(res => res.body)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const useRelationshipMutation = (
|
const useRelationshipMutation = (
|
||||||
options: UseMutationOptions<
|
options: UseMutationOptions<Mastodon.Relationship, AxiosError, MutationVarsRelationship>
|
||||||
Mastodon.Relationship,
|
|
||||||
AxiosError,
|
|
||||||
MutationVarsRelationship
|
|
||||||
>
|
|
||||||
) => {
|
) => {
|
||||||
return useMutation(mutationFunction, options)
|
return useMutation(mutationFunction, options)
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user