@@ -32,16 +32,21 @@ var sanitizeHtml = require('sanitize-html');
3232
3333linkifyMatrix ( linkify ) ;
3434
35- const NETWORK_PATTERNS = {
36- 'gitter' : / # g i t t e r _ .* / ,
37- 'irc:freenode' : / # f r e e n o d e _ .* : .* / ,
38- 'irc:mozilla' : / # m o z i l l a _ .* : .* / ,
39- 'irc:w3c' : / @ w 3 c _ .* : .* / ,
40- } ;
41-
4235module . exports = React . createClass ( {
4336 displayName : 'RoomDirectory' ,
4437
38+ propTypes : {
39+ config : React . PropTypes . object ,
40+ } ,
41+
42+ getDefaultProps : function ( ) {
43+ return {
44+ config : {
45+ networks : [ ] ,
46+ } ,
47+ }
48+ } ,
49+
4550 getInitialState : function ( ) {
4651 return {
4752 publicRooms : [ ] ,
@@ -52,6 +57,14 @@ module.exports = React.createClass({
5257 } ,
5358
5459 componentWillMount : function ( ) {
60+ // precompile Regexps
61+ this . networkPatterns = { } ;
62+ if ( this . props . config . networkPatterns ) {
63+ for ( const network of Object . keys ( this . props . config . networkPatterns ) ) {
64+ this . networkPatterns [ network ] = new RegExp ( this . props . config . networkPatterns [ network ] ) ;
65+ }
66+ }
67+
5568 // dis.dispatch({
5669 // action: 'ui_opacity',
5770 // sideOpacity: 0.3,
@@ -291,8 +304,8 @@ module.exports = React.createClass({
291304 _networkForRoom ( room ) {
292305 if ( room . aliases ) {
293306 for ( const alias of room . aliases ) {
294- for ( const network of Object . keys ( NETWORK_PATTERNS ) ) {
295- if ( NETWORK_PATTERNS [ network ] . test ( alias ) ) return network ;
307+ for ( const network of Object . keys ( this . networkPatterns ) ) {
308+ if ( this . networkPatterns [ network ] . test ( alias ) ) return network ;
296309 }
297310 }
298311 }
@@ -318,7 +331,7 @@ module.exports = React.createClass({
318331 < div className = "mx_RoomDirectory_list" >
319332 < div className = "mx_RoomDirectory_listheader" >
320333 < input ref = "roomAlias" placeholder = "Join a room (e.g. #foo:domain.com)" className = "mx_RoomDirectory_input" size = "64" onKeyUp = { this . onKeyUp } />
321- < NetworkDropdown onNetworkChange = { this . onNetworkChange } />
334+ < NetworkDropdown config = { this . props . config } onNetworkChange = { this . onNetworkChange } />
322335 </ div >
323336 < GeminiScrollbar className = "mx_RoomDirectory_tableWrapper" >
324337 < table ref = "directory_table" className = "mx_RoomDirectory_table" >
0 commit comments