Skip to content

Commit

Permalink
Decrypt events in reverse order without copying the array (#12445)
Browse files Browse the repository at this point in the history
Signed-off-by: Johannes Marbach <[email protected]>
  • Loading branch information
Johennes authored Apr 22, 2024
1 parent cc7edad commit 6dd6a76
Showing 1 changed file with 5 additions and 10 deletions.
15 changes: 5 additions & 10 deletions src/components/structures/TimelinePanel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@ import dis from "../../dispatcher/dispatcher";
import { Action } from "../../dispatcher/actions";
import Timer from "../../utils/Timer";
import shouldHideEvent from "../../shouldHideEvent";
import { arrayFastClone } from "../../utils/arrays";
import MessagePanel from "./MessagePanel";
import { IScrollState } from "./ScrollPanel";
import { ActionPayload } from "../../dispatcher/payloads";
Expand Down Expand Up @@ -1754,15 +1753,11 @@ class TimelinePanel extends React.Component<IProps, IState> {
[...mainEvents],
);

// `arrayFastClone` performs a shallow copy of the array
// we want the last event to be decrypted first but displayed last
// `reverse` is destructive and unfortunately mutates the "events" array
arrayFastClone(events)
.reverse()
.forEach((event) => {
const client = MatrixClientPeg.safeGet();
client.decryptEventIfNeeded(event);
});
// We want the last event to be decrypted first
const client = MatrixClientPeg.safeGet();
for (let i = events.length - 1; i >= 0; --i) {
client.decryptEventIfNeeded(events[i]);
}

const firstVisibleEventIndex = this.checkForPreJoinUISI(events);

Expand Down

0 comments on commit 6dd6a76

Please sign in to comment.