From 64c3e1878884b35a3cf7be8e883356c65d063b8c Mon Sep 17 00:00:00 2001 From: Cadence Ember Date: Wed, 21 Oct 2020 22:10:58 +1300 Subject: [PATCH] Don't break on rooms with a redacted name --- src/js/room-picker.js | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/src/js/room-picker.js b/src/js/room-picker.js index 9fbbece..d2e79fa 100644 --- a/src/js/room-picker.js +++ b/src/js/room-picker.js @@ -94,15 +94,20 @@ class Room extends ElemJS { } getName() { + // if the room has a name let name = this.data.state.events.find(e => e.type === "m.room.name") - if (name) { - name = name.content.name - } else { - const users = this.data.summary["m.heroes"] - const usernames = users.map(u => (u.match(/^@([^:]+):/) || [])[1] || u) - name = usernames.join(", ") + if (name && name.content.name) { + return name.content.name } - return name + // if the room has no name, use its canonical alias + let canonicalAlias = this.data.state.events.find(e => e.type === "m.room.canonical_alias") + if (canonicalAlias && canonicalAlias.content.alias) { + return canonicalAlias.content.alias + } + // if the room has no alias, use the names of its members ("heroes") + const users = this.data.summary["m.heroes"] + const usernames = users.map(u => (u.match(/^@([^:]+):/) || [])[1] || u) + return usernames.join(", ") } getIcon() {