address PR comments

This commit is contained in:
David Baker 2016-02-04 15:07:30 +00:00
parent 6e424780f1
commit 167da10b8b
2 changed files with 5 additions and 15 deletions

View file

@ -700,15 +700,14 @@ module.exports = React.createClass({
var self = this; var self = this;
var cli = MatrixClientPeg.get(); var cli = MatrixClientPeg.get();
var join_defer; var display_name_promise = q();
var join_promise;
// if this is the first room we're joining, check the user has a display name // if this is the first room we're joining, check the user has a display name
// and if they don't, prompt them to set one. // and if they don't, prompt them to set one.
// NB. This unfortunately does not re-use the ChangeDisplayName component because // NB. This unfortunately does not re-use the ChangeDisplayName component because
// it doesn't behave quite as desired here (we want an input field here rather than // it doesn't behave quite as desired here (we want an input field here rather than
// content-editable, and we want a default). // content-editable, and we want a default).
if (MatrixClientPeg.get().getRooms().length == 0) { if (MatrixClientPeg.get().getRooms().length == 0) {
join_promise = cli.getProfileInfo(cli.credentials.userId).then((result) => { display_name_promise = cli.getProfileInfo(cli.credentials.userId).then((result) => {
if (!result.displayname) { if (!result.displayname) {
var SetDisplayNameDialog = sdk.getComponent('views.dialogs.SetDisplayNameDialog'); var SetDisplayNameDialog = sdk.getComponent('views.dialogs.SetDisplayNameDialog');
var dialog_defer = q.defer(); var dialog_defer = q.defer();
@ -717,8 +716,7 @@ module.exports = React.createClass({
var dialog_instance = <SetDisplayNameDialog currentDisplayName={result.displayname} ref={(r) => { var dialog_instance = <SetDisplayNameDialog currentDisplayName={result.displayname} ref={(r) => {
dialog_ref = r; dialog_ref = r;
}} onFinished={() => { }} onFinished={() => {
var new_displayname = dialog_ref.getValue() || dialog_ref.getDefaultValue(); cli.setDisplayName(dialog_ref.getValue()).done(() => {
cli.setDisplayName(new_displayname).done(() => {
dialog_defer.resolve(); dialog_defer.resolve();
}); });
modal.close(); modal.close();
@ -727,13 +725,9 @@ module.exports = React.createClass({
return dialog_defer.promise; return dialog_defer.promise;
} }
}); });
} else {
join_defer = q.defer();
join_promise = join_defer.promise;
join_defer.resolve();
} }
join_promise.then(() => { display_name_promise.then(() => {
return MatrixClientPeg.get().joinRoom(this.props.roomId) return MatrixClientPeg.get().joinRoom(this.props.roomId)
}).done(function() { }).done(function() {
// It is possible that there is no Room yet if state hasn't come down // It is possible that there is no Room yet if state hasn't come down

View file

@ -27,14 +27,10 @@ module.exports = React.createClass({
getInitialState: function() { getInitialState: function() {
return { return {
value: this.props.currentDisplayName || this.getDefaultDisplayName(), value: this.props.currentDisplayName || "Guest "+MatrixClientPeg.get().getUserIdLocalpart(),
} }
}, },
getDefaultDisplayName: function() {
return "Guest "+MatrixClientPeg.get().getUserIdLocalpart();
},
getValue: function() { getValue: function() {
return this.state.value; return this.state.value;
}, },