From 2d5acfc0bc1337a0e816e37da5970e23272becfd Mon Sep 17 00:00:00 2001 From: Travis Ralston Date: Fri, 29 Sep 2017 11:30:52 -0600 Subject: [PATCH] Filter pinned events before rendering Signed-off-by: Travis Ralston --- .../views/rooms/PinnedEventsPanel.js | 24 ++++++++++--------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/src/components/views/rooms/PinnedEventsPanel.js b/src/components/views/rooms/PinnedEventsPanel.js index ec50ae079..e7da2ff2a 100644 --- a/src/components/views/rooms/PinnedEventsPanel.js +++ b/src/components/views/rooms/PinnedEventsPanel.js @@ -119,7 +119,8 @@ module.exports = React.createClass({ pinnedEvents.getContent().pinned.map(eventId => { promises.push(cli.getEventTimeline(this.props.room.getUnfilteredTimelineSet(), eventId, 0).then(timeline => { - return {eventId, timeline}; + const event = timeline.getEvents().find(e => e.getId() === eventId); + return {eventId, timeline, event}; }).catch(err => { console.error("Error looking up pinned event " + eventId + " in room " + this.props.room.roomId); console.error(err); @@ -128,8 +129,15 @@ module.exports = React.createClass({ }); Promise.all(promises).then(contexts => { - // Filter out the contexts that may have failed early by doing a truthy test - this.setState({ loading: false, pinned: contexts.filter(c => c) }); + // Filter out the messages before we try to render them + const pinned = contexts.filter(context => { + if (!context) return false; // no context == not applicable for the room + if (context.event.getType() !== "m.room.message") return false; + if (context.event.isRedacted()) return false; + return true; + }); + + this.setState({ loading: false, pinned }); }); } }, @@ -139,14 +147,8 @@ module.exports = React.createClass({ return
{ _t("No pinned messages.") }
; } - return this.state.pinned.map(pinnedEvent => { - const event = pinnedEvent.timeline.getEvents().find(e => e.getId() === pinnedEvent.eventId); - - // Don't show non-messages. Technically users can pin state/custom events, but we won't - // support those events. - if (event.getType() !== "m.room.message") return ''; - if (event.isRedacted()) return ''; // don't show redacted pins - return (); + return this.state.pinned.map(context => { + return (); }); },