@@ -23,16 +23,14 @@ var dis = require("matrix-react-sdk/lib/dispatcher");
2323
2424var sdk = require ( 'matrix-react-sdk' ) ;
2525var VectorConferenceHandler = require ( "../../modules/VectorConferenceHandler" ) ;
26- var CallHandler = require ( "matrix-react-sdk/lib/CallHandler" ) ;
2726
2827var HIDE_CONFERENCE_CHANS = true ;
2928
3029module . exports = {
3130 getInitialState : function ( ) {
3231 return {
3332 activityMap : null ,
34- inviteList : [ ] ,
35- roomList : [ ] ,
33+ lists : { } ,
3634 }
3735 } ,
3836
@@ -41,6 +39,7 @@ module.exports = {
4139 cli . on ( "Room" , this . onRoom ) ;
4240 cli . on ( "Room.timeline" , this . onRoomTimeline ) ;
4341 cli . on ( "Room.name" , this . onRoomName ) ;
42+ cli . on ( "Room.tags" , this . onRoomTags ) ;
4443 cli . on ( "RoomState.events" , this . onRoomStateEvents ) ;
4544 cli . on ( "RoomMember.name" , this . onRoomMemberName ) ;
4645
@@ -55,11 +54,6 @@ module.exports = {
5554
5655 onAction : function ( payload ) {
5756 switch ( payload . action ) {
58- // listen for call state changes to prod the render method, which
59- // may hide the global CallView if the call it is tracking is dead
60- case 'call_state' :
61- this . _recheckCallElement ( this . props . selectedRoom ) ;
62- break ;
6357 case 'view_tooltip' :
6458 this . tooltip = payload . tooltip ;
6559 this . _repositionTooltip ( ) ;
@@ -80,7 +74,6 @@ module.exports = {
8074
8175 componentWillReceiveProps : function ( newProps ) {
8276 this . state . activityMap [ newProps . selectedRoom ] = undefined ;
83- this . _recheckCallElement ( newProps . selectedRoom ) ;
8477 this . setState ( {
8578 activityMap : this . state . activityMap
8679 } ) ;
@@ -117,6 +110,10 @@ module.exports = {
117110 this . refreshRoomList ( ) ;
118111 } ,
119112
113+ onRoomTags : function ( room ) {
114+ this . refreshRoomList ( ) ;
115+ } ,
116+
120117 onRoomStateEvents : function ( ev , state ) {
121118 setTimeout ( this . refreshRoomList , 0 ) ;
122119 } ,
@@ -125,26 +122,31 @@ module.exports = {
125122 setTimeout ( this . refreshRoomList , 0 ) ;
126123 } ,
127124
128-
129125 refreshRoomList : function ( ) {
126+ // TODO: rather than bluntly regenerating and re-sorting everything
127+ // every time we see any kind of room change from the JS SDK
128+ // we could do incremental updates on our copy of the state
129+ // based on the room which has actually changed. This would stop
130+ // us re-rendering all the sublists every time anything changes anywhere
131+ // in the state of the client.
130132 this . setState ( this . getRoomLists ( ) ) ;
131133 } ,
132134
133135 getRoomLists : function ( ) {
134- var s = { } ;
135- var inviteList = [ ] ;
136- s . roomList = RoomListSorter . mostRecentActivityFirst (
137- MatrixClientPeg . get ( ) . getRooms ( ) . filter ( function ( room ) {
138- var me = room . getMember ( MatrixClientPeg . get ( ) . credentials . userId ) ;
139-
140- if ( me && me . membership == "invite" ) {
141- inviteList . push ( room ) ;
142- return false ;
143- }
136+ var s = { lists : { } } ;
137+
138+ MatrixClientPeg . get ( ) . getRooms ( ) . forEach ( function ( room ) {
139+ var me = room . getMember ( MatrixClientPeg . get ( ) . credentials . userId ) ;
144140
141+ if ( me && me . membership == "invite" ) {
142+ s . lists [ "invites" ] = s . lists [ "invites" ] || [ ] ;
143+ s . lists [ "invites" ] . push ( room ) ;
144+ }
145+ else {
145146 var shouldShowRoom = (
146147 me && ( me . membership == "join" )
147148 ) ;
149+
148150 // hiding conf rooms only ever toggles shouldShowRoom to false
149151 if ( shouldShowRoom && HIDE_CONFERENCE_CHANS ) {
150152 // we want to hide the 1:1 conf<->user room and not the group chat
@@ -159,23 +161,27 @@ module.exports = {
159161 }
160162 }
161163 }
162- return shouldShowRoom ;
163- } )
164- ) ;
165- s . inviteList = RoomListSorter . mostRecentActivityFirst ( inviteList ) ;
166- return s ;
167- } ,
168164
169- _recheckCallElement : function ( selectedRoomId ) {
170- // if we aren't viewing a room with an ongoing call, but there is an
171- // active call, show the call element - we need to do this to make
172- // audio/video not crap out
173- var activeCall = CallHandler . getAnyActiveCall ( ) ;
174- var callForRoom = CallHandler . getCallForRoom ( selectedRoomId ) ;
175- var showCall = ( activeCall && ! callForRoom ) ;
176- this . setState ( {
177- show_call_element : showCall
165+ if ( shouldShowRoom ) {
166+ var tagNames = Object . keys ( room . tags ) ;
167+ if ( tagNames . length ) {
168+ for ( var i = 0 ; i < tagNames . length ; i ++ ) {
169+ var tagName = tagNames [ i ] ;
170+ s . lists [ tagName ] = s . lists [ tagName ] || [ ] ;
171+ s . lists [ tagNames [ i ] ] . push ( room ) ;
172+ }
173+ }
174+ else {
175+ s . lists [ "recents" ] = s . lists [ "recents" ] || [ ] ;
176+ s . lists [ "recents" ] . push ( room ) ;
177+ }
178+ }
179+ }
178180 } ) ;
181+
182+ // we actually apply the sorting to this when receiving the prop in RoomSubLists.
183+
184+ return s ;
179185 } ,
180186
181187 _repositionTooltip : function ( e ) {
@@ -184,23 +190,4 @@ module.exports = {
184190 this . tooltip . style . top = ( scroll . parentElement . offsetTop + this . tooltip . parentElement . offsetTop - scroll . scrollTop ) + "px" ;
185191 }
186192 } ,
187-
188- makeRoomTiles : function ( list , isInvite ) {
189- var self = this ;
190- var RoomTile = sdk . getComponent ( "molecules.RoomTile" ) ;
191- return list . map ( function ( room ) {
192- var selected = room . roomId == self . props . selectedRoom ;
193- return (
194- < RoomTile
195- room = { room }
196- key = { room . roomId }
197- collapsed = { self . props . collapsed }
198- selected = { selected }
199- unread = { self . state . activityMap [ room . roomId ] === 1 }
200- highlight = { self . state . activityMap [ room . roomId ] === 2 }
201- isInvite = { isInvite }
202- />
203- ) ;
204- } ) ;
205- }
206193} ;
0 commit comments