Rollback any changes to file server if pairing authorisation failed to send

pull/1003/head
Mikunj 6 years ago
parent 3800ca2050
commit 000f95a430

@ -618,11 +618,27 @@
}; };
// Update authorisation in database with the new grant signature // Update authorisation in database with the new grant signature
await libloki.storage.savePairingAuthorisation(authorisation); await libloki.storage.savePairingAuthorisation(authorisation);
// Try to upload to the file server and then send a message
try {
await lokiFileServerAPI.updateOurDeviceMapping(); await lokiFileServerAPI.updateOurDeviceMapping();
await libloki.api.sendPairingAuthorisation( await libloki.api.sendPairingAuthorisation(
authorisation, authorisation,
secondaryDevicePubKey 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 // Always be friends with secondary devices
await secondaryConversation.setFriendRequestStatus( await secondaryConversation.setFriendRequestStatus(
window.friends.friendRequestStatusEnum.friends, window.friends.friendRequestStatusEnum.friends,

Loading…
Cancel
Save