2020-10-20 23:25:34 +02:00
/ * *
2020-12-20 13:04:54 +01:00
* @ name HideMutedCategories
2021-03-05 13:26:41 +01:00
* @ author DevilBro
2020-10-20 23:25:34 +02:00
* @ authorId 278543574059057154
2024-05-16 18:54:09 +02:00
* @ version 1.1 . 3
2021-03-05 13:26:41 +01:00
* @ description Hides muted Categories , if muted Channels are hidden
2020-10-20 23:25:34 +02:00
* @ invite Jx3TjNS
2020-11-19 16:45:36 +01:00
* @ donate https : //www.paypal.me/MircoWittrien
* @ patreon https : //www.patreon.com/MircoWittrien
2021-03-09 15:10:55 +01:00
* @ website https : //mwittrien.github.io/
* @ source https : //github.com/mwittrien/BetterDiscordAddons/tree/master/Plugins/HideMutedCategories/
2021-03-10 09:17:37 +01:00
* @ updateUrl https : //mwittrien.github.io/BetterDiscordAddons/Plugins/HideMutedCategories/HideMutedCategories.plugin.js
2020-10-20 23:25:34 +02:00
* /
2020-05-06 11:20:03 +02:00
2020-09-19 20:49:33 +02:00
module . exports = ( _ => {
2022-09-01 14:40:11 +02:00
const changeLog = {
2022-09-02 12:37:10 +02:00
2020-09-19 20:49:33 +02:00
} ;
2020-11-13 19:47:44 +01:00
2022-02-05 21:14:17 +01:00
return ! window . BDFDB _Global || ( ! window . BDFDB _Global . loaded && ! window . BDFDB _Global . started ) ? class {
2022-09-01 14:55:22 +02:00
constructor ( meta ) { for ( let key in meta ) this [ key ] = meta [ key ] ; }
getName ( ) { return this . name ; }
getAuthor ( ) { return this . author ; }
getVersion ( ) { return this . version ; }
getDescription ( ) { return ` The Library Plugin needed for ${ this . name } is missing. Open the Plugin Settings to download it. \n \n ${ this . description } ` ; }
2021-02-01 17:13:13 +01:00
downloadLibrary ( ) {
2023-11-18 18:31:04 +01:00
BdApi . Net . fetch ( "https://mwittrien.github.io/BetterDiscordAddons/Library/0BDFDB.plugin.js" ) . then ( r => {
if ( ! r || r . status != 200 ) throw new Error ( ) ;
else return r . text ( ) ;
} ) . then ( b => {
if ( ! b ) throw new Error ( ) ;
else return require ( "fs" ) . writeFile ( require ( "path" ) . join ( BdApi . Plugins . folder , "0BDFDB.plugin.js" ) , b , _ => BdApi . showToast ( "Finished downloading BDFDB Library" , { type : "success" } ) ) ;
} ) . catch ( error => {
BdApi . alert ( "Error" , "Could not download BDFDB Library Plugin. Try again later or download it manually from GitHub: https://mwittrien.github.io/downloader/?library" ) ;
2021-02-01 17:13:13 +01:00
} ) ;
}
2020-09-19 20:49:33 +02:00
2021-01-06 12:38:36 +01:00
load ( ) {
2020-11-19 16:51:14 +01:00
if ( ! window . BDFDB _Global || ! Array . isArray ( window . BDFDB _Global . pluginQueue ) ) window . BDFDB _Global = Object . assign ( { } , window . BDFDB _Global , { pluginQueue : [ ] } ) ;
2020-09-19 20:49:33 +02:00
if ( ! window . BDFDB _Global . downloadModal ) {
window . BDFDB _Global . downloadModal = true ;
2022-09-01 14:55:22 +02:00
BdApi . showConfirmationModal ( "Library Missing" , ` The Library Plugin needed for ${ this . name } is missing. Please click "Download Now" to install it. ` , {
2020-09-19 20:49:33 +02:00
confirmText : "Download Now" ,
cancelText : "Cancel" ,
onCancel : _ => { delete window . BDFDB _Global . downloadModal ; } ,
2020-09-20 08:15:13 +02:00
onConfirm : _ => {
delete window . BDFDB _Global . downloadModal ;
2021-02-01 17:13:13 +01:00
this . downloadLibrary ( ) ;
2020-09-20 08:15:13 +02:00
}
2020-09-19 20:49:33 +02:00
} ) ;
2020-05-06 11:20:03 +02:00
}
2022-09-01 14:55:22 +02:00
if ( ! window . BDFDB _Global . pluginQueue . includes ( this . name ) ) window . BDFDB _Global . pluginQueue . push ( this . name ) ;
2020-10-09 21:09:35 +02:00
}
2021-01-06 12:38:36 +01:00
start ( ) { this . load ( ) ; }
stop ( ) { }
getSettingsPanel ( ) {
2020-11-28 23:12:09 +01:00
let template = document . createElement ( "template" ) ;
2022-09-01 14:55:22 +02:00
template . innerHTML = ` <div style="color: var(--header-primary); font-size: 16px; font-weight: 300; white-space: pre; line-height: 22px;">The Library Plugin needed for ${ this . name } is missing. \n Please click <a style="font-weight: 500;">Download Now</a> to install it.</div> ` ;
2021-02-01 17:13:13 +01:00
template . content . firstElementChild . querySelector ( "a" ) . addEventListener ( "click" , this . downloadLibrary ) ;
2020-11-28 23:12:09 +01:00
return template . content . firstElementChild ;
}
2020-10-09 21:09:35 +02:00
} : ( ( [ Plugin , BDFDB ] ) => {
2022-06-12 21:39:56 +02:00
const renderLevels = {
CAN _NOT _SHOW : 1 ,
DO _NOT _SHOW : 2 ,
WOULD _SHOW _IF _UNCOLLAPSED : 3 ,
SHOW : 4
} ;
2020-10-09 21:09:35 +02:00
return class HideMutedCategories extends Plugin {
2021-01-06 12:38:36 +01:00
onLoad ( ) {
2022-10-20 12:59:37 +02:00
this . modulePatches = {
before : [
"ChannelsList"
] ,
after : [
"ChannelsList"
]
2020-09-19 20:49:33 +02:00
} ;
2020-12-02 18:07:41 +01:00
2021-04-09 18:13:38 +02:00
this . patchPriority = 9 ;
2020-05-06 11:20:03 +02:00
}
2020-09-19 20:49:33 +02:00
2021-01-06 12:38:36 +01:00
onStart ( ) {
2023-04-16 11:46:28 +02:00
BDFDB . ChannelUtils . rerenderAll ( ) ;
2020-05-06 11:20:03 +02:00
}
2020-09-19 20:49:33 +02:00
2021-01-06 12:38:36 +01:00
onStop ( ) {
2023-04-16 11:46:28 +02:00
BDFDB . ChannelUtils . rerenderAll ( ) ;
2020-05-06 11:20:03 +02:00
}
2022-10-20 12:59:37 +02:00
processChannelsList ( e ) {
2022-06-12 21:39:56 +02:00
if ( ! e . instance . props . guild || ! e . instance . props . guildChannels . hideMutedChannels ) return ;
2020-06-04 16:51:47 +02:00
2020-09-19 20:49:33 +02:00
if ( ! e . returnvalue ) {
2022-06-12 21:39:56 +02:00
e . instance . props . guildChannels . categories = Object . assign ( { } , e . instance . props . guildChannels . categories ) ;
2022-07-29 15:55:23 +02:00
for ( let id in e . instance . props . guildChannels . categories ) if ( e . instance . props . guildChannels . categories [ id ] . isMuted ) {
2022-06-12 21:39:56 +02:00
let channelArray = BDFDB . ObjectUtils . toArray ( e . instance . props . guildChannels . categories [ id ] . channels ) ;
2022-09-27 16:53:10 +02:00
for ( let n of channelArray ) if ( n . renderLevel > renderLevels . DO _NOT _SHOW && n . id != e . instance . props . selectedChannelId && n . id != e . instance . props . selectedVoiceChannelId && BDFDB . LibraryStores . ReadStateStore . getMentionCount ( n . id ) <= 0 ) {
2022-07-29 15:55:23 +02:00
n . renderLevel = renderLevels . CAN _NOT _SHOW ;
BDFDB . ArrayUtils . remove ( e . instance . props . guildChannels . categories [ id ] . shownChannelIds , n . id , true ) ;
}
2024-05-16 18:54:09 +02:00
if ( ! channelArray . length ) e . instance . props . guildChannels . categories [ id ] . channels = { "placeholder" : { } } ;
2022-06-12 21:39:56 +02:00
}
2020-09-19 20:49:33 +02:00
}
else {
2021-02-25 09:02:46 +01:00
let topBar = BDFDB . ReactUtils . findChild ( e . returnvalue , { props : [ [ "className" , BDFDB . disCN . channelsunreadbartop ] ] } ) ;
if ( topBar ) {
let topIsVisible = topBar . props . isVisible ;
2022-10-20 12:59:37 +02:00
topBar . props . isVisible = BDFDB . TimeUtils . suppress ( ( ... args ) => {
2021-02-25 09:02:46 +01:00
args [ 2 ] = args [ 2 ] . filter ( id => ! this . isCategoryMuted ( e . instance . props . guildId , id ) ) ;
2022-09-27 16:53:10 +02:00
return args [ 2 ] . some ( id => BDFDB . LibraryStores . ReadStateStore . hasUnread ( id ) || BDFDB . LibraryStores . ReadStateStore . getMentionCount ( id ) ) ? topIsVisible ( ... args ) : true ;
2022-10-20 12:59:37 +02:00
} , "Error in isVisible of Top Bar in ChannelsList!" , this ) ;
2021-02-25 09:02:46 +01:00
}
let bottomBar = BDFDB . ReactUtils . findChild ( e . returnvalue , { props : [ [ "className" , BDFDB . disCN . channelsunreadbarbottom ] ] } ) ;
if ( bottomBar ) {
let bottomIsVisible = bottomBar . props . isVisible ;
2022-10-20 12:59:37 +02:00
bottomBar . props . isVisible = BDFDB . TimeUtils . suppress ( ( ... args ) => {
2021-02-25 09:02:46 +01:00
args [ 2 ] = args [ 2 ] . filter ( id => ! this . isCategoryMuted ( e . instance . props . guildId , id ) ) ;
2022-09-27 16:53:10 +02:00
return args [ 2 ] . some ( id => BDFDB . LibraryStores . ReadStateStore . hasUnread ( id ) || BDFDB . LibraryStores . ReadStateStore . getMentionCount ( id ) ) ? bottomIsVisible ( ... args ) : true ;
2022-10-20 12:59:37 +02:00
} , "Error in isVisible of Bottom Bar in ChannelsList!" , this ) ;
2021-02-25 09:02:46 +01:00
}
2020-12-02 18:07:41 +01:00
let tree = BDFDB . ReactUtils . findChild ( e . returnvalue , { filter : n => n && n . props && typeof n . props . children == "function" } ) ;
2022-10-20 12:59:37 +02:00
if ( ! tree ) return ;
let childrenRender = tree . props . children ;
tree . props . children = BDFDB . TimeUtils . suppress ( ( ... args ) => {
let children = childrenRender ( ... args ) ;
let list = BDFDB . ReactUtils . findChild ( children , { props : [ [ "className" , BDFDB . disCN . channelsscroller ] ] } ) ;
if ( list ) {
let selectedChannel = BDFDB . LibraryStores . ChannelStore . getChannel ( e . instance . props . selectedChannelId ) ;
let selectedVoiceChannel = BDFDB . LibraryStores . ChannelStore . getChannel ( e . instance . props . selectedVoiceChannelId ) ;
let renderSection = list . props . renderSection ;
list . props . renderSection = BDFDB . TimeUtils . suppress ( ( ... args2 ) => {
let section = renderSection ( ... args2 ) ;
if ( section && section . props && section . props . channel && BDFDB . LibraryStores . UserGuildSettingsStore . isChannelMuted ( e . instance . props . guild . id , section . props . channel . id ) && ! ( selectedChannel && selectedChannel . parent _id == section . props . channel . id ) && ! ( selectedVoiceChannel && selectedVoiceChannel . parent _id == section . props . channel . id ) && BDFDB . ObjectUtils . toArray ( BDFDB . LibraryStores . ChannelStore . getMutableGuildChannelsForGuild ( e . instance . props . guild . id ) ) . filter ( n => n . parent _id == section . props . channel . id && BDFDB . LibraryStores . ReadStateStore . getMentionCount ( n . id ) > 0 ) . length == 0 ) return null ;
else return section ;
} , "Error in renderSection of ChannelsList!" , this ) ;
}
return children ;
} , "Error in Child Render of ChannelsList!" , this ) ;
2020-12-02 18:07:41 +01:00
}
}
2021-02-25 09:02:46 +01:00
isCategoryMuted ( guildId , channelId ) {
if ( ! guildId || ! channelId ) return false ;
2022-09-27 14:48:10 +02:00
let channel = BDFDB . LibraryStores . ChannelStore . getChannel ( channelId ) ;
2022-09-27 16:53:10 +02:00
return channel && channel . parent _id && BDFDB . LibraryStores . UserGuildSettingsStore . isChannelMuted ( guildId , channel . parent _id ) ;
2021-02-25 09:02:46 +01:00
}
2020-09-19 20:49:33 +02:00
} ;
2022-09-01 14:40:11 +02:00
} ) ( window . BDFDB _Global . PluginUtils . buildPlugin ( changeLog ) ) ;
2020-09-19 20:49:33 +02:00
} ) ( ) ;