From 3f2bcd2cab1a7a3c32b9cffd5d4fc5df6dde670b Mon Sep 17 00:00:00 2001 From: Nuckyz <61953774+Nuckyz@users.noreply.github.com> Date: Tue, 16 May 2023 14:15:56 -0300 Subject: [PATCH] SHC: Permissions viewer integration (#475) --- README.md | 2 +- .../components/HiddenChannelLockScreen.tsx | 100 ++++++++++++++---- src/plugins/showHiddenChannels/index.tsx | 7 +- src/plugins/showHiddenChannels/style.css | 35 +++++- 4 files changed, 118 insertions(+), 26 deletions(-) diff --git a/README.md b/README.md index 771495d2c..e1a70c6be 100644 --- a/README.md +++ b/README.md @@ -57,7 +57,7 @@ Discord is trademark of Discord Inc. and solely mentioned for the sake of descri Mention of it does not imply any affiliation with or endorsement by Discord Inc.
-Using Vencord violates Discord's terms of service +Using Vencord violates Discord's terms of service Client modifications are against Discord’s Terms of Service. diff --git a/src/plugins/showHiddenChannels/components/HiddenChannelLockScreen.tsx b/src/plugins/showHiddenChannels/components/HiddenChannelLockScreen.tsx index dc670bf0d..b08ffb420 100644 --- a/src/plugins/showHiddenChannels/components/HiddenChannelLockScreen.tsx +++ b/src/plugins/showHiddenChannels/components/HiddenChannelLockScreen.tsx @@ -16,15 +16,17 @@ * along with this program. If not, see . */ +import { Settings } from "@api/Settings"; import ErrorBoundary from "@components/ErrorBoundary"; import { LazyComponent } from "@utils/react"; import { formatDuration } from "@utils/text"; import { find, findByPropsLazy, findStoreLazy } from "@webpack"; -import { FluxDispatcher, GuildMemberStore, GuildStore, moment, Parser, PermissionStore, SnowflakeUtils, Text, Timestamp, Tooltip } from "@webpack/common"; +import { FluxDispatcher, GuildMemberStore, GuildStore, moment, Parser, PermissionStore, SnowflakeUtils, Text, Timestamp, Tooltip, useEffect, useState } from "@webpack/common"; import type { Channel } from "discord-types/general"; import type { ComponentType } from "react"; -import { VIEW_CHANNEL } from ".."; +import openRolesAndUsersPermissionsModal, { PermissionType, RoleOrUserPermission } from "../../permissionsViewer/components/RolesAndUsersPermissions"; +import { settings, VIEW_CHANNEL } from ".."; enum SortOrderTypes { LATEST_ACTIVITY = 0, @@ -124,6 +126,9 @@ const VideoQualityModesToNames = { const HiddenChannelLogo = "/assets/433e3ec4319a9d11b0cbe39342614982.svg"; function HiddenChannelLockScreen({ channel }: { channel: ExtendedChannel; }) { + const [viewAllowedUsersAndRoles, setViewAllowedUsersAndRoles] = useState(settings.store.defaultAllowedUsersAndRolesDropdownState); + const [permissions, setPermissions] = useState([]); + const { type, topic, @@ -140,27 +145,39 @@ function HiddenChannelLockScreen({ channel }: { channel: ExtendedChannel; }) { bitrate, rtcRegion, videoQualityMode, - permissionOverwrites + permissionOverwrites, + guild_id } = channel; - const membersToFetch: Array = []; + useEffect(() => { + const membersToFetch: Array = []; - const guildOwnerId = GuildStore.getGuild(channel.guild_id).ownerId; - if (!GuildMemberStore.getMember(channel.guild_id, guildOwnerId)) membersToFetch.push(guildOwnerId); + const guildOwnerId = GuildStore.getGuild(guild_id).ownerId; + if (!GuildMemberStore.getMember(guild_id, guildOwnerId)) membersToFetch.push(guildOwnerId); - Object.values(permissionOverwrites).forEach(({ type, id: userId }) => { - if (type === 1) { - if (!GuildMemberStore.getMember(channel.guild_id, userId)) membersToFetch.push(userId); - } - }); - - if (membersToFetch.length > 0) { - FluxDispatcher.dispatch({ - type: "GUILD_MEMBERS_REQUEST", - guildIds: [channel.guild_id], - userIds: membersToFetch + Object.values(permissionOverwrites).forEach(({ type, id: userId }) => { + if (type === 1 && !GuildMemberStore.getMember(guild_id, userId)) { + membersToFetch.push(userId); + } }); - } + + if (membersToFetch.length > 0) { + FluxDispatcher.dispatch({ + type: "GUILD_MEMBERS_REQUEST", + guildIds: [guild_id], + userIds: membersToFetch + }); + } + + if (Settings.plugins.PermissionsViewer.enabled) { + setPermissions(Object.values(permissionOverwrites).map(overwrite => ({ + type: overwrite.type as PermissionType, + id: overwrite.id, + overwriteAllow: overwrite.allow, + overwriteDeny: overwrite.deny + }))); + } + }, [channelId]); return (
@@ -182,7 +199,7 @@ function HiddenChannelLockScreen({ channel }: { channel: ExtendedChannel; }) { aria-hidden={true} role="img" > - + )} @@ -268,8 +285,49 @@ function HiddenChannelLockScreen({ channel }: { channel: ExtendedChannel; }) {
}
- Allowed users and roles: - +
+ {Settings.plugins.PermissionsViewer.enabled && ( + + {({ onMouseLeave, onMouseEnter }) => ( + + )} + + )} + Allowed users and roles: + + {({ onMouseLeave, onMouseEnter }) => ( + + )} + +
+ {viewAllowedUsersAndRoles && }
diff --git a/src/plugins/showHiddenChannels/index.tsx b/src/plugins/showHiddenChannels/index.tsx index 38adf67a2..667f710e3 100644 --- a/src/plugins/showHiddenChannels/index.tsx +++ b/src/plugins/showHiddenChannels/index.tsx @@ -39,7 +39,7 @@ enum ShowMode { HiddenIconWithMutedStyle } -const settings = definePluginSettings({ +export const settings = definePluginSettings({ hideUnreads: { description: "Hide Unreads", type: OptionType.BOOLEAN, @@ -54,6 +54,11 @@ const settings = definePluginSettings({ { label: "Muted style with hidden eye icon on the right", value: ShowMode.HiddenIconWithMutedStyle }, ], restartNeeded: true + }, + defaultAllowedUsersAndRolesDropdownState: { + description: "Whether the allowed users and roles dropdown on hidden channels should be open by default", + type: OptionType.BOOLEAN, + default: true } }); diff --git a/src/plugins/showHiddenChannels/style.css b/src/plugins/showHiddenChannels/style.css index f765843d6..301ad75d4 100644 --- a/src/plugins/showHiddenChannels/style.css +++ b/src/plugins/showHiddenChannels/style.css @@ -33,9 +33,8 @@ margin: inherit; } -.shc-lock-screen-heading-nsfw-icon > path { - fill: var(--text-normal); - fill-rule: evenodd; +.shc-lock-screen-heading-nsfw-icon { + color: var(--text-normal); } .shc-lock-screen-topic-container { @@ -99,6 +98,36 @@ max-width: 70vw; } +.shc-lock-screen-allowed-users-and-roles-container-title { + display: flex; + flex-direction: row; + align-items: center; +} + +.shc-lock-screen-allowed-users-and-roles-container-toggle-btn { + all: unset; + margin-left: 5px; + cursor: pointer; + display: flex; + align-items: center; +} + +.shc-lock-screen-allowed-users-and-roles-container-toggle-btn > svg { + color: var(--text-normal); +} + +.shc-lock-screen-allowed-users-and-roles-container-permdetails-btn { + all: unset; + margin-right: 5px; + cursor: pointer; + display: flex; + align-items: center; +} + +.shc-lock-screen-allowed-users-and-roles-container-permdetails-btn > svg { + color: var(--text-normal); +} + .shc-lock-screen-allowed-users-and-roles-container > [class^="members"] { margin-left: 10px; flex-wrap: wrap;