@@ -23,16 +23,23 @@ 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 = {
30+ getInitialState : function ( ) {
31+ return {
32+ activityMap : null ,
33+ lists : { } ,
34+ }
35+ } ,
36+
3137 componentWillMount : function ( ) {
3238 var cli = MatrixClientPeg . get ( ) ;
3339 cli . on ( "Room" , this . onRoom ) ;
3440 cli . on ( "Room.timeline" , this . onRoomTimeline ) ;
3541 cli . on ( "Room.name" , this . onRoomName ) ;
42+ cli . on ( "Room.tags" , this . onRoomTags ) ;
3643 cli . on ( "RoomState.events" , this . onRoomStateEvents ) ;
3744 cli . on ( "RoomMember.name" , this . onRoomMemberName ) ;
3845
@@ -47,11 +54,6 @@ module.exports = {
4754
4855 onAction : function ( payload ) {
4956 switch ( payload . action ) {
50- // listen for call state changes to prod the render method, which
51- // may hide the global CallView if the call it is tracking is dead
52- case 'call_state' :
53- this . _recheckCallElement ( this . props . selectedRoom ) ;
54- break ;
5557 case 'view_tooltip' :
5658 this . tooltip = payload . tooltip ;
5759 this . _repositionTooltip ( ) ;
@@ -72,7 +74,6 @@ module.exports = {
7274
7375 componentWillReceiveProps : function ( newProps ) {
7476 this . state . activityMap [ newProps . selectedRoom ] = undefined ;
75- this . _recheckCallElement ( newProps . selectedRoom ) ;
7677 this . setState ( {
7778 activityMap : this . state . activityMap
7879 } ) ;
@@ -109,6 +110,10 @@ module.exports = {
109110 this . refreshRoomList ( ) ;
110111 } ,
111112
113+ onRoomTags : function ( event , room ) {
114+ this . refreshRoomList ( ) ;
115+ } ,
116+
112117 onRoomStateEvents : function ( ev , state ) {
113118 setTimeout ( this . refreshRoomList , 0 ) ;
114119 } ,
@@ -117,26 +122,36 @@ module.exports = {
117122 setTimeout ( this . refreshRoomList , 0 ) ;
118123 } ,
119124
120-
121125 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.
122132 this . setState ( this . getRoomLists ( ) ) ;
123133 } ,
124134
125135 getRoomLists : function ( ) {
126- var s = { } ;
127- var inviteList = [ ] ;
128- s . roomList = RoomListSorter . mostRecentActivityFirst (
129- MatrixClientPeg . get ( ) . getRooms ( ) . filter ( function ( room ) {
130- var me = room . getMember ( MatrixClientPeg . get ( ) . credentials . userId ) ;
131-
132- if ( me && me . membership == "invite" ) {
133- inviteList . push ( room ) ;
134- return false ;
135- }
136+ var s = { lists : { } } ;
136137
138+ s . lists [ "m.invite" ] = [ ] ;
139+ s . lists [ "m.favourite" ] = [ ] ;
140+ s . lists [ "m.recent" ] = [ ] ;
141+ s . lists [ "m.lowpriority" ] = [ ] ;
142+ s . lists [ "m.archived" ] = [ ] ;
143+
144+ MatrixClientPeg . get ( ) . getRooms ( ) . forEach ( function ( room ) {
145+ var me = room . getMember ( MatrixClientPeg . get ( ) . credentials . userId ) ;
146+
147+ if ( me && me . membership == "invite" ) {
148+ s . lists [ "m.invite" ] . push ( room ) ;
149+ }
150+ else {
137151 var shouldShowRoom = (
138152 me && ( me . membership == "join" )
139153 ) ;
154+
140155 // hiding conf rooms only ever toggles shouldShowRoom to false
141156 if ( shouldShowRoom && HIDE_CONFERENCE_CHANS ) {
142157 // we want to hide the 1:1 conf<->user room and not the group chat
@@ -151,23 +166,28 @@ module.exports = {
151166 }
152167 }
153168 }
154- return shouldShowRoom ;
155- } )
156- ) ;
157- s . inviteList = RoomListSorter . mostRecentActivityFirst ( inviteList ) ;
158- return s ;
159- } ,
160169
161- _recheckCallElement : function ( selectedRoomId ) {
162- // if we aren't viewing a room with an ongoing call, but there is an
163- // active call, show the call element - we need to do this to make
164- // audio/video not crap out
165- var activeCall = CallHandler . getAnyActiveCall ( ) ;
166- var callForRoom = CallHandler . getCallForRoom ( selectedRoomId ) ;
167- var showCall = ( activeCall && ! callForRoom ) ;
168- this . setState ( {
169- show_call_element : showCall
170+ if ( shouldShowRoom ) {
171+ var tagNames = Object . keys ( room . tags ) ;
172+ if ( tagNames . length ) {
173+ for ( var i = 0 ; i < tagNames . length ; i ++ ) {
174+ var tagName = tagNames [ i ] ;
175+ s . lists [ tagName ] = s . lists [ tagName ] || [ ] ;
176+ s . lists [ tagNames [ i ] ] . push ( room ) ;
177+ }
178+ }
179+ else {
180+ s . lists [ "m.recent" ] . push ( room ) ;
181+ }
182+ }
183+ }
170184 } ) ;
185+
186+ //console.log("calculated new roomLists; m.recent = " + s.lists["m.recent"]);
187+
188+ // we actually apply the sorting to this when receiving the prop in RoomSubLists.
189+
190+ return s ;
171191 } ,
172192
173193 _repositionTooltip : function ( e ) {
@@ -176,23 +196,4 @@ module.exports = {
176196 this . tooltip . style . top = ( scroll . parentElement . offsetTop + this . tooltip . parentElement . offsetTop - scroll . scrollTop ) + "px" ;
177197 }
178198 } ,
179-
180- makeRoomTiles : function ( list , isInvite ) {
181- var self = this ;
182- var RoomTile = sdk . getComponent ( "molecules.RoomTile" ) ;
183- return list . map ( function ( room ) {
184- var selected = room . roomId == self . props . selectedRoom ;
185- return (
186- < RoomTile
187- room = { room }
188- key = { room . roomId }
189- collapsed = { self . props . collapsed }
190- selected = { selected }
191- unread = { self . state . activityMap [ room . roomId ] === 1 }
192- highlight = { self . state . activityMap [ room . roomId ] === 2 }
193- isInvite = { isInvite }
194- />
195- ) ;
196- } ) ;
197- }
198199} ;
0 commit comments