Fix SHC broken patches; Sort PermViewer channel overwrites roles (#1166)

This commit is contained in:
Nuckyz 2023-05-19 21:24:56 -03:00 committed by GitHub
parent 89a6c575c9
commit ec091a7959
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 26 additions and 11 deletions

@ -27,7 +27,7 @@ import type { Guild, GuildMember } from "discord-types/general";
import openRolesAndUsersPermissionsModal, { PermissionType, RoleOrUserPermission } from "./components/RolesAndUsersPermissions"; import openRolesAndUsersPermissionsModal, { PermissionType, RoleOrUserPermission } from "./components/RolesAndUsersPermissions";
import UserPermissions from "./components/UserPermissions"; import UserPermissions from "./components/UserPermissions";
import { getSortedRoles } from "./utils"; import { getSortedRoles, sortPermissionOverwrites } from "./utils";
export const enum PermissionsSortOrder { export const enum PermissionsSortOrder {
HighestRole, HighestRole,
@ -94,12 +94,12 @@ function MenuItem(guildId: string, id?: string, type?: MenuItemParentType) {
case MenuItemParentType.Channel: { case MenuItemParentType.Channel: {
const channel = ChannelStore.getChannel(id!); const channel = ChannelStore.getChannel(id!);
permissions = Object.values(channel.permissionOverwrites).map(({ id, allow, deny, type }) => ({ permissions = sortPermissionOverwrites(Object.values(channel.permissionOverwrites).map(({ id, allow, deny, type }) => ({
type: type as PermissionType, type: type as PermissionType,
id, id,
overwriteAllow: allow, overwriteAllow: allow,
overwriteDeny: deny overwriteDeny: deny
})); })), guildId);
header = channel.name; header = channel.name;

@ -18,11 +18,12 @@
import { classNameFactory } from "@api/Styles"; import { classNameFactory } from "@api/Styles";
import { wordsToTitle } from "@utils/text"; import { wordsToTitle } from "@utils/text";
import { i18n, Parser } from "@webpack/common"; import { GuildStore, i18n, Parser } from "@webpack/common";
import { Guild, GuildMember, Role } from "discord-types/general"; import { Guild, GuildMember, Role } from "discord-types/general";
import type { ReactNode } from "react"; import type { ReactNode } from "react";
import { PermissionsSortOrder, settings } from "."; import { PermissionsSortOrder, settings } from ".";
import { PermissionType } from "./components/RolesAndUsersPermissions";
export const cl = classNameFactory("vc-permviewer-"); export const cl = classNameFactory("vc-permviewer-");
@ -82,3 +83,16 @@ export function sortUserRoles(roles: Role[]) {
return roles; return roles;
} }
} }
export function sortPermissionOverwrites<T extends { id: string; type: number; }>(overwrites: T[], guildId: string) {
const guild = GuildStore.getGuild(guildId);
return overwrites.sort((a, b) => {
if (a.type !== PermissionType.Role || b.type !== PermissionType.Role) return 0;
const roleA = guild.roles[a.id];
const roleB = guild.roles[b.id];
return roleB.position - roleA.position;
});
}

@ -26,6 +26,7 @@ import type { Channel } from "discord-types/general";
import type { ComponentType } from "react"; import type { ComponentType } from "react";
import openRolesAndUsersPermissionsModal, { PermissionType, RoleOrUserPermission } from "../../permissionsViewer/components/RolesAndUsersPermissions"; import openRolesAndUsersPermissionsModal, { PermissionType, RoleOrUserPermission } from "../../permissionsViewer/components/RolesAndUsersPermissions";
import { sortPermissionOverwrites } from "../../permissionsViewer/utils";
import { settings, VIEW_CHANNEL } from ".."; import { settings, VIEW_CHANNEL } from "..";
enum SortOrderTypes { enum SortOrderTypes {
@ -169,12 +170,12 @@ function HiddenChannelLockScreen({ channel }: { channel: ExtendedChannel; }) {
} }
if (Settings.plugins.PermissionsViewer.enabled) { if (Settings.plugins.PermissionsViewer.enabled) {
setPermissions(Object.values(permissionOverwrites).map(overwrite => ({ setPermissions(sortPermissionOverwrites(Object.values(permissionOverwrites).map(overwrite => ({
type: overwrite.type as PermissionType, type: overwrite.type as PermissionType,
id: overwrite.id, id: overwrite.id,
overwriteAllow: overwrite.allow, overwriteAllow: overwrite.allow,
overwriteDeny: overwrite.deny overwriteDeny: overwrite.deny
}))); })), guild_id));
} }
}, [channelId]); }, [channelId]);

@ -107,13 +107,13 @@ export default definePlugin({
}, },
{ {
// Prevent Discord from trying to connect to hidden channels // Prevent Discord from trying to connect to hidden channels
match: /(?=\|\|\i\.default\.selectVoiceChannel\((\i)\.id\))/, match: /if\(!\i&&!\i(?=.{0,50}?selectVoiceChannel\((\i)\.id\))/,
replace: (_, channel) => `||$self.isHiddenChannel(${channel})` replace: (m, channel) => `${m}&&!$self.isHiddenChannel(${channel})`
}, },
{ {
// Make Discord show inside the channel if clicking on a hidden or locked channel // Make Discord show inside the channel if clicking on a hidden or locked channel
match: /(?<=\|\|\i\.default\.selectVoiceChannel\((\i)\.id\);!__OVERLAY__&&\()/, match: /!__OVERLAY__&&\((?<=selectVoiceChannel\((\i)\.id\).+?)/,
replace: (_, channel) => `$self.isHiddenChannel(${channel},true)||` replace: (m, channel) => `${m}$self.isHiddenChannel(${channel},true)||`
} }
] ]
}, },
@ -195,7 +195,7 @@ export default definePlugin({
replace: (_, pushNotificationButtonExpression, channel) => `if($self.isHiddenChannel(${channel})){${pushNotificationButtonExpression}break;}` replace: (_, pushNotificationButtonExpression, channel) => `if($self.isHiddenChannel(${channel})){${pushNotificationButtonExpression}break;}`
}, },
{ {
match: /(?<=renderHeaderToolbar=function.+?case \i\.\i\.GUILD_FORUM:if\(!\i\){)(?=.+?;(.+?{channel:(\i)},"notifications"\)\)))/, match: /(?<=renderHeaderToolbar=function.+?case \i\.\i\.GUILD_FORUM:.+?if\(!\i\){)(?=.+?;(.+?{channel:(\i)},"notifications"\)\)))/,
replace: (_, pushNotificationButtonExpression, channel) => `if($self.isHiddenChannel(${channel})){${pushNotificationButtonExpression};break;}` replace: (_, pushNotificationButtonExpression, channel) => `if($self.isHiddenChannel(${channel})){${pushNotificationButtonExpression};break;}`
}, },
{ {