From fae7af1a6261e4903d0efef694c89ecda8512d6f Mon Sep 17 00:00:00 2001 From: Luke Barnard Date: Fri, 23 Feb 2018 14:54:00 +0000 Subject: [PATCH] Do proper null-checks on decypted events to fix NPEs Previously we assumed that a decrypted event has a room_id but this isn't necessarily true for to_device events. It makes sense to ignore events that aren't associated with rooms anyway given that the list we're updating only contains rooms! --- src/stores/RoomListStore.js | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/src/stores/RoomListStore.js b/src/stores/RoomListStore.js index 7660cf8df8..b6d0949dd3 100644 --- a/src/stores/RoomListStore.js +++ b/src/stores/RoomListStore.js @@ -90,12 +90,25 @@ class RoomListStore extends Store { // When an event is decrypted, it could mean we need to reorder the room // list because we now know the type of the event. case 'MatrixActions.Event.decrypted': { - const room = this._matrixClient.getRoom(payload.event.getRoomId()); + // We may not have synced or done an initial generation of the lists + if (!this._matrixClient || !this._state.ready) break; + + const roomId = payload.event.getRoomId(); + + // We may have decrypted an event without a roomId (e.g to_device) + if (!roomId) break; + + const room = this._matrixClient.getRoom(roomId); + + // We somehow decrypted an event for a room our client is unaware of + if (!room) break; + const liveTimeline = room.getLiveTimeline(); const eventTimeline = room.getTimelineForEvent(payload.event.getId()); - if (!this._state.ready || - liveTimeline !== eventTimeline || + // Either this event was not added to the live timeline (e.g. pagination) + // or it doesn't affect the ordering of the room list. + if (liveTimeline !== eventTimeline || !this._eventTriggersRecentReorder(payload.event) ) break; this._generateRoomLists();