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

Decrypt events in reverse order without copying the array #12445

Merged
merged 1 commit into from
Apr 22, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading