Merge pull request #5409 from vector-im/luke/fix-privileged-group-ui-1

Only show UI for adding rooms/users to groups to privileged users
This commit is contained in:
Luke Barnard 2017-10-24 11:19:30 +01:00 committed by GitHub
commit 1704a2fb9c

View File

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