From a1d9c213375a5cfa71a9a549124c4278ff16d168 Mon Sep 17 00:00:00 2001 From: Ajay Bura Date: Wed, 12 Jan 2022 18:50:54 +0530 Subject: [PATCH] Add option to ban user in profile viewer Signed-off-by: Ajay Bura --- .../profile-viewer/ProfileViewer.jsx | 27 ++++++++++++++----- src/client/action/room.js | 9 ++++++- 2 files changed, 29 insertions(+), 7 deletions(-) diff --git a/src/app/organisms/profile-viewer/ProfileViewer.jsx b/src/app/organisms/profile-viewer/ProfileViewer.jsx index e6b3a83..6eb370d 100644 --- a/src/app/organisms/profile-viewer/ProfileViewer.jsx +++ b/src/app/organisms/profile-viewer/ProfileViewer.jsx @@ -44,6 +44,11 @@ function ModerationTools({ && room.currentState.hasSufficientPowerLevelFor('kick', myPowerLevel) && powerLevel < myPowerLevel ); + const canIBan = ( + ['join', 'leave'].includes(roomMember?.membership) + && room.currentState.hasSufficientPowerLevelFor('ban', myPowerLevel) + && powerLevel < myPowerLevel + ); const handleKick = (e) => { e.preventDefault(); @@ -51,15 +56,25 @@ function ModerationTools({ 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 (
{canIKick && ( - <> -
- - -
- +
+ + +
+ )} + {canIBan && ( +
+ + +
)}
); diff --git a/src/client/action/room.js b/src/client/action/room.js index 8d67afd..59839da 100644 --- a/src/client/action/room.js +++ b/src/client/action/room.js @@ -199,6 +199,13 @@ async function kick(roomId, userId, reason) { 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) { const mx = initMatrix.matrixClient; const room = mx.getRoom(roomId); @@ -225,7 +232,7 @@ function deleteSpaceShortcut(roomId) { export { join, leave, - create, invite, kick, + create, invite, kick, ban, setPowerLevel, createSpaceShortcut, deleteSpaceShortcut, };