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 @@ -1660,6 +1660,31 @@ const actionPayloadMessageStoreLocalMessageInfos = action.payload.messageStoreLocalMessageInfos ?? {}; + const messageStoreOperations: Array = []; + + for (const localMessageID in actionPayloadMessageStoreLocalMessageInfos) { + if ( + actionPayloadMessageStoreLocalMessageInfos[localMessageID] + .outboundP2PMessages && + actionPayloadMessageStoreLocalMessageInfos[localMessageID] + .outboundP2PMessages.length > 0 + ) { + // 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, + }, + }, + }); + } + } + const newThreads: { [threadID: string]: ThreadMessageInfo, } = { ...messageStore.threads }; @@ -1682,16 +1707,18 @@ }; } - const { messageStoreOperations, messageStore: updatedMessageStore } = - updateMessageStoreWithLatestThreadInfos( - { - ...messageStore, - threads: newThreads, - local: actionPayloadMessageStoreLocalMessageInfos, - }, - newThreadInfos, - ); - + const { + messageStoreOperations: updatedMessageStoreOperations, + messageStore: updatedMessageStore, + } = updateMessageStoreWithLatestThreadInfos( + { + ...messageStore, + threads: newThreads, + local: actionPayloadMessageStoreLocalMessageInfos, + }, + newThreadInfos, + ); + messageStoreOperations.push(...updatedMessageStoreOperations); let threads = { ...updatedMessageStore.threads }; let local = { ...updatedMessageStore.local }; diff --git a/lib/types/message-types.js b/lib/types/message-types.js --- a/lib/types/message-types.js +++ b/lib/types/message-types.js @@ -439,8 +439,12 @@ // Tracks client-local information about a message that hasn't been assigned an // ID by the server yet. As soon as the client gets an ack from the server for // this message, it will clear the LocalMessageInfo. +// For DMs, it keeps track of P2P Messages that are not yet sent. +// As soon as messages are queued on Tunnelbroker, it will +// clear the LocalMessageInfo. export type LocalMessageInfo = { +sendFailed?: boolean, + +outboundP2PMessageIDs?: $ReadOnlyArray, }; const localMessageInfoValidator: TInterface = tShape({