From b32fbcb64fef82f1e7c229efd29d849d93a493f9 Mon Sep 17 00:00:00 2001 From: Travis Ralston Date: Tue, 25 Feb 2020 15:40:15 -0700 Subject: [PATCH] Don't try to collapse zero events with a group Fixes https://github.com/vector-im/riot-web/issues/12423 When events are redacted they fail to make it into the Grouper because the `shouldAddEvent` check blocks them from entering. However, the grouper expects that when `getTiles()` is called that there's events to group and dutifully grabs some context from the array. Because JavaScript is the least helpful language, `myArray[-1]` returns `undefined` or `null` and thus you get `cannot read 'sender' of undefined`. Regressed in https://github.com/matrix-org/matrix-react-sdk/pull/4059 --- src/components/structures/MessagePanel.js | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/components/structures/MessagePanel.js b/src/components/structures/MessagePanel.js index b8b11fbb31..d0e35e1c2b 100644 --- a/src/components/structures/MessagePanel.js +++ b/src/components/structures/MessagePanel.js @@ -873,6 +873,11 @@ class CreationGrouper { } getTiles() { + // If we don't have any events to group, don't even try to group them. The logic + // below assumes that we have a group of events to deal with, but we might not if + // the events we were supposed to group were redacted. + if (!this.events || !this.events.length) return []; + const DateSeparator = sdk.getComponent('messages.DateSeparator'); const EventListSummary = sdk.getComponent('views.elements.EventListSummary'); @@ -959,6 +964,11 @@ class MemberGrouper { } getTiles() { + // If we don't have any events to group, don't even try to group them. The logic + // below assumes that we have a group of events to deal with, but we might not if + // the events we were supposed to group were redacted. + if (!this.events || !this.events.length) return []; + const DateSeparator = sdk.getComponent('messages.DateSeparator'); const MemberEventListSummary = sdk.getComponent('views.elements.MemberEventListSummary');