From 568ebebd34ff10303cd54bc3320751c65829ed83 Mon Sep 17 00:00:00 2001 From: lub Date: Thu, 16 Nov 2017 12:59:59 +0100 Subject: [PATCH] add support for groups --- src/components/HomePage.js | 27 ++++++++++++++++++++++----- 1 file changed, 22 insertions(+), 5 deletions(-) diff --git a/src/components/HomePage.js b/src/components/HomePage.js index 80c5fec..1c5f2de 100644 --- a/src/components/HomePage.js +++ b/src/components/HomePage.js @@ -26,6 +26,7 @@ var linkable_clients = [ room_id_url(id) { return "https://riot.im/app/#/room/" + id }, user_url(userId) { return "https://riot.im/app/#/user/" + userId }, msg_url(msg) { return "https://riot.im/app/#/room/" + msg }, + group_url(group) { return "https://riot.im/app/#/group/" + group }, maturity: "Stable", comments: "Fully-featured Matrix client for Web, iOS & Android", }, @@ -143,10 +144,10 @@ export default React.createClass({ return; } - if (!this.isAliasValid(entity) && !this.isUserIdValid(entity) && !this.isMsglinkValid(entity) && !this.isRoomIdValid(entity)) { + if (!this.isAliasValid(entity) && !this.isUserIdValid(entity) && !this.isMsglinkValid(entity) && !this.isRoomIdValid(entity) && !this.isGroupValid(entity)) { this.setState({ entity: entity, - error: "Invalid room alias, user ID or message permalink '" + entity + "'", + error: "Invalid room alias, user ID, message permalink or group '" + entity + "'", }); return; } @@ -175,8 +176,8 @@ export default React.createClass({ ev.preventDefault(); var entity = this.refs.prompt.value.trim(); - if (!this.isAliasValid(entity) && !this.isUserIdValid(entity)) { - this.setState({ error: "Invalid room alias or user ID" }); + if (!this.isAliasValid(entity) && !this.isUserIdValid(entity) && !this.isGroupValid(entity)) { + this.setState({ error: "Invalid room alias, user ID or group" }); return; } var loc = window.location; @@ -212,6 +213,12 @@ export default React.createClass({ return (msglink.match(/^[\!#]([^\/:]+?):(.+?)\/\$([^\/:]+?):(.+?)$/) && encodeURI(msglink) === msglink); }, + isGroupValid(group) { + console.log(group); + console.log(encodeURI(group)); + return (group.match(/^\+([^\/:]+?):(.+)$/) && encodeURI(group) === group); + }, + render() { var error; if (this.state.error) { @@ -226,6 +233,7 @@ export default React.createClass({ var isRoomId = this.isRoomIdValid(this.state.entity); var isUser = this.isUserIdValid(this.state.entity); var isMsg = this.isMsglinkValid(this.state.entity); + var isGroup = this.isGroupValid(this.state.entity); var links; @@ -248,6 +256,9 @@ export default React.createClass({ else if (isMsg) { description = this message; } + else if (isGroup) { + description = the { this.state.entity } group; + } links = (
@@ -294,6 +305,9 @@ export default React.createClass({ else if (isMsg && client.msg_url) { link = client.msg_url(this.state.entity); } + else if (isGroup && client.group_url) { + link = client.group_url(this.state.entity); + } if (!link) return null; return ( @@ -333,6 +347,9 @@ export default React.createClass({ else if (isMsg && client.msg_instructions) { instructions = client.msg_instructions(this.state.entity); } + else if (isGroup && client.group_instructions) { + instructions = client.group_instructions(this.state.entity); + } if (!instructions) return null; return ( @@ -381,7 +398,7 @@ export default React.createClass({ prompt = [
- +
{ error }