Merge pull request #46 from matrix-org/kegan/ops-level-update

Recalculate levels when the member prop is updated.
pull/21833/head
Kegsay 2015-12-04 16:27:56 +00:00
commit ae615b5c5e
1 changed files with 9 additions and 4 deletions

View File

@ -43,11 +43,16 @@ module.exports = React.createClass({
componentDidMount: function() { componentDidMount: function() {
// work out the current state // work out the current state
if (this.props.member) { if (this.props.member) {
var memberState = this._calculateOpsPermissions(); var memberState = this._calculateOpsPermissions(this.props.member);
this.setState(memberState); this.setState(memberState);
} }
}, },
componentWillReceiveProps: function(newProps) {
var memberState = this._calculateOpsPermissions(newProps.member);
this.setState(memberState);
},
onKick: function() { onKick: function() {
var ErrorDialog = sdk.getComponent("dialogs.ErrorDialog"); var ErrorDialog = sdk.getComponent("dialogs.ErrorDialog");
var roomId = this.props.member.roomId; var roomId = this.props.member.roomId;
@ -269,13 +274,13 @@ module.exports = React.createClass({
} }
}, },
_calculateOpsPermissions: function() { _calculateOpsPermissions: function(member) {
var defaultPerms = { var defaultPerms = {
can: {}, can: {},
muted: false, muted: false,
modifyLevel: false modifyLevel: false
}; };
var room = MatrixClientPeg.get().getRoom(this.props.member.roomId); var room = MatrixClientPeg.get().getRoom(member.roomId);
if (!room) { if (!room) {
return defaultPerms; return defaultPerms;
} }
@ -286,7 +291,7 @@ module.exports = React.createClass({
return defaultPerms; return defaultPerms;
} }
var me = room.getMember(MatrixClientPeg.get().credentials.userId); var me = room.getMember(MatrixClientPeg.get().credentials.userId);
var them = this.props.member; var them = member;
return { return {
can: this._calculateCanPermissions( can: this._calculateCanPermissions(
me, them, powerLevels.getContent() me, them, powerLevels.getContent()