From 5c57d81e9479b226738e5acca1eaf0b545af03f1 Mon Sep 17 00:00:00 2001 From: Bruno Windels Date: Fri, 14 Feb 2020 13:47:24 +0100 Subject: [PATCH 1/2] method for checking if other party supports verification method --- .../request/VerificationRequest.js | 27 +++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/src/crypto/verification/request/VerificationRequest.js b/src/crypto/verification/request/VerificationRequest.js index 0b26229b11a..a685aeff058 100644 --- a/src/crypto/verification/request/VerificationRequest.js +++ b/src/crypto/verification/request/VerificationRequest.js @@ -185,6 +185,33 @@ export class VerificationRequest extends EventEmitter { && this._phase !== PHASE_CANCELLED; } + /** Checks whether the other party supports a given verification method. + * This is useful setting up the QR code UI, as it is somewhat asymmetrical: + * if the other party supports SCAN_QR, we should show a QR code in the UI, and vice versa. + * For methods that need to be supported by both ends, use the `methods` property. + * @param {string} method the method to check + * @return {bool} whether or not the other party said the supported the method */ + otherPartySupportsMethod(method) { + if (!this.ready && !this.started) { + return false; + } + const theirMethodEvent = this._eventsByThem.get(REQUEST_TYPE) || + this._eventsByThem.get(READY_TYPE); + if (!theirMethodEvent) { + return false; + } + const content = theirMethodEvent.getContent(); + if (!content) { + return false; + } + const {methods} = content; + if (!Array.isArray(methods)) { + return false; + } + + return methods.includes(method); + } + /** Whether this request was initiated by the syncing user. * For InRoomChannel, this is who sent the .request event. * For ToDeviceChannel, this is who sent the .start event From fef03cda9ba7dacdecfd34b1af1fb291d02dd044 Mon Sep 17 00:00:00 2001 From: Bruno Windels Date: Tue, 18 Feb 2020 10:03:02 +0000 Subject: [PATCH 2/2] Update src/crypto/verification/request/VerificationRequest.js Co-Authored-By: J. Ryan Stinnett --- src/crypto/verification/request/VerificationRequest.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/crypto/verification/request/VerificationRequest.js b/src/crypto/verification/request/VerificationRequest.js index a685aeff058..51234bbc46d 100644 --- a/src/crypto/verification/request/VerificationRequest.js +++ b/src/crypto/verification/request/VerificationRequest.js @@ -186,7 +186,7 @@ export class VerificationRequest extends EventEmitter { } /** Checks whether the other party supports a given verification method. - * This is useful setting up the QR code UI, as it is somewhat asymmetrical: + * This is useful when setting up the QR code UI, as it is somewhat asymmetrical: * if the other party supports SCAN_QR, we should show a QR code in the UI, and vice versa. * For methods that need to be supported by both ends, use the `methods` property. * @param {string} method the method to check