-
-
Notifications
You must be signed in to change notification settings - Fork 830
Support adding phone numbers in UserSettings #756
Conversation
src/AddThreepid.js
Outdated
@@ -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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
email -> phone
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
src/AddThreepid.js
Outdated
/** | ||
* 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 |
There was a problem hiding this comment.
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 :)
There was a problem hiding this comment.
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(); |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we always [bind] ?
There was a problem hiding this comment.
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) { |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
looks like we still have a flaky test. Is that known? |
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 { |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
redundant?
There was a problem hiding this comment.
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();; |
There was a problem hiding this comment.
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}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
needs an unmounted guard
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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}. |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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}); |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
unmounted guard
There was a problem hiding this comment.
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()) { |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
Unmounted guards, extra semicolon, return early to lose indent level, add keys.
There was a problem hiding this 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; |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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 { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
missing msisdn_add_pending
There was a problem hiding this comment.
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, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
redundant
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
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