diff --git a/src/components/views/dialogs/ShareDialog.tsx b/src/components/views/dialogs/ShareDialog.tsx index 1569977d58..5264031cc6 100644 --- a/src/components/views/dialogs/ShareDialog.tsx +++ b/src/components/views/dialogs/ShareDialog.tsx @@ -146,7 +146,7 @@ export default class ShareDialog extends React.PureComponent { const events = this.props.target.getLiveTimeline().getEvents(); matrixToUrl = this.state.permalinkCreator.forEvent(events[events.length - 1].getId()); } else { - matrixToUrl = this.state.permalinkCreator.forRoom(); + matrixToUrl = this.state.permalinkCreator.forShareableRoom(); } } else if (this.props.target instanceof User || this.props.target instanceof RoomMember) { matrixToUrl = makeUserPermalink(this.props.target.userId); diff --git a/src/utils/permalinks/Permalinks.js b/src/utils/permalinks/Permalinks.js index 0f54bcce05..39c5776852 100644 --- a/src/utils/permalinks/Permalinks.js +++ b/src/utils/permalinks/Permalinks.js @@ -129,6 +129,17 @@ export class RoomPermalinkCreator { return getPermalinkConstructor().forEvent(this._roomId, eventId, this._serverCandidates); } + forShareableRoom() { + if (this._room) { + // Prefer to use canonical alias for permalink if possible + const alias = this._room.getCanonicalAlias(); + if (alias) { + return getPermalinkConstructor().forRoom(alias, this._serverCandidates); + } + } + return getPermalinkConstructor().forRoom(this._roomId, this._serverCandidates); + } + forRoom() { return getPermalinkConstructor().forRoom(this._roomId, this._serverCandidates); } diff --git a/test/utils/permalinks/Permalinks-test.js b/test/utils/permalinks/Permalinks-test.js index 72cd66cb69..0bd4466d97 100644 --- a/test/utils/permalinks/Permalinks-test.js +++ b/test/utils/permalinks/Permalinks-test.js @@ -34,6 +34,7 @@ function mockRoom(roomId, members, serverACL) { return { roomId, + getCanonicalAlias: () => roomId, getJoinedMembers: () => members, getMember: (userId) => members.find(m => m.userId === userId), currentState: {