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

Commit f1a6f6f

Browse files
committed
make breadcrumb room events decryption more idiomatic
1 parent d0d2907 commit f1a6f6f

File tree

2 files changed

+27
-18
lines changed

2 files changed

+27
-18
lines changed

src/components/structures/TimelinePanel.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1142,7 +1142,6 @@ class TimelinePanel extends React.Component {
11421142
_getEvents() {
11431143
const events = this._timelineWindow.getEvents();
11441144

1145-
11461145
// `slice` performs a shallow copy of the array
11471146
// we want the last event to be decrypted first but displayed last
11481147
// `reverse` is destructive and unfortunately mutates the "events" array

src/stores/BreadcrumbsStore.ts

Lines changed: 27 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,33 @@ export class BreadcrumbsStore extends AsyncStoreWithClient<IState> {
6060
return this.matrixClient && this.matrixClient.getVisibleRooms().length >= 20;
6161
}
6262

63+
componentDidUpdate(prevProps, prevState) {
64+
const prevRoomCount = (prevState.rooms?.length || 0);
65+
const currentRoomCount = (this.state.rooms?.length || 0)
66+
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+
*/
71+
if (prevRoomCount === 0 && currentRoomCount > prevRoomCount) {
72+
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+
*/
78+
this.state.rooms?.forEach(async room => {
79+
const [cryptoEvent] = room.currentState.getStateEvents("m.room.encryption");
80+
if (cryptoEvent) {
81+
if (!client.isRoomEncrypted(room.roomId)) {
82+
await client._crypto.onCryptoEvent(cryptoEvent);
83+
}
84+
room?.decryptAllEvents();
85+
}
86+
});
87+
}
88+
}
89+
6390
protected async onAction(payload: ActionPayload) {
6491
if (!this.matrixClient) return;
6592

@@ -88,23 +115,6 @@ export class BreadcrumbsStore extends AsyncStoreWithClient<IState> {
88115

89116
this.matrixClient.on("Room.myMembership", this.onMyMembership);
90117
this.matrixClient.on("Room", this.onRoom);
91-
92-
const client = MatrixClientPeg.get();
93-
const breadcrumbs = client.store.getAccountData("im.vector.setting.breadcrumbs");
94-
const breadcrumbsRooms: string[] = breadcrumbs?.getContent().recent_rooms || [];
95-
96-
breadcrumbsRooms.map(async roomId => {
97-
const room = client.getRoom(roomId);
98-
if (room) {
99-
const [cryptoEvent] = room.currentState.getStateEvents("m.room.encryption");
100-
if (cryptoEvent) {
101-
if (!client.isRoomEncrypted(roomId)) {
102-
await client._crypto.onCryptoEvent(cryptoEvent);
103-
}
104-
return room?.decryptAllEvents();
105-
}
106-
}
107-
});
108118
}
109119

110120
protected async onNotReady() {

0 commit comments

Comments
 (0)