Added small helper functions

pull/1176/head
Mikunj 5 years ago
parent a83ce4ee16
commit f681fd619d

@ -211,11 +211,9 @@
return true;
}
const ourDevices = await window.libsession.Protocols.MultiDeviceProtocol.getAllDevices(
this.ourNumber
return window.libsession.Protocols.MultiDeviceProtocol.isOurDevice(
this.id
);
return ourDevices.some(device => device.key === this.id);
},
isOurLocalDevice() {
return this.id === this.ourNumber;

@ -192,4 +192,31 @@ export class MultiDeviceProtocol {
.map(a => a.secondaryDevicePubKey)
.map(pubKey => new SecondaryPubKey(pubKey));
}
/**
* Get all devices linked to the current user.
*/
public static async getOurDevices(): Promise<Array<PubKey>> {
const ourPubKey = await UserUtil.getCurrentDevicePubKey();
if (!ourPubKey) {
throw new Error('Public key not set.');
}
return this.getAllDevices(ourPubKey);
}
/**
* Check if the given device is one of our own.
* @param device The device to check.
*/
public static async isOurDevice(device: PubKey | string): Promise<boolean> {
const pubKey = typeof device === 'string' ? new PubKey(device) : device;
try {
const ourDevices = await this.getOurDevices();
return ourDevices.some(d => PubKey.isEqual(d, pubKey));
} catch (e) {
return false;
}
}
}

Loading…
Cancel
Save