Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 2 commits into from Oct 24, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
23 changes: 15 additions & 8 deletions src/components/structures/RightPanel.js
Expand Up @@ -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() {
Expand Down Expand Up @@ -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',
Expand All @@ -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);
}
},

Expand All @@ -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;
}
Expand Down Expand Up @@ -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',
);
}

Expand Down Expand Up @@ -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.Phase.GroupMemberInfo,
this.Phase.GroupMemberList,
Expand Down