Make the network dropdown work
This commit is contained in:
parent
43b87e1f82
commit
f3cbb9fe90
3 changed files with 74 additions and 24 deletions
|
@ -32,6 +32,13 @@ 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',
|
||||
|
||||
|
@ -40,6 +47,7 @@ module.exports = React.createClass({
|
|||
publicRooms: [],
|
||||
roomAlias: '',
|
||||
loading: true,
|
||||
filterByNetwork: null,
|
||||
}
|
||||
},
|
||||
|
||||
|
@ -143,6 +151,12 @@ module.exports = React.createClass({
|
|||
}
|
||||
},
|
||||
|
||||
onNetworkChange: function(network) {
|
||||
this.setState({
|
||||
filterByNetwork: network,
|
||||
});
|
||||
},
|
||||
|
||||
showRoomAlias: function(alias) {
|
||||
this.showRoom(null, alias);
|
||||
},
|
||||
|
@ -192,9 +206,13 @@ module.exports = React.createClass({
|
|||
|
||||
if (!this.state.publicRooms) return [];
|
||||
|
||||
var rooms = this.state.publicRooms.filter(function(a) {
|
||||
var rooms = this.state.publicRooms.filter((a) => {
|
||||
// FIXME: if incrementally typing, keep narrowing down the search set
|
||||
// incrementally rather than starting over each time.
|
||||
if (this.state.filterByNetwork) {
|
||||
if (this._networkForRoom(a) != this.state.filterByNetwork) return false;
|
||||
}
|
||||
|
||||
return (((a.name && a.name.toLowerCase().search(filter.toLowerCase()) >= 0) ||
|
||||
(a.aliases && a.aliases[0].toLowerCase().search(filter.toLowerCase()) >= 0)) &&
|
||||
a.num_joined_members > 0);
|
||||
|
@ -266,6 +284,22 @@ module.exports = React.createClass({
|
|||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* Terrible temporary function that guess what network a public room
|
||||
* entry is in, until synapse is able to tell us
|
||||
*/
|
||||
_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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return 'matrix:matrix_org';
|
||||
},
|
||||
|
||||
render: function() {
|
||||
if (this.state.loading) {
|
||||
var Loader = sdk.getComponent("elements.Spinner");
|
||||
|
@ -284,7 +318,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 />
|
||||
<NetworkDropdown onNetworkChange={this.onNetworkChange} />
|
||||
</div>
|
||||
<GeminiScrollbar className="mx_RoomDirectory_tableWrapper">
|
||||
<table ref="directory_table" className="mx_RoomDirectory_table">
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue