From b9574ff38224426cc902a49fa382615ef56777ae Mon Sep 17 00:00:00 2001 From: David Baker Date: Thu, 19 Oct 2017 16:47:43 +0100 Subject: [PATCH 1/2] Group create dialog: only enter localpart Since we currently can only create groups on the local server anyway, there's no point making the user jump through the hoop of forming the whole group ID and telling them off if they got the server name wrong. --- .../views/dialogs/CreateGroupDialog.js | 46 +++---------------- src/i18n/strings/en_EN.json | 2 +- 2 files changed, 8 insertions(+), 40 deletions(-) diff --git a/src/components/views/dialogs/CreateGroupDialog.js b/src/components/views/dialogs/CreateGroupDialog.js index a0b8f84130..3fc7ee9350 100644 --- a/src/components/views/dialogs/CreateGroupDialog.js +++ b/src/components/views/dialogs/CreateGroupDialog.js @@ -58,26 +58,9 @@ export default React.createClass({ }, _checkGroupId: function(e) { - const parsedGroupId = this._parseGroupId(this.state.groupId); let error = null; - if (parsedGroupId === null) { - error = _t( - "Community IDs must be of the form +localpart:%(domain)s", - {domain: MatrixClientPeg.get().getDomain()}, - ); - } else { - const groupId = parsedGroupId[0]; - const domain = parsedGroupId[1]; - - if (!/^[a-zA-Z0-9]*$/.test(groupId)) { - error = _t("Community IDs may only contain alphanumeric characters"); - } else if (domain !== MatrixClientPeg.get().getDomain()) { - error = _t( - "It is currently only possible to create communities on your own home server: "+ - "use a community ID ending with %(domain)s", - {domain: MatrixClientPeg.get().getDomain()}, - ); - } + if (!/^[a-zA-Z0-9]*$/.test(this.state.groupId)) { + error = _t("Community IDs may only contain alphanumeric characters"); } this.setState({ groupIdError: error, @@ -90,14 +73,13 @@ export default React.createClass({ if (this._checkGroupId()) return; - const parsedGroupId = this._parseGroupId(this.state.groupId); const profile = {}; if (this.state.groupName !== '') { profile.name = this.state.groupName; } this.setState({creating: true}); MatrixClientPeg.get().createGroup({ - localpart: parsedGroupId[0], + localpart: this.state.groupId, profile: profile, }).then((result) => { dis.dispatch({ @@ -116,22 +98,6 @@ export default React.createClass({ this.props.onFinished(false); }, - /** - * Parse a string that may be a group ID - * If the string is a valid group ID, return a list of [localpart, domain], - * otherwise return null. - * - * @param {string} groupId The ID of the group - * @return {string[]} array of localpart, domain - */ - _parseGroupId: function(groupId) { - const matches = GROUP_REGEX.exec(this.state.groupId); - if (!matches || matches.length < 3) { - return null; - } - return [matches[1], matches[2]]; - }, - render: function() { const BaseDialog = sdk.getComponent('views.dialogs.BaseDialog'); const Spinner = sdk.getComponent('elements.Spinner'); @@ -176,13 +142,15 @@ export default React.createClass({
+ + + :{MatrixClientPeg.get().getDomain()}
diff --git a/src/i18n/strings/en_EN.json b/src/i18n/strings/en_EN.json index 3b48ebefaa..d64cc9c5ce 100644 --- a/src/i18n/strings/en_EN.json +++ b/src/i18n/strings/en_EN.json @@ -590,7 +590,7 @@ "Community Name": "Community Name", "Example": "Example", "Community ID": "Community ID", - "+example:%(domain)s": "+example:%(domain)s", + "example": "example", "Create": "Create", "Create Room": "Create Room", "Room name (optional)": "Room name (optional)", From cbb36f47807b3bdbb5b20dabd6c46a5de5ed70ff Mon Sep 17 00:00:00 2001 From: David Baker Date: Thu, 19 Oct 2017 17:31:06 +0100 Subject: [PATCH 2/2] Lint --- src/components/views/dialogs/CreateGroupDialog.js | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/src/components/views/dialogs/CreateGroupDialog.js b/src/components/views/dialogs/CreateGroupDialog.js index 3fc7ee9350..ed143358e9 100644 --- a/src/components/views/dialogs/CreateGroupDialog.js +++ b/src/components/views/dialogs/CreateGroupDialog.js @@ -21,10 +21,6 @@ import dis from '../../../dispatcher'; import { _t } from '../../../languageHandler'; import MatrixClientPeg from '../../../MatrixClientPeg'; -// We match fairly liberally and leave it up to the server to reject if -// there are invalid characters etc. -const GROUP_REGEX = /^\+(.*?):(.*)$/; - export default React.createClass({ displayName: 'CreateGroupDialog', propTypes: { @@ -150,7 +146,7 @@ export default React.createClass({ onBlur={this._onGroupIdBlur} value={this.state.groupId} /> - :{MatrixClientPeg.get().getDomain()} + :{ MatrixClientPeg.get().getDomain() }