Add option to unban user in profile viewer
authorAjay Bura <ajbura@gmail.com>
Thu, 13 Jan 2022 04:58:33 +0000 (10:28 +0530)
committerAjay Bura <ajbura@gmail.com>
Thu, 13 Jan 2022 04:58:33 +0000 (10:28 +0530)
Signed-off-by: Ajay Bura <ajbura@gmail.com>
src/app/organisms/profile-viewer/ProfileViewer.jsx
src/client/action/room.js

index 9c064844413760498c3c9d8def16a733c1e59bcc..320cf2cfc065a9169eca37685e1a2ffd3c2b3534 100644 (file)
@@ -163,6 +163,8 @@ function ProfileFooter({ roomId, userId, onRequestClose }) {
   const userPL = room.getMember(userId)?.powerLevel || 0;
   const canIKick = room.currentState.hasSufficientPowerLevelFor('kick', myPowerlevel) && userPL < myPowerlevel;
 
+  const isBanned = member?.membership === 'ban';
+
   const onCreated = (dmRoomId) => {
     if (isMountedRef.current === false) return;
     setIsCreatingDM(false);
@@ -184,7 +186,7 @@ function ProfileFooter({ roomId, userId, onRequestClose }) {
     setIsInviting(false);
   }, [userId]);
 
-  async function openDM() {
+  const openDM = async () => {
     const directIds = [...initMatrix.roomList.directs];
 
     // Check and open if user already have a DM with userId.
@@ -210,9 +212,9 @@ function ProfileFooter({ roomId, userId, onRequestClose }) {
       if (isMountedRef.current === false) return;
       setIsCreatingDM(false);
     }
-  }
+  };
 
-  async function toggleIgnore() {
+  const toggleIgnore = async () => {
     const ignoredUsers = mx.getIgnoredUsers();
     const uIndex = ignoredUsers.indexOf(userId);
     if (uIndex >= 0) {
@@ -230,9 +232,9 @@ function ProfileFooter({ roomId, userId, onRequestClose }) {
     } catch {
       setIsIgnoring(false);
     }
-  }
+  };
 
-  async function toggleInvite() {
+  const toggleInvite = async () => {
     try {
       setIsInviting(true);
       let isInviteSent = false;
@@ -247,7 +249,7 @@ function ProfileFooter({ roomId, userId, onRequestClose }) {
     } catch {
       setIsInviting(false);
     }
-  }
+  };
 
   return (
     <div className="profile-viewer__buttons">
@@ -258,6 +260,14 @@ function ProfileFooter({ roomId, userId, onRequestClose }) {
       >
         {isCreatingDM ? 'Creating room...' : 'Message'}
       </Button>
+      { isBanned && canIKick && (
+        <Button
+          variant="positive"
+          onClick={() => roomActions.unban(roomId, userId)}
+        >
+          Unban
+        </Button>
+      )}
       { (isInvited ? canIKick : room.canInvite(mx.getUserId())) && isInvitable && (
         <Button
           onClick={toggleInvite}
index 59839da4e1fe57423043663ce56cf29546081cfc..9849b2e0f342306c823eb81744540ec71a594591 100644 (file)
@@ -206,6 +206,13 @@ async function ban(roomId, userId, reason) {
   return result;
 }
 
+async function unban(roomId, userId) {
+  const mx = initMatrix.matrixClient;
+
+  const result = await mx.unban(roomId, userId);
+  return result;
+}
+
 async function setPowerLevel(roomId, userId, powerLevel) {
   const mx = initMatrix.matrixClient;
   const room = mx.getRoom(roomId);
@@ -232,7 +239,7 @@ function deleteSpaceShortcut(roomId) {
 
 export {
   join, leave,
-  create, invite, kick, ban,
+  create, invite, kick, ban, unban,
   setPowerLevel,
   createSpaceShortcut, deleteSpaceShortcut,
 };