Update account preferences should affect posting settings

This commit is contained in:
Zhiyuan Zheng 2021-05-17 23:33:07 +02:00
parent fd1a6b3415
commit 2b838601d5
3 changed files with 53 additions and 32 deletions

View File

@ -88,6 +88,14 @@ const ScreenCompose: React.FC<ScreenComposeProp> = ({
return { return {
...composeInitialState, ...composeInitialState,
timestamp: Date.now(), timestamp: Date.now(),
attachments: {
...composeInitialState.attachments,
sensitive:
localAccount?.preferences &&
localAccount?.preferences['posting:default:sensitive']
? localAccount?.preferences['posting:default:sensitive']
: false
},
visibility: visibility:
localAccount?.preferences && localAccount?.preferences &&
localAccount.preferences['posting:default:visibility'] localAccount.preferences['posting:default:visibility']

View File

@ -31,7 +31,10 @@ const composeInitialState: Omit<ComposeState, 'timestamp'> = {
multiple: false, multiple: false,
expire: '86400' expire: '86400'
}, },
attachments: { sensitive: false, uploads: [] }, attachments: {
sensitive: false,
uploads: []
},
visibility: 'public', visibility: 'public',
visibilityLock: false, visibilityLock: false,
replyToStatus: undefined, replyToStatus: undefined,

View File

@ -3,11 +3,13 @@ import { displayMessage } from '@components/Message'
import { useActionSheet } from '@expo/react-native-action-sheet' import { useActionSheet } from '@expo/react-native-action-sheet'
import { StackScreenProps } from '@react-navigation/stack' import { StackScreenProps } from '@react-navigation/stack'
import { useProfileMutation, useProfileQuery } from '@utils/queryHooks/profile' import { useProfileMutation, useProfileQuery } from '@utils/queryHooks/profile'
import { updateAccountPreferences } from '@utils/slices/instances/updateAccountPreferences'
import { useTheme } from '@utils/styles/ThemeManager' import { useTheme } from '@utils/styles/ThemeManager'
import React, { RefObject, useCallback } from 'react' import React, { RefObject, useCallback } from 'react'
import { useTranslation } from 'react-i18next' import { useTranslation } from 'react-i18next'
import FlashMessage from 'react-native-flash-message' import FlashMessage from 'react-native-flash-message'
import { ScrollView } from 'react-native-gesture-handler' import { ScrollView } from 'react-native-gesture-handler'
import { useDispatch } from 'react-redux'
import ProfileAvatarHeader from './Root/AvatarHeader' import ProfileAvatarHeader from './Root/AvatarHeader'
const TabMeProfileRoot: React.FC<StackScreenProps< const TabMeProfileRoot: React.FC<StackScreenProps<
@ -21,6 +23,7 @@ const TabMeProfileRoot: React.FC<StackScreenProps<
const { data, isLoading } = useProfileQuery({}) const { data, isLoading } = useProfileQuery({})
const { mutateAsync } = useProfileMutation() const { mutateAsync } = useProfileMutation()
const dispatch = useDispatch()
const onPressVisibility = useCallback(() => { const onPressVisibility = useCallback(() => {
showActionSheetWithOptions( showActionSheetWithOptions(
@ -37,8 +40,9 @@ const TabMeProfileRoot: React.FC<StackScreenProps<
async buttonIndex => { async buttonIndex => {
switch (buttonIndex) { switch (buttonIndex) {
case 0: case 0:
mutateAsync({ type: 'source[privacy]', data: 'public' }).catch( mutateAsync({ type: 'source[privacy]', data: 'public' })
err => .then(() => dispatch(updateAccountPreferences()))
.catch(err =>
displayMessage({ displayMessage({
ref: messageRef, ref: messageRef,
message: t('me.profile.feedback.failed', { message: t('me.profile.feedback.failed', {
@ -48,11 +52,12 @@ const TabMeProfileRoot: React.FC<StackScreenProps<
mode, mode,
type: 'error' type: 'error'
}) })
) )
break break
case 1: case 1:
mutateAsync({ type: 'source[privacy]', data: 'unlisted' }).catch( mutateAsync({ type: 'source[privacy]', data: 'unlisted' })
err => .then(() => dispatch(updateAccountPreferences()))
.catch(err =>
displayMessage({ displayMessage({
ref: messageRef, ref: messageRef,
message: t('me.profile.feedback.failed', { message: t('me.profile.feedback.failed', {
@ -62,11 +67,12 @@ const TabMeProfileRoot: React.FC<StackScreenProps<
mode, mode,
type: 'error' type: 'error'
}) })
) )
break break
case 2: case 2:
mutateAsync({ type: 'source[privacy]', data: 'private' }).catch( mutateAsync({ type: 'source[privacy]', data: 'private' })
err => .then(() => dispatch(updateAccountPreferences()))
.catch(err =>
displayMessage({ displayMessage({
ref: messageRef, ref: messageRef,
message: t('me.profile.feedback.failed', { message: t('me.profile.feedback.failed', {
@ -76,7 +82,7 @@ const TabMeProfileRoot: React.FC<StackScreenProps<
mode, mode,
type: 'error' type: 'error'
}) })
) )
break break
} }
} }
@ -85,32 +91,36 @@ const TabMeProfileRoot: React.FC<StackScreenProps<
const onPressSensitive = useCallback(() => { const onPressSensitive = useCallback(() => {
if (data?.source.sensitive === undefined) { if (data?.source.sensitive === undefined) {
mutateAsync({ type: 'source[sensitive]', data: true }).catch(err => mutateAsync({ type: 'source[sensitive]', data: true })
displayMessage({ .then(() => dispatch(updateAccountPreferences()))
ref: messageRef, .catch(err =>
message: t('me.profile.feedback.failed', { displayMessage({
type: t('me.profile.root.sensitive.title') ref: messageRef,
}), message: t('me.profile.feedback.failed', {
...(err && { description: err }), type: t('me.profile.root.sensitive.title')
mode, }),
type: 'error' ...(err && { description: err }),
}) mode,
) type: 'error'
})
)
} else { } else {
mutateAsync({ mutateAsync({
type: 'source[sensitive]', type: 'source[sensitive]',
data: !data.source.sensitive data: !data.source.sensitive
}).catch(err => })
displayMessage({ .then(() => dispatch(updateAccountPreferences()))
ref: messageRef, .catch(err =>
message: t('me.profile.feedback.failed', { displayMessage({
type: t('me.profile.root.sensitive.title') ref: messageRef,
}), message: t('me.profile.feedback.failed', {
...(err && { description: err }), type: t('me.profile.root.sensitive.title')
mode, }),
type: 'error' ...(err && { description: err }),
}) mode,
) type: 'error'
})
)
} }
}, [data?.source.sensitive]) }, [data?.source.sensitive])