Merge pull request #5 from matrix-org/dbkr/support_room_id_links

Support Room ID links
This commit is contained in:
Richard van der Hoff 2016-06-21 17:20:35 +01:00 committed by GitHub
commit 155a147571
2 changed files with 16 additions and 1 deletions

View file

@ -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)

View file

@ -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);
}