Skip to content

Commit

Permalink
Do not fail to bridge if a canonical alias doesn't exist
Browse files Browse the repository at this point in the history
  • Loading branch information
Half-Shot committed Oct 1, 2020
1 parent 643967f commit f98ae42
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions src/BaseSlackHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -171,11 +171,14 @@ export abstract class BaseSlackHandler {
// If we bridge the room, attempt to look up its canonical alias.
if (room !== undefined) {
const client = this.main.botIntent.getClient();
const canonical = await client.getStateEvent(room.MatrixRoomId, "m.room.canonical_alias");
if (canonical !== undefined && canonical.alias !== undefined) {
text = text.slice(0, match.index) + canonical.alias + text.slice(match.index + match[0].length);
} else {
try {
const canonical = await client.getStateEvent(room.MatrixRoomId, "m.room.canonical_alias");
if (canonical !== undefined && canonical.alias !== undefined) {
text = text.slice(0, match.index) + canonical.alias + text.slice(match.index + match[0].length);
}
} catch (ex) {
// If we can't find a canonical alias fall back to just the Slack channel name.
log.debug(`Room ${room.MatrixRoomId} does not have a canonical alias set.`);
room = undefined;
}
}
Expand Down

0 comments on commit f98ae42

Please sign in to comment.