From c1e83da35d9d314f78db756beab67e18ae95b446 Mon Sep 17 00:00:00 2001 From: David Baker Date: Thu, 15 Sep 2016 17:20:13 +0100 Subject: [PATCH] Put network list config into config file --- src/components/structures/RoomDirectory.js | 33 ++++++++++++----- .../views/directory/NetworkDropdown.js | 37 +++++-------------- 2 files changed, 33 insertions(+), 37 deletions(-) diff --git a/src/components/structures/RoomDirectory.js b/src/components/structures/RoomDirectory.js index 35194883a8..ae05851122 100644 --- a/src/components/structures/RoomDirectory.js +++ b/src/components/structures/RoomDirectory.js @@ -32,16 +32,21 @@ var sanitizeHtml = require('sanitize-html'); linkifyMatrix(linkify); -const NETWORK_PATTERNS = { - 'gitter': /#gitter_.*/, - 'irc:freenode': /#freenode_.*:.*/, - 'irc:mozilla': /#mozilla_.*:.*/, - 'irc:w3c': /@w3c_.*:.*/, -}; - module.exports = React.createClass({ displayName: 'RoomDirectory', + propTypes: { + config: React.PropTypes.object, + }, + + getDefaultProps: function() { + return { + config: { + networks: [], + }, + } + }, + getInitialState: function() { return { publicRooms: [], @@ -52,6 +57,14 @@ module.exports = React.createClass({ }, componentWillMount: function() { + // precompile Regexps + this.networkPatterns = {}; + if (this.props.config.networkPatterns) { + for (const network of Object.keys(this.props.config.networkPatterns)) { + this.networkPatterns[network] = new RegExp(this.props.config.networkPatterns[network]); + } + } + // dis.dispatch({ // action: 'ui_opacity', // sideOpacity: 0.3, @@ -291,8 +304,8 @@ module.exports = React.createClass({ _networkForRoom(room) { if (room.aliases) { for (const alias of room.aliases) { - for (const network of Object.keys(NETWORK_PATTERNS)) { - if (NETWORK_PATTERNS[network].test(alias)) return network; + for (const network of Object.keys(this.networkPatterns)) { + if (this.networkPatterns[network].test(alias)) return network; } } } @@ -318,7 +331,7 @@ module.exports = React.createClass({
- +
diff --git a/src/components/views/directory/NetworkDropdown.js b/src/components/views/directory/NetworkDropdown.js index 1ffa9c9421..e1de4ffea1 100644 --- a/src/components/views/directory/NetworkDropdown.js +++ b/src/components/views/directory/NetworkDropdown.js @@ -33,30 +33,6 @@ export default class NetworkDropdown extends React.Component { expanded: false, selectedNetwork: null, }; - - this.networks = [ - 'matrix:matrix_org', - 'gitter', - 'irc:freenode', - 'irc:mozilla', - 'irc:w3c', - ]; - - this.networkNames = { - 'matrix:matrix_org': 'matrix.org', - 'irc:freenode': 'Freenode', - 'irc:mozilla': 'Mozilla', - 'irc:w3c': 'W3C', - 'gitter': 'Gitter', - }; - - this.networkIcons = { - 'matrix:matrix_org': '//matrix.org/favicon.ico', - 'irc:freenode': '//matrix.org/_matrix/media/v1/download/matrix.org/DHLHpDDgWNNejFmrewvwEAHX', - 'irc:mozilla': '//matrix.org/_matrix/media/v1/download/matrix.org/DHLHpDDgWNNejFmrewvwEAHX', - 'irc:w3c': '//matrix.org/_matrix/media/v1/download/matrix.org/DHLHpDDgWNNejFmrewvwEAHX', - 'gitter': '//gitter.im/favicon.ico', - }; } componentWillMount() { @@ -124,8 +100,8 @@ export default class NetworkDropdown extends React.Component { name = 'All networks'; span_class = 'mx_NetworkDropdown_menu_all'; } else { - name = this.networkNames[network]; - icon = ; + name = this.props.config.networkNames[network]; + icon = ; span_class = 'mx_NetworkDropdown_menu_network'; } @@ -143,7 +119,7 @@ export default class NetworkDropdown extends React.Component { let menu; if (this.state.expanded) { const menu_options = [this._optionForNetwork(null)]; - for (const network of this.networks) { + for (const network of this.props.config.networks) { menu_options.push(this._optionForNetwork(network)); } menu =
@@ -163,5 +139,12 @@ export default class NetworkDropdown extends React.Component { NetworkDropdown.propTypes = { onNetworkChange: React.PropTypes.func.isRequired, + config: React.PropTypes.object, +}; + +NetworkDropdown.defaultProps = { + config: { + networks: [], + } };