Merge pull request #35 from lub/groups

Groups
This commit is contained in:
Matthew Hodgson 2017-11-16 12:48:26 +00:00 committed by GitHub
commit 539e4ef81d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -26,6 +26,7 @@ var linkable_clients = [
room_id_url(id) { return "https://riot.im/app/#/room/" + id }, room_id_url(id) { return "https://riot.im/app/#/room/" + id },
user_url(userId) { return "https://riot.im/app/#/user/" + userId }, user_url(userId) { return "https://riot.im/app/#/user/" + userId },
msg_url(msg) { return "https://riot.im/app/#/room/" + msg }, msg_url(msg) { return "https://riot.im/app/#/room/" + msg },
group_url(group) { return "https://riot.im/app/#/group/" + group },
maturity: "Stable", maturity: "Stable",
comments: "Fully-featured Matrix client for Web, iOS & Android", comments: "Fully-featured Matrix client for Web, iOS & Android",
}, },
@ -143,10 +144,10 @@ export default React.createClass({
return; 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({ this.setState({
entity: entity, entity: entity,
error: "Invalid room alias, user ID or message permalink '" + entity + "'", error: "Invalid room alias, user ID, message permalink or group '" + entity + "'",
}); });
return; return;
} }
@ -175,8 +176,8 @@ export default React.createClass({
ev.preventDefault(); ev.preventDefault();
var entity = this.refs.prompt.value.trim(); var entity = this.refs.prompt.value.trim();
if (!this.isAliasValid(entity) && !this.isUserIdValid(entity)) { if (!this.isAliasValid(entity) && !this.isUserIdValid(entity) && !this.isGroupValid(entity)) {
this.setState({ error: "Invalid room alias or user ID" }); this.setState({ error: "Invalid room alias, user ID or group" });
return; return;
} }
var loc = window.location; var loc = window.location;
@ -212,6 +213,12 @@ export default React.createClass({
return (msglink.match(/^[\!#]([^\/:]+?):(.+?)\/\$([^\/:]+?):(.+?)$/) && encodeURI(msglink) === msglink); return (msglink.match(/^[\!#]([^\/:]+?):(.+?)\/\$([^\/:]+?):(.+?)$/) && encodeURI(msglink) === msglink);
}, },
isGroupValid(group) {
console.log(group);
console.log(encodeURI(group));
return (group.match(/^\+([^\/:]+?):(.+)$/) && encodeURI(group) === group);
},
render() { render() {
var error; var error;
if (this.state.error) { if (this.state.error) {
@ -226,6 +233,7 @@ export default React.createClass({
var isRoomId = this.isRoomIdValid(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);
var isGroup = this.isGroupValid(this.state.entity);
var links; var links;
@ -248,6 +256,9 @@ export default React.createClass({
else if (isMsg) { else if (isMsg) {
description = <span><b>this message</b></span>; description = <span><b>this message</b></span>;
} }
else if (isGroup) {
description = <span>the <b>{ this.state.entity }</b> group</span>;
}
links = ( links = (
<div key="links" className="mxt_HomePage_links"> <div key="links" className="mxt_HomePage_links">
@ -294,6 +305,9 @@ export default React.createClass({
else if (isMsg && client.msg_url) { else if (isMsg && client.msg_url) {
link = client.msg_url(this.state.entity); link = client.msg_url(this.state.entity);
} }
else if (isGroup && client.group_url) {
link = client.group_url(this.state.entity);
}
if (!link) return null; if (!link) return null;
return ( return (
@ -333,6 +347,9 @@ export default React.createClass({
else if (isMsg && client.msg_instructions) { else if (isMsg && client.msg_instructions) {
instructions = client.msg_instructions(this.state.entity); instructions = client.msg_instructions(this.state.entity);
} }
else if (isGroup && client.group_instructions) {
instructions = client.group_instructions(this.state.entity);
}
if (!instructions) return null; if (!instructions) return null;
return ( return (
@ -381,7 +398,7 @@ export default React.createClass({
prompt = [ prompt = [
<div key="inputBox" className="mxt_HomePage_inputBox"> <div key="inputBox" className="mxt_HomePage_inputBox">
<form onSubmit={ this.onSubmit }> <form onSubmit={ this.onSubmit }>
<input autoFocus className="mxt_HomePage_inputBox_prompt" value={ this.state.entity } ref="prompt" size="36" type="text" placeholder="#room:domain.com or @user:domain.com" /> <input autoFocus className="mxt_HomePage_inputBox_prompt" value={ this.state.entity } ref="prompt" size="36" type="text" placeholder="#room:example.com, @user:example.com or +group:example.com" />
<input className="mxt_HomePage_inputBox_button" type="submit" value="Get link!" /> <input className="mxt_HomePage_inputBox_button" type="submit" value="Get link!" />
</form> </form>
{ error } { error }