From e92ac6715241eaf94063fb36b3325ffcb56e7f42 Mon Sep 17 00:00:00 2001 From: Simon Merrick Date: Sat, 28 Nov 2020 21:50:51 +1300 Subject: [PATCH 1/4] Use room alias in generated permalink for rooms Signed-off-by: Simon Merrick --- src/utils/permalinks/Permalinks.js | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/utils/permalinks/Permalinks.js b/src/utils/permalinks/Permalinks.js index 0f54bcce05..2f673e0346 100644 --- a/src/utils/permalinks/Permalinks.js +++ b/src/utils/permalinks/Permalinks.js @@ -130,7 +130,13 @@ export class RoomPermalinkCreator { } forRoom() { - return getPermalinkConstructor().forRoom(this._roomId, this._serverCandidates); + try { + // Prefer to use canonical alias for permalink if possible + const alias = this._room.getCanonicalAlias(); + return getPermalinkConstructor().forRoom(alias, this._serverCandidates); + } catch (error) { + return getPermalinkConstructor().forRoom(this._roomId, this._serverCandidates); + } } onRoomState(event) { From cf8c98e07665ec8f68846a5524b566d980c22e90 Mon Sep 17 00:00:00 2001 From: Simon Merrick Date: Wed, 2 Dec 2020 12:34:43 +1300 Subject: [PATCH 2/4] More explicit reference checking --- src/utils/permalinks/Permalinks.js | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/utils/permalinks/Permalinks.js b/src/utils/permalinks/Permalinks.js index 2f673e0346..2c38a982d3 100644 --- a/src/utils/permalinks/Permalinks.js +++ b/src/utils/permalinks/Permalinks.js @@ -130,13 +130,14 @@ export class RoomPermalinkCreator { } forRoom() { - try { + if (this._room) { // Prefer to use canonical alias for permalink if possible const alias = this._room.getCanonicalAlias(); - return getPermalinkConstructor().forRoom(alias, this._serverCandidates); - } catch (error) { - return getPermalinkConstructor().forRoom(this._roomId, this._serverCandidates); + if (alias) { + return getPermalinkConstructor().forRoom(alias, this._serverCandidates); + } } + return getPermalinkConstructor().forRoom(this._roomId, this._serverCandidates); } onRoomState(event) { From 6670c727a4adc4e177284d1fdc46a343fd6452d1 Mon Sep 17 00:00:00 2001 From: Simon Merrick Date: Wed, 2 Dec 2020 13:28:35 +1300 Subject: [PATCH 3/4] Add getCanonicalAlias to mock --- test/utils/permalinks/Permalinks-test.js | 1 + 1 file changed, 1 insertion(+) 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: { From 5544ee6408cd4cbefff75fa88ab550ceebfcc4c7 Mon Sep 17 00:00:00 2001 From: Simon Merrick Date: Sun, 6 Dec 2020 23:29:11 +1300 Subject: [PATCH 4/4] extract alias handling to separate function --- src/components/views/dialogs/ShareDialog.tsx | 2 +- src/utils/permalinks/Permalinks.js | 6 +++++- 2 files changed, 6 insertions(+), 2 deletions(-) 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 2c38a982d3..39c5776852 100644 --- a/src/utils/permalinks/Permalinks.js +++ b/src/utils/permalinks/Permalinks.js @@ -129,7 +129,7 @@ export class RoomPermalinkCreator { return getPermalinkConstructor().forEvent(this._roomId, eventId, this._serverCandidates); } - forRoom() { + forShareableRoom() { if (this._room) { // Prefer to use canonical alias for permalink if possible const alias = this._room.getCanonicalAlias(); @@ -140,6 +140,10 @@ export class RoomPermalinkCreator { return getPermalinkConstructor().forRoom(this._roomId, this._serverCandidates); } + forRoom() { + return getPermalinkConstructor().forRoom(this._roomId, this._serverCandidates); + } + onRoomState(event) { switch (event.getType()) { case "m.room.server_acl":