Skip to content

Commit 2771907

Browse files
committed
Support room aliases in url bar and show them for rooms that have them
1 parent 68d408b commit 2771907

3 files changed

Lines changed: 39 additions & 6 deletions

File tree

‎examples/vector/index.js‎

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ var React = require("react");
2424
// maps cannot pass through two stages).
2525
var MatrixReactSdk = require("../../src/index");
2626

27+
var lastLocationHashSet = null;
28+
2729
// Here, we do some crude URL analysis to allow
2830
// deep-linking. We only support registration
2931
// deep-links in this example.
@@ -46,6 +48,10 @@ function routeUrl(location) {
4648
}
4749

4850
function onHashChange(ev) {
51+
if (decodeURIComponent(window.location.hash) == lastLocationHashSet) {
52+
// we just set this: no need to route it!
53+
return;
54+
}
4955
routeUrl(window.location);
5056
}
5157

@@ -55,7 +61,9 @@ var loaded = false;
5561
// so a web page can update the URL bar appropriately.
5662
var onNewScreen = function(screen) {
5763
if (!loaded) return;
58-
window.location.hash = '#/'+screen;
64+
var hash = '#/' + screen;
65+
lastLocationHashSet = hash;
66+
window.location.hash = hash;
5967
}
6068

6169
// We use this to work out what URL the SDK should

‎src/controllers/organisms/RoomView.js‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,7 @@ module.exports = {
202202

203203
fillSpace: function() {
204204
var messageWrapper = this.refs.messageWrapper.getDOMNode();
205+
if (!messageWrapper) return;
205206
if (messageWrapper.scrollTop < messageWrapper.clientHeight && this.state.room.oldState.paginationToken) {
206207
this.setState({paginating: true});
207208

‎src/controllers/pages/MatrixChat.js‎

Lines changed: 29 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,11 @@ var MatrixClientPeg = require("../../MatrixClientPeg");
2323
var RoomListSorter = require("../../RoomListSorter");
2424
var Presence = require("../../Presence");
2525
var dis = require("../../dispatcher");
26+
var q = require("q");
2627

2728
var ComponentBroker = require('../../ComponentBroker');
2829
var Notifier = ComponentBroker.get('organisms/Notifier');
30+
var MatrixTools = require('../../MatrixTools');
2931

3032
module.exports = {
3133
PageTypes: {
@@ -136,7 +138,13 @@ module.exports = {
136138
currentRoom: payload.room_id,
137139
page_type: this.PageTypes.RoomView,
138140
});
139-
this.notifyNewScreen('room/'+payload.room_id);
141+
var presentedId = payload.room_id;
142+
var room = MatrixClientPeg.get().getRoom(payload.room_id);
143+
if (room) {
144+
var theAlias = MatrixTools.getCanonicalAliasForRoom(room);
145+
if (theAlias) presentedId = theAlias;
146+
}
147+
this.notifyNewScreen('room/'+presentedId);
140148
break;
141149
case 'view_prev_room':
142150
roomIndexDelta = -1;
@@ -249,10 +257,26 @@ module.exports = {
249257
params: params
250258
});
251259
} else if (screen.indexOf('room/') == 0) {
252-
var roomId = screen.split('/')[1];
253-
dis.dispatch({
254-
action: 'view_room',
255-
room_id: roomId
260+
var roomString = screen.split('/')[1];
261+
var defer = q.defer();
262+
if (roomString[0] == '#') {
263+
var self = this;
264+
MatrixClientPeg.get().getRoomIdForAlias(roomString).done(function(result) {
265+
self.setState({ready: true});
266+
defer.resolve(result.room_id);
267+
}, function() {
268+
self.setState({ready: true});
269+
defer.resolve(null);
270+
});
271+
this.setState({ready: false});
272+
} else {
273+
defer.resolve(roomString);
274+
}
275+
defer.promise.done(function(roomId) {
276+
dis.dispatch({
277+
action: 'view_room',
278+
room_id: roomId
279+
});
256280
});
257281
}
258282
},

0 commit comments

Comments
 (0)