Use the first alias is there's no canonical alias

pull/21833/head
David Baker 2016-06-17 16:56:34 +01:00
parent 3b5378fa53
commit 6adce649eb
2 changed files with 9 additions and 16 deletions

View File

@ -16,21 +16,13 @@ limitations under the License.
module.exports = {
/**
* Given a room object, return the canonical alias for it
* if there is one. Otherwise return null;
* Given a room object, return the alias we should use for it,
* if any. This could be the canonical alias if one exists, otherwise
* an alias selected arbitrarily but deterministically from the list
* of aliases. Otherwise return null;
*/
getCanonicalAliasForRoom: function(room) {
var aliasEvents = room.currentState.getStateEvents(
"m.room.aliases"
);
// Canonical aliases aren't implemented yet, so just return the first
for (var j = 0; j < aliasEvents.length; j++) {
var aliases = aliasEvents[j].getContent().aliases;
if (aliases && aliases.length) {
return aliases[0];
}
}
return null;
getDisplayAliasForRoom: function(room) {
return room.getCanonicalAlias() || room.getAliases()[0];
},
/**

View File

@ -33,6 +33,7 @@ var PostRegistration = require("./login/PostRegistration");
var Modal = require("../../Modal");
var Tinter = require("../../Tinter");
var sdk = require('../../index');
var MatrixTools = require('../../MatrixTools');
var linkifyMatrix = require("../../linkify-matrix");
var KeyCode = require('../../KeyCode');
@ -538,7 +539,7 @@ module.exports = React.createClass({
var presentedId = roomAlias || roomId;
var room = MatrixClientPeg.get().getRoom(roomId);
if (room) {
var theAlias = room.getCanonicalAlias();
var theAlias = MatrixTools.getDisplayAliasForRoom(room);
if (theAlias) presentedId = theAlias;
// No need to do this given RoomView triggers it itself...
@ -630,7 +631,7 @@ module.exports = React.createClass({
var presentedId = self.state.currentRoomId;
var room = MatrixClientPeg.get().getRoom(self.state.currentRoomId);
if (room) {
var theAlias = room.getCanonicalAlias();
var theAlias = MatrixTools.getDisplayAliasForRoom(room);
if (theAlias) presentedId = theAlias;
}