Skip to content
This repository has been archived by the owner on Sep 11, 2024. It is now read-only.

Commit

Permalink
Merge pull request #698 from matrix-org/dbkr/add_unban_button
Browse files Browse the repository at this point in the history
Add a button to un-ban users in RoomSettings
  • Loading branch information
richvdh authored Feb 17, 2017
2 parents cc11b3e + 8698d40 commit 97722af
Showing 1 changed file with 57 additions and 4 deletions.
61 changes: 57 additions & 4 deletions src/components/views/rooms/RoomSettings.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/*
Copyright 2015, 2016 OpenMarket Ltd
Copyright 2017 Vector Creations Ltd
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -35,6 +36,47 @@ function parseIntWithDefault(val, def) {
return isNaN(res) ? def : res;
}

const BannedUser = React.createClass({
propTypes: {
member: React.PropTypes.object.isRequired, // js-sdk RoomMember
},

_onUnbanClick: function() {
const ConfirmUserActionDialog = sdk.getComponent("dialogs.ConfirmUserActionDialog");
Modal.createDialog(ConfirmUserActionDialog, {
member: this.props.member,
action: 'Unban',
danger: false,
onFinished: (proceed) => {
if (!proceed) return;

MatrixClientPeg.get().unban(
this.props.member.roomId, this.props.member.userId,
).catch((err) => {
const ErrorDialog = sdk.getComponent("dialogs.ErrorDialog");
Modal.createDialog(ErrorDialog, {
title: "Failed to unban",
description: err.message,
});
}).done();
},
});
},

render: function() {
return (
<li>
<AccessibleButton className="mx_RoomSettings_unbanButton"
onClick={this._onUnbanClick}
>
Unban
</AccessibleButton>
{this.props.member.userId}
</li>
);
}
});

module.exports = React.createClass({
displayName: 'RoomSettings',

Expand Down Expand Up @@ -74,6 +116,9 @@ module.exports = React.createClass({

componentWillMount: function() {
ScalarMessaging.startListening();

MatrixClientPeg.get().on("RoomMember.membership", this._onRoomMemberMembership);

MatrixClientPeg.get().getRoomDirectoryVisibility(
this.props.room.roomId
).done((result) => {
Expand Down Expand Up @@ -102,6 +147,11 @@ module.exports = React.createClass({
componentWillUnmount: function() {
ScalarMessaging.stopListening();

const cli = MatrixClientPeg.get();
if (cli) {
cli.removeListener("RoomMember.membership", this._onRoomMemberMembership);
}

dis.dispatch({
action: 'ui_opacity',
sideOpacity: 1.0,
Expand Down Expand Up @@ -501,6 +551,11 @@ module.exports = React.createClass({
});
},

_onRoomMemberMembership: function() {
// Update, since our banned user list may have changed
this.forceUpdate();
},

_renderEncryptionSection: function() {
var cli = MatrixClientPeg.get();
var roomState = this.props.room.currentState;
Expand Down Expand Up @@ -611,11 +666,9 @@ module.exports = React.createClass({
<div>
<h3>Banned users</h3>
<ul className="mx_RoomSettings_banned">
{banned.map(function(member, i) {
{banned.map(function(member) {
return (
<li key={i}>
{member.userId}
</li>
<BannedUser key={member.userId} member={member} />
);
})}
</ul>
Expand Down

0 comments on commit 97722af

Please sign in to comment.