From 6bdc9b4d2ff025ece5ad8fef9913cbd68b295500 Mon Sep 17 00:00:00 2001 From: Justin Date: Tue, 17 May 2022 06:31:19 -0400 Subject: [PATCH 1/2] Fix redraft: don't set compose id --- app/soapbox/actions/compose.js | 3 ++- app/soapbox/actions/statuses.js | 4 ++-- app/soapbox/reducers/compose.js | 4 +++- 3 files changed, 7 insertions(+), 4 deletions(-) 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/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')); From e2b0994780f5478641df5b53195aff40bda38223 Mon Sep 17 00:00:00 2001 From: Justin Date: Tue, 17 May 2022 06:40:43 -0400 Subject: [PATCH 2/2] Add test --- .../reducers/__tests__/compose-test.js | 22 +++++++++++++++++++ 1 file changed, 22 insertions(+) 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', () => {