From 36b1280f0c0a4a9c06b1b3f11c261275011d22d3 Mon Sep 17 00:00:00 2001 From: David Baker Date: Mon, 20 Jul 2015 12:20:17 -0700 Subject: [PATCH] Bookmarkable room URLs --- examples/trivial/index.js | 8 ++++++++ src/controllers/pages/MatrixChat.js | 8 ++++++++ 2 files changed, 16 insertions(+) diff --git a/examples/trivial/index.js b/examples/trivial/index.js index 2be9054954..b601cfce6b 100644 --- a/examples/trivial/index.js +++ b/examples/trivial/index.js @@ -40,9 +40,17 @@ function routeUrl(location) { } } window.matrixChat.showScreen('register', params); + } else { + window.matrixChat.showScreen(location.hash.substring(2)); } } +function onHashChange(ev) { + routeUrl(window.location); +} + +window.addEventListener('hashchange', onHashChange); + var loaded = false; window.onload = function() { diff --git a/src/controllers/pages/MatrixChat.js b/src/controllers/pages/MatrixChat.js index 1e38a2150c..6ff62c9692 100644 --- a/src/controllers/pages/MatrixChat.js +++ b/src/controllers/pages/MatrixChat.js @@ -127,6 +127,7 @@ module.exports = { currentRoom: payload.room_id, page_type: this.PageTypes.RoomView, }); + this.notifyNewScreen('room/'+payload.room_id); break; case 'view_prev_room': roomIndexDelta = -1; @@ -179,6 +180,7 @@ module.exports = { )[0].roomId; } self.setState({ready: true, currentRoom: firstRoom}); + self.notifyNewScreen('room/'+firstRoom); dis.dispatch({action: 'focus_composer'}); }); cli.on('Call.incoming', function(call) { @@ -222,6 +224,12 @@ module.exports = { action: 'start_login', params: params }); + } else if (screen.indexOf('room/') == 0) { + var roomId = screen.split('/')[1]; + dis.dispatch({ + action: 'view_room', + room_id: roomId + }); } },