mirror of
https://github.com/vector-im/element-web.git
synced 2024-11-15 20:54:59 +08:00
Put network list config into config file
This commit is contained in:
parent
f3cbb9fe90
commit
c1e83da35d
@ -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({
|
||||
<div className="mx_RoomDirectory_list">
|
||||
<div className="mx_RoomDirectory_listheader">
|
||||
<input ref="roomAlias" placeholder="Join a room (e.g. #foo:domain.com)" className="mx_RoomDirectory_input" size="64" onKeyUp={ this.onKeyUp }/>
|
||||
<NetworkDropdown onNetworkChange={this.onNetworkChange} />
|
||||
<NetworkDropdown config={this.props.config} onNetworkChange={this.onNetworkChange} />
|
||||
</div>
|
||||
<GeminiScrollbar className="mx_RoomDirectory_tableWrapper">
|
||||
<table ref="directory_table" className="mx_RoomDirectory_table">
|
||||
|
@ -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 = <img src={this.networkIcons[network]} />;
|
||||
name = this.props.config.networkNames[network];
|
||||
icon = <img src={this.props.config.networkIcons[network]} />;
|
||||
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 = <div className="mx_NetworkDropdown_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: [],
|
||||
}
|
||||
};
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user