Merge pull request #3320 from matrix-org/travis/is-account-data
Persist and maintain identity server in account data
This commit is contained in:
commit
e7e22b75bc
2 changed files with 56 additions and 7 deletions
|
@ -446,6 +446,29 @@ export default React.createClass({
|
||||||
}
|
}
|
||||||
|
|
||||||
switch (payload.action) {
|
switch (payload.action) {
|
||||||
|
case 'MatrixActions.accountData':
|
||||||
|
// XXX: This is a collection of several hacks to solve a minor problem. We want to
|
||||||
|
// update our local state when the ID server changes, but don't want to put that in
|
||||||
|
// the js-sdk as we'd be then dictating how all consumers need to behave. However,
|
||||||
|
// this component is already bloated and we probably don't want this tiny logic in
|
||||||
|
// here, but there's no better place in the react-sdk for it. Additionally, we're
|
||||||
|
// abusing the MatrixActionCreator stuff to avoid errors on dispatches.
|
||||||
|
if (payload.event_type === 'm.identity_server') {
|
||||||
|
const fullUrl = payload.event_content ? payload.event_content['base_url'] : null;
|
||||||
|
if (!fullUrl) {
|
||||||
|
MatrixClientPeg.get().setIdentityServerUrl(null);
|
||||||
|
localStorage.removeItem("mx_is_access_token");
|
||||||
|
localStorage.removeItem("mx_is_url");
|
||||||
|
} else {
|
||||||
|
MatrixClientPeg.get().setIdentityServerUrl(fullUrl);
|
||||||
|
localStorage.removeItem("mx_is_access_token"); // clear token
|
||||||
|
localStorage.setItem("mx_is_url", fullUrl); // XXX: Do we still need this?
|
||||||
|
}
|
||||||
|
|
||||||
|
// redispatch the change with a more specific action
|
||||||
|
dis.dispatch({action: 'id_server_changed'});
|
||||||
|
}
|
||||||
|
break;
|
||||||
case 'logout':
|
case 'logout':
|
||||||
Lifecycle.logout();
|
Lifecycle.logout();
|
||||||
break;
|
break;
|
||||||
|
|
|
@ -107,6 +107,31 @@ export default class SetIdServer extends React.Component {
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
componentDidMount(): void {
|
||||||
|
this.dispatcherRef = dis.register(this.onAction);
|
||||||
|
}
|
||||||
|
|
||||||
|
componentWillUnmount(): void {
|
||||||
|
dis.unregister(this.dispatcherRef);
|
||||||
|
}
|
||||||
|
|
||||||
|
onAction = (payload) => {
|
||||||
|
// We react to changes in the ID server in the event the user is staring at this form
|
||||||
|
// when changing their identity server on another device. If the user is trying to change
|
||||||
|
// it in two places, we'll end up stomping all over their input, but at that point we
|
||||||
|
// should question our UX which led to them doing that.
|
||||||
|
if (payload.action !== "id_server_changed") return;
|
||||||
|
|
||||||
|
const fullUrl = MatrixClientPeg.get().getIdentityServerUrl();
|
||||||
|
let abbr = '';
|
||||||
|
if (fullUrl) abbr = abbreviateUrl(fullUrl);
|
||||||
|
|
||||||
|
this.setState({
|
||||||
|
currentClientIdServer: fullUrl,
|
||||||
|
idServer: abbr,
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
_onIdentityServerChanged = (ev) => {
|
_onIdentityServerChanged = (ev) => {
|
||||||
const u = ev.target.value;
|
const u = ev.target.value;
|
||||||
|
|
||||||
|
@ -132,10 +157,10 @@ export default class SetIdServer extends React.Component {
|
||||||
};
|
};
|
||||||
|
|
||||||
_saveIdServer = (fullUrl) => {
|
_saveIdServer = (fullUrl) => {
|
||||||
MatrixClientPeg.get().setIdentityServerUrl(fullUrl);
|
// Account data change will update localstorage, client, etc through dispatcher
|
||||||
localStorage.removeItem("mx_is_access_token");
|
MatrixClientPeg.get().setAccountData("m.identity_server", {
|
||||||
localStorage.setItem("mx_is_url", fullUrl);
|
base_url: fullUrl,
|
||||||
dis.dispatch({action: 'id_server_changed'});
|
});
|
||||||
this.setState({idServer: '', busy: false, error: null});
|
this.setState({idServer: '', busy: false, error: null});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -238,9 +263,10 @@ export default class SetIdServer extends React.Component {
|
||||||
};
|
};
|
||||||
|
|
||||||
_disconnectIdServer = () => {
|
_disconnectIdServer = () => {
|
||||||
MatrixClientPeg.get().setIdentityServerUrl(null);
|
// Account data change will update localstorage, client, etc through dispatcher
|
||||||
localStorage.removeItem("mx_is_access_token");
|
MatrixClientPeg.get().setAccountData("m.identity_server", {
|
||||||
localStorage.removeItem("mx_is_url");
|
base_url: null, // clear
|
||||||
|
});
|
||||||
|
|
||||||
let newFieldVal = '';
|
let newFieldVal = '';
|
||||||
if (SdkConfig.get()['validated_server_config']['isUrl']) {
|
if (SdkConfig.get()['validated_server_config']['isUrl']) {
|
||||||
|
|
Loading…
Reference in a new issue