mirror of
https://github.com/tulir/gomuks.git
synced 2025-04-20 10:33:41 -05:00
Add powerlevel checks
This commit is contained in:
parent
dcd2cec667
commit
8a1534df5a
1 changed files with 18 additions and 5 deletions
|
@ -23,6 +23,7 @@ import ConfirmWithMessageModal from "@/ui/timeline/menu/ConfirmWithMessageModal.
|
||||||
import Gavel from "@/icons/gavel.svg?react"
|
import Gavel from "@/icons/gavel.svg?react"
|
||||||
import PersonAdd from "@/icons/person-add.svg?react"
|
import PersonAdd from "@/icons/person-add.svg?react"
|
||||||
import PersonRemove from "@/icons/person-remove.svg?react"
|
import PersonRemove from "@/icons/person-remove.svg?react"
|
||||||
|
import { getPowerLevels } from "@/ui/timeline/menu/util.ts";
|
||||||
|
|
||||||
interface UserModerationProps {
|
interface UserModerationProps {
|
||||||
userID: string;
|
userID: string;
|
||||||
|
@ -33,7 +34,19 @@ interface UserModerationProps {
|
||||||
|
|
||||||
const UserModeration = ({ userID, client, member }: UserModerationProps) => {
|
const UserModeration = ({ userID, client, member }: UserModerationProps) => {
|
||||||
const roomCtx = use(RoomContext)
|
const roomCtx = use(RoomContext)
|
||||||
|
if(!roomCtx) {
|
||||||
|
return null // There is no room context, moderation is not an applicable context.
|
||||||
|
}
|
||||||
const openModal = use(ModalContext)
|
const openModal = use(ModalContext)
|
||||||
|
const hasPl = (action: "invite" | "kick" | "ban") => {
|
||||||
|
const [pls, ownPL] = getPowerLevels(roomCtx.store, client)
|
||||||
|
const actionPL = pls[action] ?? pls.state_default ?? 50
|
||||||
|
const otherUserPl = pls.users?.[userID] ?? pls.users_default ?? 0
|
||||||
|
if(action === "invite") {
|
||||||
|
return ownPL >= actionPL // no need to check otherUserPl
|
||||||
|
}
|
||||||
|
return ownPL >= actionPL && ownPL > otherUserPl
|
||||||
|
}
|
||||||
|
|
||||||
const runAction = (mode: Membership) => {
|
const runAction = (mode: Membership) => {
|
||||||
const callback = (reason: string) => {
|
const callback = (reason: string) => {
|
||||||
|
@ -81,31 +94,31 @@ const UserModeration = ({ userID, client, member }: UserModerationProps) => {
|
||||||
<div className="user-moderation">
|
<div className="user-moderation">
|
||||||
<h4>Moderation</h4>
|
<h4>Moderation</h4>
|
||||||
<div className="moderation-actions">
|
<div className="moderation-actions">
|
||||||
{(["knock", "leave"].includes(membership) || !member) && (
|
{(["knock", "leave"].includes(membership) || !member) && hasPl("invite") && (
|
||||||
<button className="moderation-action invite" onClick={runAction("invite")}>
|
<button className="moderation-action invite" onClick={runAction("invite")}>
|
||||||
<PersonAdd />
|
<PersonAdd />
|
||||||
<span>{membership === "knock" ? "Accept request to join" : "Invite"}</span>
|
<span>{membership === "knock" ? "Accept request to join" : "Invite"}</span>
|
||||||
</button>
|
</button>
|
||||||
)}
|
)}
|
||||||
{["knock", "invite"].includes(membership) && (
|
{["knock", "invite"].includes(membership) && hasPl("kick") && (
|
||||||
<button className="moderation-action dangerous" onClick={runAction("leave")}>
|
<button className="moderation-action dangerous" onClick={runAction("leave")}>
|
||||||
<PersonRemove />
|
<PersonRemove />
|
||||||
<span>{membership === "invite" ? "Revoke invitation" : "Reject join request"}</span>
|
<span>{membership === "invite" ? "Revoke invitation" : "Reject join request"}</span>
|
||||||
</button>
|
</button>
|
||||||
)}
|
)}
|
||||||
{membership === "join" && (
|
{membership === "join" && hasPl("kick") && (
|
||||||
<button className="moderation-action dangerous" onClick={runAction("leave")}>
|
<button className="moderation-action dangerous" onClick={runAction("leave")}>
|
||||||
<PersonRemove />
|
<PersonRemove />
|
||||||
<span>Kick</span>
|
<span>Kick</span>
|
||||||
</button>
|
</button>
|
||||||
)}
|
)}
|
||||||
{membership !== "ban" && (
|
{membership !== "ban" && hasPl("ban") && (
|
||||||
<button className="moderation-action dangerous" onClick={runAction("ban")}>
|
<button className="moderation-action dangerous" onClick={runAction("ban")}>
|
||||||
<Gavel />
|
<Gavel />
|
||||||
<span>Ban</span>
|
<span>Ban</span>
|
||||||
</button>
|
</button>
|
||||||
)}
|
)}
|
||||||
{membership === "ban" && (
|
{membership === "ban" && hasPl("ban") && (
|
||||||
<button className="moderation-action invite" onClick={runAction("leave")}>
|
<button className="moderation-action invite" onClick={runAction("leave")}>
|
||||||
<Gavel />
|
<Gavel />
|
||||||
<span>Unban</span>
|
<span>Unban</span>
|
||||||
|
|
Loading…
Add table
Reference in a new issue