1
0
mirror of https://github.com/matrix-org/matrix-js-sdk.git synced 2025-11-28 05:03:59 +03:00

Merge pull request #597 from matrix-org/dbkr/e2e_rooms_indexeddb

Migrate room encryption store to crypto store
This commit is contained in:
David Baker
2018-02-06 10:29:29 +00:00
committed by GitHub
8 changed files with 207 additions and 49 deletions

View File

@@ -42,6 +42,7 @@ const MatrixBaseApis = require("./base-apis");
const MatrixError = httpApi.MatrixError;
import ReEmitter from './ReEmitter';
import RoomList from './crypto/RoomList';
const SCROLLBACK_DELAY_MS = 3000;
let CRYPTO_ENABLED = false;
@@ -181,6 +182,11 @@ function MatrixClient(opts) {
if (CRYPTO_ENABLED) {
this.olmVersion = Crypto.getOlmVersion();
}
// List of which rooms have encryption enabled: separate from crypto because
// we still want to know which rooms are encrypted even if crypto is disabled:
// we don't want to start sending unencrypted events to them.
this._roomList = new RoomList(this._cryptoStore, this._sessionStore);
}
utils.inherits(MatrixClient, EventEmitter);
utils.extend(MatrixClient.prototype, MatrixBaseApis.prototype);
@@ -351,13 +357,6 @@ MatrixClient.prototype.initCrypto = async function() {
return;
}
if (!CRYPTO_ENABLED) {
throw new Error(
`End-to-end encryption not supported in this js-sdk build: did ` +
`you remember to load the olm library?`,
);
}
if (!this._sessionStore) {
// this is temporary, the sessionstore is supposed to be going away
throw new Error(`Cannot enable encryption: no sessionStore provided`);
@@ -367,6 +366,16 @@ MatrixClient.prototype.initCrypto = async function() {
throw new Error(`Cannot enable encryption: no cryptoStore provided`);
}
// initialise the list of encrypted rooms (whether or not crypto is enabled)
await this._roomList.init();
if (!CRYPTO_ENABLED) {
throw new Error(
`End-to-end encryption not supported in this js-sdk build: did ` +
`you remember to load the olm library?`,
);
}
const userId = this.getUserId();
if (userId === null) {
throw new Error(
@@ -387,6 +396,7 @@ MatrixClient.prototype.initCrypto = async function() {
userId, this.deviceId,
this.store,
this._cryptoStore,
this._roomList,
);
this.reEmitter.reEmit(crypto, [
@@ -646,11 +656,7 @@ MatrixClient.prototype.isRoomEncrypted = function(roomId) {
// we don't have an m.room.encrypted event, but that might be because
// the server is hiding it from us. Check the store to see if it was
// previously encrypted.
if (!this._sessionStore) {
return false;
}
return Boolean(this._sessionStore.getEndToEndRoom(roomId));
return this._roomList.isRoomEncrypted(roomId);
};
/**