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