@@ -691,6 +691,20 @@ export default React.createClass({
691
691
} ) ;
692
692
} ,
693
693
694
+ _onJoinClick : function ( ) {
695
+ this . setState ( { membershipBusy : true } ) ;
696
+ this . _matrixClient . joinGroup ( this . props . groupId ) . then ( ( ) => {
697
+ // don't reset membershipBusy here: wait for the membership change to come down the sync
698
+ } ) . catch ( ( e ) => {
699
+ this . setState ( { membershipBusy : false } ) ;
700
+ const ErrorDialog = sdk . getComponent ( "dialogs.ErrorDialog" ) ;
701
+ Modal . createTrackedDialog ( 'Error joining room' , '' , ErrorDialog , {
702
+ title : _t ( "Error" ) ,
703
+ description : _t ( "Unable to join community" ) ,
704
+ } ) ;
705
+ } ) ;
706
+ } ,
707
+
694
708
_onLeaveClick : function ( ) {
695
709
const QuestionDialog = sdk . getComponent ( "dialogs.QuestionDialog" ) ;
696
710
Modal . createTrackedDialog ( 'Leave Group' , '' , QuestionDialog , {
@@ -707,9 +721,9 @@ export default React.createClass({
707
721
} ) . catch ( ( e ) => {
708
722
this . setState ( { membershipBusy : false } ) ;
709
723
const ErrorDialog = sdk . getComponent ( "dialogs.ErrorDialog" ) ;
710
- Modal . createTrackedDialog ( 'Error leaving room ' , '' , ErrorDialog , {
724
+ Modal . createTrackedDialog ( 'Error leaving community ' , '' , ErrorDialog , {
711
725
title : _t ( "Error" ) ,
712
- description : _t ( "Unable to leave room " ) ,
726
+ description : _t ( "Unable to leave community " ) ,
713
727
} ) ;
714
728
} ) ;
715
729
} ,
@@ -875,9 +889,8 @@ export default React.createClass({
875
889
const BaseAvatar = sdk . getComponent ( "avatars.BaseAvatar" ) ;
876
890
877
891
const group = this . _matrixClient . getGroup ( this . props . groupId ) ;
878
- if ( ! group ) return null ;
879
892
880
- if ( group . myMembership === 'invite' ) {
893
+ if ( group && group . myMembership === 'invite' ) {
881
894
if ( this . state . membershipBusy || this . state . inviterProfileBusy ) {
882
895
return < div className = "mx_GroupView_membershipSection" >
883
896
< Spinner />
@@ -918,33 +931,72 @@ export default React.createClass({
918
931
</ div >
919
932
</ div >
920
933
</ div > ;
921
- } else if ( group . myMembership === 'join' && this . state . editing ) {
922
- const leaveButtonTooltip = this . state . isUserPrivileged ?
934
+ }
935
+
936
+ let membershipContainerExtraClasses ;
937
+ let membershipButtonExtraClasses ;
938
+ let membershipButtonTooltip ;
939
+ let membershipButtonText ;
940
+ let membershipButtonOnClick ;
941
+
942
+ // User is not in the group
943
+ if ( ( ! group || group . myMembership === 'leave' ) &&
944
+ this . state . summary &&
945
+ this . state . summary . profile &&
946
+ Boolean ( this . state . summary . profile . is_joinable )
947
+ ) {
948
+ membershipButtonText = _t ( "Join this community" ) ;
949
+ membershipButtonOnClick = this . _onJoinClick ;
950
+
951
+ membershipButtonExtraClasses = 'mx_GroupView_joinButton' ;
952
+ membershipContainerExtraClasses = 'mx_GroupView_membershipSection_leave' ;
953
+ } else if (
954
+ group &&
955
+ group . myMembership === 'join' &&
956
+ this . state . editing
957
+ ) {
958
+ membershipButtonText = _t ( "Leave this community" ) ;
959
+ membershipButtonOnClick = this . _onLeaveClick ;
960
+ membershipButtonTooltip = this . state . isUserPrivileged ?
923
961
_t ( "You are an administrator of this community" ) :
924
962
_t ( "You are a member of this community" ) ;
925
- const leaveButtonClasses = classnames ( {
926
- "mx_RoomHeader_textButton" : true ,
927
- "mx_GroupView_textButton" : true ,
928
- "mx_GroupView_leaveButton" : true ,
929
- "mx_RoomHeader_textButton_danger" : this . state . isUserPrivileged ,
930
- } ) ;
931
- return < div className = "mx_GroupView_membershipSection mx_GroupView_membershipSection_joined" >
932
- < div className = "mx_GroupView_membershipSubSection" >
933
- { /* Empty div for flex alignment */ }
934
- < div />
935
- < div className = "mx_GroupView_membership_buttonContainer" >
936
- < AccessibleButton
937
- className = { leaveButtonClasses }
938
- onClick = { this . _onLeaveClick }
939
- title = { leaveButtonTooltip }
940
- >
941
- { _t ( "Leave" ) }
942
- </ AccessibleButton >
943
- </ div >
944
- </ div >
945
- </ div > ;
963
+
964
+ membershipButtonExtraClasses = {
965
+ 'mx_GroupView_leaveButton' : true ,
966
+ 'mx_RoomHeader_textButton_danger' : this . state . isUserPrivileged ,
967
+ } ;
968
+ membershipContainerExtraClasses = 'mx_GroupView_membershipSection_joined' ;
969
+ } else {
970
+ return null ;
946
971
}
947
- return null ;
972
+
973
+ const membershipButtonClasses = classnames ( [
974
+ 'mx_RoomHeader_textButton' ,
975
+ 'mx_GroupView_textButton' ,
976
+ ] ,
977
+ membershipButtonExtraClasses ,
978
+ ) ;
979
+
980
+ const membershipContainerClasses = classnames (
981
+ 'mx_GroupView_membershipSection' ,
982
+ membershipContainerExtraClasses ,
983
+ ) ;
984
+
985
+ return < div className = { membershipContainerClasses } >
986
+ < div className = "mx_GroupView_membershipSubSection" >
987
+ { /* Empty div for flex alignment */ }
988
+ < div />
989
+ < div className = "mx_GroupView_membership_buttonContainer" >
990
+ < AccessibleButton
991
+ className = { membershipButtonClasses }
992
+ onClick = { membershipButtonOnClick }
993
+ title = { membershipButtonTooltip }
994
+ >
995
+ { membershipButtonText }
996
+ </ AccessibleButton >
997
+ </ div >
998
+ </ div >
999
+ </ div > ;
948
1000
} ,
949
1001
950
1002
_getJoinableNode : function ( ) {
0 commit comments