2023-05-14 21:33:04 -03:00
|
|
|
/*
|
|
|
|
|
* 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 <https://www.gnu.org/licenses/>.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
import { classNameFactory } from "@api/Styles";
|
2025-07-10 00:38:39 +02:00
|
|
|
import { Guild, GuildMember, Role } from "@vencord/discord-types";
|
2024-11-25 17:14:25 +13:00
|
|
|
import { findByPropsLazy } from "@webpack";
|
2025-06-27 21:36:31 +02:00
|
|
|
import { GuildRoleStore } from "@webpack/common";
|
2023-05-14 21:33:04 -03:00
|
|
|
|
|
|
|
|
import { PermissionsSortOrder, settings } from ".";
|
2023-05-19 21:24:56 -03:00
|
|
|
import { PermissionType } from "./components/RolesAndUsersPermissions";
|
2023-05-14 21:33:04 -03:00
|
|
|
|
2024-11-25 17:14:25 +13:00
|
|
|
export const { getGuildPermissionSpecMap } = findByPropsLazy("getGuildPermissionSpecMap");
|
2023-05-14 21:33:04 -03:00
|
|
|
|
2024-11-25 17:14:25 +13:00
|
|
|
export const cl = classNameFactory("vc-permviewer-");
|
2023-05-14 21:33:04 -03:00
|
|
|
|
2025-07-31 16:31:33 -04:00
|
|
|
export function getSortedRolesForMember({ id: guildId }: Guild, member: GuildMember) {
|
2025-08-05 23:57:51 +02:00
|
|
|
// The guild id is the @everyone role
|
2025-07-31 16:31:33 -04:00
|
|
|
return GuildRoleStore
|
|
|
|
|
.getSortedRoles(guildId)
|
|
|
|
|
.filter(role => role.id === guildId || member.roles.includes(role.id));
|
2023-05-14 21:33:04 -03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export function sortUserRoles(roles: Role[]) {
|
|
|
|
|
switch (settings.store.permissionsSortOrder) {
|
|
|
|
|
case PermissionsSortOrder.HighestRole:
|
|
|
|
|
return roles.sort((a, b) => b.position - a.position);
|
|
|
|
|
case PermissionsSortOrder.LowestRole:
|
|
|
|
|
return roles.sort((a, b) => a.position - b.position);
|
|
|
|
|
default:
|
|
|
|
|
return roles;
|
|
|
|
|
}
|
|
|
|
|
}
|
2023-05-19 21:24:56 -03:00
|
|
|
|
|
|
|
|
export function sortPermissionOverwrites<T extends { id: string; type: number; }>(overwrites: T[], guildId: string) {
|
2025-07-31 16:31:33 -04:00
|
|
|
const roles = GuildRoleStore.getRolesSnapshot(guildId);
|
2023-05-19 21:24:56 -03:00
|
|
|
|
|
|
|
|
return overwrites.sort((a, b) => {
|
|
|
|
|
if (a.type !== PermissionType.Role || b.type !== PermissionType.Role) return 0;
|
|
|
|
|
|
2024-03-11 16:13:07 +01:00
|
|
|
const roleA = roles[a.id];
|
|
|
|
|
const roleB = roles[b.id];
|
2023-05-19 21:24:56 -03:00
|
|
|
|
|
|
|
|
return roleB.position - roleA.position;
|
|
|
|
|
});
|
|
|
|
|
}
|