From 992a77e76cee25dd307a600f7c89d80b9b48f17f Mon Sep 17 00:00:00 2001 From: Nuckyz <61953774+Nuckyz@users.noreply.github.com> Date: Wed, 8 Feb 2023 17:54:11 -0300 Subject: ShowHiddenChannels: Stage and voice channels support (#469) Co-authored-by: Ven --- .../components/HiddenChannelLockScreen.tsx | 269 +++++++++++++-------- 1 file changed, 165 insertions(+), 104 deletions(-) (limited to 'src/plugins/showHiddenChannels/components') diff --git a/src/plugins/showHiddenChannels/components/HiddenChannelLockScreen.tsx b/src/plugins/showHiddenChannels/components/HiddenChannelLockScreen.tsx index e5c5ee2..7e66a6a 100644 --- a/src/plugins/showHiddenChannels/components/HiddenChannelLockScreen.tsx +++ b/src/plugins/showHiddenChannels/components/HiddenChannelLockScreen.tsx @@ -18,18 +18,17 @@ import ErrorBoundary from "@components/ErrorBoundary"; import { LazyComponent } from "@utils/misc"; -import { proxyLazy } from "@utils/proxyLazy"; import { formatDuration } from "@utils/text"; -import { find, findByCode, findByPropsLazy, findLazy } from "@webpack"; -import { moment, Parser, SnowflakeUtils, Text, Timestamp, Tooltip } from "@webpack/common"; +import { find, findByCode, findByPropsLazy } from "@webpack"; +import { FluxDispatcher, GuildMemberStore, GuildStore, moment, Parser, SnowflakeUtils, Text, Timestamp, Tooltip } from "@webpack/common"; import { Channel } from "discord-types/general"; -enum SortOrderTypesTyping { +enum SortOrderTypes { LATEST_ACTIVITY = 0, CREATION_DATE = 1 } -enum ForumLayoutTypesTyping { +enum ForumLayoutTypes { DEFAULT = 0, LIST = 1, GRID = 2 @@ -50,18 +49,31 @@ interface Tag { interface ExtendedChannel extends Channel { defaultThreadRateLimitPerUser?: number; - defaultSortOrder?: SortOrderTypesTyping | null; - defaultForumLayout?: ForumLayoutTypesTyping; + defaultSortOrder?: SortOrderTypes | null; + defaultForumLayout?: ForumLayoutTypes; defaultReactionEmoji?: DefaultReaction | null; availableTags?: Array; } -const ChatClasses = findByPropsLazy("chat", "chatContent"); -const TagClasses = findLazy(m => typeof m.tags === "string" && Object.entries(m).length === 1); // Object exported with a single key called tags -const ChannelTypes = findByPropsLazy("GUILD_TEXT", "GUILD_FORUM"); -const SortOrderTypes = findLazy(m => typeof m.LATEST_ACTIVITY === "number"); -const ForumLayoutTypes = findLazy(m => typeof m.LIST === "number"); -const ChannelFlags = findLazy(m => typeof m.REQUIRE_TAG === "number"); +enum ChannelTypes { + GUILD_TEXT = 0, + GUILD_VOICE = 2, + GUILD_ANNOUNCEMENT = 5, + GUILD_STAGE_VOICE = 13, + GUILD_FORUM = 15 +} + +enum VideoQualityModes { + AUTO = 1, + FULL = 2 +} + +enum ChannelFlags { + PINNED = 1 << 1, + REQUIRE_TAG = 1 << 4 +} + +const ChatScrollClasses = findByPropsLazy("auto", "content", "scrollerBase"); const TagComponent = LazyComponent(() => find(m => { if (typeof m !== "function") return false; @@ -70,23 +82,32 @@ const TagComponent = LazyComponent(() => find(m => { return code.includes(".Messages.FORUM_TAG_A11Y_FILTER_BY_TAG") && !code.includes("increasedActivityPill"); })); const EmojiComponent = LazyComponent(() => findByCode('.jumboable?"jumbo":"default"')); +// The component for the beggining of a channel, but we patched it so it only returns the allowed users and roles components for hidden channels +const ChannelBeginHeader = LazyComponent(() => findByCode(".Messages.ROLE_REQUIRED_SINGLE_USER_MESSAGE")); -const ChannelTypesToChannelNames = proxyLazy(() => ({ +const ChannelTypesToChannelNames = { [ChannelTypes.GUILD_TEXT]: "text", [ChannelTypes.GUILD_ANNOUNCEMENT]: "announcement", - [ChannelTypes.GUILD_FORUM]: "forum" -})); + [ChannelTypes.GUILD_FORUM]: "forum", + [ChannelTypes.GUILD_VOICE]: "voice", + [ChannelTypes.GUILD_STAGE_VOICE]: "stage" +}; -const SortOrderTypesToNames = proxyLazy(() => ({ +const SortOrderTypesToNames = { [SortOrderTypes.LATEST_ACTIVITY]: "Latest activity", [SortOrderTypes.CREATION_DATE]: "Creation date" -})); +}; -const ForumLayoutTypesToNames = proxyLazy(() => ({ +const ForumLayoutTypesToNames = { [ForumLayoutTypes.DEFAULT]: "Not set", [ForumLayoutTypes.LIST]: "List view", [ForumLayoutTypes.GRID]: "Gallery view" -})); +}; + +const VideoQualityModesToNames = { + [VideoQualityModes.AUTO]: "Automatic", + [VideoQualityModes.FULL]: "720p" +}; // Icon from the modal when clicking a message link you don't have access to view const HiddenChannelLogo = "/assets/433e3ec4319a9d11b0cbe39342614982.svg"; @@ -104,97 +125,137 @@ function HiddenChannelLockScreen({ channel }: { channel: ExtendedChannel; }) { rateLimitPerUser, defaultThreadRateLimitPerUser, defaultSortOrder, - defaultReactionEmoji + defaultReactionEmoji, + bitrate, + rtcRegion, + videoQualityMode, + permissionOverwrites } = channel; - return ( -
- - -
- This is a hidden {ChannelTypesToChannelNames[type]} channel. - {channel.isNSFW() && - - {({ onMouseLeave, onMouseEnter }) => ( - - - - )} - - } -
+ const membersToFetch: Array = []; - - You can not see the {channel.isForumChannel() ? "posts" : "messages"} of this channel. - {channel.isForumChannel() && topic && topic.length > 0 && "However you may see its guidelines:"} - + const guildOwnerId = GuildStore.getGuild(channel.guild_id).ownerId; + if (!GuildMemberStore.getMember(channel.guild_id, guildOwnerId)) membersToFetch.push(guildOwnerId); - {channel.isForumChannel() && topic && topic.length > 0 && ( -
- {Parser.parseTopic(topic, false, { channelId })} -
- )} - - {lastMessageId && - - Last {channel.isForumChannel() ? "post" : "message"} created: - - - } - - {lastPinTimestamp && - Last message pin: - } - {(rateLimitPerUser ?? 0) > 0 && - Slowmode: {formatDuration(rateLimitPerUser! * 1000)} - } - {(defaultThreadRateLimitPerUser ?? 0) > 0 && - - Default thread slowmode: {formatDuration(defaultThreadRateLimitPerUser! * 1000)} - - } - {(defaultAutoArchiveDuration ?? 0) > 0 && - - Default inactivity duration before archiving {channel.isForumChannel() ? "posts" : "threads"}: - {formatDuration(defaultAutoArchiveDuration! * 1000 * 60)} - - } - {defaultForumLayout != null && - Default layout: {ForumLayoutTypesToNames[defaultForumLayout]} - } - {defaultSortOrder != null && - Default sort order: {SortOrderTypesToNames[defaultSortOrder]} - } - {defaultReactionEmoji != null && -
- Default reaction emoji: - + 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 + }); + } + + return ( +
+
+ + +
+ This is a hidden {ChannelTypesToChannelNames[type]} channel. + {channel.isNSFW() && + + {({ onMouseLeave, onMouseEnter }) => ( + + + + )} + + }
- } - {channel.hasFlag(ChannelFlags.REQUIRE_TAG) && - Posts on this forum require a tag to be set. - } - {availableTags && availableTags.length > 0 && -
- Available tags: -
- {availableTags.map(tag => )} + + {(!channel.isGuildVoice() && !channel.isGuildStageVoice()) && ( + + You can not see the {channel.isForumChannel() ? "posts" : "messages"} of this channel. + {channel.isForumChannel() && topic && topic.length > 0 && "However you may see its guidelines:"} + + )} + + {channel.isForumChannel() && topic && topic.length > 0 && ( +
+ {Parser.parseTopic(topic, false, { channelId })}
+ )} + + {lastMessageId && + + Last {channel.isForumChannel() ? "post" : "message"} created: + + + } + + {lastPinTimestamp && + Last message pin: + } + {(rateLimitPerUser ?? 0) > 0 && + Slowmode: {formatDuration(rateLimitPerUser!, "seconds")} + } + {(defaultThreadRateLimitPerUser ?? 0) > 0 && + + Default thread slowmode: {formatDuration(defaultThreadRateLimitPerUser!, "seconds")} + + } + {((channel.isGuildVoice() || channel.isGuildStageVoice()) && bitrate != null) && + Bitrate: {bitrate} bits + } + {rtcRegion !== undefined && + Region: {rtcRegion ?? "Automatic"} + } + {(channel.isGuildVoice() || channel.isGuildStageVoice()) && + Video quality mode: {VideoQualityModesToNames[videoQualityMode ?? VideoQualityModes.AUTO]} + } + {(defaultAutoArchiveDuration ?? 0) > 0 && + + Default inactivity duration before archiving {channel.isForumChannel() ? "posts" : "threads"}: + {" " + formatDuration(defaultAutoArchiveDuration!, "minutes")} + + } + {defaultForumLayout != null && + Default layout: {ForumLayoutTypesToNames[defaultForumLayout]} + } + {defaultSortOrder != null && + Default sort order: {SortOrderTypesToNames[defaultSortOrder]} + } + {defaultReactionEmoji != null && +
+ Default reaction emoji: + +
+ } + {channel.hasFlag(ChannelFlags.REQUIRE_TAG) && + Posts on this forum require a tag to be set. + } + {availableTags && availableTags.length > 0 && +
+ Available tags: +
+ {availableTags.map(tag => )} +
+
+ } +
+ Allowed users and roles: +
- } +
); } -- cgit