From 9dc5572f53388e950db68540e884474aa10ec31f Mon Sep 17 00:00:00 2001 From: Devin Binnie <52460000+devinbinnie@users.noreply.github.com> Date: Sat, 16 Mar 2024 13:55:56 -0400 Subject: [PATCH] [MM-57076] Stop removing local drafts when calling `removeDraft` for servers with synced drafts (#26481) * [MM-57076] Stop removing local drafts when calling `removeDraft` for servers with synced drafts * Fix tests --- webapp/channels/src/actions/views/drafts.test.ts | 13 +++++++++++++ webapp/channels/src/actions/views/drafts.ts | 6 +++--- 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/webapp/channels/src/actions/views/drafts.test.ts b/webapp/channels/src/actions/views/drafts.test.ts index 361e92799b..4c706c2fc8 100644 --- a/webapp/channels/src/actions/views/drafts.test.ts +++ b/webapp/channels/src/actions/views/drafts.test.ts @@ -164,6 +164,19 @@ describe('draft actions', () => { describe('removeDraft', () => { it('calls setGlobalItem action correctly', async () => { + store = mockStore({ + ...initialState, + entities: { + ...initialState.entities, + general: { + ...initialState.entities.general, + config: { + ...initialState.entities.general.config, + AllowSyncedDrafts: 'false', + }, + }, + }, + }); await store.dispatch(removeDraft(key, channelId)); const testStore = mockStore(initialState); diff --git a/webapp/channels/src/actions/views/drafts.ts b/webapp/channels/src/actions/views/drafts.ts index 127227d7be..41921b728d 100644 --- a/webapp/channels/src/actions/views/drafts.ts +++ b/webapp/channels/src/actions/views/drafts.ts @@ -105,9 +105,6 @@ export function removeDraft(key: string, channelId: string, rootId = ''): Action // set draft to empty to re-render the component await dispatch(setGlobalItem(key, {message: '', fileInfos: [], uploadsInProgress: []})); - // remove draft from storage - await dispatch(removeGlobalItem(key)); - if (syncedDraftsAreAllowedAndEnabled(state)) { const connectionId = getConnectionId(getState()); @@ -119,6 +116,9 @@ export function removeDraft(key: string, channelId: string, rootId = ''): Action error, }; } + } else { + // only remove draft from storage for local drafts + await dispatch(removeGlobalItem(key)); } return {data: true}; };