From 000f95a4302579a62ae0285b80762b12e5ba7e68 Mon Sep 17 00:00:00 2001 From: Mikunj Date: Wed, 25 Mar 2020 11:13:41 +1100 Subject: [PATCH] Rollback any changes to file server if pairing authorisation failed to send --- libtextsecure/account_manager.js | 26 +++++++++++++++++++++----- 1 file changed, 21 insertions(+), 5 deletions(-) diff --git a/libtextsecure/account_manager.js b/libtextsecure/account_manager.js index 1e1764ac2..737bf363c 100644 --- a/libtextsecure/account_manager.js +++ b/libtextsecure/account_manager.js @@ -618,11 +618,27 @@ }; // Update authorisation in database with the new grant signature await libloki.storage.savePairingAuthorisation(authorisation); - await lokiFileServerAPI.updateOurDeviceMapping(); - await libloki.api.sendPairingAuthorisation( - authorisation, - secondaryDevicePubKey - ); + + // Try to upload to the file server and then send a message + try { + await lokiFileServerAPI.updateOurDeviceMapping(); + await libloki.api.sendPairingAuthorisation( + authorisation, + secondaryDevicePubKey + ); + } catch (e) { + log.error( + 'Failed to authorise secondary device: ', + e && e.stack ? e.stack : e + ); + // File server upload failed or message sending failed, we should rollback changes + await libloki.storage.removePairingAuthorisationForSecondaryPubKey( + secondaryDevicePubKey + ); + await lokiFileServerAPI.updateOurDeviceMapping(); + throw e; + } + // Always be friends with secondary devices await secondaryConversation.setFriendRequestStatus( window.friends.friendRequestStatusEnum.friends,