@@ -29,6 +29,7 @@ var linkify = require('linkifyjs');
2929var linkifyString = require ( 'linkifyjs/string' ) ;
3030var linkifyMatrix = require ( 'matrix-react-sdk/lib/linkify-matrix' ) ;
3131var sanitizeHtml = require ( 'sanitize-html' ) ;
32+ var q = require ( 'q' ) ;
3233
3334linkifyMatrix ( linkify ) ;
3435
@@ -50,7 +51,6 @@ module.exports = React.createClass({
5051 getInitialState : function ( ) {
5152 return {
5253 publicRooms : [ ] ,
53- roomAlias : '' ,
5454 loading : true ,
5555 filterByNetwork : null ,
5656 }
@@ -64,6 +64,8 @@ module.exports = React.createClass({
6464 this . networkPatterns [ network ] = new RegExp ( this . props . config . networkPatterns [ network ] ) ;
6565 }
6666 }
67+ this . nextBatch = null ;
68+ this . filterString = null ;
6769
6870 // dis.dispatch({
6971 // action: 'ui_opacity',
@@ -73,7 +75,7 @@ module.exports = React.createClass({
7375 } ,
7476
7577 componentDidMount : function ( ) {
76- this . getPublicRooms ( ) ;
78+ this . refreshRoomList ( ) ;
7779 } ,
7880
7981 componentWillUnmount : function ( ) {
@@ -84,24 +86,34 @@ module.exports = React.createClass({
8486 // });
8587 } ,
8688
87- getPublicRooms : function ( ) {
88- var self = this ;
89- MatrixClientPeg . get ( ) . publicRooms ( function ( err , data ) {
90- if ( err ) {
91- self . setState ( { loading : false } ) ;
92- console . error ( "Failed to get publicRooms: %s" , JSON . stringify ( err ) ) ;
93- var ErrorDialog = sdk . getComponent ( "dialogs.ErrorDialog" ) ;
94- Modal . createDialog ( ErrorDialog , {
95- title : "Failed to get public room list" ,
96- description : err . message
97- } ) ;
98- }
99- else {
100- self . setState ( {
101- publicRooms : data . chunk ,
102- loading : false ,
103- } ) ;
104- }
89+ refreshRoomList : function ( ) {
90+ this . nextBatch = null ;
91+ this . setState ( {
92+ publicRooms : [ ] ,
93+ } ) ;
94+ this . getMoreRooms ( ) . done ( ) ;
95+ } ,
96+
97+ getMoreRooms : function ( ) {
98+ const opts = { limit : 20 } ;
99+ if ( this . nextBatch ) opts . since = this . nextBatch ;
100+ if ( this . filterString ) opts . filter = { generic_search_term : this . filterString } ;
101+ return MatrixClientPeg . get ( ) . publicRooms ( opts ) . then ( ( data ) => {
102+ this . nextBatch = data . next_batch ;
103+ this . setState ( ( s ) => {
104+ s . publicRooms . push ( ...data . chunk ) ;
105+ s . loading = false ;
106+ return s ;
107+ } ) ;
108+ return Boolean ( data . next_batch ) ;
109+ } , ( err ) => {
110+ this . setState ( { loading : false } ) ;
111+ console . error ( "Failed to get publicRooms: %s" , JSON . stringify ( err ) ) ;
112+ var ErrorDialog = sdk . getComponent ( "dialogs.ErrorDialog" ) ;
113+ Modal . createDialog ( ErrorDialog , {
114+ title : "Failed to get public room list" ,
115+ description : err . message
116+ } ) ;
105117 } ) ;
106118 } ,
107119
@@ -142,10 +154,10 @@ module.exports = React.createClass({
142154 return MatrixClientPeg . get ( ) . deleteAlias ( alias ) ;
143155 } ) . done ( ( ) => {
144156 modal . close ( ) ;
145- this . getPublicRooms ( ) ;
157+ this . refreshRoomList ( ) ;
146158 } , function ( err ) {
147159 modal . close ( ) ;
148- this . getPublicRooms ( ) ;
160+ this . refreshRoomList ( ) ;
149161 Modal . createDialog ( ErrorDialog , {
150162 title : "Failed to " + step ,
151163 description : err . toString ( )
@@ -170,6 +182,23 @@ module.exports = React.createClass({
170182 } ) ;
171183 } ,
172184
185+ onFillRequest : function ( backwards ) {
186+ if ( backwards || ! this . nextBatch ) return q ( false ) ;
187+
188+ return this . getMoreRooms ( ) ;
189+ } ,
190+
191+ onFilterChange : function ( ev ) {
192+ const alias = ev . target . value ;
193+
194+ if ( ev . key == "Enter" ) {
195+ this . showRoomAlias ( alias ) ;
196+ } else {
197+ this . filterString = alias || null ;
198+ this . refreshRoomList ( ) ;
199+ }
200+ } ,
201+
173202 showRoomAlias : function ( alias ) {
174203 this . showRoom ( null , alias ) ;
175204 } ,
@@ -214,23 +243,17 @@ module.exports = React.createClass({
214243 dis . dispatch ( payload ) ;
215244 } ,
216245
217- getRows : function ( filter ) {
246+ getRows : function ( ) {
218247 var BaseAvatar = sdk . getComponent ( 'avatars.BaseAvatar' ) ;
219248
220249 if ( ! this . state . publicRooms ) return [ ] ;
221250
222251 var rooms = this . state . publicRooms . filter ( ( a ) => {
223- // FIXME: if incrementally typing, keep narrowing down the search set
224- // incrementally rather than starting over each time.
225252 if ( this . state . filterByNetwork ) {
226253 if ( ! this . _isRoomInNetwork ( a , this . state . filterByNetwork ) ) return false ;
227254 }
228255
229- return ( ( ( a . name && a . name . toLowerCase ( ) . search ( filter . toLowerCase ( ) ) >= 0 ) ||
230- ( a . aliases && a . aliases [ 0 ] . toLowerCase ( ) . search ( filter . toLowerCase ( ) ) >= 0 ) ) &&
231- a . num_joined_members > 0 ) ;
232- } ) . sort ( function ( a , b ) {
233- return a . num_joined_members - b . num_joined_members ;
256+ return true ;
234257 } ) ;
235258 var rows = [ ] ;
236259 var self = this ;
@@ -259,7 +282,7 @@ module.exports = React.createClass({
259282 var topic = rooms [ i ] . topic || '' ;
260283 topic = linkifyString ( sanitizeHtml ( topic ) ) ;
261284
262- rows . unshift (
285+ rows . push (
263286 < tr key = { rooms [ i ] . room_id }
264287 onClick = { self . onRoomClicked . bind ( self , rooms [ i ] ) }
265288 // cancel onMouseDown otherwise shift-clicking highlights text
@@ -289,14 +312,6 @@ module.exports = React.createClass({
289312 return rows ;
290313 } ,
291314
292- onKeyUp : function ( ev ) {
293- this . forceUpdate ( ) ;
294- this . setState ( { roomAlias : this . refs . roomAlias . value } )
295- if ( ev . key == "Enter" ) {
296- this . showRoomAlias ( this . refs . roomAlias . value ) ;
297- }
298- } ,
299-
300315 /**
301316 * Terrible temporary function that guess what network a public room
302317 * entry is in, until synapse is able to tell us
@@ -323,21 +338,30 @@ module.exports = React.createClass({
323338
324339 const SimpleRoomHeader = sdk . getComponent ( 'rooms.SimpleRoomHeader' ) ;
325340 const NetworkDropdown = sdk . getComponent ( 'directory.NetworkDropdown' ) ;
341+ const ScrollPanel = sdk . getComponent ( "structures.ScrollPanel" ) ;
326342 return (
327343 < div className = "mx_RoomDirectory" >
328344 < SimpleRoomHeader title = "Directory" />
329345 < div className = "mx_RoomDirectory_list" >
330346 < div className = "mx_RoomDirectory_listheader" >
331- < input ref = "roomAlias" placeholder = "Join a room (e.g. #foo:domain.com)" className = "mx_RoomDirectory_input" size = "64" onKeyUp = { this . onKeyUp } />
347+ < input type = "text" placeholder = "Find a room by keyword or room ID (#foo:matrix.org)"
348+ className = "mx_RoomDirectory_input" size = "64" onChange = { this . onFilterChange }
349+ />
332350 < NetworkDropdown config = { this . props . config } onNetworkChange = { this . onNetworkChange } />
333351 </ div >
334- < GeminiScrollbar className = "mx_RoomDirectory_tableWrapper" >
352+ < ScrollPanel
353+ className = "mx_RoomDirectory_tableWrapper"
354+ onFillRequest = { this . onFillRequest }
355+ stickyBottom = { false }
356+ startAtBottom = { false }
357+ onResize = { function ( ) { } }
358+ >
335359 < table ref = "directory_table" className = "mx_RoomDirectory_table" >
336360 < tbody >
337- { this . getRows ( this . state . roomAlias ) }
361+ { this . getRows ( ) }
338362 </ tbody >
339363 </ table >
340- </ GeminiScrollbar >
364+ </ ScrollPanel >
341365 </ div >
342366 </ div >
343367 ) ;
0 commit comments