mirror of
https://github.com/spacebarchat/client.git
synced 2024-11-25 11:42:30 +01:00
fix kick,ban,roles context menu items being shown without permission
This commit is contained in:
parent
d6e89d5d88
commit
85bd86a6e6
@ -1,6 +1,7 @@
|
||||
// loosely based on https://github.com/revoltchat/frontend/blob/master/components/app/menus/UserContextMenu.tsx
|
||||
|
||||
import { modalController } from "../../controllers/modals";
|
||||
import { useAppStore } from "../../stores/AppStore";
|
||||
import GuildMember from "../../stores/objects/GuildMember";
|
||||
import User from "../../stores/objects/User";
|
||||
import { ContextMenu, ContextMenuButton, ContextMenuDivider } from "./ContextMenu";
|
||||
@ -11,6 +12,10 @@ interface MenuProps {
|
||||
}
|
||||
|
||||
function UserContextMenu({ user, member }: MenuProps) {
|
||||
const app = useAppStore();
|
||||
const guild = member ? app.guilds.get(member.guild.id) : undefined;
|
||||
const guildMe = guild ? guild.members.get(app.account!.id) : undefined;
|
||||
|
||||
/**
|
||||
* Copy user id to clipboard
|
||||
*/
|
||||
@ -50,19 +55,29 @@ function UserContextMenu({ user, member }: MenuProps) {
|
||||
<ContextMenuButton disabled>Add Friend</ContextMenuButton>
|
||||
<ContextMenuButton disabled>Block</ContextMenuButton>
|
||||
<ContextMenuDivider />
|
||||
{member && (
|
||||
{member && guildMe && (
|
||||
<>
|
||||
<ContextMenuButton destructive onClick={kick}>
|
||||
Kick {member?.nick ?? user.username}
|
||||
</ContextMenuButton>
|
||||
<ContextMenuButton destructive onClick={ban}>
|
||||
Ban {member?.nick ?? user.username}
|
||||
</ContextMenuButton>
|
||||
<ContextMenuDivider />
|
||||
<ContextMenuButton disabled icon="mdiChevronRight">
|
||||
Roles
|
||||
</ContextMenuButton>
|
||||
<ContextMenuDivider />
|
||||
{guildMe.hasPermission("KICK_MEMBERS") && (
|
||||
<ContextMenuButton destructive onClick={kick}>
|
||||
Kick {member?.nick ?? user.username}
|
||||
</ContextMenuButton>
|
||||
)}
|
||||
{guildMe.hasPermission("BAN_MEMBERS") && (
|
||||
<>
|
||||
<ContextMenuButton destructive onClick={ban}>
|
||||
Ban {member?.nick ?? user.username}
|
||||
</ContextMenuButton>
|
||||
<ContextMenuDivider />
|
||||
</>
|
||||
)}
|
||||
{guildMe.hasPermission("MANAGE_ROLES") && (
|
||||
<>
|
||||
<ContextMenuButton disabled icon="mdiChevronRight">
|
||||
Roles
|
||||
</ContextMenuButton>
|
||||
<ContextMenuDivider />
|
||||
</>
|
||||
)}
|
||||
</>
|
||||
)}
|
||||
|
||||
|
@ -4,6 +4,7 @@ import {
|
||||
GuildMemberFlags,
|
||||
} from "@spacebarchat/spacebar-api-types/v9";
|
||||
import { action, computed, observable } from "mobx";
|
||||
import { PermissionResolvable, Permissions } from "../../utils/Permissions";
|
||||
import AppStore from "../AppStore";
|
||||
import Guild from "./Guild";
|
||||
import Role from "./Role";
|
||||
@ -68,4 +69,9 @@ export default class GuildMember {
|
||||
async ban(reason?: string, deleteMessageSeconds?: number) {
|
||||
return this.guild.banMember(this.user!.id, reason, deleteMessageSeconds);
|
||||
}
|
||||
|
||||
hasPermission(permission: PermissionResolvable) {
|
||||
const permissions = Permissions.getPermission(this.app.account!.id, this.guild);
|
||||
return permissions.has(permission);
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user