2022-10-23 11:44:21 +02:00
/ *
* Vencord , a modification for Discord ' s desktop app
* Copyright ( c ) 2022 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/>.
* /
2023-02-01 12:11:05 +01:00
import "./style.css" ;
2022-10-30 19:17:46 +01:00
2023-05-06 01:36:00 +02:00
import { definePluginSettings } from "@api/Settings" ;
2023-02-01 12:11:05 +01:00
import ErrorBoundary from "@components/ErrorBoundary" ;
2022-11-28 13:37:55 +01:00
import { Devs } from "@utils/constants" ;
2023-03-21 07:07:16 +01:00
import { canonicalizeMatch } from "@utils/patches" ;
2022-11-28 13:37:55 +01:00
import definePlugin , { OptionType } from "@utils/types" ;
2023-02-08 21:54:11 +01:00
import { findByPropsLazy } from "@webpack" ;
2023-10-25 22:20:51 +02:00
import { ChannelStore , PermissionsBits , PermissionStore , Tooltip } from "@webpack/common" ;
2023-04-15 05:02:08 +02:00
import type { Channel , Role } from "discord-types/general" ;
2023-01-23 22:04:50 +01:00
2023-10-25 22:20:51 +02:00
import HiddenChannelLockScreen from "./components/HiddenChannelLockScreen" ;
2023-02-01 12:11:05 +01:00
2024-02-08 19:33:49 +01:00
const ChannelListClasses = findByPropsLazy ( "modeMuted" , "modeSelected" , "unread" , "icon" ) ;
2023-02-08 21:54:11 +01:00
2023-06-13 02:36:25 +02:00
const enum ShowMode {
2023-01-23 22:04:50 +01:00
LockIcon ,
HiddenIconWithMutedStyle
}
2023-05-16 19:15:56 +02:00
export const settings = definePluginSettings ( {
2023-01-25 03:35:34 +01:00
hideUnreads : {
description : "Hide Unreads" ,
type : OptionType . BOOLEAN ,
default : true ,
restartNeeded : true
} ,
showMode : {
description : "The mode used to display hidden channels." ,
type : OptionType . SELECT ,
options : [
{ label : "Plain style with Lock Icon instead" , value : ShowMode.LockIcon , default : true } ,
{ label : "Muted style with hidden eye icon on the right" , value : ShowMode.HiddenIconWithMutedStyle } ,
] ,
restartNeeded : true
2023-05-16 19:15:56 +02:00
} ,
defaultAllowedUsersAndRolesDropdownState : {
description : "Whether the allowed users and roles dropdown on hidden channels should be open by default" ,
type : OptionType . BOOLEAN ,
default : true
2023-01-25 03:35:34 +01:00
}
} ) ;
2022-10-23 11:44:21 +02:00
export default definePlugin ( {
name : "ShowHiddenChannels" ,
2023-01-23 22:04:50 +01:00
description : "Show channels that you do not have access to view." ,
2023-01-28 01:40:10 +01:00
authors : [ Devs . BigDuck , Devs . AverageReactEnjoyer , Devs . D3SOX , Devs . Ven , Devs . Nuckyz , Devs . Nickyux , Devs . dzshn ] ,
2023-01-25 03:35:34 +01:00
settings ,
2022-10-23 11:44:21 +02:00
patches : [
{
// RenderLevel defines if a channel is hidden, collapsed in category, visible, etc
2023-11-15 18:50:52 +01:00
find : '"placeholder-channel-id"' ,
2023-01-23 22:04:50 +01:00
replacement : [
2023-10-26 23:13:25 +02:00
// Remove the special logic for channels we don't have access to
2023-01-23 22:04:50 +01:00
{
2023-10-25 22:20:51 +02:00
match : /if\(!\i\.\i\.can\(\i\.\i\.VIEW_CHANNEL.+?{if\(this\.id===\i\).+?threadIds:\i}}/ ,
replace : ""
2023-01-23 22:04:50 +01:00
} ,
2023-10-26 23:13:25 +02:00
// Do not check for unreads when selecting the render level if the channel is hidden
2023-10-26 23:10:32 +02:00
{
2023-12-13 02:56:01 +01:00
match : /(?<=&&)(?=!\i\.\i\.hasUnread\(this\.record\.id\))/ ,
2023-10-26 23:10:32 +02:00
replace : "$self.isHiddenChannel(this.record)||"
} ,
2023-10-26 23:13:25 +02:00
// Make channels we dont have access to be the same level as normal ones
2023-01-23 22:04:50 +01:00
{
2023-11-15 18:50:52 +01:00
match : /(activeJoinedRelevantThreads:.{0,50}VIEW_CHANNEL.+?renderLevel:(.+?),threadIds.+?renderLevel:).+?(?=,threadIds)/g ,
replace : ( _ , rest , defaultRenderLevel ) = > ` ${ rest } ${ defaultRenderLevel } `
2023-01-25 03:35:34 +01:00
} ,
2023-10-26 23:13:25 +02:00
// Remove permission checking for getRenderLevel function
2023-01-25 03:35:34 +01:00
{
2023-10-25 22:20:51 +02:00
match : /(?<=getRenderLevel\(\i\){.+?return)!\i\.\i\.can\(\i\.\i\.VIEW_CHANNEL,this\.record\)\|\|/ ,
replace : " "
2023-01-23 22:04:50 +01:00
}
]
2022-10-23 11:44:21 +02:00
} ,
{
2023-02-08 21:54:11 +01:00
find : "VoiceChannel, transitionTo: Channel does not have a guildId" ,
2023-01-25 03:35:34 +01:00
replacement : [
{
2023-02-08 21:54:11 +01:00
// Do not show confirmation to join a voice channel when already connected to another if clicking on a hidden voice channel
2023-10-25 22:20:51 +02:00
match : /(?<=getCurrentClientVoiceChannelId\((\i)\.guild_id\);return)/ ,
2023-03-08 04:11:59 +01:00
replace : ( _ , channel ) = > ` ! $ self.isHiddenChannel( ${ channel } )&& `
2023-01-25 03:35:34 +01:00
} ,
2023-02-08 21:54:11 +01:00
{
2023-10-25 22:20:51 +02:00
// Prevent Discord from trying to connect to hidden voice channels
match : /(?=&&\i\.\i\.selectVoiceChannel\((\i)\.id\))/ ,
replace : ( _ , channel ) = > ` &&! $ self.isHiddenChannel( ${ channel } ) `
2023-02-08 21:54:11 +01:00
} ,
{
2023-03-21 07:07:16 +01:00
// Make Discord show inside the channel if clicking on a hidden or locked channel
2023-05-20 02:24:56 +02:00
match : /!__OVERLAY__&&\((?<=selectVoiceChannel\((\i)\.id\).+?)/ ,
replace : ( m , channel ) = > ` ${ m } $ self.isHiddenChannel( ${ channel } ,true)|| `
2023-02-08 21:54:11 +01:00
}
]
} ,
2023-10-25 22:20:51 +02:00
// Prevent Discord from trying to connect to hidden stage channels
2023-02-08 21:54:11 +01:00
{
2023-10-25 22:20:51 +02:00
find : ".MAX_STAGE_VOICE_USER_LIMIT})" ,
replacement : {
match : /!(\i)\.isRoleSubscriptionTemplatePreviewChannel\(\)/ ,
replace : ( m , channel ) = > ` ${ m } &&! $ self.isHiddenChannel( ${ channel } ) `
}
} ,
{
find : "ChannelItemEditButton:function(){" ,
2023-02-08 21:54:11 +01:00
replacement : [
2023-01-25 03:35:34 +01:00
// Render null instead of the buttons if the channel is hidden
. . . [
"renderEditButton" ,
"renderInviteButton" ,
] . map ( func = > ( {
2023-10-25 22:20:51 +02:00
match : new RegExp ( ` (?<= ${ func } \\ ( \\ ){) ` , "g" ) , // Global because Discord has multiple declarations of the same functions
2023-01-25 03:35:34 +01:00
replace : "if($self.isHiddenChannel(this.props.channel))return null;"
} ) )
]
} ,
2023-10-25 22:20:51 +02:00
{
find : "VoiceChannel.renderPopout: There must always be something to render" ,
all : true ,
// Render null instead of the buttons if the channel is hidden
replacement : {
match : /(?<=renderOpenChatButton=\(\)=>{)/ ,
replace : "if($self.isHiddenChannel(this.props.channel))return null;"
}
} ,
2023-01-25 03:35:34 +01:00
{
find : ".Messages.CHANNEL_TOOLTIP_DIRECTORY" ,
predicate : ( ) = > settings . store . showMode === ShowMode . LockIcon ,
2022-10-24 23:22:39 +02:00
replacement : {
2023-01-25 03:35:34 +01:00
// Lock Icon
2023-10-25 22:20:51 +02:00
match : /(?=switch\((\i)\.type\).{0,30}\.GUILD_ANNOUNCEMENT.{0,70}\(0,\i\.\i\))/ ,
2023-03-08 04:11:59 +01:00
replace : ( _ , channel ) = > ` if( $ self.isHiddenChannel( ${ channel } ))return $ self.LockIcon; `
2023-02-08 21:54:11 +01:00
}
2022-10-23 11:44:21 +02:00
} ,
2023-01-23 22:04:50 +01:00
{
2023-11-21 03:16:34 +01:00
find : "UNREAD_IMPORTANT:" ,
2023-01-25 03:35:34 +01:00
predicate : ( ) = > settings . store . showMode === ShowMode . HiddenIconWithMutedStyle ,
2023-01-23 22:04:50 +01:00
replacement : [
// Make the channel appear as muted if it's hidden
{
2023-10-25 22:20:51 +02:00
match : /(?<={channel:(\i),name:\i,muted:(\i).+?;)/ ,
replace : ( _ , channel , muted ) = > ` ${ muted } = $ self.isHiddenChannel( ${ channel } )?true: ${ muted } ; `
2023-01-23 22:04:50 +01:00
} ,
// Add the hidden eye icon if the channel is hidden
{
2024-02-08 19:33:49 +01:00
match : /\.name\),.{0,120}\.children.+?:null(?<=,channel:(\i).+?)/ ,
2023-03-08 04:11:59 +01:00
replace : ( m , channel ) = > ` ${ m } , $ self.isHiddenChannel( ${ channel } )? $ self.HiddenChannelIcon():null `
2023-01-23 22:04:50 +01:00
} ,
// Make voice channels also appear as muted if they are muted
{
2023-10-25 22:20:51 +02:00
match : /(?<=\.wrapper:\i\.notInteractive,)(.+?)if\((\i)\)return (\i\.MUTED);/ ,
replace : ( _ , otherClasses , isMuted , mutedClassExpression ) = > ` ${ isMuted } ? ${ mutedClassExpression } :"", ${ otherClasses } if( ${ isMuted } )return ""; `
2023-01-23 22:04:50 +01:00
}
]
} ,
2023-01-25 03:35:34 +01:00
{
2023-11-21 03:16:34 +01:00
find : "UNREAD_IMPORTANT:" ,
2023-03-08 04:11:59 +01:00
replacement : [
{
// Make muted channels also appear as unread if hide unreads is false, using the HiddenIconWithMutedStyle and the channel is hidden
predicate : ( ) = > settings . store . hideUnreads === false && settings . store . showMode === ShowMode . HiddenIconWithMutedStyle ,
2023-10-25 22:20:51 +02:00
match : /\.LOCKED;if\((?<={channel:(\i).+?)/ ,
replace : ( m , channel ) = > ` ${ m } ! $ self.isHiddenChannel( ${ channel } )&& `
2023-03-08 04:11:59 +01:00
} ,
{
// Hide unreads
predicate : ( ) = > settings . store . hideUnreads === true ,
2023-10-25 22:20:51 +02:00
match : /(?<={channel:(\i),name:\i,.+?unread:(\i).+?;)/ ,
replace : ( _ , channel , unread ) = > ` ${ unread } = $ self.isHiddenChannel( ${ channel } )?false: ${ unread } ; `
2023-03-08 04:11:59 +01:00
}
]
2023-01-25 03:35:34 +01:00
} ,
2022-10-27 20:25:51 +02:00
{
2023-10-27 01:59:48 +02:00
// Hide the new version of unreads box for hidden channels
2024-03-28 13:48:47 +01:00
find : '="ChannelListUnreadsStore",' ,
2022-10-27 20:25:51 +02:00
replacement : {
2023-11-21 03:16:34 +01:00
match : /(?<=if\(null==(\i))(?=.{0,160}?getHasImportantUnread\)\(\i\))/g , // Global because Discord has multiple methods like that in the same module
2023-10-25 22:20:51 +02:00
replace : ( _ , channel ) = > ` || $ self.isHiddenChannel( ${ channel } ) `
2022-10-27 20:25:51 +02:00
}
2023-01-28 01:40:10 +01:00
} ,
2023-10-27 01:59:48 +02:00
{
// Make the old version of unreads box not visible for hidden channels
find : "renderBottomUnread(){" ,
replacement : {
2023-11-21 03:16:34 +01:00
match : /(?=&&\(0,\i\.getHasImportantUnread\)\((\i\.record)\))/ ,
2023-10-27 01:59:48 +02:00
replace : "&&!$self.isHiddenChannel($1)"
}
} ,
{
// Make the state of the old version of unreads box not include hidden channels
find : ".useFlattenedChannelIdListWithThreads)" ,
replacement : {
2023-11-21 03:16:34 +01:00
match : /(?=&&\(0,\i\.getHasImportantUnread\)\((\i)\))/ ,
2023-10-27 01:59:48 +02:00
replace : "&&!$self.isHiddenChannel($1)"
}
} ,
2023-02-01 12:11:05 +01:00
// Only render the channel header and buttons that work when transitioning to a hidden channel
{
find : "Missing channel in Channel.renderHeaderToolbar" ,
replacement : [
{
2023-10-25 22:20:51 +02:00
match : /(?<=renderHeaderToolbar=\(\)=>{.+?case \i\.\i\.GUILD_TEXT:)(?=.+?(\i\.push.{0,50}channel:(\i)},"notifications"\)\)))(?<=isLurking:(\i).+?)/ ,
replace : ( _ , pushNotificationButtonExpression , channel , isLurking ) = > ` if(! ${ isLurking } && $ self.isHiddenChannel( ${ channel } )){ ${ pushNotificationButtonExpression } ;break;} `
2023-02-01 12:11:05 +01:00
} ,
{
2023-10-25 22:20:51 +02:00
match : /(?<=renderHeaderToolbar=\(\)=>{.+?case \i\.\i\.GUILD_MEDIA:)(?=.+?(\i\.push.{0,40}channel:(\i)},"notifications"\)\)))(?<=isLurking:(\i).+?)/ ,
replace : ( _ , pushNotificationButtonExpression , channel , isLurking ) = > ` if(! ${ isLurking } && $ self.isHiddenChannel( ${ channel } )){ ${ pushNotificationButtonExpression } ;break;} `
2023-02-01 12:11:05 +01:00
} ,
{
2023-10-25 22:20:51 +02:00
match : /renderMobileToolbar=\(\)=>{.+?case \i\.\i\.GUILD_DIRECTORY:(?<=let{channel:(\i).+?)/ ,
replace : ( m , channel ) = > ` ${ m } if( $ self.isHiddenChannel( ${ channel } ))break; `
2023-02-01 12:11:05 +01:00
} ,
{
2023-10-25 22:20:51 +02:00
match : /(?<=renderHeaderBar=\(\)=>{.+?hideSearch:(\i)\.isDirectory\(\))/ ,
2023-03-08 04:11:59 +01:00
replace : ( _ , channel ) = > ` || $ self.isHiddenChannel( ${ channel } ) `
2023-02-01 12:11:05 +01:00
} ,
{
2023-10-25 22:20:51 +02:00
match : /(?<=renderSidebar\(\){)/ ,
2023-02-01 12:11:05 +01:00
replace : "if($self.isHiddenChannel(this.props.channel))return null;"
} ,
{
2023-10-25 22:20:51 +02:00
match : /(?<=renderChat\(\){)/ ,
2023-02-01 12:11:05 +01:00
replace : "if($self.isHiddenChannel(this.props.channel))return $self.HiddenChannelLockScreen(this.props.channel);"
2023-02-08 21:54:11 +01:00
}
2023-02-01 12:11:05 +01:00
]
} ,
// Avoid trying to fetch messages from hidden channels
{
find : '"MessageManager"' ,
2023-03-08 04:11:59 +01:00
replacement : {
2023-10-25 22:20:51 +02:00
match : /"Skipping fetch because channelId is a static route"\);return}(?=.+?getChannel\((\i)\))/ ,
2023-03-08 04:11:59 +01:00
replace : ( m , channelId ) = > ` ${ m } if( $ self.isHiddenChannel({channelId: ${ channelId } }))return; `
}
2023-02-01 12:11:05 +01:00
} ,
2023-01-28 01:40:10 +01:00
// Patch keybind handlers so you can't accidentally jump to hidden channels
{
find : '"alt+shift+down"' ,
replacement : {
2023-11-21 03:16:34 +01:00
match : /(?<=getChannel\(\i\);return null!=(\i))(?=.{0,150}?getHasImportantUnread\)\(\i\))/ ,
2023-03-08 04:11:59 +01:00
replace : ( _ , channel ) = > ` &&! $ self.isHiddenChannel( ${ channel } ) `
2023-01-28 01:40:10 +01:00
}
} ,
2023-10-25 22:20:51 +02:00
// Patch keybind handlers so you can't accidentally jump to hidden channels
2023-01-28 01:40:10 +01:00
{
2023-10-25 22:20:51 +02:00
find : ".APPLICATION_STORE&&null!=" ,
2023-01-28 01:40:10 +01:00
replacement : {
2023-03-08 04:11:59 +01:00
match : /(?<=getState\(\)\.channelId.{0,30}?\(0,\i\.\i\)\(\i\))(?=\.map\()/ ,
2023-10-25 22:20:51 +02:00
replace : ".filter(e=>!$self.isHiddenChannel(e))"
2023-01-28 01:40:10 +01:00
}
} ,
2023-02-08 21:54:11 +01:00
{
find : ".Messages.ROLE_REQUIRED_SINGLE_USER_MESSAGE" ,
replacement : [
{
2023-03-21 07:07:16 +01:00
// Change the role permission check to CONNECT if the channel is locked
2023-03-21 07:30:09 +01:00
match : /ADMINISTRATOR\)\|\|(?<=context:(\i)}.+?)(?=(.+?)VIEW_CHANNEL)/ ,
2023-10-25 22:20:51 +02:00
replace : ( m , channel , permCheck ) = > ` ${ m } !Vencord.Webpack.Common.PermissionStore.can( ${ PermissionsBits . CONNECT } n, ${ channel } )? ${ permCheck } CONNECT): `
2023-03-21 07:07:16 +01:00
} ,
{
// Change the permissionOverwrite check to CONNECT if the channel is locked
2023-03-21 07:30:09 +01:00
match : /permissionOverwrites\[.+?\i=(?<=context:(\i)}.+?)(?=(.+?)VIEW_CHANNEL)/ ,
2023-10-25 22:20:51 +02:00
replace : ( m , channel , permCheck ) = > ` ${ m } !Vencord.Webpack.Common.PermissionStore.can( ${ PermissionsBits . CONNECT } n, ${ channel } )? ${ permCheck } CONNECT): `
2023-03-21 07:07:16 +01:00
} ,
2023-04-15 05:02:08 +02:00
{
// Include the @everyone role in the allowed roles list for Hidden Channels
2023-10-25 22:20:51 +02:00
match : /sortBy.{0,30}?\.filter\(\i=>(?<=channel:(\i).+?)/ ,
2023-04-15 05:02:08 +02:00
replace : ( m , channel ) = > ` ${ m } $ self.isHiddenChannel( ${ channel } )?true: `
} ,
{
// If the @everyone role has the required permissions, make the array only contain it
2023-10-25 22:20:51 +02:00
match : /computePermissionsForRoles.+?.value\(\)(?<=channel:(\i).+?)/ ,
2023-04-15 05:02:08 +02:00
replace : ( m , channel ) = > ` ${ m } .reduce(... $ self.makeAllowedRolesReduce( ${ channel } .guild_id)) `
} ,
2023-03-21 07:07:16 +01:00
{
// Patch the header to only return allowed users and roles if it's a hidden channel or locked channel (Like when it's used on the HiddenChannelLockScreen)
2023-10-25 22:20:51 +02:00
match : /MANAGE_ROLES.{0,90}?return(?=\(.+?(\(0,\i\.jsxs\)\("div",{className:\i\.members.+?guildId:(\i)\.guild_id.+?roleColor.+?\]}\)))/ ,
2023-03-21 07:07:16 +01:00
replace : ( m , component , channel ) = > {
// Export the channel for the users allowed component patch
2023-10-26 21:51:27 +02:00
component = component . replace ( canonicalizeMatch ( /(?<=users:\i)/ ) , ` ,shcChannel: ${ channel } ` ) ;
2023-04-15 05:02:08 +02:00
// Always render the component for multiple allowed users
component = component . replace ( canonicalizeMatch ( /1!==\i\.length/ ) , "true" ) ;
2023-03-21 07:07:16 +01:00
return ` ${ m } $ self.isHiddenChannel( ${ channel } ,true)? ${ component } : ` ;
}
}
]
} ,
{
2024-03-08 04:24:04 +01:00
find : '+1]})},"overflow"))' ,
2023-03-21 07:07:16 +01:00
replacement : [
{
// Create a variable for the channel prop
2024-03-08 04:24:04 +01:00
match : /maxUsers:\i,users:\i.+?}=(\i).*?;/ ,
2023-10-26 21:51:27 +02:00
replace : ( m , props ) = > ` ${ m } let{shcChannel}= ${ props } ; `
2023-03-21 07:07:16 +01:00
} ,
{
// Make Discord always render the plus button if the component is used inside the HiddenChannelLockScreen
match : /\i>0(?=&&.{0,60}renderPopout)/ ,
2024-03-08 04:24:04 +01:00
replace : m = > ` ( $ self.isHiddenChannel(typeof shcChannel!=="undefined"?shcChannel:void 0,true)?true: ${ m } ) `
2023-03-21 07:07:16 +01:00
} ,
{
// Prevent Discord from overwriting the last children with the plus button if the overflow amount is <= 0 and the component is used inside the HiddenChannelLockScreen
match : /(?<=\.value\(\),(\i)=.+?length-)1(?=\]=.{0,60}renderPopout)/ ,
2024-03-08 04:24:04 +01:00
replace : ( _ , amount ) = > ` ( $ self.isHiddenChannel(typeof shcChannel!=="undefined"?shcChannel:void 0,true)&& ${ amount } <=0?0:1) `
2023-03-21 07:07:16 +01:00
} ,
{
// Show only the plus text without overflowed children amount if the overflow amount is <= 0 and the component is used inside the HiddenChannelLockScreen
match : /(?<="\+",)(\i)\+1/ ,
2024-03-08 04:24:04 +01:00
replace : ( m , amount ) = > ` $ self.isHiddenChannel(typeof shcChannel!=="undefined"?shcChannel:void 0,true)&& ${ amount } <=0?"": ${ m } `
2023-02-08 21:54:11 +01:00
}
]
} ,
{
2023-10-25 22:20:51 +02:00
find : ".Messages.CHANNEL_CALL_CURRENT_SPEAKER.format" ,
2023-02-08 21:54:11 +01:00
replacement : [
{
// Remove the divider and the open chat button for the HiddenChannelLockScreen
2023-12-13 02:56:01 +01:00
match : /"more-options-popout"\)\),(?<=channel:(\i).+?inCall:(\i).+?)/ ,
2023-10-25 22:20:51 +02:00
replace : ( m , channel , inCall ) = > ` ${ m } ${ inCall } ||! $ self.isHiddenChannel( ${ channel } ,true)&& `
2023-02-08 21:54:11 +01:00
} ,
2023-04-15 05:40:42 +02:00
{
// Remove invite users button for the HiddenChannelLockScreen
2023-12-13 02:56:01 +01:00
match : /"popup".{0,100}?if\((?<=channel:(\i).+?inCall:(\i).+?)/ ,
2023-10-25 22:20:51 +02:00
replace : ( m , channel , inCall ) = > ` ${ m } ( ${ inCall } ||! $ self.isHiddenChannel( ${ channel } ,true))&& `
2023-04-15 05:40:42 +02:00
} ,
2023-10-25 22:20:51 +02:00
]
} ,
{
find : ".Messages.EMBEDDED_ACTIVITIES_DEVELOPER_ACTIVITY_SHELF_FETCH_ERROR" ,
replacement : [
2023-02-08 21:54:11 +01:00
{
// Render our HiddenChannelLockScreen component instead of the main voice channel component
2023-10-25 22:20:51 +02:00
match : /renderContent\(\i\){.+?this\.renderVoiceChannelEffects.+?children:/ ,
2023-03-21 07:07:16 +01:00
replace : "$&!this.props.inCall&&$self.isHiddenChannel(this.props.channel,true)?$self.HiddenChannelLockScreen(this.props.channel):"
2023-02-08 21:54:11 +01:00
} ,
{
// Disable gradients for the HiddenChannelLockScreen of voice channels
2023-10-25 22:20:51 +02:00
match : /renderContent\(\i\){.+?disableGradients:/ ,
2023-03-21 07:07:16 +01:00
replace : "$&!this.props.inCall&&$self.isHiddenChannel(this.props.channel,true)||"
2023-02-08 21:54:11 +01:00
} ,
{
// Disable useless components for the HiddenChannelLockScreen of voice channels
2023-10-25 22:20:51 +02:00
match : /(?:{|,)render(?!Header|ExternalHeader).{0,30}?:/g ,
replace : "$&!this.props.inCall&&$self.isHiddenChannel(this.props.channel,true)?()=>null:"
2023-04-15 05:02:08 +02:00
} ,
{
// Disable bad CSS class which mess up hidden voice channels styling
2023-10-25 22:20:51 +02:00
match : /callContainer,(?<=\i\.callContainer,)/ ,
2023-04-15 05:40:42 +02:00
replace : '$&!this.props.inCall&&$self.isHiddenChannel(this.props.channel,true)?"":'
2023-02-08 21:54:11 +01:00
}
]
} ,
{
2023-10-25 22:20:51 +02:00
find : '"HasBeenInStageChannel"' ,
2023-02-08 21:54:11 +01:00
replacement : [
{
// Render our HiddenChannelLockScreen component instead of the main stage channel component
2023-10-25 22:20:51 +02:00
match : /"124px".+?children:(?<=let \i,{channel:(\i).+?)(?=.{0,20}?}\)}function)/ ,
2023-03-08 04:11:59 +01:00
replace : ( m , channel ) = > ` ${ m } $ self.isHiddenChannel( ${ channel } )? $ self.HiddenChannelLockScreen( ${ channel } ): `
2023-02-08 21:54:11 +01:00
} ,
{
// Disable useless components for the HiddenChannelLockScreen of stage channels
2023-10-25 22:20:51 +02:00
match : /render(?:BottomLeft|BottomCenter|BottomRight|ChatToasts):\(\)=>(?<=let \i,{channel:(\i).+?)/g ,
2023-03-08 04:11:59 +01:00
replace : ( m , channel ) = > ` ${ m } $ self.isHiddenChannel( ${ channel } )?null: `
2023-02-08 21:54:11 +01:00
} ,
{
// Disable gradients for the HiddenChannelLockScreen of stage channels
2023-10-25 22:20:51 +02:00
match : /"124px".+?disableGradients:(?<=let \i,{channel:(\i).+?)/ ,
2023-03-08 04:11:59 +01:00
replace : ( m , channel ) = > ` ${ m } $ self.isHiddenChannel( ${ channel } )|| `
2023-02-08 21:54:11 +01:00
} ,
{
// Disable strange styles applied to the header for the HiddenChannelLockScreen of stage channels
2023-10-25 22:20:51 +02:00
match : /"124px".+?style:(?<=let \i,{channel:(\i).+?)/ ,
2023-06-28 05:45:16 +02:00
replace : ( m , channel ) = > ` ${ m } $ self.isHiddenChannel( ${ channel } )?void 0: `
2023-10-25 22:20:51 +02:00
}
]
} ,
{
find : ".Messages.STAGE_FULL_MODERATOR_TITLE" ,
replacement : [
2023-02-08 21:54:11 +01:00
{
// Remove the divider and amount of users in stage channel components for the HiddenChannelLockScreen
2023-03-08 04:11:59 +01:00
match : /\(0,\i\.jsx\)\(\i\.\i\.Divider.+?}\)]}\)(?=.+?:(\i)\.guild_id)/ ,
replace : ( m , channel ) = > ` $ self.isHiddenChannel( ${ channel } )?null:( ${ m } ) `
2023-02-08 21:54:11 +01:00
} ,
{
// Remove the open chat button for the HiddenChannelLockScreen
2023-06-28 05:45:16 +02:00
match : /"recents".+?&&(?=\(.+?channelId:(\i)\.id,showRequestToSpeakSidebar)/ ,
2023-03-08 04:11:59 +01:00
replace : ( m , channel ) = > ` ${ m } ! $ self.isHiddenChannel( ${ channel } )&& `
2023-02-08 21:54:11 +01:00
}
2023-10-25 22:20:51 +02:00
]
2023-03-08 04:11:59 +01:00
} ,
2023-10-27 19:29:25 +02:00
{
// Make the chat input bar channel list contain hidden channels
find : ",queryStaticRouteChannels(" ,
replacement : [
{
// Make the getChannels call to GuildChannelStore return hidden channels
match : /(?<=queryChannels\(\i\){.+?getChannels\(\i)(?=\))/ ,
replace : ",true"
} ,
{
// Avoid filtering out hidden channels from the channel list
match : /(?<=queryChannels\(\i\){.+?isGuildChannelType\)\((\i)\.type\))(?=&&!\i\.\i\.can\()/ ,
replace : "&&!$self.isHiddenChannel($1)"
}
]
} ,
2023-03-08 04:11:59 +01:00
{
2023-03-19 08:53:00 +01:00
find : "\"^/guild-stages/(\\\\d+)(?:/)?(\\\\d+)?\"" ,
2023-03-08 04:11:59 +01:00
replacement : {
// Make mentions of hidden channels work
match : /\i\.\i\.can\(\i\.\i\.VIEW_CHANNEL,\i\)/ ,
replace : "true"
} ,
} ,
{
find : ".shouldCloseDefaultModals" ,
replacement : {
// Show inside voice channel instead of trying to join them when clicking on a channel mention
2023-10-25 22:20:51 +02:00
match : /(?<=getChannel\(\i\);if\(null!=(\i))(?=.{0,100}?selectVoiceChannel)/ ,
replace : ( _ , channel ) = > ` &&! $ self.isHiddenChannel( ${ channel } ) `
2023-03-08 04:11:59 +01:00
}
2023-03-20 02:03:33 +01:00
} ,
{
2024-03-28 13:48:47 +01:00
find : '="GuildChannelStore",' ,
2023-03-21 07:07:16 +01:00
replacement : [
{
// Make GuildChannelStore contain hidden channels
2023-10-25 22:20:51 +02:00
match : /isChannelGated\(.+?\)(?=&&)/ ,
replace : m = > ` ${ m } &&false `
2023-03-21 07:07:16 +01:00
} ,
{
// Filter hidden channels from GuildChannelStore.getChannels unless told otherwise
2023-10-25 22:20:51 +02:00
match : /(?<=getChannels\(\i)(\){.+?)return (.+?)}/ ,
2023-10-26 05:19:26 +02:00
replace : ( _ , rest , channels ) = > ` ,shouldIncludeHidden ${ rest } return $ self.resolveGuildChannels( ${ channels } ,shouldIncludeHidden??false);} `
2023-03-21 07:07:16 +01:00
}
]
} ,
{
find : ".Messages.FORM_LABEL_MUTED" ,
2023-03-20 02:03:33 +01:00
replacement : {
2023-03-21 07:07:16 +01:00
// Make GuildChannelStore.getChannels return hidden channels
match : /(?<=getChannels\(\i)(?=\))/ ,
replace : ",true"
2023-03-20 02:03:33 +01:00
}
2023-06-20 22:11:50 +02:00
} ,
{
2024-03-28 13:48:47 +01:00
find : '="NowPlayingViewStore",' ,
2023-06-20 22:11:50 +02:00
replacement : {
2023-10-25 22:20:51 +02:00
// Make active now voice states on hidden channels
2023-06-20 22:11:50 +02:00
match : /(getVoiceStateForUser.{0,150}?)&&\i\.\i\.canWithPartialContext.{0,20}VIEW_CHANNEL.+?}\)(?=\?)/ ,
replace : "$1"
}
2023-02-01 12:11:05 +01:00
}
2022-10-23 11:44:21 +02:00
] ,
2023-01-14 23:00:29 +01:00
2023-03-21 07:07:16 +01:00
isHiddenChannel ( channel : Channel & { channelId? : string ; } , checkConnect = false ) {
2022-10-23 11:44:21 +02:00
if ( ! channel ) return false ;
2023-01-23 22:04:50 +01:00
if ( channel . channelId ) channel = ChannelStore . getChannel ( channel . channelId ) ;
if ( ! channel || channel . isDM ( ) || channel . isGroupDM ( ) || channel . isMultiUserDM ( ) ) return false ;
2023-10-25 22:20:51 +02:00
return ! PermissionStore . can ( PermissionsBits . VIEW_CHANNEL , channel ) || checkConnect && ! PermissionStore . can ( PermissionsBits . CONNECT , channel ) ;
2023-03-21 07:07:16 +01:00
} ,
resolveGuildChannels ( channels : Record < string | number , Array < { channel : Channel ; comparator : number ; } > | string | number > , shouldIncludeHidden : boolean ) {
if ( shouldIncludeHidden ) return channels ;
const res = { } ;
for ( const [ key , maybeObjChannels ] of Object . entries ( channels ) ) {
if ( ! Array . isArray ( maybeObjChannels ) ) {
res [ key ] = maybeObjChannels ;
continue ;
}
res [ key ] ? ? = [ ] ;
for ( const objChannel of maybeObjChannels ) {
if ( objChannel . channel . id === null || ! this . isHiddenChannel ( objChannel . channel ) ) res [ key ] . push ( objChannel ) ;
}
}
return res ;
2022-10-23 11:44:21 +02:00
} ,
2023-01-14 23:00:29 +01:00
2023-04-15 05:02:08 +02:00
makeAllowedRolesReduce ( guildId : string ) {
return [
( prev : Array < Role > , _ : Role , index : number , originalArray : Array < Role > ) = > {
if ( index !== 0 ) return prev ;
const everyoneRole = originalArray . find ( role = > role . id === guildId ) ;
if ( everyoneRole ) return [ everyoneRole ] ;
return originalArray ;
} ,
[ ] as Array < Role >
] ;
} ,
2023-02-01 12:11:05 +01:00
HiddenChannelLockScreen : ( channel : any ) = > < HiddenChannelLockScreen channel = { channel } / > ,
2023-01-14 23:00:29 +01:00
2023-07-06 00:39:02 +02:00
LockIcon : ErrorBoundary.wrap ( ( ) = > (
2023-01-14 23:00:29 +01:00
< svg
2023-01-23 22:04:50 +01:00
className = { ChannelListClasses . icon }
2023-01-14 23:00:29 +01:00
height = "18"
width = "20"
viewBox = "0 0 24 24"
2023-01-23 22:04:50 +01:00
aria - hidden = { true }
role = "img"
2023-01-14 23:00:29 +01:00
>
2023-02-01 13:59:58 +01:00
< path className = "shc-evenodd-fill-current-color" d = "M17 11V7C17 4.243 14.756 2 12 2C9.242 2 7 4.243 7 7V11C5.897 11 5 11.896 5 13V20C5 21.103 5.897 22 7 22H17C18.103 22 19 21.103 19 20V13C19 11.896 18.103 11 17 11ZM12 18C11.172 18 10.5 17.328 10.5 16.5C10.5 15.672 11.172 15 12 15C12.828 15 13.5 15.672 13.5 16.5C13.5 17.328 12.828 18 12 18ZM15 11H9V7C9 5.346 10.346 4 12 4C13.654 4 15 5.346 15 7V11Z" / >
2023-01-14 23:00:29 +01:00
< / svg >
2023-07-06 00:39:02 +02:00
) , { noop : true } ) ,
2023-01-23 22:04:50 +01:00
2023-02-01 12:11:05 +01:00
HiddenChannelIcon : ErrorBoundary.wrap ( ( ) = > (
2023-01-23 22:04:50 +01:00
< Tooltip text = "Hidden Channel" >
{ ( { onMouseLeave , onMouseEnter } ) = > (
< svg
onMouseLeave = { onMouseLeave }
onMouseEnter = { onMouseEnter }
2023-02-01 12:11:05 +01:00
className = { ChannelListClasses . icon + " " + "shc-hidden-channel-icon" }
2023-01-23 22:04:50 +01:00
width = "24"
height = "24"
viewBox = "0 0 24 24"
aria - hidden = { true }
role = "img"
>
2023-02-01 13:59:58 +01:00
< path className = "shc-evenodd-fill-current-color" d = "m19.8 22.6-4.2-4.15q-.875.275-1.762.413Q12.95 19 12 19q-3.775 0-6.725-2.087Q2.325 14.825 1 11.5q.525-1.325 1.325-2.463Q3.125 7.9 4.15 7L1.4 4.2l1.4-1.4 18.4 18.4ZM12 16q.275 0 .512-.025.238-.025.513-.1l-5.4-5.4q-.075.275-.1.513-.025.237-.025.512 0 1.875 1.312 3.188Q10.125 16 12 16Zm7.3.45-3.175-3.15q.175-.425.275-.862.1-.438.1-.938 0-1.875-1.312-3.188Q13.875 7 12 7q-.5 0-.938.1-.437.1-.862.3L7.65 4.85q1.025-.425 2.1-.638Q10.825 4 12 4q3.775 0 6.725 2.087Q21.675 8.175 23 11.5q-.575 1.475-1.512 2.738Q20.55 15.5 19.3 16.45Zm-4.625-4.6-3-3q.7-.125 1.288.112.587.238 1.012.688.425.45.613 1.038.187.587.087 1.162Z" / >
2023-01-23 22:04:50 +01:00
< / svg >
) }
< / Tooltip >
2023-02-01 12:11:05 +01:00
) , { noop : true } )
2022-10-23 11:44:21 +02:00
} ) ;