Fix misuse of getAllDevicePubKeysForPrimaryPubKey and rename some vars

pull/613/head
Beaudan Brown 6 years ago
parent bce18b7ae6
commit 030264c689

@ -1235,14 +1235,18 @@
if (activeAt !== null) { if (activeAt !== null) {
activeAt = activeAt || Date.now(); activeAt = activeAt || Date.now();
} }
const ourAuthorisations = await libloki.storage.getPrimaryDeviceMapping( const ourPrimaryKey = window.storage.get('primaryDevicePubKey');
window.storage.get('primaryDevicePubKey') const ourDevices = await libloki.storage.getAllDevicePubKeysForPrimaryPubKey(
ourPrimaryKey
); );
const isSecondaryDevice = // TODO: We should probably just *not* send any secondary devices and
ourAuthorisations && // just load them all and send FRs when we get the mapping
ourAuthorisations.some(auth => auth.secondaryDevicePubKey === id); const isOurSecondaryDevice =
id !== ourPrimaryKey &&
if (isSecondaryDevice) { ourDevices &&
ourDevices.some(devicePubKey => devicePubKey === id);
if (isOurSecondaryDevice) {
await conversation.setSecondaryStatus(true); await conversation.setSecondaryStatus(true);
} }

@ -1104,13 +1104,13 @@ MessageReceiver.prototype.extend({
window.log.info( window.log.info(
`Received pairing authorisation from ${primaryDevicePubKey}` `Received pairing authorisation from ${primaryDevicePubKey}`
); );
await libloki.storage.savePairingAuthorisation(pairingAuthorisation);
// Set current device as secondary. // Set current device as secondary.
// This will ensure the authorisation is sent // This will ensure the authorisation is sent
// along with each friend request. // along with each friend request.
window.storage.remove('secondaryDeviceStatus'); window.storage.remove('secondaryDeviceStatus');
window.storage.put('isSecondaryDevice', true); window.storage.put('isSecondaryDevice', true);
window.storage.put('primaryDevicePubKey', primaryDevicePubKey); window.storage.put('primaryDevicePubKey', primaryDevicePubKey);
await libloki.storage.savePairingAuthorisation(pairingAuthorisation);
const primaryConversation = await ConversationController.getOrCreateAndWait( const primaryConversation = await ConversationController.getOrCreateAndWait(
primaryDevicePubKey, primaryDevicePubKey,
'private' 'private'
@ -1464,16 +1464,11 @@ MessageReceiver.prototype.extend({
async handleSyncMessage(envelope, syncMessage) { async handleSyncMessage(envelope, syncMessage) {
const ourNumber = textsecure.storage.user.getNumber(); const ourNumber = textsecure.storage.user.getNumber();
// NOTE: Maybe we should be caching this list? // NOTE: Maybe we should be caching this list?
const ourAuthorisations = await libloki.storage.getPrimaryDeviceMapping( const ourDevices = await libloki.storage.getAllDevicePubKeysForPrimaryPubKey(
window.storage.get('primaryDevicePubKey') window.storage.get('primaryDevicePubKey')
); );
const validSyncSender = const validSyncSender =
ourAuthorisations && ourDevices && ourDevices.some(devicePubKey => devicePubKey === ourNumber);
ourAuthorisations.some(
auth =>
auth.secondaryDevicePubKey === ourNumber ||
auth.primaryDevicePubKey === ourNumber
);
if (!validSyncSender) { if (!validSyncSender) {
throw new Error( throw new Error(
"Received sync message from a device we aren't paired with" "Received sync message from a device we aren't paired with"

Loading…
Cancel
Save