From 7dc82e2e7ac6ef94eb85c2199e6385c2da91d889 Mon Sep 17 00:00:00 2001 From: Luke Barnard Date: Fri, 16 Mar 2018 17:55:29 +0000 Subject: [PATCH] Force update RoomSubList after reading a room so that the notification count is updated. Previously we relied on a force update from RoomList, which was removed as part of the optimisations in https://github.com/matrix-org/matrix-react-sdk/pull/1801 --- src/components/structures/RoomSubList.js | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/src/components/structures/RoomSubList.js b/src/components/structures/RoomSubList.js index 70e5b18517..ed092d94ad 100644 --- a/src/components/structures/RoomSubList.js +++ b/src/components/structures/RoomSubList.js @@ -88,6 +88,11 @@ var RoomSubList = React.createClass({ this.setState({ sortedList: this.applySearchFilter(this.props.list, this.props.searchFilter), }); + this.dispatcherRef = dis.register(this.onAction); + }, + + componentWillUnmount: function() { + dis.unregister(this.dispatcherRef); }, componentWillReceiveProps: function(newProps) { @@ -116,6 +121,21 @@ var RoomSubList = React.createClass({ } }, + onAction: function(payload) { + // XXX: Previously RoomList would forceUpdate whenever on_room_read is dispatched, + // but this is no longer true, so we must do it here (and can apply the small + // optimisation of checking that we care about the room being read). + // + // Ultimately we need to transition to a state pushing flow where something + // explicitly notifies the components concerned that the notif count for a room + // has change (e.g. a Flux store). + if (payload.action === 'on_room_read' && + this.props.list.some((r) => r.roomId === payload.roomId) + ) { + this.forceUpdate(); + } + }, + onClick: function(ev) { if (this.isCollapsableOnClick()) { // The header isCollapsable, so the click is to be interpreted as collapse and truncation logic