Improve url / screen handling

Including taking you to the room you asked for originally after login
This commit is contained in:
David Baker 2015-10-05 15:31:08 +01:00
parent ad313d7711
commit a1892ee963

View file

@ -82,6 +82,7 @@ module.exports = {
var roomIndexDelta = 1; var roomIndexDelta = 1;
var Notifier = sdk.getComponent('organisms.Notifier'); var Notifier = sdk.getComponent('organisms.Notifier');
var self = this;
switch (payload.action) { switch (payload.action) {
case 'logout': case 'logout':
this.replaceState({ this.replaceState({
@ -96,7 +97,7 @@ module.exports = {
MatrixClientPeg.get().stopClient(); MatrixClientPeg.get().stopClient();
MatrixClientPeg.get().removeAllListeners(); MatrixClientPeg.get().removeAllListeners();
MatrixClientPeg.unset(); MatrixClientPeg.unset();
this.notifyNewScreen(''); this.notifyNewScreen('login');
break; break;
case 'start_registration': case 'start_registration':
if (this.state.logged_in) return; if (this.state.logged_in) return;
@ -128,10 +129,10 @@ module.exports = {
break; break;
case 'view_room': case 'view_room':
this.focusComposer = true; this.focusComposer = true;
this.setState({ var newState = {
currentRoom: payload.room_id, currentRoom: payload.room_id,
page_type: this.PageTypes.RoomView, page_type: this.PageTypes.RoomView,
}); };
if (this.sdkReady) { if (this.sdkReady) {
// if the SDK is not ready yet, remember what room // if the SDK is not ready yet, remember what room
// we're supposed to be on but don't notify about // we're supposed to be on but don't notify about
@ -146,6 +147,8 @@ module.exports = {
} }
this.notifyNewScreen('room/'+presentedId); this.notifyNewScreen('room/'+presentedId);
} }
newState.ready = true;
this.setState(newState);
break; break;
case 'view_prev_room': case 'view_prev_room':
roomIndexDelta = -1; roomIndexDelta = -1;
@ -181,6 +184,14 @@ module.exports = {
this.notifyNewScreen('room/'+allRooms[roomIndex].roomId); this.notifyNewScreen('room/'+allRooms[roomIndex].roomId);
} }
break; break;
case 'view_room_alias':
MatrixClientPeg.get().getRoomIdForAlias(payload.room_alias).done(function(result) {
dis.dispatch({
action: 'view_room',
room_id: result.room_id
});
});
break;
case 'view_user_settings': case 'view_user_settings':
this.setState({ this.setState({
page_type: this.PageTypes.UserSettings, page_type: this.PageTypes.UserSettings,
@ -218,19 +229,13 @@ module.exports = {
cli.on('syncComplete', function() { cli.on('syncComplete', function() {
self.sdkReady = true; self.sdkReady = true;
var defer = q.defer();
if (self.starting_room_alias) { if (self.starting_room_alias) {
MatrixClientPeg.get().getRoomIdForAlias(self.starting_room_alias).done(function(result) { dis.dispatch({
self.setState({currentRoom: result.room_id}); action: 'view_room_alias',
defer.resolve(); room_alias: self.starting_room_alias
}, function(error) {
defer.resolve();
}); });
delete self.starting_room_alias;
} else { } else {
defer.resolve();
}
defer.promise.done(function() {
if (!self.state.currentRoom) { if (!self.state.currentRoom) {
var firstRoom = null; var firstRoom = null;
if (cli.getRooms() && cli.getRooms().length) { if (cli.getRooms() && cli.getRooms().length) {
@ -255,7 +260,7 @@ module.exports = {
} }
self.notifyNewScreen('room/'+presentedId); self.notifyNewScreen('room/'+presentedId);
dis.dispatch({action: 'focus_composer'}); dis.dispatch({action: 'focus_composer'});
}); }
}); });
cli.on('Call.incoming', function(call) { cli.on('Call.incoming', function(call) {
dis.dispatch({ dis.dispatch({
@ -312,7 +317,17 @@ module.exports = {
} else if (screen.indexOf('room/') == 0) { } else if (screen.indexOf('room/') == 0) {
var roomString = screen.split('/')[1]; var roomString = screen.split('/')[1];
if (roomString[0] == '#') { if (roomString[0] == '#') {
if (this.state.logged_in) {
dis.dispatch({
action: 'view_room_alias',
room_alias: roomString
});
} else {
// Okay, we'll take you here soon...
this.starting_room_alias = roomString; this.starting_room_alias = roomString;
// ...but you're still going to have to log in.
this.notifyNewScreen('login');
}
} else { } else {
dis.dispatch({ dis.dispatch({
action: 'view_room', action: 'view_room',