Support Room ID links
Fixes https://github.com/vector-im/vector-web/issues/1658
This commit is contained in:
parent
63f679961e
commit
c903de8ba9
@ -29,6 +29,7 @@ The matrix.to URL scheme is:
|
|||||||
| Entity type: | Example URL |
|
| Entity type: | Example URL |
|
||||||
|--------------|-------------------------------------------------------------------|
|
|--------------|-------------------------------------------------------------------|
|
||||||
| Rooms: | https://matrix.to/#/#matrix:matrix.org |
|
| Rooms: | https://matrix.to/#/#matrix:matrix.org |
|
||||||
|
| Rooms by ID: | https://matrix.to/#/!cURbafjkfsMDVwdRDQ:matrix.org |
|
||||||
| Users: | https://matrix.to/#/@matthew:matrix.org |
|
| Users: | https://matrix.to/#/@matthew:matrix.org |
|
||||||
| Messages: | https://matrix.to/#/#matrix:matrix.org/$1448831580433WbpiJ:jki.re |
|
| 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
|
server hosting matrix.to. https://matrix.to/@matthew:matrix.org works too, and
|
||||||
provides better legibility at the expense of privacy.
|
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
|
(Technically the # and @ in the URL fragment should probably be escaped, but in
|
||||||
practice for legibility we bend the rules and include it verbatim)
|
practice for legibility we bend the rules and include it verbatim)
|
||||||
|
@ -23,6 +23,7 @@ var linkable_clients = [
|
|||||||
author: "Vector.im",
|
author: "Vector.im",
|
||||||
homepage: "https://vector.im",
|
homepage: "https://vector.im",
|
||||||
room_url(alias) { return "https://vector.im/beta/#/room/" + alias },
|
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 },
|
user_url(userId) { return "https://vector.im/beta/#/user/" + userId },
|
||||||
msg_url(msg) { return "https://vector.im/beta/#/room/" + msg },
|
msg_url(msg) { return "https://vector.im/beta/#/room/" + msg },
|
||||||
maturity: "Late beta",
|
maturity: "Late beta",
|
||||||
@ -34,6 +35,7 @@ var linkable_clients = [
|
|||||||
author: "Matrix.org",
|
author: "Matrix.org",
|
||||||
homepage: "https://matrix.org",
|
homepage: "https://matrix.org",
|
||||||
room_url(alias) { return "https://matrix.org/beta/#/room/" + alias },
|
room_url(alias) { return "https://matrix.org/beta/#/room/" + alias },
|
||||||
|
room_id_url(id) { return "https://matrix.org/beta/#/room/" + id },
|
||||||
maturity: "Deprecated",
|
maturity: "Deprecated",
|
||||||
comments: "The original developer-focused client for Web, iOS & Android",
|
comments: "The original developer-focused client for Web, iOS & Android",
|
||||||
},
|
},
|
||||||
@ -122,7 +124,7 @@ export default React.createClass({
|
|||||||
return;
|
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({
|
this.setState({
|
||||||
entity: entity,
|
entity: entity,
|
||||||
error: "Invalid room alias, user ID or message permalink '" + 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);
|
return (alias.match(/^#([^\/:]+?):(.+)$/) && encodeURI(alias) === alias);
|
||||||
},
|
},
|
||||||
|
|
||||||
|
isRoomIdValid(id) {
|
||||||
|
// XXX: FIXME SPEC-1
|
||||||
|
return (id.match(/^!([^\/:]+?):(.+)$/) && encodeURI(id) === id);
|
||||||
|
},
|
||||||
|
|
||||||
isUserIdValid(userId) {
|
isUserIdValid(userId) {
|
||||||
// XXX: FIXME SPEC-1
|
// XXX: FIXME SPEC-1
|
||||||
return (userId.match(/^@([^\/:]+?):(.+)$/) && encodeURI(userId) === userId);
|
return (userId.match(/^@([^\/:]+?):(.+)$/) && encodeURI(userId) === userId);
|
||||||
@ -197,6 +204,7 @@ export default React.createClass({
|
|||||||
var link = "https://matrix.to/#/" + this.state.entity;
|
var link = "https://matrix.to/#/" + this.state.entity;
|
||||||
|
|
||||||
var isRoom = this.isAliasValid(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 isUser = this.isUserIdValid(this.state.entity);
|
||||||
var isMsg = this.isMsglinkValid(this.state.entity);
|
var isMsg = this.isMsglinkValid(this.state.entity);
|
||||||
|
|
||||||
@ -258,6 +266,9 @@ export default React.createClass({
|
|||||||
if (isRoom && client.room_url) {
|
if (isRoom && client.room_url) {
|
||||||
link = client.room_url(this.state.entity);
|
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) {
|
else if (isUser && client.user_url) {
|
||||||
link = client.user_url(this.state.entity);
|
link = client.user_url(this.state.entity);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user