Only show UI for adding rooms/users to groups to privileged users

pull/5409/head
Luke Barnard 2017-10-24 10:38:40 +01:00
parent 8672939f0c
commit f1a700ef99
1 changed files with 15 additions and 8 deletions

View File

@ -21,11 +21,12 @@ import PropTypes from 'prop-types';
import { _t } from 'matrix-react-sdk/lib/languageHandler';
import sdk from 'matrix-react-sdk';
import dis from 'matrix-react-sdk/lib/dispatcher';
import MatrixClientPeg from 'matrix-react-sdk/lib/MatrixClientPeg';
import MatrixClient from 'matrix-js-sdk';
import Analytics from 'matrix-react-sdk/lib/Analytics';
import rate_limited_func from 'matrix-react-sdk/lib/ratelimitedfunc';
import AccessibleButton from 'matrix-react-sdk/lib/components/views/elements/AccessibleButton';
import { showGroupInviteDialog, showGroupAddRoomDialog } from 'matrix-react-sdk/lib/GroupAddressPicker';
import GroupStoreCache from 'matrix-react-sdk/lib/stores/GroupStoreCache';
class HeaderButton extends React.Component {
constructor() {
@ -80,6 +81,10 @@ module.exports = React.createClass({
collapsed: React.PropTypes.bool, // currently unused property to request for a minimized view of the panel
},
contextTypes: {
matrixClient: PropTypes.instanceOf(MatrixClient),
},
Phase: {
RoomMemberList: 'RoomMemberList',
GroupMemberList: 'GroupMemberList',
@ -92,14 +97,14 @@ module.exports = React.createClass({
componentWillMount: function() {
this.dispatcherRef = dis.register(this.onAction);
const cli = MatrixClientPeg.get();
const cli = this.context.matrixClient;
cli.on("RoomState.members", this.onRoomStateMember);
},
componentWillUnmount: function() {
dis.unregister(this.dispatcherRef);
if (MatrixClientPeg.get()) {
MatrixClientPeg.get().removeListener("RoomState.members", this.onRoomStateMember);
if (this.context.matrixClient) {
this.context.matrixClient.removeListener("RoomState.members", this.onRoomStateMember);
}
},
@ -122,7 +127,7 @@ module.exports = React.createClass({
},
onInviteButtonClick: function() {
if (MatrixClientPeg.get().isGuest()) {
if (this.context.matrixClient.isGuest()) {
dis.dispatch({action: 'view_set_mxid'});
return;
}
@ -222,13 +227,13 @@ module.exports = React.createClass({
if ((this.state.phase == this.Phase.RoomMemberList || this.state.phase === this.Phase.RoomMemberInfo)
&& this.props.roomId
) {
const cli = MatrixClientPeg.get();
const cli = this.context.matrixClient;
const room = cli.getRoom(this.props.roomId);
let userIsInRoom;
if (room) {
membersBadge = room.getJoinedMembers().length;
userIsInRoom = room.hasMembershipState(
MatrixClientPeg.get().credentials.userId, 'join',
this.context.matrixClient.credentials.userId, 'join',
);
}
@ -317,7 +322,9 @@ module.exports = React.createClass({
panel = <div className="mx_RightPanel_blank"></div>;
}
if (this.props.groupId) {
if (this.props.groupId &&
GroupStoreCache.getGroupStore(this.context.matrixClient, this.props.groupId).isUserPrivileged()
) {
inviteGroup = this.state.phase === this.Phase.GroupMemberList ? (
<AccessibleButton className="mx_RightPanel_invite" onClick={ this.onInviteButtonClick } >
<div className="mx_RightPanel_icon" >