1
0
mirror of https://github.com/matrix-org/matrix-js-sdk.git synced 2025-11-23 17:02:25 +03:00

Use a different error code for UTDs when user was not in the room (#4172)

* use a different error code for UTDs when user was not in the room

* if user is invited, treat it as unexpected UTD
This commit is contained in:
Hubert Chathi
2024-04-26 09:38:10 -04:00
committed by GitHub
parent 65d858f9a3
commit 64505de36b
5 changed files with 108 additions and 1 deletions

View File

@@ -18,6 +18,7 @@ import anotherjson from "another-json";
import * as RustSdkCryptoJs from "@matrix-org/matrix-sdk-crypto-wasm";
import type { IEventDecryptionResult, IMegolmSessionData } from "../@types/crypto";
import { KnownMembership } from "../@types/membership";
import type { IDeviceLists, IToDeviceEvent } from "../sync-accumulator";
import type { IEncryptedEventInfo } from "../crypto/api";
import { IContent, MatrixEvent, MatrixEventEvent } from "../models/event";
@@ -1741,6 +1742,17 @@ class EventDecryptor {
) {
this.perSessionBackupDownloader.onDecryptionKeyMissingError(event.getRoomId()!, content.session_id!);
// If the server is telling us our membership at the time the event
// was sent, and it isn't "join", we use a different error code.
const membership = event.getMembershipAtEvent();
if (membership && membership !== KnownMembership.Join && membership !== KnownMembership.Invite) {
throw new DecryptionError(
DecryptionFailureCode.HISTORICAL_MESSAGE_USER_NOT_JOINED,
"This message was sent when we were not a member of the room.",
errorDetails,
);
}
// If the event was sent before this device was created, we use some different error codes.
if (event.getTs() <= this.olmMachine.deviceCreationTimeMs) {
if (serverBackupInfo === null) {