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

Commit f137bf3

Browse files
authored
Fix all megolm error reported as unknown (#8916)
* Fix all megolm error reported as unknown * code review * bad paste in comment
1 parent 4eab0de commit f137bf3

File tree

3 files changed

+13
-5
lines changed

3 files changed

+13
-5
lines changed

src/DecryptionFailureTracker.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ See the License for the specific language governing permissions and
1414
limitations under the License.
1515
*/
1616

17-
import { MatrixError } from "matrix-js-sdk/src/http-api";
17+
import { DecryptionError } from "matrix-js-sdk/src/crypto/algorithms";
1818
import { MatrixEvent } from "matrix-js-sdk/src/models/event";
1919
import { Error as ErrorEvent } from "@matrix-org/analytics-events/types/typescript/Error";
2020

@@ -129,9 +129,13 @@ export class DecryptionFailureTracker {
129129
// localStorage.setItem('mx-decryption-failure-event-ids', JSON.stringify([...this.trackedEvents]));
130130
// }
131131

132-
public eventDecrypted(e: MatrixEvent, err: MatrixError): void {
132+
public eventDecrypted(e: MatrixEvent, err: DecryptionError): void {
133+
// for now we only track megolm decrytion failures
134+
if (e.getWireContent().algorithm != "m.megolm.v1.aes-sha2") {
135+
return;
136+
}
133137
if (err) {
134-
this.addDecryptionFailure(new DecryptionFailure(e.getId(), err.errcode));
138+
this.addDecryptionFailure(new DecryptionFailure(e.getId(), err.code));
135139
} else {
136140
// Could be an event in the failures, remove it
137141
this.removeDecryptionFailuresForEvent(e);

src/components/structures/MatrixChat.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ import { logger } from "matrix-js-sdk/src/logger";
3232
import { throttle } from "lodash";
3333
import { CryptoEvent } from "matrix-js-sdk/src/crypto";
3434
import { RoomType } from "matrix-js-sdk/src/@types/event";
35+
import { DecryptionError } from 'matrix-js-sdk/src/crypto/algorithms';
3536

3637
// focus-visible is a Polyfill for the :focus-visible CSS pseudo-attribute used by various components
3738
import 'focus-visible';
@@ -1452,7 +1453,7 @@ export default class MatrixChat extends React.PureComponent<IProps, IState> {
14521453

14531454
// When logging out, stop tracking failures and destroy state
14541455
cli.on(HttpApiEvent.SessionLoggedOut, () => dft.stop());
1455-
cli.on(MatrixEventEvent.Decrypted, (e, err) => dft.eventDecrypted(e, err as MatrixError));
1456+
cli.on(MatrixEventEvent.Decrypted, (e, err) => dft.eventDecrypted(e, err as DecryptionError));
14561457

14571458
cli.on(ClientEvent.Room, (room) => {
14581459
if (MatrixClientPeg.get().isCryptoEnabled()) {

test/DecryptionFailureTracker-test.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,16 @@ class MockDecryptionError extends Error {
2222
constructor(code) {
2323
super();
2424

25-
this.errcode = code || 'MOCK_DECRYPTION_ERROR';
25+
this.code = code || 'MOCK_DECRYPTION_ERROR';
2626
}
2727
}
2828

2929
function createFailedDecryptionEvent() {
3030
const event = new MatrixEvent({
3131
event_id: "event-id-" + Math.random().toString(16).slice(2),
32+
content: {
33+
algorithm: "m.megolm.v1.aes-sha2",
34+
},
3235
});
3336
event.setClearData(event.badEncryptedMessage(":("));
3437
return event;

0 commit comments

Comments
 (0)