Skip to content
This repository has been archived by the owner on Sep 11, 2024. It is now read-only.

Commit

Permalink
Fix all megolm error reported as unknown (#8916)
Browse files Browse the repository at this point in the history
* Fix all megolm error reported as unknown

* code review

* bad paste in comment
  • Loading branch information
BillCarsonFr authored Jun 30, 2022
1 parent 4eab0de commit f137bf3
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 5 deletions.
10 changes: 7 additions & 3 deletions src/DecryptionFailureTracker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";

Expand Down Expand Up @@ -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);
Expand Down
3 changes: 2 additions & 1 deletion src/components/structures/MatrixChat.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -1452,7 +1453,7 @@ export default class MatrixChat extends React.PureComponent<IProps, IState> {

// 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()) {
Expand Down
5 changes: 4 additions & 1 deletion test/DecryptionFailureTracker-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit f137bf3

Please sign in to comment.