Decrypt events in reverse order without copying the array (#12445)

Signed-off-by: Johannes Marbach <n0-0ne+github@mailbox.org>
This commit is contained in:
Johannes Marbach 2024-04-22 10:52:50 +02:00 committed by GitHub
parent cc7edade21
commit 6dd6a7697c
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -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";
@ -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) => {
// We want the last event to be decrypted first
const client = MatrixClientPeg.safeGet();
client.decryptEventIfNeeded(event);
});
for (let i = events.length - 1; i >= 0; --i) {
client.decryptEventIfNeeded(events[i]);
}
const firstVisibleEventIndex = this.checkForPreJoinUISI(events);