diff --git a/src/components/structures/GroupView.js b/src/components/structures/GroupView.js
index 2b5b3d5353..c8773296e5 100644
--- a/src/components/structures/GroupView.js
+++ b/src/components/structures/GroupView.js
@@ -670,6 +670,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, {
@@ -686,9 +700,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"),
});
});
},
@@ -853,9 +867,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
@@ -896,33 +909,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 */ }
-
-
-
-
;
+
+ 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 }
+
+
+
+
;
},
_getLongDescriptionNode: function() {