From 2cf2df20f6458c933f8d806ce87ff19333494c48 Mon Sep 17 00:00:00 2001 From: wmwragg Date: Tue, 23 Aug 2016 12:40:15 +0100 Subject: [PATCH] Added updating of count when room tile notification state changed --- src/components/structures/RoomSubList.js | 66 ++++++++++++++---------- 1 file changed, 40 insertions(+), 26 deletions(-) diff --git a/src/components/structures/RoomSubList.js b/src/components/structures/RoomSubList.js index 746d0fb1c1..6ddea56067 100644 --- a/src/components/structures/RoomSubList.js +++ b/src/components/structures/RoomSubList.js @@ -82,11 +82,15 @@ 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], }; }, @@ -121,30 +125,35 @@ var RoomSubList = React.createClass({ if (this.state.hidden && (this.state.capTruncate && isTruncatable)) { isHidden = false; - this.setState({ hidden : isHidden }); - this.setState({ capTruncate : true }); - // Show truncated list - this.setState({ truncateAt : TRUNCATE_AT }); - } else if ((!this.state.hidden && this.state.capTruncate) || - (this.state.hidden && (this.state.capTruncate && !isTruncatable))) { + this.setState({ + hidden : isHidden, + capTruncate : true, + truncateAt : TRUNCATE_AT + }); + } else if ((!this.state.hidden && this.state.capTruncate) + || (this.state.hidden && (this.state.capTruncate && !isTruncatable))) + { isHidden = false; - this.setState({ hidden : isHidden }); - this.setState({ capTruncate : false }); - // Show full list - this.setState({ truncateAt : -1 }); + this.setState({ + hidden : isHidden, + capTruncate : false, + truncateAt : -1 + }); } else if (!this.state.hidden && !this.state.capTruncate) { isHidden = true; - this.setState({ hidden : isHidden }); - this.setState({ capTruncate : true }); - // Truncated list - this.setState({ truncateAt : TRUNCATE_AT }); + this.setState({ + hidden : isHidden, + capTruncate : true, + truncateAt : TRUNCATE_AT + }); } else { // Catch any weird states the system gets into isHidden = false; - this.setState({ hidden : isHidden }); - this.setState({ capTruncate : true }); - // Show truncated list - this.setState({ truncateAt : TRUNCATE_AT }); + this.setState({ + hidden : isHidden, + capTruncate : true, + truncateAt : TRUNCATE_AT + }); } this.props.onShowMoreRooms(); @@ -230,7 +239,7 @@ var RoomSubList = React.createClass({ var subListHighlight = false; var cli = MatrixClientPeg.get(); - this.state.sortedList.map(function(room) { + this.props.list.map(function(room) { var roomNotifState = RoomNotifs.getRoomNotifsState(room.roomId); var highlight = room.getUnreadNotificationCount('highlight') > 0 || self.props.label === 'Invites'; var notificationCount = room.getUnreadNotificationCount(); @@ -250,6 +259,14 @@ var RoomSubList = React.createClass({ return [subListCount, subListHighlight]; }, + _updateSubListCount: function() { + var subListNotifications = this.roomNotificationCount(); + this.setState({ + subListNotifCount: subListNotifications[0], + subListNotifHighlight: subListNotifications[1] + }); + }, + moveRoomTile: function(room, atIndex) { if (debug) console.log("moveRoomTile: id " + room.roomId + ", atIndex " + atIndex); //console.log("moveRoomTile before: " + JSON.stringify(this.state.rooms)); @@ -357,6 +374,7 @@ var RoomSubList = React.createClass({ unread={ Unread.doesRoomHaveUnreadMessages(room) } highlight={ room.getUnreadNotificationCount('highlight') > 0 || self.props.label === 'Invites' } isInvite={ self.props.label === 'Invites' } + refreshSubList={ self._updateSubListCount } incomingCall={ self.props.incomingCall && (self.props.incomingCall.roomId === room.roomId) ? self.props.incomingCall : null } /> ); }); @@ -365,10 +383,6 @@ var RoomSubList = React.createClass({ _getHeaderJsx: function() { var TintableSvg = sdk.getComponent("elements.TintableSvg"); - var subListNotifications = this.roomNotificationCount(); - var subListNotificationsCount = subListNotifications[0]; - var subListNotificationsHighlight = 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) { @@ -384,12 +398,12 @@ var RoomSubList = React.createClass({ var badgeClasses = classNames({ 'mx_RoomSubList_badge': true, - 'mx_RoomSubList_badgeHighlight': subListNotificationsHighlight, + 'mx_RoomSubList_badgeHighlight': this.state.subListNotifHighlight, }); var badge; - if (subListNotificationsCount > 0) { - badge =
{subListNotificationsCount}
; + if (this.state.subListNotifCount > 0) { + badge =
{this.state.subListNotifCount}
; } return (