@@ -85,13 +85,17 @@ var RoomSubList = React.createClass({
8585 } ,
8686
8787 componentWillMount : function ( ) {
88- this . sortList ( this . applySearchFilter ( this . props . list , this . props . searchFilter ) , this . props . order ) ;
88+ this . setState ( {
89+ sortedList : this . applySearchFilter ( this . props . list , this . props . searchFilter ) ,
90+ } ) ;
8991 } ,
9092
9193 componentWillReceiveProps : function ( newProps ) {
9294 // order the room list appropriately before we re-render
9395 //if (debug) console.log("received new props, list = " + newProps.list);
94- this . sortList ( this . applySearchFilter ( newProps . list , newProps . searchFilter ) , newProps . order ) ;
96+ this . setState ( {
97+ sortedList : this . applySearchFilter ( newProps . list , newProps . searchFilter ) ,
98+ } ) ;
9599 } ,
96100
97101 applySearchFilter : function ( list , filter ) {
@@ -139,71 +143,6 @@ var RoomSubList = React.createClass({
139143 } ) ;
140144 } ,
141145
142- tsOfNewestEvent : function ( room ) {
143- for ( var i = room . timeline . length - 1 ; i >= 0 ; -- i ) {
144- var ev = room . timeline [ i ] ;
145- if ( ev . getTs ( ) &&
146- ( Unread . eventTriggersUnreadCount ( ev ) ||
147- ( ev . getSender ( ) === MatrixClientPeg . get ( ) . credentials . userId ) )
148- ) {
149- return ev . getTs ( ) ;
150- }
151- }
152-
153- // we might only have events that don't trigger the unread indicator,
154- // in which case use the oldest event even if normally it wouldn't count.
155- // This is better than just assuming the last event was forever ago.
156- if ( room . timeline . length && room . timeline [ 0 ] . getTs ( ) ) {
157- return room . timeline [ 0 ] . getTs ( ) ;
158- } else {
159- return Number . MAX_SAFE_INTEGER ;
160- }
161- } ,
162-
163- // TODO: factor the comparators back out into a generic comparator
164- // so that view_prev_room and view_next_room can do the right thing
165-
166- recentsComparator : function ( roomA , roomB ) {
167- return this . tsOfNewestEvent ( roomB ) - this . tsOfNewestEvent ( roomA ) ;
168- } ,
169-
170- lexicographicalComparator : function ( roomA , roomB ) {
171- return roomA . name > roomB . name ? 1 : - 1 ;
172- } ,
173-
174- // Generates the manual comparator using the given list
175- manualComparator : function ( roomA , roomB ) {
176- if ( ! roomA . tags [ this . props . tagName ] || ! roomB . tags [ this . props . tagName ] ) return 0 ;
177-
178- // Make sure the room tag has an order element, if not set it to be the bottom
179- var a = roomA . tags [ this . props . tagName ] . order ;
180- var b = roomB . tags [ this . props . tagName ] . order ;
181-
182- // Order undefined room tag orders to the bottom
183- if ( a === undefined && b !== undefined ) {
184- return 1 ;
185- } else if ( a !== undefined && b === undefined ) {
186- return - 1 ;
187- }
188-
189- return a == b ? this . lexicographicalComparator ( roomA , roomB ) : ( a > b ? 1 : - 1 ) ;
190- } ,
191-
192- sortList : function ( list , order ) {
193- if ( list === undefined ) list = this . state . sortedList ;
194- if ( order === undefined ) order = this . props . order ;
195- var comparator ;
196- list = list || [ ] ;
197- if ( order === "manual" ) comparator = this . manualComparator ;
198- if ( order === "recent" ) comparator = this . recentsComparator ;
199-
200- // Fix undefined orders here, and make sure the backend gets updated as well
201- this . _fixUndefinedOrder ( list ) ;
202-
203- //if (debug) console.log("sorting list for sublist " + this.props.label + " with length " + list.length + ", this.props.list = " + this.props.list);
204- this . setState ( { sortedList : list . sort ( comparator ) } ) ;
205- } ,
206-
207146 _shouldShowNotifBadge : function ( roomNotifState ) {
208147 const showBadgeInStates = [ RoomNotifs . ALL_MESSAGES , RoomNotifs . ALL_MESSAGES_LOUD ] ;
209148 return showBadgeInStates . indexOf ( roomNotifState ) > - 1 ;
@@ -380,47 +319,6 @@ var RoomSubList = React.createClass({
380319 this . props . onHeaderClick ( false ) ;
381320 } ,
382321
383- // Fix any undefined order elements of a room in a manual ordered list
384- // room.tag[tagname].order
385- _fixUndefinedOrder : function ( list ) {
386- if ( this . props . order === "manual" ) {
387- var order = 0.0 ;
388- var self = this ;
389-
390- // Find the highest (lowest position) order of a room in a manual ordered list
391- list . forEach ( function ( room ) {
392- if ( room . tags . hasOwnProperty ( self . props . tagName ) ) {
393- if ( order < room . tags [ self . props . tagName ] . order ) {
394- order = room . tags [ self . props . tagName ] . order ;
395- }
396- }
397- } ) ;
398-
399- // Fix any undefined order elements of a room in a manual ordered list
400- // Do this one at a time, as each time a rooms tag data is updated the RoomList
401- // gets triggered and another list is passed in. Doing it one at a time means that
402- // we always correctly calculate the highest order for the list - stops multiple
403- // rooms getting the same order. This is only really relevant for the first time this
404- // is run with historical room tag data, after that there should only be undefined
405- // in the list at a time anyway.
406- for ( let i = 0 ; i < list . length ; i ++ ) {
407- if ( list [ i ] . tags [ self . props . tagName ] && list [ i ] . tags [ self . props . tagName ] . order === undefined ) {
408- MatrixClientPeg . get ( ) . setRoomTag ( list [ i ] . roomId , self . props . tagName , { order : ( order + 1.0 ) / 2.0 } ) . finally ( function ( ) {
409- // Do any final stuff here
410- } ) . catch ( function ( err ) {
411- var ErrorDialog = sdk . getComponent ( "dialogs.ErrorDialog" ) ;
412- console . error ( "Failed to add tag " + self . props . tagName + " to room" + err ) ;
413- Modal . createTrackedDialog ( 'Failed to add tag to room' , '' , ErrorDialog , {
414- title : _t ( 'Failed to add tag %(tagName)s to room' , { tagName : self . props . tagName } ) ,
415- description : ( ( err && err . message ) ? err . message : _t ( 'Operation failed' ) ) ,
416- } ) ;
417- } ) ;
418- break ;
419- } ;
420- } ;
421- }
422- } ,
423-
424322 render : function ( ) {
425323 var connectDropTarget = this . props . connectDropTarget ;
426324 var TruncatedList = sdk . getComponent ( 'elements.TruncatedList' ) ;
0 commit comments