Skip to content
This repository has been archived by the owner on Sep 11, 2024. It is now read-only.

Support adding phone numbers in UserSettings #756

Merged
merged 10 commits into from
Mar 24, 2017
Merged

Support adding phone numbers in UserSettings #756

merged 10 commits into from
Mar 24, 2017

Conversation

dbkr
Copy link
Member

@dbkr dbkr commented Mar 16, 2017

Requires element-hq/element-web#3451

Based off msisdn branch, so probably best to wait until after that's merged to review. [Now merged]

element-hq/element-web#1903

@@ -52,10 +53,34 @@ class AddThreepid {
}

/**
* Attempt to add a msisdn threepid. This will trigger a side-effect of
* sending a test message to the provided phone number.
* @param {string} emailAddress The email address to add
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

email -> phone

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

/**
* Takes a phone number verification code as entered by the user and validates
* it with the ID server, then if successful, adds the phone number.
* @return {Promise} Resolves if the email address was added. Rejects with an object
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

email address -> phone number

ironic given you'd fixed the email one :)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

const ErrorDialog = sdk.getComponent("dialogs.ErrorDialog");
const QuestionDialog = sdk.getComponent("dialogs.QuestionDialog");

this._addThreepid = new AddThreepid();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hrm. What happens if someone tries to add a misisdn and an email at the same time? Might be possible if the requestToken call takes ages?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Refactored so this doesn't matter

const QuestionDialog = sdk.getComponent("dialogs.QuestionDialog");

this._addThreepid = new AddThreepid();
// we always phone numbers when registering, so let's do the
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we always [bind] ?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

</div>
);
}
if (this.state.msisdn_add_pending) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

how about factoriong the whole add-phone-number business out to a separate component? Apart from making this neater, it would solve the fight over this._addThreePid?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done, although the CSS is a bit of a mess because it needs to be multiple parts of a table layout. Unsure how to fix this as all the solutions I can think of involve passing around the components or some callback functions, and I can't see a react-blessed way of doing that.

@richvdh
Copy link
Member

richvdh commented Mar 21, 2017

looks like we still have a flaky test. Is that known?

@richvdh richvdh assigned dbkr and unassigned richvdh Mar 21, 2017
@dbkr dbkr assigned richvdh and unassigned dbkr Mar 22, 2017
@dbkr
Copy link
Member Author

dbkr commented Mar 22, 2017

Also it might make sense to do similar things to the email adding bit, if this looks sensible. It seems the test is flaky - I was going to try & make it less flaky by using the waitForComponent stuff from react-sdk, although this involves cross-project testing code which we've not done before.

import Modal from '../../../Modal';


class AddPhoneNumber extends React.Component {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I asked this before, but... I thought we were sticking with react.createClass for now.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Point - I'll change it, especially as it makes WithMatrixClient much less awful


_addMsisdn() {
const ErrorDialog = sdk.getComponent("dialogs.ErrorDialog");
const QuestionDialog = sdk.getComponent("dialogs.QuestionDialog");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

redundant?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

});
}).finally(() => {
this.setState({msisdn_add_pending: false});
}).done();;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

;;

description: msg,
});
}).finally(() => {
this.setState({msisdn_add_pending: false});
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

needs an unmounted guard

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

// we always bind phone numbers when registering, so let's do the
// same here.
this._addThreepid.addMsisdn(this.state.phoneCountry, this.state.phoneNumber, true).then((resp) => {
this._promptForMsisdnVerificationCode(resp.msisdn);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

probably needs an unmounted guard?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

_promptForMsisdnVerificationCode(msisdn, err) {
const TextInputDialog = sdk.getComponent("dialogs.TextInputDialog");
let msgElements = [
<div>A text message has been sent to +{msisdn}.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

doesn't this need an index, to keep react happy?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ah yes, probably

this._addThreepid = null;
return;
}
this.setState({msisdn_add_pending: true});
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

probably needs an unmounted guard?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

}).catch((err) => {
this._promptForMsisdnVerificationCode(msisdn, err);
}).finally(() => {
this.setState({msisdn_add_pending: false});
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

unmounted guard

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

const Loader = sdk.getComponent("elements.Spinner");
if (this.state.msisdn_add_pending) {
return <Loader />;
} else if (!this.props.matrixClient.isGuest()) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

return early if isGuest to lose a level of indentation?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

@richvdh richvdh assigned dbkr and unassigned richvdh Mar 22, 2017
dbkr added 4 commits March 22, 2017 16:15
Unmounted guards, extra semicolon, return early to lose indent
level, add keys.
@dbkr dbkr assigned richvdh and unassigned dbkr Mar 22, 2017
Copy link
Member

@richvdh richvdh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nearly

</form>
);
} else if (this.props.matrixClient.isGuest()) {
return null;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think you're allowed to return null from a render. Return an empty div or sth instead.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, right you are.

},

getInitialState: function() {
return {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

missing msisdn_add_pending

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

@@ -132,13 +133,15 @@ module.exports = React.createClass({
threePids: [],
phase: "UserSettings.LOADING", // LOADING, DISPLAY
email_add_pending: false,
msisdn_add_pending: false,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

redundant

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

@richvdh richvdh assigned dbkr and unassigned richvdh Mar 24, 2017
@dbkr dbkr assigned richvdh and unassigned dbkr Mar 24, 2017
@richvdh richvdh removed their assignment Mar 24, 2017
@dbkr dbkr merged commit a8d85ca into develop Mar 24, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants