From b78340ff51c40c6b7ec6de6ac9c9614897043c45 Mon Sep 17 00:00:00 2001 From: David Baker Date: Fri, 8 Jul 2016 17:28:04 +0100 Subject: [PATCH 1/2] Use HS proxy API for requestToken on adding email So we report an error if the email is already taken. Also fix a bug where the spinner wouldn't disappear if adding an email failed (and don't include the raw errcode in the user-facing dialog) --- src/AddThreepid.js | 6 ++++-- src/components/structures/UserSettings.js | 3 ++- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/src/AddThreepid.js b/src/AddThreepid.js index 31805aad11..c32eb3aab1 100644 --- a/src/AddThreepid.js +++ b/src/AddThreepid.js @@ -38,11 +38,13 @@ class AddThreepid { */ addEmailAddress(emailAddress, bind) { this.bind = bind; - return MatrixClientPeg.get().requestEmailToken(emailAddress, this.clientSecret, 1).then((res) => { + return MatrixClientPeg.get().request3pidAddEmailToken(emailAddress, this.clientSecret, 1).then((res) => { this.sessionId = res.sid; return res; }, function(err) { - if (err.httpStatus) { + if (err.errcode == 'M_THREEPID_IN_USE') { + err.message = "This email address is already in use"; + } else if (err.httpStatus) { err.message = err.message + ` (Status ${err.httpStatus})`; } throw err; diff --git a/src/components/structures/UserSettings.js b/src/components/structures/UserSettings.js index 7fcb81a60c..c54a10c7c0 100644 --- a/src/components/structures/UserSettings.js +++ b/src/components/structures/UserSettings.js @@ -214,9 +214,10 @@ module.exports = React.createClass({ onFinished: this.onEmailDialogFinished, }); }, (err) => { + this.setState({email_add_pending: false}); Modal.createDialog(ErrorDialog, { title: "Unable to add email address", - description: err.toString() + description: err.message }); }); ReactDOM.findDOMNode(this.refs.add_threepid_input).blur(); From 8e8e54a3bfec44b837c86ce4d91d73c8932ed533 Mon Sep 17 00:00:00 2001 From: David Baker Date: Fri, 8 Jul 2016 17:53:06 +0100 Subject: [PATCH 2/2] Update function name as per js-sdk PR feedback --- src/AddThreepid.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/AddThreepid.js b/src/AddThreepid.js index c32eb3aab1..5593d46ff7 100644 --- a/src/AddThreepid.js +++ b/src/AddThreepid.js @@ -38,7 +38,7 @@ class AddThreepid { */ addEmailAddress(emailAddress, bind) { this.bind = bind; - return MatrixClientPeg.get().request3pidAddEmailToken(emailAddress, this.clientSecret, 1).then((res) => { + return MatrixClientPeg.get().requestAdd3pidEmailToken(emailAddress, this.clientSecret, 1).then((res) => { this.sessionId = res.sid; return res; }, function(err) {