Update all 3PID state in Settings when IS changes

This ensures we update all 3PID state (like bind status) whenever the IS
changes.
This commit is contained in:
J. Ryan Stinnett 2019-09-11 16:16:07 +01:00
parent 0b7995dc11
commit db33c138aa
3 changed files with 25 additions and 9 deletions

View file

@ -58,6 +58,11 @@ export class EmailAddress extends React.Component {
}; };
} }
componentWillReceiveProps(nextProps) {
const { bound } = nextProps.email;
this.setState({ bound });
}
async changeBinding({ bind, label, errorTitle }) { async changeBinding({ bind, label, errorTitle }) {
const ErrorDialog = sdk.getComponent("dialogs.ErrorDialog"); const ErrorDialog = sdk.getComponent("dialogs.ErrorDialog");
const { medium, address } = this.props.email; const { medium, address } = this.props.email;

View file

@ -50,6 +50,11 @@ export class PhoneNumber extends React.Component {
}; };
} }
componentWillReceiveProps(nextProps) {
const { bound } = nextProps.msisdn;
this.setState({ bound });
}
async changeBinding({ bind, label, errorTitle }) { async changeBinding({ bind, label, errorTitle }) {
const ErrorDialog = sdk.getComponent("dialogs.ErrorDialog"); const ErrorDialog = sdk.getComponent("dialogs.ErrorDialog");
const { medium, address } = this.props.msisdn; const { medium, address } = this.props.msisdn;

View file

@ -72,14 +72,7 @@ export default class GeneralUserSettingsTab extends React.Component {
const serverRequiresIdServer = await cli.doesServerRequireIdServerParam(); const serverRequiresIdServer = await cli.doesServerRequireIdServerParam();
this.setState({serverRequiresIdServer}); this.setState({serverRequiresIdServer});
// Check to see if terms need accepting this._getThreepidState();
this._checkTerms();
// Need to get 3PIDs generally for Account section and possibly also for
// Discovery (assuming we have an IS and terms are agreed).
const threepids = await getThreepidsWithBindStatus(cli);
this.setState({ emails: threepids.filter((a) => a.medium === 'email') });
this.setState({ msisdns: threepids.filter((a) => a.medium === 'msisdn') });
} }
componentWillUnmount() { componentWillUnmount() {
@ -89,7 +82,7 @@ export default class GeneralUserSettingsTab extends React.Component {
_onAction = (payload) => { _onAction = (payload) => {
if (payload.action === 'id_server_changed') { if (payload.action === 'id_server_changed') {
this.setState({haveIdServer: Boolean(MatrixClientPeg.get().getIdentityServerUrl())}); this.setState({haveIdServer: Boolean(MatrixClientPeg.get().getIdentityServerUrl())});
this._checkTerms(); this._getThreepidState();
} }
}; };
@ -101,6 +94,19 @@ export default class GeneralUserSettingsTab extends React.Component {
this.setState({ msisdns }); this.setState({ msisdns });
} }
async _getThreepidState() {
const cli = MatrixClientPeg.get();
// Check to see if terms need accepting
this._checkTerms();
// Need to get 3PIDs generally for Account section and possibly also for
// Discovery (assuming we have an IS and terms are agreed).
const threepids = await getThreepidsWithBindStatus(cli);
this.setState({ emails: threepids.filter((a) => a.medium === 'email') });
this.setState({ msisdns: threepids.filter((a) => a.medium === 'msisdn') });
}
async _checkTerms() { async _checkTerms() {
if (!this.state.haveIdServer) { if (!this.state.haveIdServer) {
this.setState({idServerHasUnsignedTerms: false}); this.setState({idServerHasUnsignedTerms: false});