Fixup PubKey.isEqual

pull/1177/head
Vincent 6 years ago
parent 20b2ba1c8a
commit 99674ed2ba

@ -512,7 +512,7 @@ export async function handleDataMessage(
const pubKey = new PubKey(device); const pubKey = new PubKey(device);
const allDevices = await MultiDeviceProtocol.getAllDevices(pubKey); const allDevices = await MultiDeviceProtocol.getAllDevices(pubKey);
return allDevices.some(d => PubKey.isEqual(d, pubKey)); return allDevices.some(d => d.isEqual(pubKey));
}; };
const ownDevice = await isOwnDevice(source); const ownDevice = await isOwnDevice(source);

@ -31,37 +31,27 @@ export class MultiDeviceProtocol {
// This return here stops an infinite loop when we get all our other devices // This return here stops an infinite loop when we get all our other devices
const ourKey = await UserUtil.getCurrentDevicePubKey(); const ourKey = await UserUtil.getCurrentDevicePubKey();
if (!ourKey || device.key === ourKey) { if (!ourKey || device.key === ourKey) {
console.log(`[vince] 1 GUARD`);
console.log('[vince] ourKey:', ourKey);
console.log('[vince] device:', device);
return; return;
} }
// We always prefer our local pairing over the one on the server // We always prefer our local pairing over the one on the server
const isOurDevice = await this.isOurDevice(device); const isOurDevice = await this.isOurDevice(device);
if (isOurDevice) { if (isOurDevice) {
console.log(`[vince] 2 GUARD`);
return; return;
} }
// Only fetch if we hit the refresh delay // Only fetch if we hit the refresh delay
const lastFetchTime = this.lastFetch[device.key]; const lastFetchTime = this.lastFetch[device.key];
if (lastFetchTime && lastFetchTime + this.refreshDelay > Date.now()) { if (lastFetchTime && lastFetchTime + this.refreshDelay > Date.now()) {
console.log(`[vince] 3 GUARD`);
return; return;
} }
this.lastFetch[device.key] = Date.now(); this.lastFetch[device.key] = Date.now();
console.log(`[vince] 4 GUARD`);
try { try {
console.log(`[vince] 5 GUARD`);
const authorisations = await this.fetchPairingAuthorisations(device); const authorisations = await this.fetchPairingAuthorisations(device);
await Promise.all(authorisations.map(this.savePairingAuthorisation)); await Promise.all(authorisations.map(this.savePairingAuthorisation));
} catch (e) { } catch (e) {
console.log(`[vince] 6 GUARD`);
// Something went wrong, let it re-try another time // Something went wrong, let it re-try another time
this.lastFetch[device.key] = lastFetchTime; this.lastFetch[device.key] = lastFetchTime;
} }
@ -225,7 +215,7 @@ export class MultiDeviceProtocol {
try { try {
const ourDevices = await this.getOurDevices(); const ourDevices = await this.getOurDevices();
return ourDevices.some(d => PubKey.isEqual(d, pubKey)); return ourDevices.some(d => d.isEqual(pubKey));
} catch (e) { } catch (e) {
return false; return false;
} }

@ -300,10 +300,7 @@ async function queryConversationsAndContacts(
const primaryDevice = resultPrimaryDevices[i]; const primaryDevice = resultPrimaryDevices[i];
if (primaryDevice) { if (primaryDevice) {
if ( if (isSecondaryDevice && primaryDevice.isEqual(ourPrimaryDevice)) {
isSecondaryDevice &&
PubKey.isEqual(primaryDevice, ourPrimaryDevice)
) {
conversations.push(ourNumber); conversations.push(ourNumber);
} else { } else {
conversations.push(primaryDevice.key); conversations.push(primaryDevice.key);

@ -63,7 +63,7 @@ describe('MessageQueue', () => {
let sendToOpenGroupStub: sinon.SinonStub<[OpenGroupMessage]>; let sendToOpenGroupStub: sinon.SinonStub<[OpenGroupMessage]>;
// Utils Stubs // Utils Stubs
let groupMembersStub: sinon.SinonStub; let groupMembersStub: sinon.SinonStub;
let canSyncStub: sinon.SinonStub; let canSyncStub: sinon.SinonStub<[ContentMessage], boolean>;
// Session Protocol Stubs // Session Protocol Stubs
let hasSessionStub: sinon.SinonStub<[PubKey]>; let hasSessionStub: sinon.SinonStub<[PubKey]>;
let sendSessionRequestIfNeededStub: sinon.SinonStub<[PubKey], Promise<void>>; let sendSessionRequestIfNeededStub: sinon.SinonStub<[PubKey], Promise<void>>;
@ -280,7 +280,10 @@ describe('MessageQueue', () => {
// argsPairedKeys and pairedDeviceKeys should contain the same values // argsPairedKeys and pairedDeviceKeys should contain the same values
const keyArgsValid = _.isEmpty(_.xor(argsPairedKeys, pairedDeviceKeys)); const keyArgsValid = _.isEmpty(_.xor(argsPairedKeys, pairedDeviceKeys));
expect(keyArgsValid).to.equal(true, 'devices passed into sendSyncMessage were invalid'); expect(keyArgsValid).to.equal(
true,
'devices passed into sendSyncMessage were invalid'
);
}); });
}); });

@ -79,9 +79,7 @@ export function generateFakePubKey(): PubKey {
} }
export function generateFakePubKeys(amount: number): Array<PubKey> { export function generateFakePubKeys(amount: number): Array<PubKey> {
const numPubKeys = amount > 0 const numPubKeys = amount > 0 ? Math.floor(amount) : 0;
? Math.floor(amount)
: 0;
// tslint:disable-next-line: no-unnecessary-callback-wrapper // tslint:disable-next-line: no-unnecessary-callback-wrapper
return new Array(numPubKeys).fill(0).map(() => generateFakePubKey()); return new Array(numPubKeys).fill(0).map(() => generateFakePubKey());
@ -126,4 +124,3 @@ export function generateClosedGroupMessage(
chatMessage: generateChatMessage(), chatMessage: generateChatMessage(),
}); });
} }

Loading…
Cancel
Save