diff --git a/js/models/conversations.js b/js/models/conversations.js index 2bb2ba599..df7051338 100644 --- a/js/models/conversations.js +++ b/js/models/conversations.js @@ -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; diff --git a/ts/session/protocols/MultiDeviceProtocol.ts b/ts/session/protocols/MultiDeviceProtocol.ts index 0c2aebfdd..18a9a7138 100644 --- a/ts/session/protocols/MultiDeviceProtocol.ts +++ b/ts/session/protocols/MultiDeviceProtocol.ts @@ -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> { + 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 { + 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; + } + } }