Improve comments and explainer for new decryption approach

pull/21833/head
Germain Souquet 2021-05-11 10:18:53 +01:00
parent be236309c5
commit da1df70557
3 changed files with 19 additions and 11 deletions

View File

@ -906,6 +906,10 @@ export default class MatrixChat extends React.PureComponent<IProps, IState> {
let presentedId = roomInfo.room_alias || roomInfo.room_id; let presentedId = roomInfo.room_alias || roomInfo.room_id;
const room = MatrixClientPeg.get().getRoom(roomInfo.room_id); const room = MatrixClientPeg.get().getRoom(roomInfo.room_id);
if (room) { if (room) {
// Not all timeline events are decrypted ahead of time anymore
// Only the critical ones for a typical UI are
// This will start the decryption process for all events when a
// user views a room
room.decryptAllEvents(); room.decryptAllEvents();
const theAlias = Rooms.getDisplayAliasForRoom(room); const theAlias = Rooms.getDisplayAliasForRoom(room);
if (theAlias) { if (theAlias) {

View File

@ -188,6 +188,7 @@ export default class EventIndex extends EventEmitter {
} }
if (ev.isBeingDecrypted()) { if (ev.isBeingDecrypted()) {
// XXX: Private member access
await ev._decryptionPromise; await ev._decryptionPromise;
} }
@ -523,6 +524,11 @@ export default class EventIndex extends EventEmitter {
emit: false, emit: false,
}); });
} else { } else {
// TODO the decryption promise is a private property, this
// should either be made public or we should convert the
// event that gets fired when decryption is done into a
// promise using the once event emitter method:
// https://nodejs.org/api/events.html#events_events_once_emitter_name
return event._decryptionPromise; return event._decryptionPromise;
} }
}); });

View File

@ -16,13 +16,14 @@ limitations under the License.
import SettingsStore from "../settings/SettingsStore"; import SettingsStore from "../settings/SettingsStore";
import { Room } from "matrix-js-sdk/src/models/room"; import { Room } from "matrix-js-sdk/src/models/room";
import { EventType } from "matrix-js-sdk/src/@types/event";
import { ActionPayload } from "../dispatcher/payloads"; import { ActionPayload } from "../dispatcher/payloads";
import { AsyncStoreWithClient } from "./AsyncStoreWithClient"; import { AsyncStoreWithClient } from "./AsyncStoreWithClient";
import defaultDispatcher from "../dispatcher/dispatcher"; import defaultDispatcher from "../dispatcher/dispatcher";
import { arrayHasDiff } from "../utils/arrays"; import { arrayHasDiff } from "../utils/arrays";
import { isNullOrUndefined } from "matrix-js-sdk/src/utils"; import { isNullOrUndefined } from "matrix-js-sdk/src/utils";
import { SettingLevel } from "../settings/SettingLevel"; import { SettingLevel } from "../settings/SettingLevel";
import {MatrixClientPeg} from '../MatrixClientPeg'; import { MatrixClientPeg } from '../MatrixClientPeg';
const MAX_ROOMS = 20; // arbitrary const MAX_ROOMS = 20; // arbitrary
const AUTOJOIN_WAIT_THRESHOLD_MS = 90000; // 90s, the time we wait for an autojoined room to show up const AUTOJOIN_WAIT_THRESHOLD_MS = 90000; // 90s, the time we wait for an autojoined room to show up
@ -64,21 +65,18 @@ export class BreadcrumbsStore extends AsyncStoreWithClient<IState> {
const prevRoomCount = (prevState.rooms?.length || 0); const prevRoomCount = (prevState.rooms?.length || 0);
const currentRoomCount = (this.state.rooms?.length || 0) const currentRoomCount = (this.state.rooms?.length || 0)
/** // Only decrypting the breadcrumb rooms events on app initialisation
* Only decrypting the breadcrumb rooms events on app initialisation // when room count transitions from 0 to the number of rooms it contains
* when room count transitions from 0 to the number of rooms it contains
*/
if (prevRoomCount === 0 && currentRoomCount > prevRoomCount) { if (prevRoomCount === 0 && currentRoomCount > prevRoomCount) {
const client = MatrixClientPeg.get(); const client = MatrixClientPeg.get();
/** // Rooms in the breadcrumb have a good chance to be interacted with
* Rooms in the breadcrumb have a good chance to be interacted with // again by a user. Decrypting the messages ahead of time will help
* again by a user. Decrypting the messages ahead of time will help // reduce content shift on first render
* reduce content shift on first render
*/
this.state.rooms?.forEach(async room => { this.state.rooms?.forEach(async room => {
const [cryptoEvent] = room.currentState.getStateEvents("m.room.encryption"); const [cryptoEvent] = room.currentState.getStateEvents(EventType.RoomEncryption);
if (cryptoEvent) { if (cryptoEvent) {
if (!client.isRoomEncrypted(room.roomId)) { if (!client.isRoomEncrypted(room.roomId)) {
// XXX: Private member access
await client._crypto.onCryptoEvent(cryptoEvent); await client._crypto.onCryptoEvent(cryptoEvent);
} }
room?.decryptAllEvents(); room?.decryptAllEvents();