diff --git a/lib/tunnelbroker/peer-to-peer-context.js b/lib/tunnelbroker/peer-to-peer-context.js --- a/lib/tunnelbroker/peer-to-peer-context.js +++ b/lib/tunnelbroker/peer-to-peer-context.js @@ -55,7 +55,7 @@ contentPayload: string, recipients: $ReadOnlyArray, authMetadata: AuthMetadata, - ) => Promise, + ) => Promise<$ReadOnlyArray>, }; const PeerToPeerContext: React.Context = @@ -377,7 +377,7 @@ contentPayload: string, recipients: $ReadOnlyArray, authMetadata: AuthMetadata, - ) => { + ): Promise<$ReadOnlyArray> => { const { userID: thisUserID, deviceID: thisDeviceID } = authMetadata; if (!thisDeviceID || !thisUserID) { throw new Error('No auth metadata'); @@ -385,6 +385,8 @@ const { olmAPI } = getConfig(); await olmAPI.initializeCryptoAccount(); + const recipientsThatReceivedMessages: Array = []; + // 1. Optimistically attempt to send all messages, and all should // succeed, the only exceptions are messages for devices we don't // have a session with or some other issues like network connection. @@ -404,6 +406,9 @@ const userDevicesWithoutSession: { [userID: string]: Array } = {}; const recipientsToRetry: Array = []; for (const result of messagesResults) { + if (result.status === 'success') { + recipientsThatReceivedMessages.push(result.recipient); + } if (result.status === 'missing_session') { recipientsToRetry.push(result.recipient); const { userID, deviceID } = result.recipient; @@ -415,7 +420,9 @@ } } if (recipientsToRetry.length === 0) { - return; + return recipientsThatReceivedMessages.map( + recipient => recipient.deviceID, + ); } // 3.Create a session with users which has at @@ -436,7 +443,15 @@ olmDebugLog, ), ); - await Promise.all(retryPromises); + const retryResults = await Promise.all(retryPromises); + for (const result of retryResults) { + if (result.status === 'success') { + recipientsThatReceivedMessages.push(result.recipient); + } + } + return recipientsThatReceivedMessages.map( + recipient => recipient.deviceID, + ); }, [addLog, olmDebugLog, peerOlmSessionsCreator, sendMessageToDevice], );