2020-10-20 23:25:34 +02:00
/ * *
2021-07-11 18:46:40 +02:00
* @ name RemoveBlockedUsers
2021-03-05 13:26:41 +01:00
* @ author DevilBro
2020-10-20 23:25:34 +02:00
* @ authorId 278543574059057154
2024-01-02 18:40:39 +01:00
* @ version 1.6 . 8
2021-03-05 13:26:41 +01:00
* @ description Removes blocked Messages / Users
2020-10-20 23:25:34 +02:00
* @ invite Jx3TjNS
* @ 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/
2021-07-11 18:46:40 +02:00
* @ source https : //github.com/mwittrien/BetterDiscordAddons/tree/master/Plugins/RemoveBlockedUsers/
* @ updateUrl https : //mwittrien.github.io/BetterDiscordAddons/Plugins/RemoveBlockedUsers/RemoveBlockedUsers.plugin.js
2020-10-20 23:25:34 +02:00
* /
2020-02-04 10:22:02 +01:00
2020-09-19 20:49:33 +02:00
module . exports = ( _ => {
2022-09-01 14:40:11 +02:00
const changeLog = {
2023-05-26 15:01:26 +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-02-04 10:22:02 +01: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 ] ) => {
2021-01-10 14:10:06 +01:00
var cachedChannelId , cachedReactions ;
2020-10-06 09:40:54 +02:00
2021-07-11 18:46:40 +02:00
return class RemoveBlockedUsers extends Plugin {
2021-01-06 12:38:36 +01:00
onLoad ( ) {
2020-11-28 20:27:04 +01:00
this . defaults = {
2024-01-02 18:40:39 +01:00
general : {
hideBlocked : { value : false , description : "Hide 'Blocked' Tab in Friends List" }
} ,
2022-10-17 23:02:55 +02:00
notifications : {
2021-05-04 19:33:36 +02:00
messages : { value : true , description : "Messages Notifications" } ,
voiceChat : { value : true , description : "Voice Chat Notifications" } ,
} ,
places : {
messages : { value : true , description : "Messages" } ,
pins : { value : true , description : "Pinned Messages" } ,
inbox : { value : true , description : "Inbox Messages" } ,
replies : { value : true , description : "Replies" } ,
mentions : { value : true , description : "Mentions" } ,
reactions : { value : true , description : "Reactions" } ,
2022-08-02 17:03:30 +02:00
threads : { value : true , description : "Threads" } ,
2023-11-18 18:31:04 +01:00
autocompletes : { value : true , description : "Autocomplete Entries" } ,
2021-05-04 19:33:36 +02:00
memberList : { value : true , description : "Members in List" } ,
voiceList : { value : true , description : "Members in Voice List" } ,
2021-06-09 17:52:32 +02:00
voiceChat : { value : true , description : "Members in Voice Chat" } ,
2022-04-11 13:49:42 +02:00
activity : { value : true , description : "Activity Page" } ,
2023-11-18 18:31:04 +01:00
channelList : { value : true , description : "Channel/Group List" } ,
2021-06-09 17:52:32 +02:00
recentDms : { value : true , description : "Group Notifications" }
2020-11-28 20:27:04 +01:00
}
} ;
2022-10-14 16:34:52 +02:00
this . modulePatches = {
before : [
"ChannelCall" ,
"ChannelItem" ,
"ChannelMembers" ,
"PrivateChannel" ,
"PrivateChannelRecipients" ,
"Message" ,
"Messages" ,
"NowPlayingItem" ,
2023-11-02 12:39:09 +01:00
"ReactionsModalUsers" ,
2023-05-26 15:01:26 +02:00
"RTCConnectionVoiceUsers" ,
2022-10-14 16:34:52 +02:00
"SearchResults" ,
2024-01-02 18:40:39 +01:00
"TabBar" ,
2022-10-14 16:34:52 +02:00
"UserSummaryItem" ,
"VoiceUsers"
] ,
after : [
2022-10-27 15:13:25 +02:00
"BlockedMessageGroup" ,
2022-10-14 16:34:52 +02:00
"ChannelPins" ,
"DirectMessage" ,
"PrivateChannel" ,
"Reactions" ,
2023-11-02 12:39:09 +01:00
"ReactionsModal" ,
2022-10-14 16:34:52 +02:00
"RecentMentions" ,
"RichUserMention" ,
"SearchResultsInner" ,
2023-11-02 12:39:09 +01:00
"ThreadCard" ,
2022-11-05 00:26:25 +01:00
"UserMention" ,
2022-10-14 16:34:52 +02:00
"VoiceUser" ,
"VoiceUsers"
]
2020-09-19 20:49:33 +02:00
} ;
2020-10-15 19:14:17 +02:00
2020-11-13 21:25:46 +01:00
this . patchPriority = 8 ;
2020-02-04 10:22:02 +01:00
}
2020-09-19 20:49:33 +02:00
2021-01-06 12:38:36 +01:00
onStart ( ) {
2022-09-27 14:48:10 +02:00
BDFDB . PatchUtils . patch ( this , BDFDB . LibraryStores . ChannelStore , "getChannel" , { after : e => {
2022-09-27 16:53:10 +02:00
if ( e . returnValue && e . returnValue . isGroupDM ( ) ) return new BDFDB . DiscordObjects . Channel ( Object . assign ( { } , e . returnValue , { rawRecipients : e . returnValue . rawRecipients . filter ( n => ! n || ! BDFDB . LibraryStores . RelationshipStore . isBlocked ( n . id ) ) , recipients : e . returnValue . recipients . filter ( id => ! id || ! BDFDB . LibraryStores . RelationshipStore . isBlocked ( id ) ) } ) )
2021-06-09 17:52:32 +02:00
} } ) ;
2022-05-15 08:04:15 +02:00
2022-09-27 16:53:10 +02:00
BDFDB . PatchUtils . patch ( this , BDFDB . LibraryStores . StageChannelParticipantStore , "getMutableParticipants" , { after : e => {
e . returnValue = e . returnValue . filter ( n => ! n . user || ! BDFDB . LibraryStores . RelationshipStore . isBlocked ( n . user . id ) ) ;
2022-05-12 13:20:47 +02:00
} } ) ;
2021-06-09 17:52:32 +02:00
2021-03-15 14:03:32 +01:00
BDFDB . PatchUtils . patch ( this , BDFDB . LibraryModules . RelationshipUtils , "addRelationship" , { after : e => {
2022-10-14 16:35:54 +02:00
if ( e . methodArguments [ 2 ] == BDFDB . DiscordConstants . RelationshipTypes . BLOCKED ) BDFDB . DiscordUtils . rerenderAll ( ) ;
2021-03-15 14:03:32 +01:00
} } ) ;
2022-11-01 18:31:03 +01:00
BDFDB . PatchUtils . patch ( this , BDFDB . LibraryModules . RelationshipUtils , "removeRelationship" , { after : e => BDFDB . DiscordUtils . rerenderAll ( ) } ) ;
2021-03-15 14:03:32 +01:00
2022-09-27 16:53:10 +02:00
BDFDB . PatchUtils . patch ( this , BDFDB . LibraryStores . ReadStateStore , "getUnreadCount" , { after : e => {
2022-10-17 23:02:55 +02:00
if ( e . returnValue && this . settings . notifications . messages && e . returnValue < BDFDB . DiscordConstants . MAX _MESSAGES _PER _CHANNEL ) {
2022-09-27 16:53:10 +02:00
let sub = 0 , messages = [ ] . concat ( BDFDB . LibraryStores . MessageStore . getMessages ( e . methodArguments [ 0 ] ) . _array ) . reverse ( ) ;
2021-05-04 19:33:36 +02:00
for ( let i = 0 ; i < e . returnValue ; i ++ ) if ( messages [ i ] && messages [ i ] . blocked ) sub ++ ;
e . returnValue -= sub ;
}
} } ) ;
2022-09-27 16:53:10 +02:00
BDFDB . PatchUtils . patch ( this , BDFDB . LibraryStores . ReadStateStore , "hasUnread" , { after : e => {
2022-10-17 23:02:55 +02:00
if ( e . returnValue && this . settings . notifications . messages && BDFDB . LibraryStores . ReadStateStore . getUnreadCount ( e . methodArguments [ 0 ] ) < BDFDB . DiscordConstants . MAX _MESSAGES _PER _CHANNEL ) {
2022-09-27 16:53:10 +02:00
let id = BDFDB . LibraryStores . ReadStateStore . lastMessageId ( e . methodArguments [ 0 ] ) ;
let message = id && BDFDB . LibraryStores . MessageStore . getMessage ( e . methodArguments [ 0 ] , id ) ;
2022-04-22 18:33:34 +02:00
if ( message && message . blocked ) {
2022-09-27 16:53:10 +02:00
let oldestId = BDFDB . LibraryStores . ReadStateStore . getOldestUnreadMessageId ( e . methodArguments [ 0 ] ) ;
let messages = BDFDB . LibraryStores . MessageStore . getMessages ( e . methodArguments [ 0 ] ) ;
2022-04-22 18:33:34 +02:00
if ( messages && oldestId ) {
let index = messages . _array . indexOf ( messages . _array . find ( c => c . id == oldestId ) ) ;
if ( index > - 1 ) return messages . _array . slice ( index ) . some ( c => ! c . blocked ) ;
2020-09-29 08:10:01 +02:00
}
}
}
} } ) ;
2022-09-27 16:53:10 +02:00
BDFDB . PatchUtils . patch ( this , BDFDB . LibraryStores . GuildReadStateStore , "hasUnread" , { after : e => {
2022-10-17 23:02:55 +02:00
if ( e . returnValue && this . settings . notifications . messages ) return BDFDB . LibraryStores . GuildChannelStore . getChannels ( e . methodArguments [ 0 ] ) . SELECTABLE . map ( n => n . channel && n . channel . id ) . filter ( n => n && n != "null" ) . some ( id => BDFDB . LibraryStores . ReadStateStore . hasUnread ( id ) ) ;
2020-09-29 08:10:01 +02:00
} } ) ;
2020-09-29 08:10:27 +02:00
2022-09-27 20:22:50 +02:00
BDFDB . PatchUtils . patch ( this , BDFDB . LibraryModules . QuerySearchUtils , [ "queryDMUsers" , "queryFriends" , "queryGuildUsers" , "queryChannelUsers" ] , { after : e => {
if ( ! e . methodArguments [ 0 ] . query ) return ;
e . returnValue = e . returnValue . filter ( n => ! n || ! n . record || ! n . record . id || ! BDFDB . LibraryStores . RelationshipStore . isBlocked ( n . record . id ) ) ;
2020-10-15 19:14:17 +02:00
} } ) ;
2020-11-13 21:25:46 +01:00
let muteTimeout ;
2022-09-27 20:19:49 +02:00
let channelId = BDFDB . LibraryModules . RTCConnectionUtils . getChannelId ( ) ;
2023-04-16 11:08:32 +02:00
let oldUnblockedConnectedUsers = [ BDFDB . LibraryStores . SortedVoiceStateStore . getVoiceStates ( BDFDB . LibraryModules . RTCConnectionUtils . getGuildId ( ) ) [ channelId ] ] . flat ( ) . filter ( n => n && n . user && ! BDFDB . LibraryStores . RelationshipStore . isBlocked ( n . user . id ) ) ;
2022-10-17 23:51:55 +02:00
BDFDB . PatchUtils . patch ( this , BDFDB . LibraryModules . SoundUtils , "playSound" , { before : e => {
2020-11-13 21:25:46 +01:00
let type = e . methodArguments [ 0 ] ;
2022-10-17 23:51:55 +02:00
if ( ! this . settings . notifications . voiceChat || ! [ "disconnect" , "user_join" , "user_leave" , "user_moved" ] . includes ( type ) ) return ;
channelId = BDFDB . LibraryModules . RTCConnectionUtils . getChannelId ( ) ;
if ( channelId ) {
2023-04-15 18:14:11 +02:00
let allConnectedUsers = [ BDFDB . LibraryStores . SortedVoiceStateStore . getVoiceStates ( BDFDB . LibraryModules . RTCConnectionUtils . getGuildId ( ) ) [ channelId ] ] . flat ( ) ;
2023-04-16 11:08:32 +02:00
let unblockedUsers = allConnectedUsers . filter ( n => n && ! BDFDB . LibraryStores . RelationshipStore . isBlocked ( n . user . id ) ) ;
let unmutedBlockedUsers = allConnectedUsers . filter ( n => n && BDFDB . LibraryStores . RelationshipStore . isBlocked ( n . user . id ) && ! BDFDB . LibraryStores . MediaEngineStore . isLocalMute ( n . userId ) ) ;
2022-10-17 23:51:55 +02:00
if ( unmutedBlockedUsers . length ) {
BDFDB . TimeUtils . clear ( muteTimeout ) ;
muteTimeout = BDFDB . TimeUtils . timeout ( _ => {
2023-06-08 11:05:01 +02:00
while ( unmutedBlockedUsers . length ) {
let userId = unmutedBlockedUsers . pop ( ) . user . id ;
if ( ! BDFDB . LibraryStores . MediaEngineStore . isLocalMute ( userId ) ) BDFDB . LibraryModules . MediaEngineUtils . toggleLocalMute ( userId ) ;
}
2022-10-17 23:51:55 +02:00
} , 1000 ) ;
2022-06-28 18:41:58 +02:00
}
2023-04-16 11:08:32 +02:00
if ( unblockedUsers . length == oldUnblockedConnectedUsers . length ) e . methodArguments [ 1 ] = 0 ;
oldUnblockedConnectedUsers = unblockedUsers ;
2020-11-13 21:25:46 +01:00
}
2023-04-16 11:08:32 +02:00
else oldUnblockedConnectedUsers = [ ] ;
2020-11-13 21:25:46 +01:00
} } ) ;
2022-10-14 16:35:54 +02:00
BDFDB . DiscordUtils . rerenderAll ( ) ;
2020-09-19 20:49:33 +02:00
}
2021-01-06 12:38:36 +01:00
onStop ( ) {
2022-10-14 16:35:54 +02:00
BDFDB . DiscordUtils . rerenderAll ( ) ;
2020-10-06 09:40:54 +02:00
}
getSettingsPanel ( collapseStates = { } ) {
2021-05-04 19:33:36 +02:00
let settingsPanel ;
return settingsPanel = BDFDB . PluginUtils . createSettingsPanel ( this , {
collapseStates : collapseStates ,
children : _ => {
let settingsItems = [ ] ;
2024-01-02 18:40:39 +01:00
for ( let key in this . defaults . general ) settingsItems . push ( BDFDB . ReactUtils . createElement ( BDFDB . LibraryComponents . SettingsSaveItem , {
type : "Switch" ,
plugin : this ,
keys : [ "general" , key ] ,
label : this . defaults . general [ key ] . description ,
value : this . settings . general [ key ]
} ) ) ;
2021-05-04 19:33:36 +02:00
settingsItems . push ( BDFDB . ReactUtils . createElement ( BDFDB . LibraryComponents . SettingsPanelList , {
title : "Disable" ,
2022-10-17 23:02:55 +02:00
children : Object . keys ( this . defaults . notifications ) . map ( key => BDFDB . ReactUtils . createElement ( BDFDB . LibraryComponents . SettingsSaveItem , {
2021-05-04 19:33:36 +02:00
type : "Switch" ,
plugin : this ,
2022-10-17 23:02:55 +02:00
keys : [ "notifications" , key ] ,
label : this . defaults . notifications [ key ] . description ,
value : this . settings . notifications [ key ]
2021-05-04 19:33:36 +02:00
} ) )
} ) ) ;
settingsItems . push ( BDFDB . ReactUtils . createElement ( BDFDB . LibraryComponents . SettingsPanelList , {
title : "Remove" ,
children : Object . keys ( this . defaults . places ) . map ( key => BDFDB . ReactUtils . createElement ( BDFDB . LibraryComponents . SettingsSaveItem , {
type : "Switch" ,
plugin : this ,
keys : [ "places" , key ] ,
label : this . defaults . places [ key ] . description ,
value : this . settings . places [ key ]
} ) )
} ) ) ;
return settingsItems ;
}
} ) ;
2020-10-06 09:40:54 +02:00
}
2021-01-06 12:38:36 +01:00
onSettingsClosed ( ) {
2020-10-06 09:40:54 +02:00
if ( this . SettingsUpdated ) {
delete this . SettingsUpdated ;
2022-10-14 16:35:54 +02:00
BDFDB . DiscordUtils . rerenderAll ( ) ;
2020-10-06 09:40:54 +02:00
}
}
2020-09-19 20:49:33 +02:00
processMessages ( e ) {
2022-10-14 16:34:52 +02:00
if ( ! this . settings . places . messages ) return ;
if ( BDFDB . ArrayUtils . is ( e . instance . props . channelStream ) ) {
let oldStream = e . instance . props . channelStream . filter ( n => n . type != "MESSAGE_GROUP_BLOCKED" ) , newStream = [ ] ;
2022-10-17 23:02:55 +02:00
if ( oldStream . length != e . instance . props . channelStream . length ) {
for ( let i in oldStream ) {
let next = parseInt ( i ) + 1 ;
if ( oldStream [ i ] . type != "DIVIDER" || ( oldStream [ next ] && oldStream [ i ] . type == "DIVIDER" && oldStream [ next ] . type != "DIVIDER" && oldStream . slice ( next ) . some ( nextStream => nextStream . type != "DIVIDER" ) ) ) newStream . push ( oldStream [ i ] ) ;
}
let groupId , timestamp , author ;
for ( let i in newStream ) {
if ( newStream [ i ] . type == "MESSAGE" && BDFDB . DiscordConstants . MessageTypeGroups . USER _MESSAGE . has ( newStream [ i ] . content . type ) && groupId != newStream [ i ] . groupId && timestamp && newStream [ i ] . content . timestamp - timestamp < 600000 ) {
if ( author && author . id == newStream [ i ] . content . author . id && author . username == newStream [ i ] . content . author . username ) newStream [ i ] = Object . assign ( { } , newStream [ i ] , { groupId : groupId } ) ;
author = newStream [ i ] . content . author ;
}
else author = null ;
groupId = newStream [ i ] . groupId ;
timestamp = newStream [ i ] . content . timestamp ;
2022-10-14 16:34:52 +02:00
}
2022-10-17 23:02:55 +02:00
e . instance . props . channelStream = newStream ;
2020-09-19 20:49:33 +02:00
}
2022-10-14 16:34:52 +02:00
}
if ( BDFDB . ObjectUtils . is ( e . instance . props . messages ) && BDFDB . ArrayUtils . is ( e . instance . props . messages . _array ) ) {
let messages = e . instance . props . messages ;
e . instance . props . messages = new BDFDB . DiscordObjects . Messages ( messages ) ;
for ( let key in messages ) e . instance . props . messages [ key ] = messages [ key ] ;
e . instance . props . messages . _array = [ ] . concat ( e . instance . props . messages . _array . filter ( n => ! n . author || ! BDFDB . LibraryStores . RelationshipStore . isBlocked ( n . author . id ) ) ) ;
if ( e . instance . props . oldestUnreadMessageId && e . instance . props . messages . _array . every ( n => n . id != e . instance . props . oldestUnreadMessageId ) ) e . instance . props . oldestUnreadMessageId = null ;
2020-09-16 16:20:38 +02:00
}
2020-02-04 10:22:02 +01:00
}
2020-10-06 09:40:54 +02:00
2022-10-27 15:13:25 +02:00
processBlockedMessageGroup ( e ) {
if ( ! this . settings . places . messages ) return ;
return null ;
}
2020-11-21 17:55:42 +01:00
processMessage ( e ) {
2022-10-14 16:34:52 +02:00
if ( ! this . settings . places . replies ) return ;
let repliedMessage = e . instance . props . childrenRepliedMessage ;
if ( repliedMessage && repliedMessage . props && repliedMessage . props . children && repliedMessage . props . children . props && repliedMessage . props . children . props . referencedMessage && repliedMessage . props . children . props . referencedMessage . message && repliedMessage . props . children . props . referencedMessage . message . author && BDFDB . LibraryStores . RelationshipStore . isBlocked ( repliedMessage . props . children . props . referencedMessage . message . author . id ) ) {
delete e . instance . props . childrenRepliedMessage ;
let header = e . instance . props . childrenHeader ;
if ( header && header . props ) {
delete header . props . referencedMessage ;
delete header . props . referencedUsernameProfile ;
delete header . props . replyReference ;
header . props . message = new BDFDB . DiscordObjects . Message ( Object . assign ( { } , header . props . message , { messageReference : null } ) ) ;
2020-11-21 17:55:42 +01:00
}
}
}
2022-04-27 14:55:19 +02:00
processSearchResults ( e ) {
if ( this . settings . places . messages && e . instance . props . blockCount && e . instance . props . search && e . instance . props . search . totalResults <= BDFDB . DiscordConstants . SEARCH _PAGE _SIZE ) e . instance . props . search = Object . assign ( { } , e . instance . props . search , { totalResults : e . instance . props . search . totalResults - e . instance . props . blockCount } ) ;
}
processSearchResultsInner ( e ) {
2022-10-14 16:34:52 +02:00
if ( ! this . settings . places . messages || ! e . instance . props . search ) return ;
let [ children , index ] = BDFDB . ReactUtils . findParent ( e . returnvalue , { props : [ [ "className" , BDFDB . disCN . searchresultsblocked ] ] } ) ;
if ( index > - 1 ) children . splice ( index , 1 ) ;
2022-04-27 14:55:19 +02:00
}
2020-11-21 17:55:42 +01:00
2020-11-20 16:52:10 +01:00
processChannelPins ( e ) {
2022-09-27 16:53:10 +02:00
if ( this . settings . places . pins && e . returnvalue . props && e . returnvalue . props . children && e . returnvalue . props . children . props && BDFDB . ArrayUtils . is ( e . returnvalue . props . children . props . messages ) ) e . returnvalue . props . children . props . messages = e . returnvalue . props . children . props . messages . filter ( n => ! n || ! n . author || ! n . author . id || ! BDFDB . LibraryStores . RelationshipStore . isBlocked ( n . author . id ) ) ;
2020-11-20 16:52:10 +01:00
}
2020-11-21 17:55:42 +01:00
2020-11-20 16:52:10 +01:00
processRecentMentions ( e ) {
2022-09-27 16:53:10 +02:00
if ( this . settings . places . inbox && BDFDB . ArrayUtils . is ( e . returnvalue . props . messages ) ) e . returnvalue . props . messages = e . returnvalue . props . messages . filter ( n => ! n || ! n . author || ! n . author . id || ! BDFDB . LibraryStores . RelationshipStore . isBlocked ( n . author . id ) ) ;
2020-10-29 00:15:33 +01:00
}
2021-01-10 14:10:06 +01:00
processReactions ( e ) {
2022-10-14 16:34:52 +02:00
if ( ! this . settings . places . reactions ) return ;
2022-10-28 09:51:59 +02:00
if ( ! e . returnvalue || ! e . returnvalue . props . children ) return ;
let emojiArrayIndex = e . returnvalue . props . children . findIndex ( n => BDFDB . ArrayUtils . is ( n ) && n [ 0 ] && n [ 0 ] . props && n [ 0 ] . props . emoji ) ;
if ( emojiArrayIndex == - 1 ) return ;
for ( let i in e . returnvalue . props . children [ emojiArrayIndex ] ) {
let reaction = e . returnvalue . props . children [ emojiArrayIndex ] [ i ] ;
2023-06-07 18:32:27 +02:00
let nativeReaction = reaction . props . message . reactions . find ( n => n && n . emoji == reaction . props . emoji ) ;
if ( nativeReaction ) reaction . props . count = nativeReaction . count ;
let reactions = BDFDB . ObjectUtils . toArray ( BDFDB . LibraryStores . MessageReactionsStore . getReactions ( reaction . props . message . channel _id , reaction . props . message . id , reaction . props . emoji ) ) ;
if ( ! reactions || ! reactions . length ) return ;
let blocked = 0 ;
reactions . forEach ( n => { if ( n && BDFDB . LibraryStores . RelationshipStore . isBlocked ( n . id ) ) blocked ++ ; } ) ;
if ( blocked ) {
reaction . props . count -= blocked ;
if ( ! reaction . props . count ) e . returnvalue . props . children [ emojiArrayIndex ] [ i ] = null ;
2021-01-10 14:10:06 +01:00
}
}
2022-10-28 09:51:59 +02:00
if ( ! e . returnvalue . props . children [ emojiArrayIndex ] . filter ( n => n ) . length ) return null ;
2021-01-10 14:10:06 +01:00
}
2020-10-29 00:15:33 +01:00
2023-11-02 12:39:09 +01:00
processReactionsModal ( e ) {
2023-06-07 18:32:27 +02:00
if ( ! this . settings . places . reactions ) return ;
let [ reactionEntries , index ] = BDFDB . ReactUtils . findParent ( e . returnvalue . props . children , { filter : n => n && n . props && n . props . emoji } ) ;
if ( index == - 1 ) return ;
for ( let i in reactionEntries ) {
let reaction = reactionEntries [ i ] ;
reaction . props = Object . assign ( { } , reaction . props ) ;
let reactions = BDFDB . ObjectUtils . toArray ( BDFDB . LibraryStores . MessageReactionsStore . getReactions ( e . instance . props . message . channel _id , e . instance . props . message . id , reaction . props . emoji ) ) ;
if ( reactions && reactions . length ) {
let blocked = 0 ;
reactions . forEach ( n => { if ( n && BDFDB . LibraryStores . RelationshipStore . isBlocked ( n . id ) ) blocked ++ ; } ) ;
if ( blocked ) reaction . props . count -= blocked ;
if ( ! reaction . props . count ) reactionEntries [ i ] = null ;
}
}
}
2023-11-02 12:39:09 +01:00
processReactionsModalUsers ( e ) {
2022-09-27 16:53:10 +02:00
if ( this . settings . places . reactions && BDFDB . ArrayUtils . is ( e . instance . props . reactors ) ) e . instance . props . reactors = e . instance . props . reactors . filter ( n => ! n || ! BDFDB . LibraryStores . RelationshipStore . isBlocked ( n . id ) ) ;
2020-10-19 10:38:04 +02:00
}
2022-04-11 13:49:42 +02:00
2022-11-29 18:50:17 +01:00
processThreadCard ( e ) {
2022-08-02 17:03:30 +02:00
if ( ! this . settings . places . threads ) return ;
let [ children , index ] = BDFDB . ReactUtils . findParent ( e . returnvalue , { filter : n => n && n . type && n . type . toString ( ) . indexOf ( ".getMostRecentMessage" ) > - 1 } ) ;
if ( index > - 1 && children [ index ] . props && children [ index ] . props . channel ) {
2022-09-27 16:53:10 +02:00
let message = BDFDB . LibraryStores . MessageStore . getMessage ( children [ index ] . props . channel . id , children [ index ] . props . channel . lastMessageId ) ;
if ( message && BDFDB . LibraryStores . RelationshipStore . isBlocked ( message . author . id ) ) children [ index ] = null ;
2022-08-02 17:03:30 +02:00
}
}
2022-10-14 16:34:52 +02:00
processChannelMembers ( e ) {
2022-04-11 13:49:42 +02:00
if ( ! this . settings . places . memberList ) return ;
2022-10-14 16:34:52 +02:00
let hiddenRows = false , newRows = new Array ( e . instance . props . rows . length ) , newGroups = new Array ( e . instance . props . groups . length ) ;
for ( let i in e . instance . props . groups ) newGroups [ i ] = Object . assign ( { } , e . instance . props . groups [ i ] ) ;
for ( let i in e . instance . props . rows ) {
let row = e . instance . props . rows [ i ] ;
2022-04-11 13:49:42 +02:00
if ( ! row || row . type != "MEMBER" ) newRows [ i ] = row ;
2022-09-27 16:53:10 +02:00
else if ( ! row . user || ! BDFDB . LibraryStores . RelationshipStore . isBlocked ( row . user . id ) ) newRows [ i ] = row ;
2022-04-11 13:49:42 +02:00
else {
hiddenRows = true ;
let found = false , rowIndex = i - 1 ;
while ( ! found && rowIndex > - 1 ) {
if ( newRows [ rowIndex ] && newRows [ rowIndex ] . type == "GROUP" ) {
found = true ;
let groupIndex = newGroups . findIndex ( r => r . id == newRows [ rowIndex ] . id ) ;
if ( groupIndex > - 1 ) {
newGroups [ groupIndex ] . count = newGroups [ groupIndex ] . count - 1 ;
newRows [ rowIndex ] . count = newGroups [ groupIndex ] . count ;
2020-10-15 14:34:57 +02:00
}
}
2022-04-11 13:49:42 +02:00
else rowIndex -- ;
2020-10-15 14:34:57 +02:00
}
}
2022-04-11 13:49:42 +02:00
}
if ( hiddenRows ) {
let indexSum = 0 ;
2022-04-24 11:59:31 +02:00
for ( let i in newGroups ) {
newGroups [ i ] . index = indexSum ;
if ( newGroups [ i ] . count > 0 ) indexSum += ( newGroups [ i ] . count + 1 ) ;
}
2022-04-11 13:49:42 +02:00
for ( let i in newRows ) if ( newRows [ i ] && newRows [ i ] . type == "GROUP" && newRows [ i ] . count <= 0 ) newRows [ i ] = undefined ;
const removeEmptyWithin = ( array , filter ) => {
2022-08-12 13:12:53 +02:00
let reversed = [ ] . concat ( array ) . reverse ( ) , suffixLength = 0 ;
2022-04-11 13:49:42 +02:00
for ( let i in reversed ) if ( reversed [ i ] !== undefined ) {
suffixLength = parseInt ( i ) ;
break ;
2022-03-02 19:22:13 +01:00
}
2022-08-12 13:12:53 +02:00
return [ ] . concat ( array . filter ( filter ) , new Array ( suffixLength ) )
2022-04-11 13:49:42 +02:00
} ;
2022-10-14 16:34:52 +02:00
e . instance . props . rows = removeEmptyWithin ( newRows , n => n ) ;
e . instance . props . groups = removeEmptyWithin ( newGroups , g => g && g . count > 0 ) ;
2020-10-15 14:34:57 +02:00
}
2020-10-06 09:40:54 +02:00
}
2020-10-15 14:34:57 +02:00
2022-08-12 13:12:53 +02:00
processPrivateChannelRecipients ( e ) {
2022-09-27 16:53:10 +02:00
if ( this . settings . places . voiceChat && e . instance . props . channel && e . instance . props . channel . isGroupDM ( ) ) e . instance . props . channel = new BDFDB . DiscordObjects . Channel ( Object . assign ( { } , e . instance . props . channel , { rawRecipients : e . instance . props . channel . rawRecipients . filter ( n => ! n || ! BDFDB . LibraryStores . RelationshipStore . isBlocked ( n . id ) ) , recipients : e . instance . props . channel . recipients . filter ( id => ! id || ! BDFDB . LibraryStores . RelationshipStore . isBlocked ( id ) ) } ) ) ;
2022-08-12 13:12:53 +02:00
}
2022-04-11 13:49:42 +02:00
processNowPlayingItem ( e ) {
2022-10-14 16:34:52 +02:00
if ( ! this . settings . places . activity ) return ;
let [ children , index ] = BDFDB . ReactUtils . findParent ( e . instance , { name : "NowPlayingHeader" } ) ;
if ( index > - 1 ) for ( let child of children ) if ( child && child . props && child . props . party ) {
2022-11-29 18:50:17 +01:00
child . props . party = Object . assign ( { } , child . props . party ) ;
2022-10-19 11:42:54 +02:00
if ( child . props . party . priorityMembers ) {
child . props . party . priorityMembers = child . props . party . priorityMembers . filter ( n => ! n || ! n . user || ! BDFDB . LibraryStores . RelationshipStore . isBlocked ( n . user . id ) ) ;
if ( ! child . props . party . priorityMembers . length ) child . props . party . priorityMembers . push ( { user : new BDFDB . DiscordObjects . User ( { id : 0 , username : "" } ) } ) ;
2022-04-11 13:49:42 +02:00
}
2022-10-19 11:42:54 +02:00
if ( child . props . party . partiedMembers ) child . props . party . partiedMembers = child . props . party . partiedMembers . filter ( n => ! n || ! BDFDB . LibraryStores . RelationshipStore . isBlocked ( n . id ) ) ;
if ( child . props . party . voiceChannels ) for ( let i in child . props . party . voiceChannels ) child . props . party . voiceChannels [ i ] = Object . assign ( { } , child . props . party . voiceChannels [ i ] , { members : child . props . party . voiceChannels [ i ] . members . filter ( n => ! n || ! BDFDB . LibraryStores . RelationshipStore . isBlocked ( n . id ) ) } ) ;
2022-04-11 13:49:42 +02:00
}
}
2022-05-12 13:20:47 +02:00
processChannelItem ( e ) {
2022-10-14 16:34:52 +02:00
if ( ! this . settings . places . voiceList ) return ;
let channelInfo = BDFDB . ReactUtils . findChild ( e . instance . props . children , { props : [ [ "className" , BDFDB . disCN . channelinfo ] ] } ) ;
if ( channelInfo && channelInfo . props && channelInfo . props . children && channelInfo . props . children . props && BDFDB . ArrayUtils . is ( channelInfo . props . children . props . voiceStates ) ) {
let newVoiceStates = [ ] . concat ( channelInfo . props . children . props . voiceStates ) . filter ( n => ! n . user || ! BDFDB . LibraryStores . RelationshipStore . isBlocked ( n . user . id ) ) ;
if ( channelInfo . props . children . props . channel . userLimit ) channelInfo . props . children . props . channel = new BDFDB . DiscordObjects . Channel ( Object . assign ( { } , channelInfo . props . children . props . channel , { userLimit : channelInfo . props . children . props . channel . userLimit - ( channelInfo . props . children . props . voiceStates . length - newVoiceStates . length ) } ) ) ;
channelInfo . props . children . props . voiceStates = newVoiceStates ;
2022-05-12 13:20:47 +02:00
}
}
2022-10-14 16:34:52 +02:00
processVoiceUser ( e ) {
if ( this . settings . places . voiceList && e . instance . props . user && BDFDB . LibraryStores . RelationshipStore . isBlocked ( e . instance . props . user . id ) ) return null ;
}
2020-10-06 09:40:54 +02:00
processVoiceUsers ( e ) {
2022-10-14 16:34:52 +02:00
if ( ! this . settings . places . voiceList || ! BDFDB . ArrayUtils . is ( e . instance . props . voiceStates ) ) return ;
if ( ! e . returnvalue ) {
if ( e . instance . props . children && e . instance . props . children . props && e . instance . props . children . props . numAudience ) e . instance . props . children . props . numAudience = BDFDB . LibraryStores . StageChannelParticipantStore . getMutableParticipants ( e . instance . props . channel . id ) . length ;
e . instance . props . voiceStates = [ ] . concat ( e . instance . props . voiceStates ) . filter ( n => ! n . user || ! BDFDB . LibraryStores . RelationshipStore . isBlocked ( n . user . id ) ) ;
}
else {
if ( e . instance . props . children && e . instance . props . children . props && e . instance . props . children . props . numAudience === 0 ) return null ;
2022-05-12 13:20:47 +02:00
}
2020-10-15 14:34:57 +02:00
}
2020-10-06 09:40:54 +02:00
2023-05-26 15:01:26 +02:00
processRTCConnectionVoiceUsers ( e ) {
if ( ! this . settings . places . voiceChat || ! e . instance . props . voiceStates ) return ;
e . instance . props . voiceStates = [ ] . concat ( e . instance . props . voiceStates ) . filter ( n => ! n . user || ! BDFDB . LibraryStores . RelationshipStore . isBlocked ( n . user . id ) ) ;
}
2021-06-09 17:52:32 +02:00
processDirectMessage ( e ) {
2022-10-14 16:34:52 +02:00
if ( ! this . settings . places . recentDms || ! e . instance . props . channel ) return ;
if ( e . instance . props . channel . isGroupDM ( ) ) {
if ( ! e . instance . props . channel . name ) {
let tooltip = BDFDB . ReactUtils . findChild ( e . returnvalue , { name : "ListItemTooltip" } ) ;
if ( tooltip ) tooltip . props . text = this . getGroupName ( e . instance . props . channel . id ) ;
2022-03-30 12:57:12 +02:00
}
2021-06-09 17:52:32 +02:00
}
2022-10-14 16:34:52 +02:00
else {
if ( BDFDB . LibraryStores . RelationshipStore . isBlocked ( e . instance . props . channel . getRecipientId ( ) ) ) e . returnvalue = null ;
}
2021-06-09 17:52:32 +02:00
}
2020-10-15 19:14:17 +02:00
processPrivateChannel ( e ) {
2022-10-14 16:34:52 +02:00
if ( ! this . settings . places . channelList || ! e . instance . props . channel ) return ;
if ( e . instance . props . channel . isGroupDM ( ) ) {
if ( ! e . returnvalue ) {
e . instance . props . channel = new BDFDB . DiscordObjects . Channel ( Object . assign ( { } , e . instance . props . channel , { rawRecipients : e . instance . props . channel . rawRecipients . filter ( n => ! n || ! BDFDB . LibraryStores . RelationshipStore . isBlocked ( n . id ) ) , recipients : e . instance . props . channel . recipients . filter ( id => ! id || ! BDFDB . LibraryStores . RelationshipStore . isBlocked ( id ) ) } ) ) ;
2021-06-09 17:52:32 +02:00
}
2022-03-30 12:57:12 +02:00
else {
2022-10-14 16:34:52 +02:00
if ( ! e . instance . props . channel . name ) {
let wrapper = e . returnvalue && e . returnvalue . props . children && e . returnvalue . props . children . props && typeof e . returnvalue . props . children . props . children == "function" ? e . returnvalue . props . children : e . returnvalue ;
if ( typeof wrapper . props . children == "function" ) {
let childrenRender = wrapper . props . children ;
wrapper . props . children = BDFDB . TimeUtils . suppress ( ( ... args ) => {
let children = childrenRender ( ... args ) ;
children . props . name = BDFDB . ReactUtils . createElement ( "span" , { children : this . getGroupName ( e . instance . props . channel . id ) } ) ;
return children ;
2022-11-05 00:26:25 +01:00
} , "Error in Children Render of PrivateChannel!" , this ) ;
2022-10-14 16:34:52 +02:00
}
else wrapper . props . name = BDFDB . ReactUtils . createElement ( "span" , { children : this . getGroupName ( e . instance . props . channel . id ) } ) ;
}
2022-03-30 12:57:12 +02:00
}
2021-06-09 17:52:32 +02:00
}
2022-10-14 16:34:52 +02:00
else {
if ( e . returnvalue && BDFDB . LibraryStores . RelationshipStore . isBlocked ( e . instance . props . channel . getRecipientId ( ) ) ) e . returnvalue = null ;
2021-07-19 09:00:02 +02:00
}
2020-10-06 09:40:54 +02:00
}
processChannelCall ( e ) {
2022-10-14 16:34:52 +02:00
if ( ! this . settings . places . voiceChat ) return ;
if ( BDFDB . ArrayUtils . is ( e . instance . props . participants ) ) e . instance . props . participants = [ ] . concat ( e . instance . props . participants ) . filter ( n => ! n . user || ! BDFDB . LibraryStores . RelationshipStore . isBlocked ( n . user . id ) ) ;
if ( BDFDB . ArrayUtils . is ( e . instance . props . filteredParticipants ) ) e . instance . props . filteredParticipants = [ ] . concat ( e . instance . props . filteredParticipants ) . filter ( n => ! n . user || ! BDFDB . LibraryStores . RelationshipStore . isBlocked ( n . user . id ) ) ;
2020-10-06 09:40:54 +02:00
}
processUserSummaryItem ( e ) {
2022-09-27 16:53:10 +02:00
if ( this . settings . places . memberList && BDFDB . ArrayUtils . is ( e . instance . props . users ) ) e . instance . props . users = [ ] . concat ( e . instance . props . users ) . filter ( n => ! n || ! BDFDB . LibraryStores . RelationshipStore . isBlocked ( n . id ) ) ;
2020-10-06 09:40:54 +02:00
}
2020-10-15 19:14:17 +02:00
2021-02-24 17:32:17 +01:00
processRichUserMention ( e ) {
2022-09-27 16:53:10 +02:00
if ( e . instance . props . id && this . settings . places . mentions && BDFDB . LibraryStores . RelationshipStore . isBlocked ( e . instance . props . id ) ) return BDFDB . ReactUtils . createElement ( "span" , {
2021-02-24 17:32:17 +01:00
className : BDFDB . DOMUtils . formatClassName ( BDFDB . disCN . mention , BDFDB . disCN . mentionwrapper , e . instance . props . className ) ,
2021-01-10 14:10:06 +01:00
children : [ "@" + BDFDB . LanguageUtils . LanguageStrings . UNKNOWN _USER ]
2020-10-15 19:14:17 +02:00
} ) ;
}
2021-06-09 17:52:32 +02:00
2022-11-05 00:26:25 +01:00
processUserMention ( e ) {
if ( e . instance . props . userId && this . settings . places . mentions && BDFDB . LibraryStores . RelationshipStore . isBlocked ( e . instance . props . userId ) ) {
let childrenRender = e . returnvalue . props . children ;
e . returnvalue . props . children = BDFDB . TimeUtils . suppress ( ( ... args ) => {
let children = childrenRender ( ... args ) ;
if ( children && children . props ) children . props . children = "@" + BDFDB . LanguageUtils . LanguageStrings . UNKNOWN _USER ;
return children ;
} , "Error in Children Render of PrivateChannel!" , this ) ;
}
}
2024-01-02 18:40:39 +01:00
processTabBar ( e ) {
if ( this . settings . general . hideBlocked && e . instance . props . children && e . instance . props . children . some ( c => c && c . props && c . props . id == BDFDB . DiscordConstants . FriendsSections . ADD _FRIEND ) ) {
e . instance . props . children = e . instance . props . children . filter ( c => c && c . props . id != BDFDB . DiscordConstants . FriendsSections . BLOCKED ) ;
}
}
2021-06-09 17:52:32 +02:00
getGroupName ( channelId ) {
2022-09-27 14:48:10 +02:00
let channel = BDFDB . LibraryStores . ChannelStore . getChannel ( channelId ) ;
2021-06-09 17:52:32 +02:00
if ( channel . name ) return channel . name ;
2022-09-27 16:53:10 +02:00
let recipients = channel . recipients . map ( BDFDB . LibraryStores . UserStore . getUser ) . filter ( n => n && ! BDFDB . LibraryStores . RelationshipStore . isBlocked ( n . id ) ) ;
2021-06-09 17:52:32 +02:00
return recipients . length > 0 ? recipients . map ( u => u . toString ( ) ) . join ( ", " ) : BDFDB . LanguageUtils . LanguageStrings . UNNAMED ;
}
2020-09-19 20:49:33 +02:00
} ;
2022-09-01 14:40:11 +02:00
} ) ( window . BDFDB _Global . PluginUtils . buildPlugin ( changeLog ) ) ;
2021-02-07 22:48:32 +01:00
} ) ( ) ;