From c903de8ba91a1866fc2929b17dcafd7efe4f846d Mon Sep 17 00:00:00 2001 From: David Baker Date: Tue, 21 Jun 2016 16:03:05 +0100 Subject: [PATCH] Support Room ID links Fixes https://github.com/vector-im/vector-web/issues/1658 --- README.md | 4 ++++ src/components/HomePage.js | 13 ++++++++++++- 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 99e4cf8..ebfca83 100644 --- a/README.md +++ b/README.md @@ -29,6 +29,7 @@ The matrix.to URL scheme is: | Entity type: | Example URL | |--------------|-------------------------------------------------------------------| | Rooms: | https://matrix.to/#/#matrix:matrix.org | +| Rooms by ID: | https://matrix.to/#/!cURbafjkfsMDVwdRDQ:matrix.org | | Users: | https://matrix.to/#/@matthew:matrix.org | | Messages: | https://matrix.to/#/#matrix:matrix.org/$1448831580433WbpiJ:jki.re | @@ -36,5 +37,8 @@ The #/ component is optional, and exists to avoid leaking the target URL to the server hosting matrix.to. https://matrix.to/@matthew:matrix.org works too, and provides better legibility at the expense of privacy. +Note that linking to rooms by ID should only be used for rooms to which the target +user has been invited: these links cannot be assumed to work for all visitors. + (Technically the # and @ in the URL fragment should probably be escaped, but in practice for legibility we bend the rules and include it verbatim) diff --git a/src/components/HomePage.js b/src/components/HomePage.js index e9d3db6..e17dfb8 100644 --- a/src/components/HomePage.js +++ b/src/components/HomePage.js @@ -23,6 +23,7 @@ var linkable_clients = [ author: "Vector.im", homepage: "https://vector.im", room_url(alias) { return "https://vector.im/beta/#/room/" + alias }, + room_id_url(id) { return "https://vector.im/beta/#/room/" + id }, user_url(userId) { return "https://vector.im/beta/#/user/" + userId }, msg_url(msg) { return "https://vector.im/beta/#/room/" + msg }, maturity: "Late beta", @@ -34,6 +35,7 @@ var linkable_clients = [ author: "Matrix.org", homepage: "https://matrix.org", room_url(alias) { return "https://matrix.org/beta/#/room/" + alias }, + room_id_url(id) { return "https://matrix.org/beta/#/room/" + id }, maturity: "Deprecated", comments: "The original developer-focused client for Web, iOS & Android", }, @@ -122,7 +124,7 @@ export default React.createClass({ return; } - if (!this.isAliasValid(entity) && !this.isUserIdValid(entity) && !this.isMsglinkValid(entity)) { + if (!this.isAliasValid(entity) && !this.isUserIdValid(entity) && !this.isMsglinkValid(entity) && !this.isRoomIdValid(entity)) { this.setState({ entity: entity, error: "Invalid room alias, user ID or message permalink '" + entity + "'", @@ -174,6 +176,11 @@ export default React.createClass({ return (alias.match(/^#([^\/:]+?):(.+)$/) && encodeURI(alias) === alias); }, + isRoomIdValid(id) { + // XXX: FIXME SPEC-1 + return (id.match(/^!([^\/:]+?):(.+)$/) && encodeURI(id) === id); + }, + isUserIdValid(userId) { // XXX: FIXME SPEC-1 return (userId.match(/^@([^\/:]+?):(.+)$/) && encodeURI(userId) === userId); @@ -197,6 +204,7 @@ export default React.createClass({ var link = "https://matrix.to/#/" + this.state.entity; var isRoom = this.isAliasValid(this.state.entity); + var isRoomId = this.isRoomIdValid(this.state.entity); var isUser = this.isUserIdValid(this.state.entity); var isMsg = this.isMsglinkValid(this.state.entity); @@ -258,6 +266,9 @@ export default React.createClass({ if (isRoom && client.room_url) { link = client.room_url(this.state.entity); } + else if (isRoomId && client.room_id_url) { + link = client.room_id_url(this.state.entity); + } else if (isUser && client.user_url) { link = client.user_url(this.state.entity); }