2020-10-20 23:25:34 +02:00
/ * *
* @ name PinDMs
* @ authorId 278543574059057154
* @ invite Jx3TjNS
* @ donate https : //www.paypal.me/MircoWittrien
* @ patreon https : //www.patreon.com/MircoWittrien
* @ website https : //github.com/mwittrien/BetterDiscordAddons/tree/master/Plugins/PinDMs
* @ source https : //raw.githubusercontent.com/mwittrien/BetterDiscordAddons/master/Plugins/PinDMs/PinDMs.plugin.js
2020-11-12 17:30:48 +01:00
* @ updateUrl https : //raw.githubusercontent.com/mwittrien/BetterDiscordAddons/master/Plugins/PinDMs/PinDMs.plugin.js
2020-10-20 23:25:34 +02:00
* /
2018-10-11 10:21:26 +02:00
2020-09-19 20:49:33 +02:00
module . exports = ( _ => {
2020-10-09 21:09:35 +02:00
const config = {
2020-09-19 20:49:33 +02:00
"info" : {
"name" : "PinDMs" ,
"author" : "DevilBro" ,
2020-11-16 16:38:04 +01:00
"version" : "1.7.7" ,
2020-10-16 10:25:30 +02:00
"description" : "Allow you to pin DMs, making them appear at the top of your DMs/Server-List"
2020-11-16 16:38:04 +01:00
} ,
"changeLog" : {
"fixed" : {
"Works again" : "Some of you really need to learn how to be a little bit more patient and give plugin devs some time to fix their stuff if discord breaks it..."
}
2020-08-21 16:17:47 +02:00
}
2020-09-19 20:49:33 +02:00
} ;
2020-11-13 19:47:44 +01:00
2020-10-09 21:09:35 +02:00
return ! window . BDFDB _Global || ( ! window . BDFDB _Global . loaded && ! window . BDFDB _Global . started ) ? class {
2020-09-19 20:49:33 +02:00
getName ( ) { return config . info . name ; }
getAuthor ( ) { return config . info . author ; }
getVersion ( ) { return config . info . version ; }
getDescription ( ) { return config . info . description ; }
2020-10-09 21:09:35 +02: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 ;
BdApi . showConfirmationModal ( "Library Missing" , ` The library plugin needed for ${ config . info . name } is missing. Please click "Download Now" to install it. ` , {
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 ;
require ( "request" ) . get ( "https://mwittrien.github.io/BetterDiscordAddons/Library/0BDFDB.plugin.js" , ( e , r , b ) => {
2020-10-20 23:25:34 +02:00
if ( ! e && b && b . indexOf ( ` * @name BDFDB ` ) > - 1 ) require ( "fs" ) . writeFile ( require ( "path" ) . join ( BdApi . Plugins . folder , "0BDFDB.plugin.js" ) , b , _ => { } ) ;
2020-09-20 08:15:13 +02:00
else BdApi . alert ( "Error" , "Could not download BDFDB library plugin, try again some time later." ) ;
} ) ;
}
2020-09-19 20:49:33 +02:00
} ) ;
2020-02-11 17:05:06 +01:00
}
2020-09-19 20:49:33 +02:00
if ( ! window . BDFDB _Global . pluginQueue . includes ( config . info . name ) ) window . BDFDB _Global . pluginQueue . push ( config . info . name ) ;
2020-10-09 21:09:35 +02:00
}
start ( ) { this . load ( ) ; }
stop ( ) { }
2020-11-28 23:12:09 +01:00
getSettingsPanel ( ) {
let template = document . createElement ( "template" ) ;
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 ${ config . info . name } is missing. \n Please click <a style="font-weight: 500;">Download Now</a> to install it.</div> ` ;
template . content . firstElementChild . querySelector ( "a" ) . addEventListener ( "click" , _ => {
require ( "request" ) . get ( "https://mwittrien.github.io/BetterDiscordAddons/Library/0BDFDB.plugin.js" , ( e , r , b ) => {
if ( ! e && b && b . indexOf ( ` * @name BDFDB ` ) > - 1 ) require ( "fs" ) . writeFile ( require ( "path" ) . join ( BdApi . Plugins . folder , "0BDFDB.plugin.js" ) , b , _ => { } ) ;
else BdApi . alert ( "Error" , "Could not download BDFDB library plugin, try again some time later." ) ;
} ) ;
} ) ;
return template . content . firstElementChild ;
}
2020-10-09 21:09:35 +02:00
} : ( ( [ Plugin , BDFDB ] ) => {
2020-09-19 20:49:33 +02:00
var hoveredCategory , draggedCategory , releasedCategory ;
var hoveredChannel , draggedChannel , releasedChannel ;
var settings = { } ;
2020-10-09 21:09:35 +02:00
return class PinDMs extends Plugin {
2020-09-19 20:49:33 +02:00
onLoad ( ) {
this . defaults = {
settings : {
2020-11-19 16:51:14 +01:00
sortInRecentOrder : { value : false , inner : true , description : "Channel List" } ,
sortInRecentOrderGuild : { value : false , inner : true , description : "Guild List" } ,
showPinIcon : { value : true , inner : false , description : "Show a little 'Pin' icon for pinned DMs in the server list: " } ,
showCategoryUnread : { value : true , inner : false , description : "Show the amount of unread Messages in a category in the channel list: " } ,
showCategoryAmount : { value : true , inner : false , description : "Show the amount of pinned DMs in a category in the channel list: " }
2020-09-19 20:49:33 +02:00
}
} ;
2020-02-11 17:05:06 +01:00
2020-09-19 20:49:33 +02:00
this . patchedModules = {
before : {
PrivateChannelsList : "render" ,
UnreadDMs : "render"
} ,
after : {
PrivateChannelsList : "render" ,
UnreadDMs : "render" ,
PrivateChannel : [ "render" , "componentDidMount" ] ,
DirectMessage : [ "render" , "componentDidMount" , "componentWillUnmount" ]
}
} ;
this . css = `
$ { BDFDB . dotCNS . dmchannel + BDFDB . dotCN . namecontainerchildren } {
display : flex ;
}
$ { BDFDB . dotCN . dmchannel } : hover $ { BDFDB . dotCN . _pindmsunpinbutton } {
display : block ;
}
$ { BDFDB . dotCN . _pindmspinnedchannelsheadercontainer } {
display : flex ;
cursor : pointer ;
}
$ { BDFDB . dotCNS . _pindmspinnedchannelsheadercontainer + BDFDB . dotCN . dmchannelheadertext } {
margin - right : 6 px ;
}
$ { BDFDB . dotCN . _pindmspinnedchannelsheadercontainer + BDFDB . dotCN . _pindmspinnedchannelsheadercolored } : hover $ { BDFDB . dotCN . dmchannelheadertext } {
filter : brightness ( 150 % ) ;
}
$ { BDFDB . dotCNS . _pindmspinnedchannelsheadercontainer + BDFDB . dotCN . _pindmspinnedchannelsheaderamount } {
position : relative ;
top : - 1 px ;
margin - right : 6 px ;
}
$ { BDFDB . dotCN . _pindmspinnedchannelsheaderarrow } {
flex : 0 ;
width : 16 px ;
height : 16 px ;
margin - left : 0 ;
margin - right : 2 px ;
}
$ { BDFDB . dotCNS . _pindmspinnedchannelsheadercollapsed + BDFDB . dotCN . _pindmspinnedchannelsheaderarrow + BDFDB . dotCN . channelheadericonwrapper } {
transform : rotate ( - 90 deg ) ;
}
$ { BDFDB . dotCN . _pindmsunpinbutton } {
display : none ;
width : 16 px ;
height : 16 px ;
opacity : . 7 ;
margin : 2 px ;
}
$ { BDFDB . dotCN . _pindmsunpinbutton } : hover {
opacity : 1 ;
}
$ { BDFDB . dotCN . _pindmsunpinicon } {
display : block ;
width : 16 px ;
height : 16 px ;
}
$ { BDFDB . dotCNS . _pindmsdmchannelplaceholder + BDFDB . dotCN . namecontainerlayout } {
box - sizing : border - box ;
border : 1 px dashed currentColor ;
}
$ { BDFDB . dotCN . _pindmspinnedchannelsheadercontainer + BDFDB . dotCN . _pindmsdmchannelplaceholder } {
margin - left : 8 px ;
height : 12 px ;
box - sizing : border - box ;
border : 1 px dashed currentColor ;
}
$ { BDFDB . dotCN . _pindmsdragpreview } {
pointer - events : none ! important ;
position : absolute ! important ;
opacity : 0.5 ! important ;
z - index : 10000 ! important ;
}
` ;
}
onStart ( ) {
2020-02-11 17:05:06 +01:00
this . forceUpdateAll ( ) ;
2020-01-05 14:01:45 +01:00
}
2020-09-19 20:49:33 +02:00
onStop ( ) {
2020-07-02 09:54:10 +02:00
this . forceUpdateAll ( ) ;
2020-02-11 17:05:06 +01:00
2020-11-19 16:51:14 +01:00
let unreadDMsInstance = BDFDB . ReactUtils . findOwner ( document . querySelector ( BDFDB . dotCN . app ) , { name : "UnreadDMs" , unlimited : true } ) ;
2020-02-11 17:05:06 +01:00
if ( unreadDMsInstance ) {
delete unreadDMsInstance . props . pinnedPrivateChannelIds ;
unreadDMsInstance . props . unreadPrivateChannelIds = BDFDB . LibraryModules . DirectMessageUnreadStore . getUnreadPrivateChannelIds ( ) ;
BDFDB . ReactUtils . forceUpdate ( unreadDMsInstance ) ;
}
}
2019-09-04 12:34:02 +02:00
2020-09-19 20:49:33 +02:00
getSettingsPanel ( collapseStates = { } ) {
let settingsPanel , settingsItems = [ ] ;
for ( let key in settings ) if ( ! this . defaults . settings [ key ] . inner ) settingsItems . push ( BDFDB . ReactUtils . createElement ( BDFDB . LibraryComponents . SettingsSaveItem , {
type : "Switch" ,
plugin : this ,
keys : [ "settings" , key ] ,
label : this . defaults . settings [ key ] . description ,
value : settings [ key ]
} ) ) ;
settingsItems . push ( BDFDB . ReactUtils . createElement ( BDFDB . LibraryComponents . SettingsPanelInner , {
title : "Sort pinned DMs in the recent message order instead of the pinned at order in:" ,
first : settingsItems . length == 0 ,
children : Object . keys ( settings ) . map ( key => this . defaults . settings [ key ] . inner && BDFDB . ReactUtils . createElement ( BDFDB . LibraryComponents . SettingsSaveItem , {
type : "Switch" ,
plugin : this ,
keys : [ "settings" , key ] ,
label : this . defaults . settings [ key ] . description ,
value : settings [ key ]
} ) )
} ) ) ;
settingsItems . push ( BDFDB . ReactUtils . createElement ( BDFDB . LibraryComponents . SettingsItem , {
type : "Button" ,
color : BDFDB . LibraryComponents . Button . Colors . RED ,
label : "Unpin all pinned DMs" ,
onClick : _ => {
BDFDB . ModalUtils . confirm ( this , "Are you sure you want to unpin all pinned DMs?" , _ => {
BDFDB . DataUtils . remove ( this , "dmCategories" ) ;
BDFDB . DataUtils . remove ( this , "pinnedRecents" ) ;
} ) ;
} ,
children : BDFDB . LanguageUtils . LanguageStrings . UNPIN
} ) ) ;
return settingsPanel = BDFDB . PluginUtils . createSettingsPanel ( this , settingsItems ) ;
}
2019-01-26 22:45:19 +01:00
2020-09-19 20:49:33 +02:00
onSettingsClosed ( ) {
if ( this . SettingsUpdated ) {
delete this . SettingsUpdated ;
this . forceUpdateAll ( ) ;
}
}
2019-01-26 22:45:19 +01:00
2020-09-19 20:49:33 +02:00
forceUpdateAll ( ) {
settings = BDFDB . DataUtils . get ( this , "settings" ) ;
2020-11-19 16:51:14 +01:00
BDFDB . ReactUtils . forceUpdate ( BDFDB . ReactUtils . findOwner ( document . querySelector ( BDFDB . dotCN . app ) , { name : "FluxContainer(PrivateChannels)" , all : true , unlimited : true } ) ) ;
2020-09-19 20:49:33 +02:00
BDFDB . PatchUtils . forceAllUpdates ( this ) ;
2020-02-11 17:05:06 +01:00
}
2019-11-21 14:56:53 +01:00
2020-09-19 20:49:33 +02:00
onUserContextMenu ( e ) {
if ( e . instance . props . user ) {
let [ children , index ] = BDFDB . ContextMenuUtils . findItem ( e . returnvalue , { id : "close-dm" } ) ;
if ( index > - 1 ) {
let id = BDFDB . LibraryModules . ChannelStore . getDMFromUserId ( e . instance . props . user . id ) ;
if ( id ) this . injectItem ( e . instance , id , children , index ) ;
}
2020-02-11 17:05:06 +01:00
}
2019-01-11 15:32:04 +01:00
}
2019-01-26 22:45:19 +01:00
2020-09-19 20:49:33 +02:00
onGroupDMContextMenu ( e ) {
if ( e . instance . props . channel ) {
let [ children , index ] = BDFDB . ContextMenuUtils . findItem ( e . returnvalue , { id : "change-icon" } ) ;
if ( index > - 1 ) this . injectItem ( e . instance , e . instance . props . channel . id , children , index + 1 ) ;
}
2020-02-11 17:05:06 +01:00
}
2019-01-26 22:45:19 +01:00
2020-09-19 20:49:33 +02:00
injectItem ( instance , id , children , index ) {
let pinnedInGuild = this . isPinned ( id , "pinnedRecents" ) ;
let categories = this . sortAndUpdateCategories ( "dmCategories" , true ) ;
let currentCategory = this . getCategory ( id , "dmCategories" ) ;
children . splice ( index , 0 , BDFDB . ContextMenuUtils . createItem ( BDFDB . LibraryComponents . MenuItems . MenuItem , {
label : this . labels . context _pindm _text ,
id : BDFDB . ContextMenuUtils . createItemId ( this . name , "submenu-pin" ) ,
children : [
BDFDB . ContextMenuUtils . createItem ( BDFDB . LibraryComponents . MenuItems . MenuItem , {
label : this . labels . context _pinchannel _text ,
id : BDFDB . ContextMenuUtils . createItemId ( this . name , "submenu-channelist" ) ,
children : [
BDFDB . ContextMenuUtils . createItem ( BDFDB . LibraryComponents . MenuItems . MenuGroup , {
children : currentCategory ? BDFDB . ContextMenuUtils . createItem ( BDFDB . LibraryComponents . MenuItems . MenuItem , {
label : this . labels . context _unpinchannel _text ,
id : BDFDB . ContextMenuUtils . createItemId ( this . name , "unpin-channellist" ) ,
color : BDFDB . LibraryComponents . MenuItems . Colors . DANGER ,
action : _ => {
this . removeFromCategory ( id , currentCategory , "dmCategories" ) ;
}
} ) : BDFDB . ContextMenuUtils . createItem ( BDFDB . LibraryComponents . MenuItems . MenuItem , {
label : this . labels . context _addtonewcategory _text ,
id : BDFDB . ContextMenuUtils . createItemId ( this . name , "new-channellist" ) ,
color : BDFDB . LibraryComponents . MenuItems . Colors . BRAND ,
action : _ => {
this . openCategorySettingsModal ( {
id : this . generateID ( "dmCategories" ) . toString ( ) ,
name : ` ${ this . labels . header _pinneddms _text } # ${ categories . length + 1 } ` ,
dms : [ id ] ,
pos : categories . length ,
collapsed : false ,
color : null
} , "dmCategories" , true ) ;
}
} )
} ) ,
categories . length ? BDFDB . ContextMenuUtils . createItem ( BDFDB . LibraryComponents . MenuItems . MenuGroup , {
children : categories . map ( category => currentCategory && currentCategory . id == category . id ? null : BDFDB . ContextMenuUtils . createItem ( BDFDB . LibraryComponents . MenuItems . MenuItem , {
label : category . name || this . labels . header _pinneddms _text ,
id : BDFDB . ContextMenuUtils . createItemId ( this . name , "pin-channellist" , category . id ) ,
action : _ => {
if ( currentCategory ) this . removeFromCategory ( id , currentCategory , "dmCategories" ) ;
this . addToCategory ( id , category , "dmCategories" ) ;
}
} ) ) . filter ( n => n )
} ) : null
] . filter ( n => n )
} ) ,
BDFDB . ContextMenuUtils . createItem ( BDFDB . LibraryComponents . MenuItems . MenuItem , {
label : this . labels [ pinnedInGuild ? "context_unpinguild_text" : "context_pinguild_text" ] ,
id : BDFDB . ContextMenuUtils . createItemId ( this . name , pinnedInGuild ? "unpin-serverlist" : "pin-serverlist" ) ,
danger : pinnedInGuild ,
action : _ => {
if ( ! pinnedInGuild ) this . addPin ( id , "pinnedRecents" ) ;
else this . removePin ( id , "pinnedRecents" ) ;
}
} )
]
} ) ) ;
}
2020-02-11 17:05:06 +01:00
2020-09-19 20:49:33 +02:00
processPrivateChannelsList ( e ) {
let categories = this . sortAndUpdateCategories ( "dmCategories" , true ) ;
if ( categories . length ) {
e . instance . props . channels = Object . assign ( { } , e . instance . props . channels ) ;
e . instance . props . privateChannelIds = [ ] . concat ( e . instance . props . privateChannelIds || [ ] ) ;
e . instance . props . pinnedChannelIds = Object . assign ( { } , e . instance . props . pinnedChannelIds ) ;
if ( ! e . returnvalue ) {
if ( draggedChannel && releasedChannel ) {
let categoryId = releasedChannel . split ( "header_" ) [ 1 ] ;
let category = categories . find ( n => categoryId != undefined ? n . id == categoryId : n . dms . includes ( releasedChannel ) ) ;
if ( category ) {
BDFDB . ArrayUtils . remove ( category . dms , draggedChannel , true ) ;
category . dms . splice ( categoryId != undefined ? 0 : category . dms . indexOf ( releasedChannel ) + 1 , 0 , draggedChannel ) ;
BDFDB . DataUtils . save ( category , this , "dmCategories" , category . id ) ;
}
draggedChannel = null ;
releasedChannel = null ;
2020-04-01 19:28:13 +02:00
}
2020-09-19 20:49:33 +02:00
if ( draggedCategory && releasedCategory ) {
let maybedDraggedCategory = categories . find ( n => n . id == draggedCategory ) ;
let maybedReleasedCategory = categories . find ( n => n . id == releasedCategory ) ;
if ( maybedDraggedCategory && maybedReleasedCategory ) {
BDFDB . ArrayUtils . remove ( categories , maybedDraggedCategory , true ) ;
categories . splice ( categories . indexOf ( maybedReleasedCategory ) + 1 , 0 , maybedDraggedCategory ) ;
let newCategories = { } , newPos = 0 ;
2020-11-19 16:51:14 +01:00
for ( let category of [ ] . concat ( categories ) . reverse ( ) ) newCategories [ category . id ] = Object . assign ( category , { pos : newPos ++ } ) ;
2020-09-19 20:49:33 +02:00
BDFDB . DataUtils . save ( newCategories , this , "dmCategories" ) ;
}
draggedCategory = null ;
releasedCategory = null ;
2020-04-24 19:33:47 +02:00
}
2020-09-19 20:49:33 +02:00
e . instance . props . pinnedChannelIds = { } ;
for ( let category of [ ] . concat ( categories ) . reverse ( ) ) {
e . instance . props . pinnedChannelIds [ category . id ] = [ ] ;
for ( let id of this . sortDMsByTime ( this . filterDMs ( category . dms ) , "dmCategories" ) . reverse ( ) ) {
BDFDB . ArrayUtils . remove ( e . instance . props . privateChannelIds , id , true ) ;
if ( ! category . collapsed || e . instance . props . selectedChannelId == id ) {
e . instance . props . privateChannelIds . unshift ( id ) ;
e . instance . props . pinnedChannelIds [ category . id ] . push ( id ) ;
}
2020-04-24 19:33:47 +02:00
}
}
}
2020-09-19 20:49:33 +02:00
else {
2020-11-16 16:38:04 +01:00
if ( typeof e . returnvalue . props . children == "function" ) {
let childrenRender = e . returnvalue . props . children ;
e . returnvalue . props . children = ( ... args ) => {
let children = childrenRender ( ... args ) ;
this . injectCategories ( e . instance , children , categories ) ;
return children ;
} ;
}
else this . injectCategories ( e . instance , e . returnvalue , categories ) ;
2020-09-19 20:49:33 +02:00
}
let pinnedIds = BDFDB . ObjectUtils . toArray ( e . instance . props . pinnedChannelIds ) . reverse ( ) ;
BDFDB . PatchUtils . unpatch ( this , e . instance , "renderDM" ) ;
BDFDB . PatchUtils . patch ( this , e . instance , "renderDM" , { before : e2 => {
if ( e2 . methodArguments [ 0 ] != 0 ) e2 . methodArguments [ 1 ] += pinnedIds . slice ( 0 , e2 . methodArguments [ 0 ] - 1 ) . flat ( ) . length ;
} , after : e2 => {
if ( e2 . methodArguments [ 0 ] != 0 ) {
let id = e . instance . props . privateChannelIds [ e2 . methodArguments [ 1 ] ] ;
e2 . returnValue = e . instance . props . channels [ id ] ? BDFDB . ReactUtils . createElement ( BDFDB . LibraryComponents . PrivateChannelItems [ e . instance . props . channels [ id ] . isMultiUserDM ( ) ? "GroupDM" : "DirectMessage" ] , Object . assign ( {
key : id ,
channel : e . instance . props . channels [ id ] ,
selected : e . instance . props . selectedChannelId == id
} , ( e . instance . props . navigator || e . instance . props . listNavigator ) . getItemProps ( {
index : e2 . methodArguments [ 2 ]
} ) ) ) : null ;
let category = categories [ e2 . methodArguments [ 0 ] - 1 ] ;
if ( category ) {
if ( ! id || ( category . collapsed && e . instance . props . selectedChannelId != id ) || ! category . dms . includes ( id ) || draggedCategory == category . id || draggedChannel == id ) e2 . returnValue = null ;
else if ( hoveredCategory == category . id && [ ] . concat ( category . dms ) . reverse ( ) [ 0 ] == id ) e2 . returnValue = [
e2 . returnValue ,
BDFDB . ReactUtils . createElement ( "h2" , {
className : BDFDB . disCNS . dmchannelheadercontainer + BDFDB . disCNS . _pindmspinnedchannelsheadercontainer + BDFDB . disCNS . _pindmsdmchannelplaceholder + BDFDB . disCN . namecontainernamecontainer
} )
] . filter ( n => n ) ;
else if ( hoveredChannel == id ) e2 . returnValue = [
e2 . returnValue ,
BDFDB . ReactUtils . createElement ( "div" , {
2020-07-02 09:54:10 +02:00
className : BDFDB . disCNS . dmchannel + BDFDB . disCNS . _pindmsdmchannelpinned + BDFDB . disCNS . _pindmsdmchannelplaceholder + BDFDB . disCN . namecontainernamecontainer ,
children : BDFDB . ReactUtils . createElement ( "div" , {
className : BDFDB . disCN . namecontainerlayout
2020-04-24 21:57:57 +02:00
} )
2020-04-25 09:23:03 +02:00
} )
2020-07-02 09:54:10 +02:00
] . filter ( n => n ) ;
}
2020-04-01 19:28:13 +02:00
}
2020-09-19 20:49:33 +02:00
} } , { force : true , noCache : true } ) ;
2020-07-02 09:54:10 +02:00
}
2020-09-19 20:49:33 +02:00
}
2020-11-16 16:38:04 +01:00
injectCategories ( instance , returnvalue , categories ) {
returnvalue . props . sections = [ ] ;
returnvalue . props . sections . push ( instance . state . preRenderedChildren ) ;
let shownPinnedIds = BDFDB . ObjectUtils . toArray ( instance . props . pinnedChannelIds ) . reverse ( ) ;
for ( let ids of shownPinnedIds ) returnvalue . props . sections . push ( ids . length || 1 ) ;
returnvalue . props . sections . push ( instance . props . privateChannelIds . length - shownPinnedIds . flat ( ) . length ) ;
let sectionHeight = returnvalue . props . sectionHeight ;
let sectionHeightFunc = typeof sectionHeight != "function" ? _ => sectionHeight : sectionHeight ;
returnvalue . props . sectionHeight = ( ... args ) => {
if ( args [ 0 ] != 0 && args [ 0 ] != returnvalue . props . sections . length - 1 ) {
let category = categories [ args [ 0 ] - 1 ] ;
if ( category ) return 40 ;
}
return sectionHeightFunc ( ... args ) ;
} ;
let rowHeight = returnvalue . props . rowHeight ;
let rowHeightFunc = typeof rowHeight != "function" ? _ => rowHeight : rowHeight ;
returnvalue . props . rowHeight = ( ... args ) => {
if ( args [ 0 ] != 0 && args [ 0 ] != returnvalue . props . sections . length - 1 ) {
let category = categories [ args [ 0 ] - 1 ] ;
if ( category && ( category . collapsed || category . id == draggedCategory ) ) return 0 ;
}
return rowHeightFunc ( ... args ) ;
} ;
let renderRow = returnvalue . props . renderRow ;
returnvalue . props . renderRow = ( ... args ) => {
let row = renderRow ( ... args ) ;
return row && row . key == "no-private-channels" ? null : row ;
} ;
let renderSection = returnvalue . props . renderSection ;
returnvalue . props . renderSection = ( ... args ) => {
if ( args [ 0 ] . section != 0 && args [ 0 ] . section != returnvalue . props . sections . length - 1 ) {
let category = categories [ args [ 0 ] . section - 1 ] ;
if ( category && draggedCategory != category . id ) {
let color = BDFDB . ColorUtils . convert ( category . color , "RGBA" ) ;
let foundDMs = this . filterDMs ( category . dms ) ;
let unreadAmount = settings . showCategoryUnread && BDFDB . ArrayUtils . sum ( foundDMs . map ( id => BDFDB . LibraryModules . UnreadChannelUtils . getMentionCount ( id ) ) ) ;
return [
BDFDB . ReactUtils . createElement ( "h2" , {
className : BDFDB . DOMUtils . formatClassName ( BDFDB . disCN . dmchannelheadercontainer , BDFDB . disCN . _pindmspinnedchannelsheadercontainer , category . collapsed && BDFDB . disCN . _pindmspinnedchannelsheadercollapsed , color && BDFDB . disCN . _pindmspinnedchannelsheadercolored , BDFDB . disCN . namecontainernamecontainer ) ,
categoryId : category . id ,
onMouseDown : event => {
event = event . nativeEvent || event ;
let node = BDFDB . DOMUtils . getParent ( BDFDB . dotCN . _pindmspinnedchannelsheadercontainer , event . target ) . cloneNode ( true ) ;
let mousemove = event2 => {
if ( Math . sqrt ( ( event . pageX - event2 . pageX ) * * 2 ) > 20 || Math . sqrt ( ( event . pageY - event2 . pageY ) * * 2 ) > 20 ) {
BDFDB . ListenerUtils . stopEvent ( event ) ;
draggedCategory = category . id ;
this . updateContainer ( "dmCategories" ) ;
let dragPreview = this . createDragPreview ( node , event2 ) ;
document . removeEventListener ( "mousemove" , mousemove ) ;
document . removeEventListener ( "mouseup" , mouseup ) ;
let dragging = event3 => {
this . updateDragPreview ( dragPreview , event3 ) ;
let placeholder = BDFDB . DOMUtils . getParent ( BDFDB . dotCN . _pindmsdmchannelplaceholder , event3 . target ) ;
let categoryNode = BDFDB . DOMUtils . getParent ( BDFDB . dotCN . _pindmspinnedchannelsheadercontainer , placeholder ? placeholder . previousSibling : event3 . target ) ;
let maybeHoveredCategory = categoryNode && categoryNode . getAttribute ( "categoryId" ) ;
let update = maybeHoveredCategory != hoveredCategory ;
if ( maybeHoveredCategory ) hoveredCategory = maybeHoveredCategory ;
else hoveredCategory = null ;
if ( update ) this . updateContainer ( "dmCategories" ) ;
} ;
let releasing = event3 => {
BDFDB . DOMUtils . remove ( dragPreview ) ;
if ( hoveredCategory ) releasedCategory = hoveredCategory ;
else draggedCategory = null ;
hoveredCategory = null ;
this . updateContainer ( "dmCategories" ) ;
document . removeEventListener ( "mousemove" , dragging ) ;
document . removeEventListener ( "mouseup" , releasing ) ;
} ;
document . addEventListener ( "mousemove" , dragging ) ;
document . addEventListener ( "mouseup" , releasing ) ;
}
} ;
let mouseup = _ => {
document . removeEventListener ( "mousemove" , mousemove ) ;
document . removeEventListener ( "mouseup" , mouseup ) ;
} ;
document . addEventListener ( "mousemove" , mousemove ) ;
document . addEventListener ( "mouseup" , mouseup ) ;
} ,
onClick : _ => {
if ( foundDMs . length || ! category . collapsed ) {
category . collapsed = ! category . collapsed ;
BDFDB . DataUtils . save ( category , this , "dmCategories" , category . id ) ;
this . updateContainer ( "dmCategories" ) ;
}
} ,
onContextMenu : event => {
BDFDB . ContextMenuUtils . open ( this , event , BDFDB . ContextMenuUtils . createItem ( BDFDB . LibraryComponents . MenuItems . MenuGroup , {
children : [
BDFDB . ContextMenuUtils . createItem ( BDFDB . LibraryComponents . MenuItems . MenuItem , {
label : BDFDB . LanguageUtils . LanguageStrings . CATEGORY _SETTINGS ,
id : BDFDB . ContextMenuUtils . createItemId ( this . name , "category-settings" ) ,
action : event2 => {
this . openCategorySettingsModal ( category , "dmCategories" ) ;
}
} ) ,
BDFDB . ContextMenuUtils . createItem ( BDFDB . LibraryComponents . MenuItems . MenuItem , {
label : BDFDB . LanguageUtils . LanguageStrings . DELETE _CATEGORY ,
id : BDFDB . ContextMenuUtils . createItemId ( this . name , "remove-category" ) ,
color : BDFDB . LibraryComponents . MenuItems . Colors . DANGER ,
action : event2 => {
BDFDB . DataUtils . remove ( this , "dmCategories" , category . id ) ;
this . updateContainer ( "dmCategories" ) ;
}
} )
]
} ) ) ;
} ,
children : [
BDFDB . ObjectUtils . is ( color ) ? BDFDB . ReactUtils . createElement ( "span" , {
className : BDFDB . disCN . dmchannelheadertext ,
children : BDFDB . ReactUtils . createElement ( BDFDB . LibraryComponents . TextGradientElement , {
gradient : BDFDB . ColorUtils . createGradient ( color ) ,
children : category . name
} )
} ) : BDFDB . ReactUtils . createElement ( "span" , {
className : BDFDB . disCN . dmchannelheadertext ,
style : { color : color } ,
children : category . name ,
} ) ,
unreadAmount ? BDFDB . ReactUtils . createElement ( BDFDB . LibraryComponents . Badges . NumberBadge , {
className : BDFDB . disCN . _pindmspinnedchannelsheaderamount ,
count : unreadAmount ,
style : { backgroundColor : BDFDB . DiscordConstants . Colors . STATUS _RED }
} ) : null ,
settings . showCategoryAmount ? BDFDB . ReactUtils . createElement ( BDFDB . LibraryComponents . Badges . NumberBadge , {
className : BDFDB . disCN . _pindmspinnedchannelsheaderamount ,
count : foundDMs . length ,
style : { backgroundColor : BDFDB . DiscordConstants . Colors . BRAND }
} ) : null ,
BDFDB . ReactUtils . createElement ( "div" , {
className : BDFDB . disCNS . _pindmspinnedchannelsheaderarrow + BDFDB . disCNS . channelheadericonwrapper + BDFDB . disCN . channelheadericonclickable ,
children : BDFDB . ReactUtils . createElement ( BDFDB . LibraryComponents . SvgIcon , {
className : BDFDB . disCNS . _pindmspinnedchannelsheaderarrow + BDFDB . disCN . channelheadericon ,
nativeClass : true ,
iconSVG : ` <svg width="24" height="24" viewBox="4 4 16 16"><path fill="currentColor" fill-rule="evenodd" clip-rule="evenodd" d="M16.59 8.59004L12 13.17L7.41 8.59004L6 10L12 16L18 10L16.59 8.59004Z"></path></svg> `
} )
} )
] . filter ( n => n )
} ) ,
hoveredChannel == "header_" + category . id && BDFDB . ReactUtils . createElement ( "div" , {
className : BDFDB . disCNS . dmchannel + BDFDB . disCNS . _pindmsdmchannelpinned + BDFDB . disCNS . _pindmsdmchannelplaceholder + BDFDB . disCN . namecontainernamecontainer ,
children : BDFDB . ReactUtils . createElement ( "div" , {
className : BDFDB . disCN . namecontainerlayout
} )
} )
] . filter ( n => n ) ;
}
else return null ;
}
else return renderSection ( ... args ) ;
} ;
}
2020-09-19 20:49:33 +02:00
processUnreadDMs ( e ) {
e . instance . props . pinnedPrivateChannelIds = [ ] ;
let sortedRecents = this . sortAndUpdate ( "pinnedRecents" ) ;
if ( sortedRecents . length ) {
e . instance . props . unreadPrivateChannelIds = [ ] ;
for ( let pos in sortedRecents ) {
let id = sortedRecents [ pos ] ;
if ( e . instance . props . channels [ id ] ) {
if ( ! e . instance . props . pinnedPrivateChannelIds . includes ( id ) ) e . instance . props . pinnedPrivateChannelIds . push ( id ) ;
if ( ! e . instance . props . unreadPrivateChannelIds . includes ( id ) ) e . instance . props . unreadPrivateChannelIds . push ( id ) ;
}
}
e . instance . props . unreadPrivateChannelIds = e . instance . props . unreadPrivateChannelIds . concat ( BDFDB . LibraryModules . DirectMessageUnreadStore . getUnreadPrivateChannelIds ( ) ) ;
if ( e . returnvalue ) {
if ( draggedChannel && releasedChannel ) {
let pinnedPrivateChannelIds = [ ] . concat ( e . instance . props . pinnedPrivateChannelIds ) , newData = { } ;
BDFDB . ArrayUtils . remove ( pinnedPrivateChannelIds , draggedChannel , true ) ;
pinnedPrivateChannelIds . splice ( pinnedPrivateChannelIds . indexOf ( releasedChannel ) + 1 , 0 , draggedChannel ) ;
for ( let pos in pinnedPrivateChannelIds ) newData [ pinnedPrivateChannelIds [ pos ] ] = parseInt ( pos ) ;
BDFDB . DataUtils . save ( newData , this , "pinnedRecents" ) ;
draggedChannel = null ;
releasedChannel = null ;
BDFDB . ReactUtils . forceUpdate ( e . instance ) ;
}
if ( draggedChannel ) {
let [ children , index ] = BDFDB . ReactUtils . findParent ( e . returnvalue , { filter : child => BDFDB . ObjectUtils . get ( child , "props.channel.id" ) == draggedChannel } ) ;
children . splice ( index , 1 ) ;
}
if ( this . hoveredChannel ) {
let [ children , index ] = BDFDB . ReactUtils . findParent ( e . returnvalue , { filter : child => BDFDB . ObjectUtils . get ( child , "props.channel.id" ) == this . hoveredChannel } ) ;
children . splice ( index + 1 , 0 , BDFDB . ReactUtils . createElement ( "div" , {
className : BDFDB . disCNS . guildouter + BDFDB . disCN . _pindmsrecentplaceholder ,
children : BDFDB . ReactUtils . createElement ( "div" , {
children : BDFDB . ReactUtils . createElement ( BDFDB . LibraryComponents . GuildComponents . Items . DragPlaceholder , { } )
2020-04-25 09:23:03 +02:00
} )
2020-09-19 20:49:33 +02:00
} ) ) ;
2020-04-24 19:33:47 +02:00
}
2020-04-25 09:23:03 +02:00
}
2020-09-19 20:49:33 +02:00
}
else e . instance . props . unreadPrivateChannelIds = BDFDB . LibraryModules . DirectMessageUnreadStore . getUnreadPrivateChannelIds ( ) ;
2019-01-24 22:27:15 +01:00
}
2019-01-26 22:45:19 +01:00
2020-09-19 20:49:33 +02:00
processPrivateChannel ( e ) {
if ( e . instance . props . channel ) {
let category = this . getCategory ( e . instance . props . channel . id , "dmCategories" ) ;
if ( category ) {
if ( e . node ) {
BDFDB . DOMUtils . addClass ( e . node , BDFDB . disCN . _pindmsdmchannelpinned ) ;
e . node . removeEventListener ( "mousedown" , e . node . PinDMsMouseDownListener ) ;
if ( ! settings . sortInRecentOrder ) {
e . node . setAttribute ( "draggable" , false ) ;
e . node . PinDMsMouseDownListener = event => {
if ( ! BDFDB . BDUtils . isPluginEnabled ( "PinDMs" ) ) e . node . removeEventListener ( "mousedown" , e . node . PinDMsMouseDownListener ) ;
else {
event = event . nativeEvent || event ;
let mousemove = event2 => {
if ( Math . sqrt ( ( event . pageX - event2 . pageX ) * * 2 ) > 20 || Math . sqrt ( ( event . pageY - event2 . pageY ) * * 2 ) > 20 ) {
BDFDB . ListenerUtils . stopEvent ( event ) ;
draggedChannel = e . instance . props . channel . id ;
this . updateContainer ( "dmCategories" ) ;
let dragPreview = this . createDragPreview ( e . node , event2 ) ;
document . removeEventListener ( "mousemove" , mousemove ) ;
document . removeEventListener ( "mouseup" , mouseup ) ;
let dragging = event3 => {
this . updateDragPreview ( dragPreview , event3 ) ;
let maybeHoveredChannel = null ;
let categoryNode = BDFDB . DOMUtils . getParent ( BDFDB . dotCN . _pindmspinnedchannelsheadercontainer , event3 . target ) ;
if ( categoryNode ) {
let hoveredCategoryId = categoryNode . getAttribute ( "categoryid" ) ;
if ( hoveredCategoryId && hoveredCategoryId == category . id ) maybeHoveredChannel = "header_" + category . id ;
}
else {
let placeholder = BDFDB . DOMUtils . getParent ( BDFDB . dotCN . _pindmsdmchannelplaceholder , event3 . target ) ;
maybeHoveredChannel = ( BDFDB . ReactUtils . findValue ( BDFDB . DOMUtils . getParent ( BDFDB . dotCN . _pindmsdmchannelpinned , placeholder ? placeholder . previousSibling : event3 . target ) , "channel" , { up : true } ) || { } ) . id ;
let maybeHoveredCategory = maybeHoveredChannel && this . getCategory ( maybeHoveredChannel , "dmCategories" ) ;
if ( ! maybeHoveredCategory || maybeHoveredCategory . id != category . id ) maybeHoveredChannel = null ;
} ;
let update = maybeHoveredChannel != hoveredChannel ;
if ( maybeHoveredChannel ) hoveredChannel = maybeHoveredChannel ;
else hoveredChannel = null ;
if ( update ) this . updateContainer ( "dmCategories" ) ;
} ;
let releasing = event3 => {
BDFDB . DOMUtils . remove ( dragPreview ) ;
if ( hoveredChannel ) releasedChannel = hoveredChannel ;
else draggedChannel = null ;
hoveredChannel = null ;
this . updateContainer ( "dmCategories" ) ;
document . removeEventListener ( "mousemove" , dragging ) ;
document . removeEventListener ( "mouseup" , releasing ) ;
} ;
document . addEventListener ( "mousemove" , dragging ) ;
document . addEventListener ( "mouseup" , releasing ) ;
}
} ;
let mouseup = _ => {
document . removeEventListener ( "mousemove" , mousemove ) ;
document . removeEventListener ( "mouseup" , mouseup ) ;
} ;
document . addEventListener ( "mousemove" , mousemove ) ;
document . addEventListener ( "mouseup" , mouseup ) ;
}
} ;
e . node . addEventListener ( "mousedown" , e . node . PinDMsMouseDownListener ) ;
}
}
if ( e . returnvalue ) e . returnvalue . props . children = [
BDFDB . ReactUtils . createElement ( BDFDB . LibraryComponents . TooltipContainer , {
text : BDFDB . LanguageUtils . LanguageStrings . UNPIN ,
children : BDFDB . ReactUtils . createElement ( BDFDB . LibraryComponents . Clickable , {
className : BDFDB . disCN . _pindmsunpinbutton ,
onClick : event => {
BDFDB . ListenerUtils . stopEvent ( event ) ;
this . removeFromCategory ( e . instance . props . channel . id , category , "dmCategories" ) ;
} ,
children : BDFDB . ReactUtils . createElement ( BDFDB . LibraryComponents . SvgIcon , {
className : BDFDB . disCN . _pindmsunpinicon ,
name : BDFDB . LibraryComponents . SvgIcon . Names . PIN
} )
} )
} ) ,
e . returnvalue . props . children
] . flat ( 10 ) . filter ( n => n ) ;
2020-02-11 17:05:06 +01:00
}
2019-11-21 14:56:53 +01:00
}
2020-02-11 17:05:06 +01:00
}
2020-09-19 20:49:33 +02:00
processDirectMessage ( e ) {
if ( e . instance . props . channel ) {
if ( e . node && e . methodname == "componentDidMount" ) {
BDFDB . DOMUtils . removeClass ( e . node , BDFDB . disCN . _pindmsrecentpinned ) ;
e . node . removeEventListener ( "contextmenu" , e . node . PinDMsContextMenuListener ) ;
e . node . PinDMsContextMenuListener = event => { BDFDB . DMUtils . openMenu ( e . instance . props . channel . id , event ) ; } ;
e . node . addEventListener ( "contextmenu" , e . node . PinDMsContextMenuListener ) ;
if ( this . isPinned ( e . instance . props . channel . id , "pinnedRecents" ) ) {
BDFDB . DOMUtils . addClass ( e . node , BDFDB . disCN . _pindmsrecentpinned ) ;
e . node . removeEventListener ( "mousedown" , e . node . PinDMsMouseDownListener ) ;
if ( ! settings . sortInRecentOrderGuild ) {
for ( let child of e . node . querySelectorAll ( "a" ) ) child . setAttribute ( "draggable" , false ) ;
e . node . PinDMsMouseDownListener = event => {
2020-02-11 17:05:06 +01:00
let mousemove = event2 => {
if ( Math . sqrt ( ( event . pageX - event2 . pageX ) * * 2 ) > 20 || Math . sqrt ( ( event . pageY - event2 . pageY ) * * 2 ) > 20 ) {
BDFDB . ListenerUtils . stopEvent ( event ) ;
2020-04-24 19:33:47 +02:00
draggedChannel = e . instance . props . channel . id ;
2020-09-19 20:49:33 +02:00
BDFDB . PatchUtils . forceAllUpdates ( this , "UnreadDMs" ) ;
2020-04-24 19:33:47 +02:00
let dragPreview = this . createDragPreview ( e . node , event2 ) ;
2020-02-11 17:05:06 +01:00
document . removeEventListener ( "mousemove" , mousemove ) ;
document . removeEventListener ( "mouseup" , mouseup ) ;
let dragging = event3 => {
2020-04-24 19:33:47 +02:00
this . updateDragPreview ( dragPreview , event3 ) ;
2020-09-19 20:49:33 +02:00
let placeholder = BDFDB . DOMUtils . getParent ( BDFDB . dotCN . _pindmsrecentplaceholder , event3 . target ) ;
let maybeHoveredChannel = ( BDFDB . ReactUtils . findValue ( BDFDB . DOMUtils . getParent ( BDFDB . dotCN . _pindmsrecentpinned , placeholder ? placeholder . previousSibling : event3 . target ) , "channel" , { up : true } ) || { } ) . id ;
2020-04-24 19:33:47 +02:00
let update = maybeHoveredChannel != hoveredChannel ;
if ( maybeHoveredChannel ) hoveredChannel = maybeHoveredChannel ;
else hoveredChannel = null ;
2020-09-19 20:49:33 +02:00
if ( update ) BDFDB . PatchUtils . forceAllUpdates ( this , "UnreadDMs" ) ;
2020-02-11 17:05:06 +01:00
} ;
let releasing = event3 => {
2020-04-24 19:33:47 +02:00
BDFDB . DOMUtils . remove ( dragPreview ) ;
if ( hoveredChannel ) releasedChannel = hoveredChannel ;
else draggedChannel = null ;
hoveredChannel = null ;
2020-09-19 20:49:33 +02:00
BDFDB . PatchUtils . forceAllUpdates ( this , "UnreadDMs" ) ;
2020-02-11 17:05:06 +01:00
document . removeEventListener ( "mousemove" , dragging ) ;
document . removeEventListener ( "mouseup" , releasing ) ;
} ;
document . addEventListener ( "mousemove" , dragging ) ;
document . addEventListener ( "mouseup" , releasing ) ;
}
} ;
let mouseup = _ => {
document . removeEventListener ( "mousemove" , mousemove ) ;
document . removeEventListener ( "mouseup" , mouseup ) ;
} ;
document . addEventListener ( "mousemove" , mousemove ) ;
document . addEventListener ( "mouseup" , mouseup ) ;
2020-01-05 17:46:10 +01:00
} ;
2020-09-19 20:49:33 +02:00
e . node . addEventListener ( "mousedown" , e . node . PinDMsMouseDownListener ) ;
}
2020-02-11 17:05:06 +01:00
}
2020-01-05 17:46:10 +01:00
}
2020-09-19 20:49:33 +02:00
if ( e . node && e . methodname == "componentWillUnmount" ) {
BDFDB . PatchUtils . forceAllUpdates ( this , "PrivateChannelsList" ) ;
}
if ( e . returnvalue && this . isPinned ( e . instance . props . channel . id , "pinnedRecents" ) && settings . showPinIcon ) {
2020-11-19 16:51:14 +01:00
let [ children , index ] = BDFDB . ReactUtils . findParent ( e . returnvalue , { name : "BlobMask" } ) ;
2020-09-19 20:49:33 +02:00
if ( index > - 1 ) children [ index ] . props . upperLeftBadge = BDFDB . ReactUtils . createElement ( BDFDB . LibraryComponents . Badges . IconBadge , {
className : BDFDB . disCN . guildiconbadge ,
disableColor : true ,
style : { transform : "scale(-1, 1)" } ,
icon : BDFDB . LibraryComponents . SvgIcon . Names . NOVA _PIN
} ) ;
}
2019-11-21 14:56:53 +01:00
}
}
2019-02-05 14:23:34 +01:00
2020-09-19 20:49:33 +02:00
generateID ( type ) {
if ( ! type ) return null ;
let categories = BDFDB . DataUtils . load ( this , type ) ;
let id = Math . round ( Math . random ( ) * 10000000000000000 ) ;
return categories [ id ] ? this . generateID ( ) : id ;
}
filterDMs ( dms ) {
return dms . filter ( id => BDFDB . LibraryModules . ChannelStore . getChannel ( id ) ) ;
}
2020-01-05 14:01:45 +01:00
2020-09-19 20:49:33 +02:00
addToCategory ( id , category , type ) {
if ( ! id || ! category || ! type ) return ;
let wasEmpty = ! this . filterDMs ( category . dms ) . length ;
if ( ! category . dms . includes ( id ) ) category . dms . unshift ( id ) ;
if ( wasEmpty && category . dms . length ) category . collapsed = false ;
BDFDB . DataUtils . save ( category , this , type , category . id ) ;
this . updateContainer ( type ) ;
}
2020-01-05 14:01:45 +01:00
2020-09-19 20:49:33 +02:00
removeFromCategory ( id , category , type ) {
if ( ! id || ! category || ! type ) return ;
BDFDB . ArrayUtils . remove ( category . dms , id , true ) ;
if ( ! this . filterDMs ( category . dms ) . length ) category . collapsed = true ;
BDFDB . DataUtils . save ( category , this , type , category . id ) ;
this . updateContainer ( type ) ;
}
2020-01-05 14:01:45 +01:00
2020-09-19 20:49:33 +02:00
getCategory ( id , type ) {
if ( ! id || ! type ) return null ;
let categories = BDFDB . DataUtils . load ( this , type ) ;
for ( let catId in categories ) if ( categories [ catId ] . dms . includes ( id ) ) return categories [ catId ] ;
return null ;
}
2020-01-05 14:01:45 +01:00
2020-09-19 20:49:33 +02:00
sortAndUpdateCategories ( type , reverse ) {
let data = BDFDB . ObjectUtils . sort ( BDFDB . DataUtils . load ( this , type ) , "pos" ) , newData = { } ;
let sorted = [ ] , pos = 0 , sort = id => {
if ( sorted [ pos ] === undefined ) {
newData [ id ] = Object . assign ( { } , data [ id ] , { pos } ) ;
sorted [ pos ] = newData [ id ] ;
}
else {
pos ++ ;
sort ( id ) ;
}
} ;
for ( let id in data ) sort ( id ) ;
if ( ! BDFDB . equals ( data , newData ) ) BDFDB . DataUtils . save ( newData , this , type ) ;
return ( reverse ? sorted . reverse ( ) : sorted ) . filter ( n => n ) ;
}
sortDMsByTime ( dms , type ) {
if ( dms . length > 1 && settings [ type == "dmCategories" ? "sortInRecentOrder" : "sortInRecentOrderGuild" ] ) {
let timestamps = BDFDB . LibraryModules . DirectMessageStore . getPrivateChannelIds ( ) . reduce ( ( newObj , channelId ) => ( newObj [ channelId ] = BDFDB . LibraryModules . UnreadChannelUtils . lastMessageId ( channelId ) , newObj ) , { } ) ;
return [ ] . concat ( dms ) . sort ( function ( x , y ) { return timestamps [ x ] > timestamps [ y ] ? - 1 : timestamps [ x ] < timestamps [ y ] ? 1 : 0 ; } ) ;
2020-02-11 17:05:06 +01:00
}
2020-09-19 20:49:33 +02:00
else return dms ;
2020-01-05 14:01:45 +01:00
}
2020-09-19 20:49:33 +02:00
openCategorySettingsModal ( data , type , isNew ) {
if ( BDFDB . ObjectUtils . is ( data ) && type ) BDFDB . ModalUtils . open ( this , {
size : "MEDIUM" ,
header : BDFDB . LanguageUtils . LanguageStrings . CATEGORY _SETTINGS ,
subheader : data . name ,
children : [
BDFDB . ReactUtils . createElement ( BDFDB . LibraryComponents . FormComponents . FormItem , {
title : BDFDB . LanguageUtils . LanguageStrings . CATEGORY _NAME ,
className : BDFDB . disCN . marginbottom20 + " input-categoryname" ,
children : [
BDFDB . ReactUtils . createElement ( BDFDB . LibraryComponents . TextInput , {
value : data . name ,
placeholder : data . name ,
autoFocus : true
} ) ,
BDFDB . ReactUtils . createElement ( BDFDB . LibraryComponents . FormComponents . FormDivider , {
className : BDFDB . disCN . dividerdefault
} )
]
} ) ,
BDFDB . ReactUtils . createElement ( BDFDB . LibraryComponents . FormComponents . FormItem , {
title : this . labels . modal _colorpicker1 _text ,
className : BDFDB . disCN . marginbottom20 ,
children : [
BDFDB . ReactUtils . createElement ( BDFDB . LibraryComponents . ColorSwatches , {
color : data . color ,
number : 1
} )
]
} )
] ,
buttons : [ {
contents : isNew ? BDFDB . LanguageUtils . LanguageStrings . CREATE : BDFDB . LanguageUtils . LanguageStrings . SAVE ,
color : "BRAND" ,
close : true ,
click : modal => {
data . name = modal . querySelector ( ".input-categoryname " + BDFDB . dotCN . input ) . value . trim ( ) || data . name ;
2020-01-15 10:45:35 +01:00
2020-09-19 20:49:33 +02:00
data . color = BDFDB . ColorUtils . getSwatchColor ( modal , 1 ) ;
if ( data . color != null && ! BDFDB . ObjectUtils . is ( data . color ) ) {
if ( data . color [ 0 ] < 30 && data . color [ 1 ] < 30 && data . color [ 2 ] < 30 ) data . color = BDFDB . ColorUtils . change ( data . color , 30 ) ;
else if ( data . color [ 0 ] > 225 && data . color [ 1 ] > 225 && data . color [ 2 ] > 225 ) data . color = BDFDB . ColorUtils . change ( data . color , - 30 ) ;
}
BDFDB . DataUtils . save ( data , this , type , data . id ) ;
this . updateContainer ( type ) ;
2020-02-11 17:05:06 +01:00
}
2020-09-19 20:49:33 +02:00
} ]
} ) ;
2020-02-11 17:05:06 +01:00
}
2019-01-26 22:45:19 +01:00
2020-09-19 20:49:33 +02:00
addPin ( newid , type ) {
if ( ! newid ) return ;
let pinnedDMs = BDFDB . DataUtils . load ( this , type ) ;
for ( let id in pinnedDMs ) pinnedDMs [ id ] = pinnedDMs [ id ] + 1 ;
pinnedDMs [ newid ] = 0 ;
BDFDB . DataUtils . save ( pinnedDMs , this , type ) ;
this . updateContainer ( type ) ;
2020-02-11 17:05:06 +01:00
}
2019-01-26 22:45:19 +01:00
2020-09-19 20:49:33 +02:00
removePin ( id , type ) {
if ( ! id ) return ;
BDFDB . DataUtils . remove ( this , type , id ) ;
this . updateContainer ( type ) ;
}
2020-07-02 09:54:10 +02:00
2020-09-19 20:49:33 +02:00
isPinned ( id , type ) {
return BDFDB . DataUtils . load ( this , type , id ) != undefined ;
}
updateContainer ( type ) {
switch ( type ) {
case "dmCategories" :
BDFDB . PatchUtils . forceAllUpdates ( this , "PrivateChannelsList" ) ;
break ;
case "pinnedRecents" :
BDFDB . PatchUtils . forceAllUpdates ( this , "UnreadDMs" ) ;
break ;
}
}
2019-09-04 12:34:02 +02:00
2020-09-19 20:49:33 +02:00
sortAndUpdate ( type ) {
let data = BDFDB . DataUtils . load ( this , type ) , newData = { } ;
delete data [ "" ] ;
delete data [ "null" ] ;
let sortedDMs = [ ] , existingDMs = [ ] , sortDM = ( id , pos ) => {
if ( sortedDMs [ pos ] === undefined ) sortedDMs [ pos ] = id ;
else sortDM ( id , pos + 1 ) ;
} ;
for ( let id in data ) sortDM ( id , data [ id ] ) ;
sortedDMs = sortedDMs . filter ( n => n ) ;
for ( let pos in sortedDMs ) {
newData [ sortedDMs [ pos ] ] = parseInt ( pos ) ;
if ( BDFDB . LibraryModules . ChannelStore . getChannel ( sortedDMs [ pos ] ) ) existingDMs . push ( sortedDMs [ pos ] ) ;
}
if ( ! BDFDB . equals ( data , newData ) ) BDFDB . DataUtils . save ( newData , this , type ) ;
return this . sortDMsByTime ( existingDMs , type ) ;
}
2020-04-24 19:33:47 +02:00
2020-09-19 20:49:33 +02:00
createDragPreview ( div , event ) {
if ( ! Node . prototype . isPrototypeOf ( div ) ) return ;
let dragPreview = div . cloneNode ( true ) ;
BDFDB . DOMUtils . addClass ( dragPreview , BDFDB . disCN . _pindmsdragpreview ) ;
BDFDB . DOMUtils . remove ( dragPreview . querySelector ( BDFDB . dotCNC . guildlowerbadge + BDFDB . dotCNC . guildupperbadge + BDFDB . dotCN . guildpillwrapper ) ) ;
document . querySelector ( BDFDB . dotCN . appmount ) . appendChild ( dragPreview ) ;
let rects = BDFDB . DOMUtils . getRects ( dragPreview ) ;
BDFDB . DOMUtils . hide ( dragPreview ) ;
dragPreview . style . setProperty ( "pointer-events" , "none" , "important" ) ;
dragPreview . style . setProperty ( "left" , event . clientX - ( rects . width / 2 ) + "px" , "important" ) ;
dragPreview . style . setProperty ( "top" , event . clientY - ( rects . height / 2 ) + "px" , "important" ) ;
return dragPreview ;
}
2019-04-26 23:16:20 +02:00
2020-09-19 20:49:33 +02:00
updateDragPreview ( dragPreview , event ) {
if ( ! Node . prototype . isPrototypeOf ( dragPreview ) ) return ;
BDFDB . DOMUtils . show ( dragPreview ) ;
let rects = BDFDB . DOMUtils . getRects ( dragPreview ) ;
dragPreview . style . setProperty ( "left" , event . clientX - ( rects . width / 2 ) + "px" , "important" ) ;
dragPreview . style . setProperty ( "top" , event . clientY - ( rects . height / 2 ) + "px" , "important" ) ;
2020-02-11 17:05:06 +01:00
}
2020-07-26 17:02:25 +02:00
2020-09-19 20:49:33 +02:00
setLabelsByLanguage ( ) {
switch ( BDFDB . LanguageUtils . getLanguage ( ) . id ) {
case "hr" : //croatian
return {
context _pindm _text : "Prikljucite Izravnu Poruku" ,
context _pinchannel _text : "Priložite popisu kanala" ,
context _unpinchannel _text : "Ukloni s popisa kanala" ,
context _addtonewcategory _text : "Dodavanje u novu kategoriju" ,
context _pinguild _text : "Priložite popisu poslužitelja" ,
context _unpinguild _text : "Ukloni s popisa poslužitelja" ,
header _pinneddms _text : "Prikvačene Izravne Poruke" ,
modal _colorpicker1 _text : "Boja kategorije"
} ;
case "da" : //danish
return {
context _pindm _text : "Fastgør PB" ,
context _pinchannel _text : "Vedhæft til kanalliste" ,
context _unpinchannel _text : "Fjern fra kanalliste" ,
context _addtonewcategory _text : "Føj til ny kategori" ,
context _pinguild _text : "Vedhæft til serverliste" ,
context _unpinguild _text : "Fjern fra serverliste" ,
header _pinneddms _text : "Pinned Privat Beskeder" ,
modal _colorpicker1 _text : "Kategori farve"
} ;
case "de" : //german
return {
context _pindm _text : "Direktnachricht anheften" ,
context _pinchannel _text : "An Kanalliste anheften" ,
context _unpinchannel _text : "Von Kanalliste loslösen" ,
context _addtonewcategory _text : "Zur neuen Kategorie hinzufügen" ,
context _pinguild _text : "An Serverliste anheften" ,
context _unpinguild _text : "Von Serverliste loslösen" ,
header _pinneddms _text : "Gepinnte Direktnachrichten" ,
modal _colorpicker1 _text : "Kategoriefarbe"
} ;
case "es" : //spanish
return {
context _pindm _text : "Anclar MD" ,
context _pinchannel _text : "Adjuntar a la lista de canales" ,
context _unpinchannel _text : "Deshazte de la lista de canales" ,
context _addtonewcategory _text : "Agregar a nueva categoría" ,
context _pinguild _text : "Adjuntar a la lista de servidores" ,
context _unpinguild _text : "Deshazte de la lista de servidores" ,
header _pinneddms _text : "Mensajes Directos Fijados" ,
modal _colorpicker1 _text : "Color de la categoría"
} ;
case "fr" : //french
return {
context _pindm _text : "Épingler MP" ,
context _pinchannel _text : "Épingler à la liste des salons" ,
context _unpinchannel _text : "Détacher de la liste des salons" ,
context _addtonewcategory _text : "Ajouter à une nouvelle catégorie" ,
context _pinguild _text : "Épingler à la liste de serveurs" ,
context _unpinguild _text : "Détacher de la liste de serveurs" ,
header _pinneddms _text : "Messages Prives Épinglés" ,
modal _colorpicker1 _text : "Couleur de la catégorie"
} ;
case "it" : //italian
return {
context _pindm _text : "Fissa il messaggio diretto" ,
context _pinchannel _text : "Allega alla lista dei canali" ,
context _unpinchannel _text : "Rimuovi dalla lista dei canali" ,
context _addtonewcategory _text : "Aggiungi a nuova categoria" ,
context _pinguild _text : "Allega alla lista dei server" ,
context _unpinguild _text : "Rimuovi dalla lista dei server" ,
header _pinneddms _text : "Messaggi Diretti Aggiunti" ,
modal _colorpicker1 _text : "Colore della categoria"
} ;
case "nl" : //dutch
return {
context _pindm _text : "PB pinnen" ,
context _pinchannel _text : "Pin naar de kanalenlijst" ,
context _unpinchannel _text : "Losmaken van kanalenlijst" ,
context _addtonewcategory _text : "Toevoegen aan nieuwe categorie" ,
context _pinguild _text : "Pin naar de serverlijst" ,
context _unpinguild _text : "Losmaken van serverlijst" ,
header _pinneddms _text : "Vastgezette Persoonluke Berichten" ,
modal _colorpicker1 _text : "Categorie kleur"
} ;
case "no" : //norwegian
return {
context _pindm _text : "Fest DM" ,
context _pinchannel _text : "Fest på kanalliste" ,
context _unpinchannel _text : "Fjern fra kanalliste" ,
context _addtonewcategory _text : "Legg til i ny kategori" ,
context _pinguild _text : "Fest på serverliste" ,
context _unpinguild _text : "Fjern fra serverlisten" ,
header _pinneddms _text : "Pinned Direktemeldinger" ,
modal _colorpicker1 _text : "Kategorifarge"
} ;
case "pl" : //polish
return {
context _pindm _text : "Przypnij PW" ,
context _pinchannel _text : "Dołącz do listy kanałów" ,
context _unpinchannel _text : "Usuń z listy kanałów" ,
context _addtonewcategory _text : "Dodaj do nowej kategorii" ,
context _pinguild _text : "Dołącz do listy serwerów" ,
context _unpinguild _text : "Usuń z listy serwerów" ,
header _pinneddms _text : "Prywatne Wiadomości Bezpośrednie" ,
modal _colorpicker1 _text : "Kolor kategorii"
} ;
case "pt-BR" : //portuguese (brazil)
return {
context _pindm _text : "Fixar MD" ,
context _pinchannel _text : "Anexar à lista de canais" ,
context _unpinchannel _text : "Remover da lista de canais" ,
context _addtonewcategory _text : "Adicionar à nova categoria" ,
context _pinguild _text : "Anexar à lista de servidores" ,
context _unpinguild _text : "Remover da lista de servidores" ,
header _pinneddms _text : "Mensagens diretas fixadas" ,
modal _colorpicker1 _text : "Cor da categoria"
} ;
case "fi" : //finnish
return {
context _pindm _text : "Kiinnitä yksityisviestit" ,
context _pinchannel _text : "Liitä kanavaluetteloon" ,
context _unpinchannel _text : "Poista kanavaluettelosta" ,
context _addtonewcategory _text : "Lisää uuteen luokkaan" ,
context _pinguild _text : "Liitä palvelinluetteloon" ,
context _unpinguild _text : "Poista palvelinluettelosta" ,
header _pinneddms _text : "Liitetyt yksityisviestit" ,
modal _colorpicker1 _text : "Luokan väri"
} ;
case "sv" : //swedish
return {
context _pindm _text : "Fäst DM" ,
context _pinchannel _text : "Fäst till kanallista" ,
context _unpinchannel _text : "Ta bort från kanallistan" ,
context _addtonewcategory _text : "Lägg till i ny kategori" ,
context _pinguild _text : "Fäst till servernlista" ,
context _unpinguild _text : "Ta bort från servernlista" ,
header _pinneddms _text : "Inlagda Direktmeddelanden" ,
modal _colorpicker1 _text : "Kategori färg"
} ;
case "tr" : //turkish
return {
context _pindm _text : "DM'yi Sabitle" ,
context _pinchannel _text : "Kanal listesine ekle" ,
context _unpinchannel _text : "Kanal listesinden kaldı r" ,
context _addtonewcategory _text : "Yeni kategoriye ekle" ,
context _pinguild _text : "Sunucu listesine ekle" ,
context _unpinguild _text : "Sunucu listesinden kaldı r" ,
header _pinneddms _text : "Direkt Mesajlar Sabitleyin" ,
modal _colorpicker1 _text : "Kategori rengi"
} ;
case "cs" : //czech
return {
context _pindm _text : "Připnout PZ" ,
context _pinchannel _text : "Připojení k seznamu kanálů" ,
context _unpinchannel _text : "Odstranit ze seznamu kanálů" ,
context _addtonewcategory _text : "Přidat do nové kategorie" ,
context _pinguild _text : "Připojit ke seznamu serverů" ,
context _unpinguild _text : "Odstranit ze seznamu serverů" ,
header _pinneddms _text : "Připojené Přímá Zpráva" ,
modal _colorpicker1 _text : "Barva kategorie"
} ;
case "bg" : //bulgarian
return {
context _pindm _text : "Закачени ДС" ,
context _pinchannel _text : "Прикачете към списъка с канали" ,
context _unpinchannel _text : "Премахване от списъка с канали" ,
context _addtonewcategory _text : "Добавяне към нова категория" ,
context _pinguild _text : "Прикачване към списъка със сървъри" ,
context _unpinguild _text : "Премахване от списъка със сървъри" ,
header _pinneddms _text : "Свързани директни съобщения" ,
modal _colorpicker1 _text : "Цвят на категорията"
} ;
case "ru" : //russian
return {
context _pindm _text : "Закрепить ЛС" ,
context _pinchannel _text : "Прикрепить к списку каналов" ,
context _unpinchannel _text : "Удалить из списка каналов" ,
context _addtonewcategory _text : "Добавить в новую категорию" ,
context _pinguild _text : "Присоединить к списку серверов" ,
context _unpinguild _text : "Удалить из списка серверов" ,
header _pinneddms _text : "Прикрепленные Личные Сообщения" ,
modal _colorpicker1 _text : "Цвет категории"
} ;
case "uk" : //ukrainian
return {
context _pindm _text : "Закріпити ОП" ,
context _pinchannel _text : "Додайте до списку каналів" ,
context _unpinchannel _text : "Видалити зі списку каналів" ,
context _addtonewcategory _text : "Додати до нової категорії" ,
context _pinguild _text : "Додайте до списку серверів" ,
context _unpinguild _text : "Видалити зі списку серверів" ,
header _pinneddms _text : "Прикріплені oс о б ис ті повідомлення" ,
modal _colorpicker1 _text : "Колір категорії"
} ;
case "ja" : //japanese
return {
context _pindm _text : "DMピン" ,
context _pinchannel _text : "チャンネルリストに添付" ,
context _unpinchannel _text : "チャンネルリストから削除" ,
context _addtonewcategory _text : "新しいカテゴリに追加" ,
context _pinguild _text : "サーバーリストに添付" ,
context _unpinguild _text : "サーバーリストから削除" ,
header _pinneddms _text : "固定された直接メッセージ" ,
modal _colorpicker1 _text : "カテゴリーの色"
} ;
case "zh-TW" : //chinese (traditional)
return {
context _pindm _text : "引腳直接留言" ,
context _pinchannel _text : "附加到頻道列表" ,
context _unpinchannel _text : "從頻道列表中刪除" ,
context _addtonewcategory _text : "添加到新類別" ,
context _pinguild _text : "附加到服務器列表" ,
context _unpinguild _text : "從服務器列表中刪除" ,
header _pinneddms _text : "固定私人信息" ,
modal _colorpicker1 _text : "類別顏色"
} ;
case "ko" : //korean
return {
context _pindm _text : "비공개 메시지 고정" ,
context _pinchannel _text : "채널 목록에 첨부" ,
context _unpinchannel _text : "채널 목록에서 삭제" ,
context _addtonewcategory _text : "새 카테고리에 추가" ,
context _pinguild _text : "서버 목록에 첨부" ,
context _unpinguild _text : "서버 목록에서 제거" ,
header _pinneddms _text : "고정 된 비공개 메시지" ,
modal _colorpicker1 _text : "카테고리 색상"
} ;
default : //default: english
return {
context _pindm _text : "Pin DM" ,
context _pinchannel _text : "Pin to Channellist" ,
context _unpinchannel _text : "Unpin from Channellist" ,
context _addtonewcategory _text : "Add to new Category" ,
context _pinguild _text : "Pin to Serverlist" ,
context _unpinguild _text : "Unpin from Serverlist" ,
header _pinneddms _text : "Pinned Direct Messages" ,
modal _colorpicker1 _text : "Categorycolor"
} ;
}
}
} ;
2020-10-09 21:09:35 +02:00
} ) ( window . BDFDB _Global . PluginUtils . buildPlugin ( config ) ) ;
2020-09-19 20:49:33 +02:00
} ) ( ) ;