This commit is contained in:
Zhiyuan Zheng 2021-03-11 22:22:17 +01:00
parent 8a49c92c79
commit 4319e83bb9
No known key found for this signature in database
GPG Key ID: 078A93AB607D85E0
1 changed files with 33 additions and 13 deletions

View File

@ -3,6 +3,36 @@ import { getInstanceAccount } from '@utils/slices/instancesSlice'
import composeInitialState from './initialState' import composeInitialState from './initialState'
import { ComposeState } from './types' import { ComposeState } from './types'
const assignVisibility = (
target: ComposeState['visibility']
): Pick<ComposeState, 'visibility' | 'visibilityLock'> => {
const accountPreference = getInstanceAccount(store.getState())?.preferences[
'posting:default:visibility'
]
switch (target) {
case 'direct':
return { visibility: 'direct', visibilityLock: true }
case 'private':
return { visibility: 'private', visibilityLock: false }
case 'unlisted':
if (accountPreference === 'private') {
return { visibility: 'private', visibilityLock: false }
} else {
return { visibility: 'unlisted', visibilityLock: false }
}
case 'public':
switch (accountPreference) {
case 'private':
return { visibility: 'private', visibilityLock: false }
case 'unlisted':
return { visibility: 'unlisted', visibilityLock: false }
default:
return { visibility: 'public', visibilityLock: false }
}
}
}
const composeParseState = ( const composeParseState = (
params: NonNullable<Nav.RootStackParamList['Screen-Compose']> params: NonNullable<Nav.RootStackParamList['Screen-Compose']>
): ComposeState => { ): ComposeState => {
@ -37,15 +67,7 @@ const composeParseState = (
})) }))
} }
}), }),
visibility: ...assignVisibility(params.incomingStatus.visibility),
params.incomingStatus.visibility ||
getInstanceAccount(store.getState())?.preferences[
'posting:default:visibility'
] ||
'public',
...(params.incomingStatus.visibility === 'direct' && {
visibilityLock: true
}),
...(params.replyToStatus && { replyToStatus: params.replyToStatus }) ...(params.replyToStatus && { replyToStatus: params.replyToStatus })
} }
case 'reply': case 'reply':
@ -57,8 +79,7 @@ const composeParseState = (
...(actualStatus.spoiler_text && { ...(actualStatus.spoiler_text && {
spoiler: { ...composeInitialState.spoiler, active: true } spoiler: { ...composeInitialState.spoiler, active: true }
}), }),
visibility: actualStatus.visibility, ...assignVisibility(actualStatus.visibility),
visibilityLock: actualStatus.visibility === 'direct',
replyToStatus: actualStatus replyToStatus: actualStatus
} }
case 'conversation': case 'conversation':
@ -66,8 +87,7 @@ const composeParseState = (
...composeInitialState, ...composeInitialState,
dirty: true, dirty: true,
timestamp: Date.now(), timestamp: Date.now(),
visibility: 'direct', ...assignVisibility('direct')
visibilityLock: true
} }
} }
} }