Skip to content

Commit 85ea45a

Browse files
committed
Room dir: New filtering & 3rd party networks
Changes filtering on 3rd party networks to divide into portal / non portal rooms and not show portal rooms by default. Adds a special '_matrix' network for all rooms that aren't portal rooms. Also adds ability to query 3rd party directory servers.
1 parent 7b258bc commit 85ea45a

4 files changed

Lines changed: 129 additions & 36 deletions

File tree

‎src/components/structures/RoomDirectory.js‎

Lines changed: 31 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ module.exports = React.createClass({
5353
publicRooms: [],
5454
loading: true,
5555
filterByNetwork: null,
56+
roomServer: null,
5657
}
5758
},
5859

@@ -76,10 +77,6 @@ module.exports = React.createClass({
7677
// });
7778
},
7879

79-
componentDidMount: function() {
80-
this.refreshRoomList();
81-
},
82-
8380
componentWillUnmount: function() {
8481
// dis.dispatch({
8582
// action: 'ui_opacity',
@@ -102,6 +99,9 @@ module.exports = React.createClass({
10299

103100
const my_filter_string = this.filterString;
104101
const opts = {limit: 20};
102+
if (this.state.roomServer != MatrixClientPeg.getHomeServerName()) {
103+
opts.server = this.state.roomServer;
104+
}
105105
if (this.nextBatch) opts.since = this.nextBatch;
106106
if (this.filterString) opts.filter = { generic_search_term: my_filter_string } ;
107107
return MatrixClientPeg.get().publicRooms(opts).then((data) => {
@@ -194,18 +194,11 @@ module.exports = React.createClass({
194194
}
195195
},
196196

197-
onNetworkChange: function(network) {
197+
onOptionChange: function(server, network) {
198198
this.setState({
199+
roomServer: server,
199200
filterByNetwork: network,
200-
}, () => {
201-
// we just filtered out a bunch of rooms, so check to see if
202-
// we need to fill up the scrollpanel again
203-
// NB. Because we filter the results, the HS can keep giving
204-
// us more rooms and we'll keep requesting more if none match
205-
// the filter, which is pretty terrible. We need a way
206-
// to filter by network on the server.
207-
if (this.scrollPanel) this.scrollPanel.checkFillState();
208-
});
201+
}, this.refreshRoomList);
209202
},
210203

211204
onFillRequest: function(backwards) {
@@ -295,7 +288,7 @@ module.exports = React.createClass({
295288

296289
var rooms = this.state.publicRooms.filter((a) => {
297290
if (this.state.filterByNetwork) {
298-
if (!this._isRoomInNetwork(a, this.state.filterByNetwork)) return false;
291+
if (!this._isRoomInNetwork(a, this.state.roomServer, this.state.filterByNetwork)) return false;
299292
}
300293

301294
return true;
@@ -365,14 +358,30 @@ module.exports = React.createClass({
365358
* Terrible temporary function that guess what network a public room
366359
* entry is in, until synapse is able to tell us
367360
*/
368-
_isRoomInNetwork(room, network) {
369-
if (room.aliases && this.networkPatterns[network]) {
370-
for (const alias of room.aliases) {
371-
if (this.networkPatterns[network].test(alias)) return true;
361+
_isRoomInNetwork(room, server, network) {
362+
// We carve rooms into two categories here. 'portal' rooms are
363+
// rooms created by a user joining a bridge 'portal' alias to
364+
// participate in that room or a foreign network. A room is a
365+
// portal room if it has exactly one alias and that alias matches
366+
// a pattern defined in the config. It's network is the key
367+
// of the pattern that it matches.
368+
// All other rooms are considered 'native matrix' rooms, and
369+
// go into the special '_matrix' network.
370+
371+
let roomNetwork = '_matrix';
372+
if (room.aliases && room.aliases.length == 1) {
373+
if (this.props.config.serverConfig && this.props.config.serverConfig[server] && this.props.config.serverConfig[server].networks) {
374+
for (const n of this.props.config.serverConfig[server].networks) {
375+
const pat = this.networkPatterns[n];
376+
if (pat && pat) {
377+
if (this.networkPatterns[n].test(room.aliases[0])) {
378+
roomNetwork = n;
379+
}
380+
}
381+
}
372382
}
373383
}
374-
375-
return false;
384+
return roomNetwork == network;
376385
},
377386

378387
render: function() {
@@ -411,7 +420,7 @@ module.exports = React.createClass({
411420
className="mx_RoomDirectory_searchbox"
412421
onChange={this.onFilterChange} onClear={this.onFilterClear} onJoinClick={this.onJoinClick}
413422
/>
414-
<NetworkDropdown config={this.props.config} onNetworkChange={this.onNetworkChange} />
423+
<NetworkDropdown config={this.props.config} onOptionChange={this.onOptionChange} />
415424
</div>
416425
{content}
417426
</div>

‎src/components/views/directory/NetworkDropdown.js‎

Lines changed: 80 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ limitations under the License.
1515
*/
1616

1717
import React from 'react';
18+
import MatrixClientPeg from 'matrix-react-sdk/lib/MatrixClientPeg';
1819

1920
export default class NetworkDropdown extends React.Component {
2021
constructor() {
@@ -26,19 +27,27 @@ export default class NetworkDropdown extends React.Component {
2627
this.onInputClick = this.onInputClick.bind(this);
2728
this.onRootClick = this.onRootClick.bind(this);
2829
this.onDocumentClick = this.onDocumentClick.bind(this);
29-
this.onNetworkClick = this.onNetworkClick.bind(this);
30+
this.onMenuOptionClick = this.onMenuOptionClick.bind(this);
31+
this.onInputKeyUp = this.onInputKeyUp.bind(this);
3032
this.collectRoot = this.collectRoot.bind(this);
33+
this.collectInputTextBox = this.collectInputTextBox.bind(this);
34+
35+
this.inputTextBox = null;
3136

3237
this.state = {
3338
expanded: false,
34-
selectedNetwork: null,
39+
selectedServer: MatrixClientPeg.getHomeServerName(),
40+
selectedNetwork: '_matrix',
3541
};
3642
}
3743

3844
componentWillMount() {
3945
// Listen for all clicks on the document so we can close the
4046
// menu when the user clicks somewhere else
4147
document.addEventListener('click', this.onDocumentClick, false);
48+
49+
// fire this now so the defaults can be set up
50+
this.props.onOptionChange(this.state.selectedServer, this.state.selectedNetwork);
4251
}
4352

4453
componentWillUnmount() {
@@ -72,12 +81,24 @@ export default class NetworkDropdown extends React.Component {
7281
ev.preventDefault();
7382
}
7483

75-
onNetworkClick(network, ev) {
84+
onMenuOptionClick(server, network, ev) {
7685
this.setState({
7786
expanded: false,
87+
selectedServer: server,
7888
selectedNetwork: network,
7989
});
80-
this.props.onNetworkChange(network);
90+
this.props.onOptionChange(server, network);
91+
}
92+
93+
onInputKeyUp(e) {
94+
if (e.key == 'Enter') {
95+
this.setState({
96+
expanded: false,
97+
selectedServer: e.target.value,
98+
selectedNetwork: null,
99+
});
100+
this.props.onOptionChange(e.target.value, null);
101+
}
81102
}
82103

83104
collectRoot(e) {
@@ -90,41 +111,86 @@ export default class NetworkDropdown extends React.Component {
90111
this.dropdownRootElement = e;
91112
}
92113

93-
_optionForNetwork(network, wire_onclick) {
114+
collectInputTextBox(e) {
115+
this.inputTextBox = e;
116+
}
117+
118+
_getMenuOptions() {
119+
const options = [];
120+
121+
let servers = [];
122+
if (this.props.config.servers) {
123+
servers = servers.concat(this.props.config.servers);
124+
}
125+
126+
if (servers.indexOf(MatrixClientPeg.getHomeServerName()) == -1) {
127+
servers.unshift(MatrixClientPeg.getHomeServerName());
128+
}
129+
130+
for (const server of servers) {
131+
options.push(this._makeMenuOption(server, null));
132+
if (this.props.config.serverConfig && this.props.config.serverConfig[server] && this.props.config.serverConfig[server].networks) {
133+
for (const network of this.props.config.serverConfig[server].networks) {
134+
options.push(this._makeMenuOption(server, network));
135+
}
136+
}
137+
}
138+
139+
return options;
140+
}
141+
142+
_makeMenuOption(server, network, wire_onclick) {
94143
if (wire_onclick === undefined) wire_onclick = true;
95144
let icon;
96145
let name;
97146
let span_class;
98147

99148
if (network === null) {
100-
name = 'All networks';
149+
name = server;
101150
span_class = 'mx_NetworkDropdown_menu_all';
151+
} else if (network == '_matrix') {
152+
name = 'Matrix';
153+
icon = <img src="/img/network-matrix.svg" width="16" height="16" />;
154+
span_class = 'mx_NetworkDropdown_menu_network';
102155
} else {
103156
name = this.props.config.networkNames[network];
104157
icon = <img src={this.props.config.networkIcons[network]} />;
105158
span_class = 'mx_NetworkDropdown_menu_network';
106159
}
107160

108-
const click_handler = wire_onclick ? this.onNetworkClick.bind(this, network) : null;
161+
const click_handler = wire_onclick ? this.onMenuOptionClick.bind(this, server, network) : null;
109162

110-
return <div key={network} className="mx_NetworkDropdown_networkoption" onClick={click_handler}>
163+
let key = server;
164+
if (network !== null) {
165+
key += '_' + network;
166+
}
167+
168+
return <div key={key} className="mx_NetworkDropdown_networkoption" onClick={click_handler}>
111169
{icon}
112170
<span className={span_class}>{name}</span>
113171
</div>;
114172
}
115173

174+
componentDidUpdate() {
175+
if (this.state.expanded && this.inputTextBox) {
176+
this.inputTextBox.focus();
177+
}
178+
}
179+
116180
render() {
117-
const current_value = this._optionForNetwork(this.state.selectedNetwork, false);
181+
let current_value = this._makeMenuOption(
182+
this.state.selectedServer, this.state.selectedNetwork, false
183+
);
118184

119185
let menu;
120186
if (this.state.expanded) {
121-
const menu_options = [this._optionForNetwork(null)];
122-
for (const network of this.props.config.networks) {
123-
menu_options.push(this._optionForNetwork(network));
124-
}
187+
const menu_options = this._getMenuOptions();
125188
menu = <div className="mx_NetworkDropdown_menu">
126189
{menu_options}
127190
</div>;
191+
current_value = <input type="text" className="mx_NetworkDropdown_networkoption"
192+
ref={this.collectInputTextBox} onKeyUp={this.onInputKeyUp}
193+
/>
128194
}
129195

130196
return <div className="mx_NetworkDropdown" ref={this.collectRoot}>
@@ -138,7 +204,7 @@ export default class NetworkDropdown extends React.Component {
138204
}
139205

140206
NetworkDropdown.propTypes = {
141-
onNetworkChange: React.PropTypes.func.isRequired,
207+
onOptionChange: React.PropTypes.func.isRequired,
142208
config: React.PropTypes.object,
143209
};
144210

‎src/skins/vector/css/vector-web/views/directory/NetworkDropdown.css‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,10 @@ limitations under the License.
5252
vertical-align: middle;
5353
}
5454

55+
input.mx_NetworkDropdown_networkoption, input.mx_NetworkDropdown_networkoption:focus {
56+
border: 0;
57+
}
58+
5559
.mx_NetworkDropdown_menu {
5660
position: absolute;
5761
left: -1px;
Lines changed: 14 additions & 0 deletions
Loading

0 commit comments

Comments
 (0)