diff --git a/spec/integ/matrix-client-crypto.spec.ts b/spec/integ/matrix-client-crypto.spec.ts index d0f46b9e5..262975ead 100644 --- a/spec/integ/matrix-client-crypto.spec.ts +++ b/spec/integ/matrix-client-crypto.spec.ts @@ -132,7 +132,7 @@ async function aliDownloadsKeys(): Promise { // check that the localStorage is updated as we expect (not sure this is // an integration test, but meh) await Promise.all([p1(), p2()]); - await aliTestClient.client.crypto.deviceList.saveIfDirty(); + await aliTestClient.client.crypto!.deviceList.saveIfDirty(); // @ts-ignore - protected aliTestClient.client.cryptoStore.getEndToEndDeviceData(null, (data) => { const devices = data.devices[bobUserId]; @@ -494,7 +494,7 @@ describe("MatrixClient crypto", () => { aliTestClient.expectKeyQuery({ device_keys: { [aliUserId]: {} }, failures: {} }); await aliTestClient.start(); await bobTestClient.start(); - bobTestClient.client.crypto.deviceList.downloadKeys = () => Promise.resolve({}); + bobTestClient.client.crypto!.deviceList.downloadKeys = () => Promise.resolve({}); await firstSync(aliTestClient); await aliEnablesEncryption(); await aliSendsFirstMessage(); @@ -505,7 +505,7 @@ describe("MatrixClient crypto", () => { aliTestClient.expectKeyQuery({ device_keys: { [aliUserId]: {} }, failures: {} }); await aliTestClient.start(); await bobTestClient.start(); - bobTestClient.client.crypto.deviceList.downloadKeys = () => Promise.resolve({}); + bobTestClient.client.crypto!.deviceList.downloadKeys = () => Promise.resolve({}); await firstSync(aliTestClient); await aliEnablesEncryption(); await aliSendsFirstMessage(); @@ -569,7 +569,7 @@ describe("MatrixClient crypto", () => { aliTestClient.expectKeyQuery({ device_keys: { [aliUserId]: {} }, failures: {} }); await aliTestClient.start(); await bobTestClient.start(); - bobTestClient.client.crypto.deviceList.downloadKeys = () => Promise.resolve({}); + bobTestClient.client.crypto!.deviceList.downloadKeys = () => Promise.resolve({}); await firstSync(aliTestClient); await aliEnablesEncryption(); await aliSendsFirstMessage(); diff --git a/spec/integ/matrix-client-syncing.spec.ts b/spec/integ/matrix-client-syncing.spec.ts index 03126c506..e07e52c7b 100644 --- a/spec/integ/matrix-client-syncing.spec.ts +++ b/spec/integ/matrix-client-syncing.spec.ts @@ -225,6 +225,44 @@ describe("MatrixClient syncing", () => { return httpBackend!.flushAllExpected(); }); + + it("should emit ClientEvent.Room when invited while crypto is disabled", async () => { + const roomId = "!invite:example.org"; + + // First sync: an invite + const inviteSyncRoomSection = { + invite: { + [roomId]: { + invite_state: { + events: [{ + type: "m.room.member", + state_key: selfUserId, + content: { + membership: "invite", + }, + }], + }, + }, + }, + }; + httpBackend!.when("GET", "/sync").respond(200, { + ...syncData, + rooms: inviteSyncRoomSection, + }); + + // First fire: an initial invite + let fires = 0; + client!.once(ClientEvent.Room, (room) => { + fires++; + expect(room.roomId).toBe(roomId); + }); + + // noinspection ES6MissingAwait + client!.startClient(); + await httpBackend!.flushAllExpected(); + + expect(fires).toBe(1); + }); }); describe("initial sync", () => { diff --git a/src/client.ts b/src/client.ts index 918dfccaa..e0e051126 100644 --- a/src/client.ts +++ b/src/client.ts @@ -923,7 +923,7 @@ export class MatrixClient extends TypedEventEmitter } = {}; public identityServer: IIdentityServerProvider; public http: MatrixHttpApi; // XXX: Intended private, used in code. - public crypto: Crypto; // XXX: Intended private, used in code. + public crypto?: Crypto; // XXX: Intended private, used in code. public cryptoCallbacks: ICryptoCallbacks; // XXX: Intended private, used in code. public callEventHandler: CallEventHandler; // XXX: Intended private, used in code. public supportsCallTransfer = false; // XXX: Intended private, used in code. diff --git a/src/sync.ts b/src/sync.ts index 7defdc4b1..768547949 100644 --- a/src/sync.ts +++ b/src/sync.ts @@ -1200,19 +1200,22 @@ export class SyncApi { await this.processRoomEvents(room, stateEvents); const inviter = room.currentState.getStateEvents(EventType.RoomMember, client.getUserId())?.getSender(); - const parkedHistory = await client.crypto.cryptoStore.takeParkedSharedHistory(room.roomId); - for (const parked of parkedHistory) { - if (parked.senderId === inviter) { - await this.client.crypto.olmDevice.addInboundGroupSession( - room.roomId, - parked.senderKey, - parked.forwardingCurve25519KeyChain, - parked.sessionId, - parked.sessionKey, - parked.keysClaimed, - true, - { sharedHistory: true, untrusted: true }, - ); + + if (client.isCryptoEnabled()) { + const parkedHistory = await client.crypto.cryptoStore.takeParkedSharedHistory(room.roomId); + for (const parked of parkedHistory) { + if (parked.senderId === inviter) { + await client.crypto.olmDevice.addInboundGroupSession( + room.roomId, + parked.senderKey, + parked.forwardingCurve25519KeyChain, + parked.sessionId, + parked.sessionKey, + parked.keysClaimed, + true, + { sharedHistory: true, untrusted: true }, + ); + } } }