/* * Vencord, a modification for Discord's desktop app * Copyright (c) 2023 Vendicated and contributors * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ import ErrorBoundary from "@components/ErrorBoundary"; import { Flex } from "@components/Flex"; import { InfoIcon, OwnerCrownIcon } from "@components/Icons"; import { ModalCloseButton, ModalContent, ModalHeader, ModalProps, ModalRoot, ModalSize, openModal } from "@utils/modal"; import { ContextMenu, FluxDispatcher, GuildMemberStore, Menu, PermissionsBits, Text, Tooltip, useEffect, UserStore, useState, useStateFromStores } from "@webpack/common"; import type { Guild } from "discord-types/general"; import { cl, getPermissionDescription, getPermissionString } from "../utils"; import { PermissionAllowedIcon, PermissionDefaultIcon, PermissionDeniedIcon } from "./icons"; export const enum PermissionType { Role = 0, User = 1, Owner = 2 } export interface RoleOrUserPermission { type: PermissionType; id?: string; permissions?: bigint; overwriteAllow?: bigint; overwriteDeny?: bigint; } function openRolesAndUsersPermissionsModal(permissions: Array, guild: Guild, header: string) { return openModal(modalProps => ( )); } function RolesAndUsersPermissionsComponent({ permissions, guild, modalProps, header }: { permissions: Array; guild: Guild; modalProps: ModalProps; header: string; }) { permissions.sort((a, b) => a.type - b.type); useStateFromStores( [GuildMemberStore], () => GuildMemberStore.getMemberIds(guild.id), null, (old, current) => old.length === current.length ); useEffect(() => { const usersToRequest = permissions .filter(p => p.type === PermissionType.User && !GuildMemberStore.isMember(guild.id, p.id!)) .map(({ id }) => id); FluxDispatcher.dispatch({ type: "GUILD_MEMBERS_REQUEST", guildIds: [guild.id], userIds: usersToRequest }); }, []); const [selectedItemIndex, selectItem] = useState(0); const selectedItem = permissions[selectedItemIndex]; return ( {header} permissions: {!selectedItem && (
No permissions to display!
)} {selectedItem && (
{permissions.map((permission, index) => { const user = UserStore.getUser(permission.id ?? ""); const role = guild.roles[permission.id ?? ""]; return ( ); })}
{Object.entries(PermissionsBits).map(([permissionName, bit]) => (
{(() => { const { permissions, overwriteAllow, overwriteDeny } = selectedItem; if (permissions) return (permissions & bit) === bit ? PermissionAllowedIcon() : PermissionDeniedIcon(); if (overwriteAllow && (overwriteAllow & bit) === bit) return PermissionAllowedIcon(); if (overwriteDeny && (overwriteDeny & bit) === bit) return PermissionDeniedIcon(); return PermissionDefaultIcon(); })()}
{getPermissionString(permissionName)} {props => }
))}
)}
); } function RoleContextMenu({ guild, roleId, onClose }: { guild: Guild; roleId: string; onClose: () => void; }) { return ( { const role = guild.roles[roleId]; if (!role) return; onClose(); FluxDispatcher.dispatch({ type: "IMPERSONATE_UPDATE", guildId: guild.id, data: { type: "ROLES", roles: { [roleId]: role } } }); }} /> ); } const RolesAndUsersPermissions = ErrorBoundary.wrap(RolesAndUsersPermissionsComponent); export default openRolesAndUsersPermissionsModal;