Support room aliases in url bar and show them for rooms that have them
This commit is contained in:
parent
68d408bfff
commit
2771907573
3 changed files with 39 additions and 6 deletions
|
@ -24,6 +24,8 @@ var React = require("react");
|
||||||
// maps cannot pass through two stages).
|
// maps cannot pass through two stages).
|
||||||
var MatrixReactSdk = require("../../src/index");
|
var MatrixReactSdk = require("../../src/index");
|
||||||
|
|
||||||
|
var lastLocationHashSet = null;
|
||||||
|
|
||||||
// Here, we do some crude URL analysis to allow
|
// Here, we do some crude URL analysis to allow
|
||||||
// deep-linking. We only support registration
|
// deep-linking. We only support registration
|
||||||
// deep-links in this example.
|
// deep-links in this example.
|
||||||
|
@ -46,6 +48,10 @@ function routeUrl(location) {
|
||||||
}
|
}
|
||||||
|
|
||||||
function onHashChange(ev) {
|
function onHashChange(ev) {
|
||||||
|
if (decodeURIComponent(window.location.hash) == lastLocationHashSet) {
|
||||||
|
// we just set this: no need to route it!
|
||||||
|
return;
|
||||||
|
}
|
||||||
routeUrl(window.location);
|
routeUrl(window.location);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -55,7 +61,9 @@ var loaded = false;
|
||||||
// so a web page can update the URL bar appropriately.
|
// so a web page can update the URL bar appropriately.
|
||||||
var onNewScreen = function(screen) {
|
var onNewScreen = function(screen) {
|
||||||
if (!loaded) return;
|
if (!loaded) return;
|
||||||
window.location.hash = '#/'+screen;
|
var hash = '#/' + screen;
|
||||||
|
lastLocationHashSet = hash;
|
||||||
|
window.location.hash = hash;
|
||||||
}
|
}
|
||||||
|
|
||||||
// We use this to work out what URL the SDK should
|
// We use this to work out what URL the SDK should
|
||||||
|
|
|
@ -202,6 +202,7 @@ module.exports = {
|
||||||
|
|
||||||
fillSpace: function() {
|
fillSpace: function() {
|
||||||
var messageWrapper = this.refs.messageWrapper.getDOMNode();
|
var messageWrapper = this.refs.messageWrapper.getDOMNode();
|
||||||
|
if (!messageWrapper) return;
|
||||||
if (messageWrapper.scrollTop < messageWrapper.clientHeight && this.state.room.oldState.paginationToken) {
|
if (messageWrapper.scrollTop < messageWrapper.clientHeight && this.state.room.oldState.paginationToken) {
|
||||||
this.setState({paginating: true});
|
this.setState({paginating: true});
|
||||||
|
|
||||||
|
|
|
@ -23,9 +23,11 @@ var MatrixClientPeg = require("../../MatrixClientPeg");
|
||||||
var RoomListSorter = require("../../RoomListSorter");
|
var RoomListSorter = require("../../RoomListSorter");
|
||||||
var Presence = require("../../Presence");
|
var Presence = require("../../Presence");
|
||||||
var dis = require("../../dispatcher");
|
var dis = require("../../dispatcher");
|
||||||
|
var q = require("q");
|
||||||
|
|
||||||
var ComponentBroker = require('../../ComponentBroker');
|
var ComponentBroker = require('../../ComponentBroker');
|
||||||
var Notifier = ComponentBroker.get('organisms/Notifier');
|
var Notifier = ComponentBroker.get('organisms/Notifier');
|
||||||
|
var MatrixTools = require('../../MatrixTools');
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
PageTypes: {
|
PageTypes: {
|
||||||
|
@ -136,7 +138,13 @@ module.exports = {
|
||||||
currentRoom: payload.room_id,
|
currentRoom: payload.room_id,
|
||||||
page_type: this.PageTypes.RoomView,
|
page_type: this.PageTypes.RoomView,
|
||||||
});
|
});
|
||||||
this.notifyNewScreen('room/'+payload.room_id);
|
var presentedId = payload.room_id;
|
||||||
|
var room = MatrixClientPeg.get().getRoom(payload.room_id);
|
||||||
|
if (room) {
|
||||||
|
var theAlias = MatrixTools.getCanonicalAliasForRoom(room);
|
||||||
|
if (theAlias) presentedId = theAlias;
|
||||||
|
}
|
||||||
|
this.notifyNewScreen('room/'+presentedId);
|
||||||
break;
|
break;
|
||||||
case 'view_prev_room':
|
case 'view_prev_room':
|
||||||
roomIndexDelta = -1;
|
roomIndexDelta = -1;
|
||||||
|
@ -249,11 +257,27 @@ module.exports = {
|
||||||
params: params
|
params: params
|
||||||
});
|
});
|
||||||
} else if (screen.indexOf('room/') == 0) {
|
} else if (screen.indexOf('room/') == 0) {
|
||||||
var roomId = screen.split('/')[1];
|
var roomString = screen.split('/')[1];
|
||||||
|
var defer = q.defer();
|
||||||
|
if (roomString[0] == '#') {
|
||||||
|
var self = this;
|
||||||
|
MatrixClientPeg.get().getRoomIdForAlias(roomString).done(function(result) {
|
||||||
|
self.setState({ready: true});
|
||||||
|
defer.resolve(result.room_id);
|
||||||
|
}, function() {
|
||||||
|
self.setState({ready: true});
|
||||||
|
defer.resolve(null);
|
||||||
|
});
|
||||||
|
this.setState({ready: false});
|
||||||
|
} else {
|
||||||
|
defer.resolve(roomString);
|
||||||
|
}
|
||||||
|
defer.promise.done(function(roomId) {
|
||||||
dis.dispatch({
|
dis.dispatch({
|
||||||
action: 'view_room',
|
action: 'view_room',
|
||||||
room_id: roomId
|
room_id: roomId
|
||||||
});
|
});
|
||||||
|
});
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue