2015-11-30 21:11:04 +03:00
|
|
|
/*
|
2016-01-07 07:06:39 +03:00
|
|
|
Copyright 2015, 2016 OpenMarket Ltd
|
2019-01-25 00:07:49 +03:00
|
|
|
Copyright 2019 New Vector Ltd
|
2015-11-30 21:11:04 +03:00
|
|
|
|
|
|
|
Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
you may not use this file except in compliance with the License.
|
|
|
|
You may obtain a copy of the License at
|
|
|
|
|
|
|
|
http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
|
|
|
|
Unless required by applicable law or agreed to in writing, software
|
|
|
|
distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
See the License for the specific language governing permissions and
|
|
|
|
limitations under the License.
|
|
|
|
*/
|
|
|
|
|
2019-01-29 06:44:41 +03:00
|
|
|
import React from 'react';
|
2017-12-26 04:03:18 +03:00
|
|
|
import PropTypes from 'prop-types';
|
2019-01-29 06:44:41 +03:00
|
|
|
import Modal from '../../../Modal';
|
|
|
|
import sdk from '../../../index';
|
2017-05-30 17:09:57 +03:00
|
|
|
import { _t } from '../../../languageHandler';
|
2015-11-30 21:11:04 +03:00
|
|
|
|
2019-01-29 06:44:41 +03:00
|
|
|
/*
|
2015-11-30 21:11:04 +03:00
|
|
|
* A pure UI component which displays the HS and IS to use.
|
|
|
|
*/
|
|
|
|
|
2019-01-29 06:44:41 +03:00
|
|
|
export default class ServerConfig extends React.PureComponent {
|
|
|
|
static propTypes = {
|
2017-12-26 04:03:18 +03:00
|
|
|
onServerConfigChange: PropTypes.func,
|
2016-03-15 16:48:46 +03:00
|
|
|
|
|
|
|
// default URLs are defined in config.json (or the hardcoded defaults)
|
|
|
|
// they are used if the user has not overridden them with a custom URL.
|
|
|
|
// In other words, if the custom URL is blank, the default is used.
|
2017-12-26 04:03:18 +03:00
|
|
|
defaultHsUrl: PropTypes.string, // e.g. https://matrix.org
|
|
|
|
defaultIsUrl: PropTypes.string, // e.g. https://vector.im
|
2016-03-15 16:48:46 +03:00
|
|
|
|
|
|
|
// custom URLs are explicitly provided by the user and override the
|
|
|
|
// default URLs. The user enters them via the component's input fields,
|
|
|
|
// which is reflected on these properties whenever on..UrlChanged fires.
|
|
|
|
// They are persisted in localStorage by MatrixClientPeg, and so can
|
|
|
|
// override the default URLs when the component initially loads.
|
2017-12-26 04:03:18 +03:00
|
|
|
customHsUrl: PropTypes.string,
|
|
|
|
customIsUrl: PropTypes.string,
|
2016-03-15 16:48:46 +03:00
|
|
|
|
2017-12-26 04:03:18 +03:00
|
|
|
delayTimeMs: PropTypes.number, // time to wait before invoking onChanged
|
2019-01-29 06:44:41 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
static defaultProps = {
|
|
|
|
onServerConfigChange: function() {},
|
|
|
|
customHsUrl: "",
|
|
|
|
customIsUrl: "",
|
|
|
|
delayTimeMs: 0,
|
|
|
|
}
|
|
|
|
|
|
|
|
constructor(props) {
|
|
|
|
super(props);
|
2015-11-30 21:11:04 +03:00
|
|
|
|
2019-01-29 06:44:41 +03:00
|
|
|
this.state = {
|
|
|
|
hsUrl: props.customHsUrl,
|
|
|
|
isUrl: props.customIsUrl,
|
2017-01-20 17:22:27 +03:00
|
|
|
};
|
2019-01-29 06:44:41 +03:00
|
|
|
}
|
2015-11-30 21:11:04 +03:00
|
|
|
|
2019-01-29 06:44:41 +03:00
|
|
|
componentWillReceiveProps(newProps) {
|
2019-01-26 09:48:33 +03:00
|
|
|
if (newProps.customHsUrl === this.state.hsUrl &&
|
|
|
|
newProps.customIsUrl === this.state.isUrl) return;
|
2018-10-19 01:42:54 +03:00
|
|
|
|
|
|
|
this.setState({
|
2019-01-26 09:48:33 +03:00
|
|
|
hsUrl: newProps.customHsUrl,
|
|
|
|
isUrl: newProps.customIsUrl,
|
2018-10-19 01:42:54 +03:00
|
|
|
});
|
|
|
|
this.props.onServerConfigChange({
|
|
|
|
hsUrl: newProps.customHsUrl,
|
|
|
|
isUrl: newProps.customIsUrl,
|
|
|
|
});
|
2019-01-29 06:44:41 +03:00
|
|
|
}
|
2018-10-19 01:42:54 +03:00
|
|
|
|
2019-01-30 08:47:35 +03:00
|
|
|
onHomeserverBlur = (ev) => {
|
|
|
|
this._hsTimeoutId = this._waitThenInvoke(this._hsTimeoutId, () => {
|
|
|
|
this.props.onServerConfigChange({
|
|
|
|
hsUrl: this.state.hsUrl,
|
|
|
|
isUrl: this.state.isUrl,
|
2015-11-30 21:11:04 +03:00
|
|
|
});
|
|
|
|
});
|
2019-01-29 06:44:41 +03:00
|
|
|
}
|
2015-11-30 21:11:04 +03:00
|
|
|
|
2019-01-30 08:47:35 +03:00
|
|
|
onHomeserverChange = (ev) => {
|
|
|
|
const hsUrl = ev.target.value;
|
|
|
|
this.setState({ hsUrl });
|
|
|
|
}
|
|
|
|
|
|
|
|
onIdentityServerBlur = (ev) => {
|
|
|
|
this._isTimeoutId = this._waitThenInvoke(this._isTimeoutId, () => {
|
|
|
|
this.props.onServerConfigChange({
|
|
|
|
hsUrl: this.state.hsUrl,
|
|
|
|
isUrl: this.state.isUrl,
|
2015-11-30 21:11:04 +03:00
|
|
|
});
|
|
|
|
});
|
2019-01-29 06:44:41 +03:00
|
|
|
}
|
2015-11-30 21:11:04 +03:00
|
|
|
|
2019-01-30 08:47:35 +03:00
|
|
|
onIdentityServerChange = (ev) => {
|
|
|
|
const isUrl = ev.target.value;
|
|
|
|
this.setState({ isUrl });
|
|
|
|
}
|
|
|
|
|
2019-01-29 06:44:41 +03:00
|
|
|
_waitThenInvoke(existingTimeoutId, fn) {
|
2015-11-30 21:11:04 +03:00
|
|
|
if (existingTimeoutId) {
|
|
|
|
clearTimeout(existingTimeoutId);
|
|
|
|
}
|
|
|
|
return setTimeout(fn.bind(this), this.props.delayTimeMs);
|
2019-01-29 06:44:41 +03:00
|
|
|
}
|
2015-11-30 21:11:04 +03:00
|
|
|
|
2019-01-29 06:44:41 +03:00
|
|
|
showHelpPopup = () => {
|
2019-01-22 01:11:10 +03:00
|
|
|
const CustomServerDialog = sdk.getComponent('auth.CustomServerDialog');
|
2017-07-27 19:19:18 +03:00
|
|
|
Modal.createTrackedDialog('Custom Server Dialog', '', CustomServerDialog);
|
2019-01-29 06:44:41 +03:00
|
|
|
}
|
2015-11-30 21:11:04 +03:00
|
|
|
|
2019-01-29 06:44:41 +03:00
|
|
|
render() {
|
2019-01-26 09:48:33 +03:00
|
|
|
const Field = sdk.getComponent('elements.Field');
|
2015-11-30 21:11:04 +03:00
|
|
|
|
|
|
|
return (
|
2019-01-26 09:48:33 +03:00
|
|
|
<div className="mx_ServerConfig">
|
|
|
|
<h3>{_t("Other servers")}</h3>
|
|
|
|
{_t("Enter custom server URLs <a>What does this mean?</a>", {}, {
|
|
|
|
a: sub => <a className="mx_ServerConfig_help" href="#" onClick={this.showHelpPopup}>
|
|
|
|
{ sub }
|
|
|
|
</a>,
|
|
|
|
})}
|
|
|
|
<div className="mx_ServerConfig_fields">
|
|
|
|
<Field id="mx_ServerConfig_hsUrl"
|
|
|
|
label={_t("Homeserver URL")}
|
2016-03-06 22:33:36 +03:00
|
|
|
placeholder={this.props.defaultHsUrl}
|
2019-01-26 09:48:33 +03:00
|
|
|
value={this.state.hsUrl}
|
2019-01-30 08:47:35 +03:00
|
|
|
onBlur={this.onHomeserverBlur}
|
|
|
|
onChange={this.onHomeserverChange}
|
2019-01-26 09:48:33 +03:00
|
|
|
/>
|
|
|
|
<Field id="mx_ServerConfig_isUrl"
|
|
|
|
label={_t("Identity Server URL")}
|
2016-03-06 22:33:36 +03:00
|
|
|
placeholder={this.props.defaultIsUrl}
|
2019-01-26 09:48:33 +03:00
|
|
|
value={this.state.isUrl}
|
2019-01-30 08:47:35 +03:00
|
|
|
onBlur={this.onIdentityServerBlur}
|
|
|
|
onChange={this.onIdentityServerChange}
|
2019-01-26 09:48:33 +03:00
|
|
|
/>
|
2015-11-30 21:11:04 +03:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
);
|
2019-01-29 06:44:41 +03:00
|
|
|
}
|
|
|
|
}
|