From d2e8201d79c3188b558f82e2f83f77a31ac0c0cb Mon Sep 17 00:00:00 2001 From: wmwragg Date: Tue, 23 Aug 2016 13:24:02 +0100 Subject: [PATCH] Making sure that the sub list count always stays up to date, including when people read the outstanding notifications --- src/components/structures/RoomSubList.js | 23 +++++++++++------------ 1 file changed, 11 insertions(+), 12 deletions(-) diff --git a/src/components/structures/RoomSubList.js b/src/components/structures/RoomSubList.js index 6ddea5606..e79f612de 100644 --- a/src/components/structures/RoomSubList.js +++ b/src/components/structures/RoomSubList.js @@ -82,15 +82,11 @@ var RoomSubList = React.createClass({ }, getInitialState: function() { - var subListNotifications = this.roomNotificationCount(); - return { hidden: this.props.startAsHidden || false, capTruncate: this.props.list.length > TRUNCATE_AT, truncateAt: this.props.list.length > TRUNCATE_AT ? TRUNCATE_AT : -1, sortedList: [], - subListNotifCount: subListNotifications[0], - subListNotifHighlight: subListNotifications[1], }; }, @@ -260,11 +256,10 @@ var RoomSubList = React.createClass({ }, _updateSubListCount: function() { - var subListNotifications = this.roomNotificationCount(); - this.setState({ - subListNotifCount: subListNotifications[0], - subListNotifHighlight: subListNotifications[1] - }); + // Force an update by setting the state to the current state + // Doing it this way rather than using forceUpdate(), so that the shouldComponentUpdate() + // method is honoured + this.setState(this.state); }, moveRoomTile: function(room, atIndex) { @@ -383,6 +378,10 @@ var RoomSubList = React.createClass({ _getHeaderJsx: function() { var TintableSvg = sdk.getComponent("elements.TintableSvg"); + var subListNotifications = this.roomNotificationCount(); + var subListNotifCount = subListNotifications[0]; + var subListNotifHighlight = subListNotifications[1]; + var roomCount = this.props.list.length > 0 ? this.props.list.length : ''; var isTruncatable = this.props.list.length > TRUNCATE_AT; if (!this.state.hidden && this.state.capTruncate && isTruncatable) { @@ -398,12 +397,12 @@ var RoomSubList = React.createClass({ var badgeClasses = classNames({ 'mx_RoomSubList_badge': true, - 'mx_RoomSubList_badgeHighlight': this.state.subListNotifHighlight, + 'mx_RoomSubList_badgeHighlight': subListNotifHighlight, }); var badge; - if (this.state.subListNotifCount > 0) { - badge =
{this.state.subListNotifCount}
; + if (subListNotifCount > 0) { + badge =
{subListNotifCount}
; } return (