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.
|
|
|
|
*/
|
|
|
|
|
|
|
|
'use strict';
|
|
|
|
|
2017-10-11 19:56:17 +03:00
|
|
|
const React = require('react');
|
2017-12-26 04:03:18 +03:00
|
|
|
import PropTypes from 'prop-types';
|
2017-10-11 19:56:17 +03:00
|
|
|
const Modal = require('../../../Modal');
|
|
|
|
const sdk = require('../../../index');
|
2017-05-30 17:09:57 +03:00
|
|
|
import { _t } from '../../../languageHandler';
|
2015-11-30 21:11:04 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* A pure UI component which displays the HS and IS to use.
|
|
|
|
*/
|
|
|
|
module.exports = React.createClass({
|
|
|
|
displayName: 'ServerConfig',
|
|
|
|
|
|
|
|
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
|
2015-11-30 21:11:04 +03:00
|
|
|
},
|
|
|
|
|
|
|
|
getDefaultProps: function() {
|
|
|
|
return {
|
2017-04-21 13:37:08 +03:00
|
|
|
onServerConfigChange: function() {},
|
2016-03-15 18:20:51 +03:00
|
|
|
customHsUrl: "",
|
|
|
|
customIsUrl: "",
|
2017-10-11 19:56:17 +03:00
|
|
|
delayTimeMs: 0,
|
2015-11-30 21:11:04 +03:00
|
|
|
};
|
|
|
|
},
|
|
|
|
|
|
|
|
getInitialState: function() {
|
|
|
|
return {
|
2019-01-26 09:48:33 +03:00
|
|
|
hsUrl: this.props.customHsUrl,
|
|
|
|
isUrl: this.props.customIsUrl,
|
2017-01-20 17:22:27 +03:00
|
|
|
};
|
2015-11-30 21:11:04 +03:00
|
|
|
},
|
|
|
|
|
2018-10-19 01:42:54 +03:00
|
|
|
componentWillReceiveProps: function(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,
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
2015-11-30 21:11:04 +03:00
|
|
|
onHomeserverChanged: function(ev) {
|
2019-01-26 09:48:33 +03:00
|
|
|
this.setState({hsUrl: ev.target.value}, () => {
|
2019-01-24 03:32:36 +03:00
|
|
|
this._hsTimeoutId = this._waitThenInvoke(this._hsTimeoutId, () => {
|
2019-01-26 09:48:33 +03:00
|
|
|
let hsUrl = this.state.hsUrl.trim().replace(/\/$/, "");
|
2016-03-06 22:33:36 +03:00
|
|
|
if (hsUrl === "") hsUrl = this.props.defaultHsUrl;
|
2017-04-21 13:37:08 +03:00
|
|
|
this.props.onServerConfigChange({
|
2019-01-26 09:48:33 +03:00
|
|
|
hsUrl: this.state.hsUrl,
|
|
|
|
isUrl: this.state.isUrl,
|
2017-04-21 13:37:08 +03:00
|
|
|
});
|
2015-11-30 21:11:04 +03:00
|
|
|
});
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
|
|
|
onIdentityServerChanged: function(ev) {
|
2019-01-26 09:48:33 +03:00
|
|
|
this.setState({isUrl: ev.target.value}, () => {
|
2019-01-24 03:32:36 +03:00
|
|
|
this._isTimeoutId = this._waitThenInvoke(this._isTimeoutId, () => {
|
2019-01-26 09:48:33 +03:00
|
|
|
let isUrl = this.state.isUrl.trim().replace(/\/$/, "");
|
2016-03-06 22:33:36 +03:00
|
|
|
if (isUrl === "") isUrl = this.props.defaultIsUrl;
|
2017-04-21 13:37:08 +03:00
|
|
|
this.props.onServerConfigChange({
|
2019-01-26 09:48:33 +03:00
|
|
|
hsUrl: this.state.hsUrl,
|
|
|
|
isUrl: this.state.isUrl,
|
2017-04-21 13:37:08 +03:00
|
|
|
});
|
2015-11-30 21:11:04 +03:00
|
|
|
});
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
|
|
|
_waitThenInvoke: function(existingTimeoutId, fn) {
|
|
|
|
if (existingTimeoutId) {
|
|
|
|
clearTimeout(existingTimeoutId);
|
|
|
|
}
|
|
|
|
return setTimeout(fn.bind(this), this.props.delayTimeMs);
|
|
|
|
},
|
|
|
|
|
|
|
|
showHelpPopup: function() {
|
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);
|
2015-11-30 21:11:04 +03:00
|
|
|
},
|
|
|
|
|
|
|
|
render: function() {
|
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}
|
|
|
|
onChange={this.onHomeserverChanged}
|
|
|
|
/>
|
|
|
|
<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}
|
|
|
|
onChange={this.onIdentityServerChanged}
|
|
|
|
/>
|
2015-11-30 21:11:04 +03:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
);
|
2017-10-11 19:56:17 +03:00
|
|
|
},
|
2015-11-30 21:11:04 +03:00
|
|
|
});
|