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

Show session restore errors on the login screen #435

Merged
merged 2 commits into from
Sep 2, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 30 additions & 9 deletions src/components/structures/MatrixChat.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

import q from 'q';

var React = require('react');
var Matrix = require("matrix-js-sdk");
var Favico = require('favico.js');
Expand Down Expand Up @@ -164,6 +167,9 @@ module.exports = React.createClass({
// their mind & log back in)
this.guestCreds = null;

// if the automatic session load failed, the error
this.sessionLoadError = null;

if (this.props.config.sync_timeline_limit) {
MatrixClientPeg.opts.initialSyncLimit = this.props.config.sync_timeline_limit;
}
Expand Down Expand Up @@ -191,13 +197,20 @@ module.exports = React.createClass({
window.addEventListener('resize', this.handleResize);
this.handleResize();

Lifecycle.loadSession({
realQueryParams: this.props.realQueryParams,
fragmentQueryParams: this.props.startingFragmentQueryParams,
enableGuest: this.props.enableGuest,
guestHsUrl: this.getCurrentHsUrl(),
guestIsUrl: this.getCurrentIsUrl(),
defaultDeviceDisplayName: this.props.defaultDeviceDisplayName,
// the extra q() ensures that synchronous exceptions hit the same codepath as
// asynchronous ones.
q().then(() => {
Copy link
Member

Choose a reason for hiding this comment

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

i'm a little confused as to why we have to wrap the .loadSession in a q().then() rather than just just doing loadSession.catch().done()? Might be worth commenting it given the subtlety.

return Lifecycle.loadSession({
realQueryParams: this.props.realQueryParams,
fragmentQueryParams: this.props.startingFragmentQueryParams,
enableGuest: this.props.enableGuest,
guestHsUrl: this.getCurrentHsUrl(),
guestIsUrl: this.getCurrentIsUrl(),
defaultDeviceDisplayName: this.props.defaultDeviceDisplayName,
});
}).catch((e) => {
console.error("Unable to load session", e);
this.sessionLoadError = e.message;
}).done(()=>{
// stuff this through the dispatcher so that it happens
// after the on_logged_in action.
Expand Down Expand Up @@ -1085,7 +1098,7 @@ module.exports = React.createClass({
onLoginClick={this.onLoginClick} />
);
} else {
return (
var r = (
<Login
onLoggedIn={Lifecycle.setLoggedIn}
onRegisterClick={this.onRegisterClick}
Expand All @@ -1098,8 +1111,16 @@ module.exports = React.createClass({
onForgotPasswordClick={this.onForgotPasswordClick}
enableGuest={this.props.enableGuest}
onCancelClick={this.guestCreds ? this.onReturnToGuestClick : null}
/>
initialErrorText={this.sessionLoadError}
/>
);

// we only want to show the session load error the first time the
// Login component is rendered. This is pretty hacky but I can't
// think of another way to achieve it.
this.sessionLoadError = null;

return r;
}
}
});
11 changes: 7 additions & 4 deletions src/components/structures/login/Login.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,12 +52,14 @@ module.exports = React.createClass({
// login shouldn't care how password recovery is done.
onForgotPasswordClick: React.PropTypes.func,
onCancelClick: React.PropTypes.func,

initialErrorText: React.PropTypes.string,
},

getInitialState: function() {
return {
busy: false,
errorText: null,
errorText: this.props.initialErrorText,
loginIncorrect: false,
enteredHomeserverUrl: this.props.customHsUrl || this.props.defaultHsUrl,
enteredIdentityServerUrl: this.props.customIsUrl || this.props.defaultIsUrl,
Expand Down Expand Up @@ -116,7 +118,8 @@ module.exports = React.createClass({
onHsUrlChanged: function(newHsUrl) {
var self = this;
this.setState({
enteredHomeserverUrl: newHsUrl
enteredHomeserverUrl: newHsUrl,
errorText: null, // reset err messages
}, function() {
self._initLoginLogic(newHsUrl);
});
Expand All @@ -125,7 +128,8 @@ module.exports = React.createClass({
onIsUrlChanged: function(newIsUrl) {
var self = this;
this.setState({
enteredIdentityServerUrl: newIsUrl
enteredIdentityServerUrl: newIsUrl,
errorText: null, // reset err messages
}, function() {
self._initLoginLogic(null, newIsUrl);
});
Expand Down Expand Up @@ -160,7 +164,6 @@ module.exports = React.createClass({
enteredHomeserverUrl: hsUrl,
enteredIdentityServerUrl: isUrl,
busy: true,
errorText: null, // reset err messages
loginIncorrect: false,
});
},
Expand Down