diff --git a/app/soapbox/actions/compose.js b/app/soapbox/actions/compose.js index 607fe9481..1d16fe554 100644 --- a/app/soapbox/actions/compose.js +++ b/app/soapbox/actions/compose.js @@ -98,7 +98,7 @@ export const ensureComposeIsVisible = (getState, routerHistory) => { } }; -export function setComposeToStatus(status, rawText, spoilerText, contentType) { +export function setComposeToStatus(status, rawText, spoilerText, contentType, withRedraft) { return (dispatch, getState) => { const { instance } = getState(); const { explicitAddressing } = getFeatures(instance); @@ -111,6 +111,7 @@ export function setComposeToStatus(status, rawText, spoilerText, contentType) { spoilerText, contentType, v: parseVersion(instance.version), + withRedraft, }); }; } diff --git a/app/soapbox/actions/statuses.js b/app/soapbox/actions/statuses.js index a274f181d..7363f979d 100644 --- a/app/soapbox/actions/statuses.js +++ b/app/soapbox/actions/statuses.js @@ -98,7 +98,7 @@ export const editStatus = (id) => (dispatch, getState) => { api(getState).get(`/api/v1/statuses/${id}/source`).then(response => { dispatch({ type: STATUS_FETCH_SOURCE_SUCCESS }); - dispatch(setComposeToStatus(status, response.data.text, response.data.spoiler_text)); + dispatch(setComposeToStatus(status, response.data.text, response.data.spoiler_text, false)); dispatch(openModal('COMPOSE')); }).catch(error => { dispatch({ type: STATUS_FETCH_SOURCE_FAIL, error }); @@ -139,7 +139,7 @@ export function deleteStatus(id, routerHistory, withRedraft = false) { dispatch(deleteFromTimelines(id)); if (withRedraft) { - dispatch(setComposeToStatus(status, response.data.text, response.data.spoiler_text, response.data.pleroma?.content_type)); + dispatch(setComposeToStatus(status, response.data.text, response.data.spoiler_text, response.data.pleroma?.content_type, withRedraft)); dispatch(openModal('COMPOSE')); } }).catch(error => { diff --git a/app/soapbox/reducers/__tests__/compose-test.js b/app/soapbox/reducers/__tests__/compose-test.js index 47565d5d6..1c4e70948 100644 --- a/app/soapbox/reducers/__tests__/compose-test.js +++ b/app/soapbox/reducers/__tests__/compose-test.js @@ -59,6 +59,28 @@ describe('compose reducer', () => { const result = reducer(undefined, action); expect(result.getIn(['media_attachments', 0, 'id'])).toEqual('508107650'); }); + + it('sets the id when editing a post', () => { + const action = { + withRedraft: false, + type: actions.COMPOSE_SET_STATUS, + status: normalizeStatus(fromJS(require('soapbox/__fixtures__/pleroma-status-deleted.json'))), + }; + + const result = reducer(undefined, action); + expect(result.get('id')).toEqual('AHU2RrX0wdcwzCYjFQ'); + }); + + it('does not set the id when redrafting a post', () => { + const action = { + withRedraft: true, + type: actions.COMPOSE_SET_STATUS, + status: normalizeStatus(fromJS(require('soapbox/__fixtures__/pleroma-status-deleted.json'))), + }; + + const result = reducer(undefined, action); + expect(result.get('id')).toEqual(null); + }); }); it('uses \'public\' scope as default', () => { diff --git a/app/soapbox/reducers/compose.js b/app/soapbox/reducers/compose.js index 537934a85..60f713657 100644 --- a/app/soapbox/reducers/compose.js +++ b/app/soapbox/reducers/compose.js @@ -429,7 +429,9 @@ export default function compose(state = initialState, action) { })); case COMPOSE_SET_STATUS: return state.withMutations(map => { - map.set('id', action.status.get('id')); + if (!action.withRedraft) { + map.set('id', action.status.get('id')); + } map.set('text', action.rawText || unescapeHTML(expandMentions(action.status))); map.set('to', action.explicitAddressing ? getExplicitMentions(action.status.get('account', 'id'), action.status) : ImmutableOrderedSet()); map.set('in_reply_to', action.status.get('in_reply_to_id'));