Add option to unban user in profile viewer
Signed-off-by: Ajay Bura <ajbura@gmail.com>
This commit is contained in:
parent
0e17c57856
commit
090ada5807
2 changed files with 24 additions and 7 deletions
|
@ -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}
|
||||
|
|
|
@ -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,
|
||||
};
|
||||
|
|
Loading…
Reference in a new issue