diff --git a/native/calendar/entry.react.js b/native/calendar/entry.react.js --- a/native/calendar/entry.react.js +++ b/native/calendar/entry.react.js @@ -49,6 +49,8 @@ } from 'lib/types/minimally-encoded-thread-permissions-types.js'; import type { Dispatch } from 'lib/types/redux-types.js'; import { threadPermissions } from 'lib/types/thread-permission-types.js'; +import { updateTypes } from 'lib/types/update-types-enum.js'; +import type { ServerCreateUpdatesResponse } from 'lib/types/update-types.js'; import { dateString } from 'lib/utils/date-utils.js'; import { useResolvedThreadInfo } from 'lib/utils/entity-helpers.js'; import { ServerError } from 'lib/utils/errors.js'; @@ -635,7 +637,7 @@ invariant(localID, "if there's no serverID, there should be a localID"); const curSaveAttempt = this.nextSaveAttemptIndex++; try { - const response = await this.props.createEntry({ + let response = await this.props.createEntry({ text, timestamp: this.props.entryInfo.creationTime, date: dateString( @@ -658,6 +660,12 @@ if (this.needsDeleteAfterCreation) { this.needsDeleteAfterCreation = false; this.dispatchDelete(response.entryID); + response = { + ...response, + updatesResult: this.patchUpdateInfosForDeletion( + response.updatesResult, + ), + }; } return response; } catch (e) { @@ -676,7 +684,7 @@ ): Promise { const curSaveAttempt = this.nextSaveAttemptIndex++; try { - const response = await this.props.saveEntry({ + let response = await this.props.saveEntry({ entryID, text: newText, prevText: this.props.entryInfo.text, @@ -686,6 +694,14 @@ if (curSaveAttempt + 1 === this.nextSaveAttemptIndex) { this.guardedSetState({ loadingStatus: 'inactive' }); } + if (this.deleted) { + response = { + ...response, + updatesResult: this.patchUpdateInfosForDeletion( + response.updatesResult, + ), + }; + } return { ...response, threadID: this.props.entryInfo.threadID }; } catch (e) { if (curSaveAttempt + 1 === this.nextSaveAttemptIndex) { @@ -716,6 +732,25 @@ } } + patchUpdateInfosForDeletion( + updatesResponse: ServerCreateUpdatesResponse, + ): ServerCreateUpdatesResponse { + const { viewerUpdates, ...rest } = updatesResponse; + const patchedViewerUpdates = viewerUpdates.map(update => { + if (update.type !== updateTypes.UPDATE_ENTRY) { + return update; + } + return { + ...update, + entryInfo: { + ...update.entryInfo, + deleted: true, + }, + }; + }); + return { viewerUpdates: patchedViewerUpdates, ...rest }; + } + delete: () => void = () => { this.dispatchDelete(this.props.entryInfo.id); };