diff --git a/lib/tunnelbroker/use-peer-to-peer-message-handler.js b/lib/tunnelbroker/use-peer-to-peer-message-handler.js --- a/lib/tunnelbroker/use-peer-to-peer-message-handler.js +++ b/lib/tunnelbroker/use-peer-to-peer-message-handler.js @@ -4,6 +4,7 @@ import _isEqual from 'lodash/fp/isEqual.js'; import * as React from 'react'; +import { useResendPeerToPeerMessages } from './use-resend-peer-to-peer-messages.js'; import { removePeerUsersActionType } from '../actions/aux-user-actions.js'; import { invalidateTunnelbrokerDeviceTokenActionType } from '../actions/tunnelbroker-actions.js'; import { logOutActionTypes, useLogOut } from '../actions/user-actions.js'; @@ -171,6 +172,7 @@ const dispatch = useDispatch(); const handleOlmMessageToDevice = useHandleOlmMessageToDevice(); + const resendPeerToPeerMessages = useResendPeerToPeerMessages(); return React.useCallback( async (message: PeerToPeerMessage, messageID: string) => { @@ -235,8 +237,7 @@ `${senderDeviceID}: ${result}, ` + `session version: ${sessionVersion}`, ); - // Resend all not-yet confirmed messages that were encrypted - // with overwrite session. Tracked in ENG-6982. + await resendPeerToPeerMessages(senderDeviceID); } } else { console.log( @@ -381,6 +382,7 @@ handleOlmMessageToDevice, identityClient, olmAPI, + resendPeerToPeerMessages, sqliteAPI, ], ); diff --git a/lib/tunnelbroker/use-resend-peer-to-peer-messages.js b/lib/tunnelbroker/use-resend-peer-to-peer-messages.js new file mode 100644 --- /dev/null +++ b/lib/tunnelbroker/use-resend-peer-to-peer-messages.js @@ -0,0 +1,22 @@ +// @flow + +import * as React from 'react'; + +import { usePeerToPeerCommunication } from './peer-to-peer-context.js'; +import { getConfig } from '../utils/config.js'; + +function useResendPeerToPeerMessages(): (deviceID: string) => Promise { + const { sqliteAPI } = getConfig(); + const { processOutboundMessages } = usePeerToPeerCommunication(); + + return React.useCallback( + async (deviceID: string) => { + const messageIDs = + await sqliteAPI.resetOutboundP2PMessagesForDevice(deviceID); + return processOutboundMessages(messageIDs); + }, + [processOutboundMessages, sqliteAPI], + ); +} + +export { useResendPeerToPeerMessages };