From 18fcb1d6a628b78c3f18cabed5cfb2a2c4972164 Mon Sep 17 00:00:00 2001 From: Luke Barnard Date: Thu, 29 Mar 2018 12:36:59 +0100 Subject: [PATCH] Implement "Join this community" button for groups that have truthy summary.profile.is_joinable. --- src/components/structures/GroupView.js | 108 ++++++++++++++++++------- 1 file changed, 80 insertions(+), 28 deletions(-) diff --git a/src/components/structures/GroupView.js b/src/components/structures/GroupView.js index 8a5d3d2025..14c6b4a0be 100644 --- a/src/components/structures/GroupView.js +++ b/src/components/structures/GroupView.js @@ -691,6 +691,20 @@ export default React.createClass({ }); }, + _onJoinClick: function() { + this.setState({membershipBusy: true}); + this._matrixClient.joinGroup(this.props.groupId).then(() => { + // don't reset membershipBusy here: wait for the membership change to come down the sync + }).catch((e) => { + this.setState({membershipBusy: false}); + const ErrorDialog = sdk.getComponent("dialogs.ErrorDialog"); + Modal.createTrackedDialog('Error joining room', '', ErrorDialog, { + title: _t("Error"), + description: _t("Unable to join community"), + }); + }); + }, + _onLeaveClick: function() { const QuestionDialog = sdk.getComponent("dialogs.QuestionDialog"); Modal.createTrackedDialog('Leave Group', '', QuestionDialog, { @@ -707,9 +721,9 @@ export default React.createClass({ }).catch((e) => { this.setState({membershipBusy: false}); const ErrorDialog = sdk.getComponent("dialogs.ErrorDialog"); - Modal.createTrackedDialog('Error leaving room', '', ErrorDialog, { + Modal.createTrackedDialog('Error leaving community', '', ErrorDialog, { title: _t("Error"), - description: _t("Unable to leave room"), + description: _t("Unable to leave community"), }); }); }, @@ -875,9 +889,8 @@ export default React.createClass({ const BaseAvatar = sdk.getComponent("avatars.BaseAvatar"); const group = this._matrixClient.getGroup(this.props.groupId); - if (!group) return null; - if (group.myMembership === 'invite') { + if (group && group.myMembership === 'invite') { if (this.state.membershipBusy || this.state.inviterProfileBusy) { return
@@ -918,33 +931,72 @@ export default React.createClass({
; - } else if (group.myMembership === 'join' && this.state.editing) { - const leaveButtonTooltip = this.state.isUserPrivileged ? + } + + let membershipContainerExtraClasses; + let membershipButtonExtraClasses; + let membershipButtonTooltip; + let membershipButtonText; + let membershipButtonOnClick; + + // User is not in the group + if ((!group || group.myMembership === 'leave') && + this.state.summary && + this.state.summary.profile && + Boolean(this.state.summary.profile.is_joinable) + ) { + membershipButtonText = _t("Join this community"); + membershipButtonOnClick = this._onJoinClick; + + membershipButtonExtraClasses = 'mx_GroupView_joinButton'; + membershipContainerExtraClasses = 'mx_GroupView_membershipSection_leave'; + } else if ( + group && + group.myMembership === 'join' && + this.state.editing + ) { + membershipButtonText = _t("Leave this community"); + membershipButtonOnClick = this._onLeaveClick; + membershipButtonTooltip = this.state.isUserPrivileged ? _t("You are an administrator of this community") : _t("You are a member of this community"); - const leaveButtonClasses = classnames({ - "mx_RoomHeader_textButton": true, - "mx_GroupView_textButton": true, - "mx_GroupView_leaveButton": true, - "mx_RoomHeader_textButton_danger": this.state.isUserPrivileged, - }); - return
-
- { /* Empty div for flex alignment */ } -
-
- - { _t("Leave") } - -
-
-
; + + membershipButtonExtraClasses = { + 'mx_GroupView_leaveButton': true, + 'mx_RoomHeader_textButton_danger': this.state.isUserPrivileged, + }; + membershipContainerExtraClasses = 'mx_GroupView_membershipSection_joined'; + } else { + return null; } - return null; + + const membershipButtonClasses = classnames([ + 'mx_RoomHeader_textButton', + 'mx_GroupView_textButton', + ], + membershipButtonExtraClasses, + ); + + const membershipContainerClasses = classnames( + 'mx_GroupView_membershipSection', + membershipContainerExtraClasses, + ); + + return
+
+ { /* Empty div for flex alignment */ } +
+
+ + { membershipButtonText } + +
+
+
; }, _getJoinableNode: function() {