Add option to ban user in profile viewer
Signed-off-by: Ajay Bura <ajbura@gmail.com>
This commit is contained in:
parent
248fc15716
commit
a1d9c21337
2 changed files with 29 additions and 7 deletions
|
@ -44,6 +44,11 @@ function ModerationTools({
|
||||||
&& room.currentState.hasSufficientPowerLevelFor('kick', myPowerLevel)
|
&& room.currentState.hasSufficientPowerLevelFor('kick', myPowerLevel)
|
||||||
&& powerLevel < myPowerLevel
|
&& powerLevel < myPowerLevel
|
||||||
);
|
);
|
||||||
|
const canIBan = (
|
||||||
|
['join', 'leave'].includes(roomMember?.membership)
|
||||||
|
&& room.currentState.hasSufficientPowerLevelFor('ban', myPowerLevel)
|
||||||
|
&& powerLevel < myPowerLevel
|
||||||
|
);
|
||||||
|
|
||||||
const handleKick = (e) => {
|
const handleKick = (e) => {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
|
@ -51,15 +56,25 @@ function ModerationTools({
|
||||||
roomActions.kick(roomId, userId, kickReason !== '' ? kickReason : undefined);
|
roomActions.kick(roomId, userId, kickReason !== '' ? kickReason : undefined);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const handleBan = (e) => {
|
||||||
|
e.preventDefault();
|
||||||
|
const banReason = e.target.elements['ban-reason']?.value.trim();
|
||||||
|
roomActions.ban(roomId, userId, banReason !== '' ? banReason : undefined);
|
||||||
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="moderation-tools">
|
<div className="moderation-tools">
|
||||||
{canIKick && (
|
{canIKick && (
|
||||||
<>
|
<form onSubmit={handleKick}>
|
||||||
<form onSubmit={handleKick}>
|
<Input label="Kick reason" name="kick-reason" />
|
||||||
<Input label="Kick reason" name="kick-reason" />
|
<Button type="submit">Kick</Button>
|
||||||
<Button type="submit">Kick</Button>
|
</form>
|
||||||
</form>
|
)}
|
||||||
</>
|
{canIBan && (
|
||||||
|
<form onSubmit={handleBan}>
|
||||||
|
<Input label="Ban reason" name="ban-reason" />
|
||||||
|
<Button type="submit">Ban</Button>
|
||||||
|
</form>
|
||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
|
|
|
@ -199,6 +199,13 @@ async function kick(roomId, userId, reason) {
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async function ban(roomId, userId, reason) {
|
||||||
|
const mx = initMatrix.matrixClient;
|
||||||
|
|
||||||
|
const result = await mx.ban(roomId, userId, reason);
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
async function setPowerLevel(roomId, userId, powerLevel) {
|
async function setPowerLevel(roomId, userId, powerLevel) {
|
||||||
const mx = initMatrix.matrixClient;
|
const mx = initMatrix.matrixClient;
|
||||||
const room = mx.getRoom(roomId);
|
const room = mx.getRoom(roomId);
|
||||||
|
@ -225,7 +232,7 @@ function deleteSpaceShortcut(roomId) {
|
||||||
|
|
||||||
export {
|
export {
|
||||||
join, leave,
|
join, leave,
|
||||||
create, invite, kick,
|
create, invite, kick, ban,
|
||||||
setPowerLevel,
|
setPowerLevel,
|
||||||
createSpaceShortcut, deleteSpaceShortcut,
|
createSpaceShortcut, deleteSpaceShortcut,
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in a new issue