From 3b5378fa53a5a1f83820e59d36ad55d24046c49d Mon Sep 17 00:00:00 2001 From: David Baker Date: Fri, 17 Jun 2016 15:17:45 +0100 Subject: [PATCH 1/2] Show canonical alias in URL bar Use https://github.com/matrix-org/matrix-js-sdk/pull/140 to get the canonical alias, because that's a thing now. --- src/components/structures/MatrixChat.js | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/components/structures/MatrixChat.js b/src/components/structures/MatrixChat.js index 9899f66cc5..9fd15f2d2f 100644 --- a/src/components/structures/MatrixChat.js +++ b/src/components/structures/MatrixChat.js @@ -33,7 +33,6 @@ 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'); @@ -539,7 +538,7 @@ module.exports = React.createClass({ var presentedId = roomAlias || roomId; var room = MatrixClientPeg.get().getRoom(roomId); if (room) { - var theAlias = MatrixTools.getCanonicalAliasForRoom(room); + var theAlias = room.getCanonicalAlias(); if (theAlias) presentedId = theAlias; // No need to do this given RoomView triggers it itself... @@ -631,7 +630,7 @@ module.exports = React.createClass({ var presentedId = self.state.currentRoomId; var room = MatrixClientPeg.get().getRoom(self.state.currentRoomId); if (room) { - var theAlias = MatrixTools.getCanonicalAliasForRoom(room); + var theAlias = room.getCanonicalAlias(); if (theAlias) presentedId = theAlias; } From 6adce649ebe7672c376de3aa6163d4a2b37d5f28 Mon Sep 17 00:00:00 2001 From: David Baker Date: Fri, 17 Jun 2016 16:56:34 +0100 Subject: [PATCH 2/2] Use the first alias is there's no canonical alias --- src/MatrixTools.js | 20 ++++++-------------- src/components/structures/MatrixChat.js | 5 +++-- 2 files changed, 9 insertions(+), 16 deletions(-) diff --git a/src/MatrixTools.js b/src/MatrixTools.js index 7fded4adea..372f17f69c 100644 --- a/src/MatrixTools.js +++ b/src/MatrixTools.js @@ -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]; }, /** diff --git a/src/components/structures/MatrixChat.js b/src/components/structures/MatrixChat.js index 9fd15f2d2f..1973fedbcd 100644 --- a/src/components/structures/MatrixChat.js +++ b/src/components/structures/MatrixChat.js @@ -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; }