diff --git a/lib/ops/message-store-ops.js b/lib/ops/message-store-ops.js --- a/lib/ops/message-store-ops.js +++ b/lib/ops/message-store-ops.js @@ -61,7 +61,11 @@ // MessageStore local ops export type ReplaceMessageStoreLocalMessageInfoOperation = { +type: 'replace_local_message_info', - +payload: { +id: string, +localMessageInfo: LocalMessageInfo }, + +payload: { + +id: string, + +localMessageInfo: LocalMessageInfo, + +isBackedUp: boolean, + }, }; export type RemoveMessageStoreLocalMessageInfosOperation = { @@ -308,8 +312,31 @@ return ops; } +function createReplaceMessageStoreLocalOperation( + id: string, + localMessageInfo: LocalMessageInfo, +): ReplaceMessageStoreLocalMessageInfoOperation { + // For backup purposes, the only thing that needs to be tracked + // is whether the DM message failed. + if (localMessageInfo.sendFailed && localMessageInfo.outboundP2PMessageIDs) { + return { + type: 'replace_local_message_info', + payload: { id, localMessageInfo, isBackedUp: true }, + }; + } + return { + type: 'replace_local_message_info', + payload: { + id, + localMessageInfo, + isBackedUp: false, + }, + }; +} + export { messageStoreOpsHandlers, createReplaceMessageOperation, + createReplaceMessageStoreLocalOperation, createReplaceMessageStoreThreadsOperations, }; diff --git a/lib/reducers/message-reducer.js b/lib/reducers/message-reducer.js --- a/lib/reducers/message-reducer.js +++ b/lib/reducers/message-reducer.js @@ -63,6 +63,7 @@ type MessageStoreOperation, type ReplaceMessageStoreLocalMessageInfoOperation, createReplaceMessageOperation, + createReplaceMessageStoreLocalOperation, createReplaceMessageStoreThreadsOperations, } from '../ops/message-store-ops.js'; import { pendingToRealizedThreadIDsSelector } from '../selectors/thread-selectors.js'; @@ -530,13 +531,9 @@ oldMessageInfosToCombine.push(oldMessageInfo); const localInfo = updatedMessageStore.local[id]; if (localInfo) { - newMessageOps.push({ - type: 'replace_local_message_info', - payload: { - id, - localMessageInfo: localInfo, - }, - }); + newMessageOps.push( + createReplaceMessageStoreLocalOperation(id, localInfo), + ); } } const startReached = @@ -584,13 +581,9 @@ } const localInfo = updatedMessageStore.local[id]; if (localInfo) { - newMessageOps.push({ - type: 'replace_local_message_info', - payload: { - id, - localMessageInfo: localInfo, - }, - }); + newMessageOps.push( + createReplaceMessageStoreLocalOperation(id, localInfo), + ); } } } @@ -1186,13 +1179,7 @@ } const messageStoreOperations = [ - { - type: 'replace_local_message_info', - payload: { - id: localID, - localMessageInfo: newLocalMessageInfo, - }, - }, + createReplaceMessageStoreLocalOperation(localID, newLocalMessageInfo), ]; const processedMessageStore = processMessageStoreOperations( @@ -1735,16 +1722,12 @@ // If there are `outboundP2PMessages` it means the message failed, // but setting `sendFailed` could not be done, e.g. when the app was // killed in the process of sending messages. - messageStoreOperations.push({ - type: 'replace_local_message_info', - payload: { - id: localMessageID, - localMessageInfo: { - ...actionPayloadMessageStoreLocalMessageInfos[localMessageID], - sendFailed: true, - }, - }, - }); + messageStoreOperations.push( + createReplaceMessageStoreLocalOperation(localMessageID, { + ...actionPayloadMessageStoreLocalMessageInfos[localMessageID], + sendFailed: true, + }), + ); } } @@ -1938,19 +1921,14 @@ // Messages to other peers that can be retried from UI, // we need to track statuses of each one. const outboundP2PMessageIDs = outboundP2PMessages.map(msg => msg.messageID); - const localOperation: ReplaceMessageStoreLocalMessageInfoOperation = { - type: 'replace_local_message_info', - payload: { - id: composableMessageID, - localMessageInfo: { - // Setting it to `false` because sending a message is in progress. - // It will be set to `true` after we fail to queue at least one - // message on Tunnelbroker, or this entry will be removed on success. - sendFailed: false, - outboundP2PMessageIDs, - }, - }, - }; + const localOperation: ReplaceMessageStoreLocalMessageInfoOperation = + createReplaceMessageStoreLocalOperation(composableMessageID, { + // Setting it to `false` because sending a message is in progress. + // It will be set to `true` after we fail to queue at least one + // message on Tunnelbroker, or this entry will be removed on success. + sendFailed: false, + outboundP2PMessageIDs, + }); return { messageStoreOperations: [...messageStoreOperations, localOperation], diff --git a/native/redux/persist.js b/native/redux/persist.js --- a/native/redux/persist.js +++ b/native/redux/persist.js @@ -1418,6 +1418,11 @@ payload: { id, localMessageInfo: message, + // Adding this only to support types, when this migration was + // implemented, backup was not yet supported, because of that, + // this migration should maintain the default behaviour. + // Migrating DM entries to be supported by backup is added later. + isBackedUp: false, }, })); diff --git a/web/redux/persist.js b/web/redux/persist.js --- a/web/redux/persist.js +++ b/web/redux/persist.js @@ -546,6 +546,11 @@ payload: { id, localMessageInfo, + // Adding this only to support types, when this migration was + // implemented, backup was not yet supported, because of that, + // this migration should maintain the default behaviour. + // Migrating DM entries to be supported by backup is added later. + isBackedUp: false, }, }));