diff --git a/src/components/contextMenus/UserContextMenu.tsx b/src/components/contextMenus/UserContextMenu.tsx index 6c8eea4..95eacdb 100644 --- a/src/components/contextMenus/UserContextMenu.tsx +++ b/src/components/contextMenus/UserContextMenu.tsx @@ -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) { Add Friend Block - {member && ( + {member && guildMe && ( <> - - Kick {member?.nick ?? user.username} - - - Ban {member?.nick ?? user.username} - - - - Roles - - + {guildMe.hasPermission("KICK_MEMBERS") && ( + + Kick {member?.nick ?? user.username} + + )} + {guildMe.hasPermission("BAN_MEMBERS") && ( + <> + + Ban {member?.nick ?? user.username} + + + + )} + {guildMe.hasPermission("MANAGE_ROLES") && ( + <> + + Roles + + + + )} )} diff --git a/src/stores/objects/GuildMember.ts b/src/stores/objects/GuildMember.ts index c0add6f..ac89fb3 100644 --- a/src/stores/objects/GuildMember.ts +++ b/src/stores/objects/GuildMember.ts @@ -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); + } }