2020-12-30 00:56:25 +01:00
|
|
|
import { store } from '@root/store'
|
2021-01-07 19:13:09 +01:00
|
|
|
import { getLocalAccount } from '@utils/slices/instancesSlice'
|
2020-12-30 00:56:25 +01:00
|
|
|
import composeInitialState from './initialState'
|
|
|
|
import { ComposeState } from './types'
|
|
|
|
|
2021-01-24 02:25:43 +01:00
|
|
|
const composeParseState = (
|
2021-02-07 00:39:11 +01:00
|
|
|
params: NonNullable<Nav.RootStackParamList['Screen-Compose']>
|
2021-01-24 02:25:43 +01:00
|
|
|
): ComposeState => {
|
|
|
|
switch (params.type) {
|
2020-12-30 00:56:25 +01:00
|
|
|
case 'edit':
|
|
|
|
return {
|
|
|
|
...composeInitialState,
|
2021-02-07 00:39:11 +01:00
|
|
|
dirty: true,
|
|
|
|
timestamp: Date.now(),
|
2021-01-24 02:25:43 +01:00
|
|
|
...(params.incomingStatus.spoiler_text && {
|
2021-01-01 16:48:16 +01:00
|
|
|
spoiler: { ...composeInitialState.spoiler, active: true }
|
|
|
|
}),
|
2021-01-24 02:25:43 +01:00
|
|
|
...(params.incomingStatus.poll && {
|
2020-12-30 00:56:25 +01:00
|
|
|
poll: {
|
|
|
|
active: true,
|
2021-01-24 02:25:43 +01:00
|
|
|
total: params.incomingStatus.poll.options.length,
|
2020-12-30 00:56:25 +01:00
|
|
|
options: {
|
2021-01-24 02:25:43 +01:00
|
|
|
'0': params.incomingStatus.poll.options[0]?.title || undefined,
|
|
|
|
'1': params.incomingStatus.poll.options[1]?.title || undefined,
|
|
|
|
'2': params.incomingStatus.poll.options[2]?.title || undefined,
|
|
|
|
'3': params.incomingStatus.poll.options[3]?.title || undefined
|
2020-12-30 00:56:25 +01:00
|
|
|
},
|
2021-01-24 02:25:43 +01:00
|
|
|
multiple: params.incomingStatus.poll.multiple,
|
2020-12-30 00:56:25 +01:00
|
|
|
expire: '86400' // !!!
|
|
|
|
}
|
|
|
|
}),
|
2021-01-24 02:25:43 +01:00
|
|
|
...(params.incomingStatus.media_attachments && {
|
2020-12-30 00:56:25 +01:00
|
|
|
attachments: {
|
2021-01-24 02:25:43 +01:00
|
|
|
sensitive: params.incomingStatus.sensitive,
|
|
|
|
uploads: params.incomingStatus.media_attachments.map(media => ({
|
2020-12-30 00:56:25 +01:00
|
|
|
remote: media
|
|
|
|
}))
|
|
|
|
}
|
|
|
|
}),
|
|
|
|
visibility:
|
2021-01-24 02:25:43 +01:00
|
|
|
params.incomingStatus.visibility ||
|
2021-01-07 19:13:09 +01:00
|
|
|
getLocalAccount(store.getState())?.preferences[
|
2020-12-30 00:56:25 +01:00
|
|
|
'posting:default:visibility'
|
2021-01-07 19:13:09 +01:00
|
|
|
] ||
|
|
|
|
'public',
|
2021-01-24 02:25:43 +01:00
|
|
|
...(params.incomingStatus.visibility === 'direct' && {
|
|
|
|
visibilityLock: true
|
|
|
|
})
|
2020-12-30 00:56:25 +01:00
|
|
|
}
|
|
|
|
case 'reply':
|
2021-01-24 02:25:43 +01:00
|
|
|
const actualStatus = params.incomingStatus.reblog || params.incomingStatus
|
2020-12-30 00:56:25 +01:00
|
|
|
return {
|
|
|
|
...composeInitialState,
|
2021-02-07 00:39:11 +01:00
|
|
|
dirty: true,
|
|
|
|
timestamp: Date.now(),
|
2021-01-04 10:50:24 +01:00
|
|
|
visibility: actualStatus.visibility,
|
|
|
|
visibilityLock: actualStatus.visibility === 'direct',
|
2020-12-30 00:56:25 +01:00
|
|
|
replyToStatus: actualStatus
|
|
|
|
}
|
|
|
|
case 'conversation':
|
|
|
|
return {
|
|
|
|
...composeInitialState,
|
2021-02-07 00:39:11 +01:00
|
|
|
dirty: true,
|
|
|
|
timestamp: Date.now(),
|
2020-12-30 00:56:25 +01:00
|
|
|
visibility: 'direct',
|
|
|
|
visibilityLock: true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export default composeParseState
|