From f137bf3fd39587bd7f0aa56351c593236e7e0456 Mon Sep 17 00:00:00 2001 From: Valere Date: Thu, 30 Jun 2022 09:55:05 +0200 Subject: [PATCH] Fix all megolm error reported as unknown (#8916) * Fix all megolm error reported as unknown * code review * bad paste in comment --- src/DecryptionFailureTracker.ts | 10 +++++++--- src/components/structures/MatrixChat.tsx | 3 ++- test/DecryptionFailureTracker-test.js | 5 ++++- 3 files changed, 13 insertions(+), 5 deletions(-) diff --git a/src/DecryptionFailureTracker.ts b/src/DecryptionFailureTracker.ts index 019f06d775..b0d9b7ef58 100644 --- a/src/DecryptionFailureTracker.ts +++ b/src/DecryptionFailureTracker.ts @@ -14,7 +14,7 @@ See the License for the specific language governing permissions and limitations under the License. */ -import { MatrixError } from "matrix-js-sdk/src/http-api"; +import { DecryptionError } from "matrix-js-sdk/src/crypto/algorithms"; import { MatrixEvent } from "matrix-js-sdk/src/models/event"; import { Error as ErrorEvent } from "@matrix-org/analytics-events/types/typescript/Error"; @@ -129,9 +129,13 @@ export class DecryptionFailureTracker { // localStorage.setItem('mx-decryption-failure-event-ids', JSON.stringify([...this.trackedEvents])); // } - public eventDecrypted(e: MatrixEvent, err: MatrixError): void { + public eventDecrypted(e: MatrixEvent, err: DecryptionError): void { + // for now we only track megolm decrytion failures + if (e.getWireContent().algorithm != "m.megolm.v1.aes-sha2") { + return; + } if (err) { - this.addDecryptionFailure(new DecryptionFailure(e.getId(), err.errcode)); + this.addDecryptionFailure(new DecryptionFailure(e.getId(), err.code)); } else { // Could be an event in the failures, remove it this.removeDecryptionFailuresForEvent(e); diff --git a/src/components/structures/MatrixChat.tsx b/src/components/structures/MatrixChat.tsx index 8e973d60db..3f6ffd1154 100644 --- a/src/components/structures/MatrixChat.tsx +++ b/src/components/structures/MatrixChat.tsx @@ -32,6 +32,7 @@ import { logger } from "matrix-js-sdk/src/logger"; import { throttle } from "lodash"; import { CryptoEvent } from "matrix-js-sdk/src/crypto"; import { RoomType } from "matrix-js-sdk/src/@types/event"; +import { DecryptionError } from 'matrix-js-sdk/src/crypto/algorithms'; // focus-visible is a Polyfill for the :focus-visible CSS pseudo-attribute used by various components import 'focus-visible'; @@ -1452,7 +1453,7 @@ export default class MatrixChat extends React.PureComponent { // When logging out, stop tracking failures and destroy state cli.on(HttpApiEvent.SessionLoggedOut, () => dft.stop()); - cli.on(MatrixEventEvent.Decrypted, (e, err) => dft.eventDecrypted(e, err as MatrixError)); + cli.on(MatrixEventEvent.Decrypted, (e, err) => dft.eventDecrypted(e, err as DecryptionError)); cli.on(ClientEvent.Room, (room) => { if (MatrixClientPeg.get().isCryptoEnabled()) { diff --git a/test/DecryptionFailureTracker-test.js b/test/DecryptionFailureTracker-test.js index 997c4913c3..8572365f08 100644 --- a/test/DecryptionFailureTracker-test.js +++ b/test/DecryptionFailureTracker-test.js @@ -22,13 +22,16 @@ class MockDecryptionError extends Error { constructor(code) { super(); - this.errcode = code || 'MOCK_DECRYPTION_ERROR'; + this.code = code || 'MOCK_DECRYPTION_ERROR'; } } function createFailedDecryptionEvent() { const event = new MatrixEvent({ event_id: "event-id-" + Math.random().toString(16).slice(2), + content: { + algorithm: "m.megolm.v1.aes-sha2", + }, }); event.setClearData(event.badEncryptedMessage(":(")); return event;