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

Commit da1df70

Browse files
committed
Improve comments and explainer for new decryption approach
1 parent be23630 commit da1df70

File tree

3 files changed

+19
-11
lines changed

3 files changed

+19
-11
lines changed

src/components/structures/MatrixChat.tsx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -906,6 +906,10 @@ export default class MatrixChat extends React.PureComponent<IProps, IState> {
906906
let presentedId = roomInfo.room_alias || roomInfo.room_id;
907907
const room = MatrixClientPeg.get().getRoom(roomInfo.room_id);
908908
if (room) {
909+
// Not all timeline events are decrypted ahead of time anymore
910+
// Only the critical ones for a typical UI are
911+
// This will start the decryption process for all events when a
912+
// user views a room
909913
room.decryptAllEvents();
910914
const theAlias = Rooms.getDisplayAliasForRoom(room);
911915
if (theAlias) {

src/indexing/EventIndex.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,7 @@ export default class EventIndex extends EventEmitter {
188188
}
189189

190190
if (ev.isBeingDecrypted()) {
191+
// XXX: Private member access
191192
await ev._decryptionPromise;
192193
}
193194

@@ -523,6 +524,11 @@ export default class EventIndex extends EventEmitter {
523524
emit: false,
524525
});
525526
} else {
527+
// TODO the decryption promise is a private property, this
528+
// should either be made public or we should convert the
529+
// event that gets fired when decryption is done into a
530+
// promise using the once event emitter method:
531+
// https://nodejs.org/api/events.html#events_events_once_emitter_name
526532
return event._decryptionPromise;
527533
}
528534
});

src/stores/BreadcrumbsStore.ts

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,14 @@ limitations under the License.
1616

1717
import SettingsStore from "../settings/SettingsStore";
1818
import { Room } from "matrix-js-sdk/src/models/room";
19+
import { EventType } from "matrix-js-sdk/src/@types/event";
1920
import { ActionPayload } from "../dispatcher/payloads";
2021
import { AsyncStoreWithClient } from "./AsyncStoreWithClient";
2122
import defaultDispatcher from "../dispatcher/dispatcher";
2223
import { arrayHasDiff } from "../utils/arrays";
2324
import { isNullOrUndefined } from "matrix-js-sdk/src/utils";
2425
import { SettingLevel } from "../settings/SettingLevel";
25-
import {MatrixClientPeg} from '../MatrixClientPeg';
26+
import { MatrixClientPeg } from '../MatrixClientPeg';
2627

2728
const MAX_ROOMS = 20; // arbitrary
2829
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> {
6465
const prevRoomCount = (prevState.rooms?.length || 0);
6566
const currentRoomCount = (this.state.rooms?.length || 0)
6667

67-
/**
68-
* Only decrypting the breadcrumb rooms events on app initialisation
69-
* when room count transitions from 0 to the number of rooms it contains
70-
*/
68+
// Only decrypting the breadcrumb rooms events on app initialisation
69+
// when room count transitions from 0 to the number of rooms it contains
7170
if (prevRoomCount === 0 && currentRoomCount > prevRoomCount) {
7271
const client = MatrixClientPeg.get();
73-
/**
74-
* Rooms in the breadcrumb have a good chance to be interacted with
75-
* again by a user. Decrypting the messages ahead of time will help
76-
* reduce content shift on first render
77-
*/
72+
// Rooms in the breadcrumb have a good chance to be interacted with
73+
// again by a user. Decrypting the messages ahead of time will help
74+
// reduce content shift on first render
7875
this.state.rooms?.forEach(async room => {
79-
const [cryptoEvent] = room.currentState.getStateEvents("m.room.encryption");
76+
const [cryptoEvent] = room.currentState.getStateEvents(EventType.RoomEncryption);
8077
if (cryptoEvent) {
8178
if (!client.isRoomEncrypted(room.roomId)) {
79+
// XXX: Private member access
8280
await client._crypto.onCryptoEvent(cryptoEvent);
8381
}
8482
room?.decryptAllEvents();

0 commit comments

Comments
 (0)