From a283bc4889917e8d248ffa6458a6e53e166c8245 Mon Sep 17 00:00:00 2001 From: Richard van der Hoff <1389908+richvdh@users.noreply.github.com> Date: Tue, 17 Oct 2023 16:54:22 +0100 Subject: [PATCH] Avoid `MatrixEvent.toJSON` in event indexer (#11765) Part of the solution to https://github.com/vector-im/element-web/issues/26380: `toJSON` is dangerous, and I'd like to kill it off. There is no need for it here; it is simpler to call `getEffectiveEvent` directly. --- src/indexing/EventIndex.ts | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/indexing/EventIndex.ts b/src/indexing/EventIndex.ts index 97688d725a..fbc731e9a9 100644 --- a/src/indexing/EventIndex.ts +++ b/src/indexing/EventIndex.ts @@ -309,8 +309,7 @@ export default class EventIndex extends EventEmitter { } private eventToJson(ev: MatrixEvent): IEventWithRoomId { - const jsonEvent: any = ev.toJSON(); - const e = ev.isEncrypted() ? jsonEvent.decrypted : jsonEvent; + const e = ev.getEffectiveEvent() as any; if (ev.isEncrypted()) { // Let us store some additional data so we can re-verify the event.