From 711bf583abee7617b919cd9f411e4dbda10af51e Mon Sep 17 00:00:00 2001 From: David Baker Date: Thu, 6 Aug 2015 16:04:22 +0100 Subject: [PATCH] missed a file --- src/MatrixTools.js | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 src/MatrixTools.js diff --git a/src/MatrixTools.js b/src/MatrixTools.js new file mode 100644 index 00000000..fa9f038b --- /dev/null +++ b/src/MatrixTools.js @@ -0,0 +1,22 @@ +var MatrixClientPeg = require('./MatrixClientPeg'); + +module.exports = { + /** + * Given a room object, return the canonical alias for it + * if there is one. 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; + } +} +