2019-09-20 22:32:52 +02:00
//META{"name":"PinDMs","website":"https://github.com/mwittrien/BetterDiscordAddons/tree/master/Plugins/PinDMs","source":"https://raw.githubusercontent.com/mwittrien/BetterDiscordAddons/master/Plugins/PinDMs/PinDMs.plugin.js"}*//
2018-10-11 10:21:26 +02:00
class PinDMs {
2019-01-11 15:32:04 +01:00
getName ( ) { return "PinDMs" ; }
2020-01-07 12:05:44 +01:00
getVersion ( ) { return "1.5.6" ; }
2019-01-11 15:32:04 +01:00
getAuthor ( ) { return "DevilBro" ; }
2019-01-31 18:09:39 +01:00
getDescription ( ) { return "Allows you to pin DMs, making them appear at the top of your DMs/Guild-list." ; }
2019-01-26 22:45:19 +01:00
2019-09-04 12:34:02 +02:00
constructor ( ) {
2019-02-05 14:23:34 +01:00
this . changelog = {
2020-01-07 12:05:44 +01:00
"added" : [ [ "Sorting Categories" , "You can now drag categories to sort them the same way as pinned DMs" ] , [ "Sort Order" , "You can now enable the option in the plugin settings to sort pinned DMs in the most recent message order within category" ] , [ "Move to other Category" , "Context Menu Layout was changed you can now pin a DM to another category (this will remove the DM from the other category)" ] ] ,
2020-01-06 12:23:12 +01:00
"fixed" : [ [ "Deleting" , "Fixed the bug where deleting a category between other categories would break all other categories" ] ] ,
2020-01-05 14:01:45 +01:00
"improved" : [ [ "Categories" , "Instead of pinning all your channels into the same category in the private channel list, you can now create your own collapsable categories, old pinned channel data was ported to the new category format" ] , [ "New Library Structure & React" , "Restructured my Library and switched to React rendering instead of DOM manipulation" ] ]
2019-02-05 14:23:34 +01:00
} ;
2019-09-04 12:34:02 +02:00
2019-11-14 17:56:26 +01:00
this . patchedModules = {
2019-11-21 14:56:53 +01:00
before : {
PrivateChannelsList : "render" ,
UnreadDMs : "render" ,
} ,
2019-11-14 17:56:26 +01:00
after : {
2019-11-21 14:56:53 +01:00
PrivateChannelsList : "render" ,
UnreadDMs : "render" ,
PrivateChannel : [ "render" , "componentDidMount" ] ,
DirectMessage : [ "render" , "componentDidMount" ]
2019-11-14 17:56:26 +01:00
}
2019-01-11 15:32:04 +01:00
} ;
2019-09-04 12:34:02 +02:00
}
2019-01-26 22:45:19 +01:00
2019-09-04 12:34:02 +02:00
initConstructor ( ) {
2019-01-24 22:27:15 +01:00
this . css = `
2019-11-21 14:56:53 +01:00
$ { BDFDB . dotCNS . dmchannel + BDFDB . dotCN . namecontainerchildren } {
display : flex ;
}
$ { BDFDB . dotCN . dmchannel } : hover $ { BDFDB . dotCN . _pindmsunpinbutton } {
display : block ;
}
2020-01-05 14:01:45 +01:00
$ { BDFDB . dotCN . _pindmspinnedchannelsheadercontainer } {
display : flex ;
cursor : pointer ;
}
$ { BDFDB . dotCNS . _pindmspinnedchannelsheadercontainer + BDFDB . dotCN . dmchannelheadertext } {
margin - right : 6 px ;
}
$ { 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 ) ;
}
2019-11-21 14:56:53 +01:00
$ { 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 ;
}
2020-01-07 12:05:44 +01:00
$ { BDFDB . dotCN . _pindmspinnedchannelsheadercontainer + BDFDB . dotCNS . _pindmsdmchannelplaceholder } {
margin - left : 8 px ;
height : 12 px ;
box - sizing : border - box ;
border : 1 px dashed currentColor ;
}
2019-11-21 14:56:53 +01:00
$ { BDFDB . dotCN . _pindmsdragpreview } {
2019-02-28 10:44:12 +01:00
pointer - events : none ! important ;
position : absolute ! important ;
opacity : 0.5 ! important ;
z - index : 10000 ! important ;
} ` ;
this . defaults = {
settings : {
2020-01-06 20:53:06 +01:00
sortInRecentOrder : { value : false , inner : true , description : "Channel List" } ,
sortInRecentOrderGuild : { value : false , inner : true , description : "Guild List" } ,
showPinIcon : { value : true , inner : false , description : "Shows a little 'Pin' icon for pinned DMs in the server list:" } ,
showCategoryAmount : { value : true , inner : false , description : "Shows the amount of pinned DMs in a category in the channel list:" }
2019-02-05 14:23:34 +01:00
}
2019-02-28 10:44:12 +01:00
} ;
2019-01-24 22:27:15 +01:00
}
2019-01-26 22:45:19 +01:00
2019-01-24 22:27:15 +01:00
getSettingsPanel ( ) {
if ( ! global . BDFDB || typeof BDFDB != "object" || ! BDFDB . loaded || ! this . started ) return ;
2019-10-22 23:04:35 +02:00
let settings = BDFDB . DataUtils . get ( this , "settings" ) ;
2020-01-06 20:53:06 +01:00
let settingspanel , settingsitems = [ ] , inneritems = [ ] ;
2019-11-21 14:56:53 +01:00
for ( let key in settings ) ( ! this . defaults . settings [ key ] . inner ? settingsitems : inneritems ) . push ( BDFDB . ReactUtils . createElement ( BDFDB . LibraryComponents . SettingsSaveItem , {
className : BDFDB . disCN . marginbottom8 ,
type : "Switch" ,
plugin : this ,
keys : [ "settings" , key ] ,
label : this . defaults . settings [ key ] . description ,
value : settings [ key ]
} ) ) ;
2020-01-06 20:53:06 +01:00
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 : inneritems
} ) ) ;
2019-11-21 14:56:53 +01:00
settingsitems . push ( BDFDB . ReactUtils . createElement ( BDFDB . LibraryComponents . SettingsItem , {
type : "Button" ,
className : BDFDB . disCN . marginbottom8 ,
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?" , ( ) => {
2020-01-05 14:01:45 +01:00
BDFDB . DataUtils . remove ( this , "dmCategories" ) ;
2019-11-21 14:56:53 +01:00
BDFDB . DataUtils . remove ( this , "pinnedRecents" ) ;
} ) ;
} ,
children : BDFDB . LanguageUtils . LanguageStrings . UNPIN
} ) ) ;
2019-12-18 16:45:08 +01:00
return settingspanel = BDFDB . PluginUtils . createSettingsPanel ( this , settingsitems ) ;
2018-10-11 10:21:26 +02:00
}
//legacy
load ( ) { }
start ( ) {
2019-02-04 09:13:15 +01:00
if ( ! global . BDFDB ) global . BDFDB = { myPlugins : { } } ;
if ( global . BDFDB && global . BDFDB . myPlugins && typeof global . BDFDB . myPlugins == "object" ) global . BDFDB . myPlugins [ this . getName ( ) ] = this ;
2019-05-26 13:55:26 +02:00
var libraryScript = document . querySelector ( 'head script#BDFDBLibraryScript' ) ;
if ( ! libraryScript || ( performance . now ( ) - libraryScript . getAttribute ( "date" ) ) > 600000 ) {
2018-10-11 10:21:26 +02:00
if ( libraryScript ) libraryScript . remove ( ) ;
libraryScript = document . createElement ( "script" ) ;
2019-05-26 13:55:26 +02:00
libraryScript . setAttribute ( "id" , "BDFDBLibraryScript" ) ;
2018-10-11 10:21:26 +02:00
libraryScript . setAttribute ( "type" , "text/javascript" ) ;
2019-10-18 10:56:41 +02:00
libraryScript . setAttribute ( "src" , "https://mwittrien.github.io/BetterDiscordAddons/Plugins/BDFDB.min.js" ) ;
2019-01-17 23:48:29 +01:00
libraryScript . setAttribute ( "date" , performance . now ( ) ) ;
2019-05-26 13:55:26 +02:00
libraryScript . addEventListener ( "load" , ( ) => { this . initialize ( ) ; } ) ;
2018-10-11 10:21:26 +02:00
document . head . appendChild ( libraryScript ) ;
}
2019-01-17 23:48:29 +01:00
else if ( global . BDFDB && typeof BDFDB === "object" && BDFDB . loaded ) this . initialize ( ) ;
2019-11-01 10:27:07 +01:00
this . startTimeout = setTimeout ( ( ) => {
try { return this . initialize ( ) ; }
catch ( err ) { console . error ( ` %c[ ${ this . getName ( ) } ]%c ` , "color: #3a71c1; font-weight: 700;" , "" , "Fatal Error: Could not initiate plugin! " + err ) ; }
} , 30000 ) ;
2018-10-11 10:21:26 +02:00
}
initialize ( ) {
2019-01-17 23:48:29 +01:00
if ( global . BDFDB && typeof BDFDB === "object" && BDFDB . loaded ) {
2019-01-22 11:05:54 +01:00
if ( this . started ) return ;
2019-10-22 18:55:25 +02:00
BDFDB . PluginUtils . init ( this ) ;
2020-01-05 14:01:45 +01:00
// REMOVE 05.01.2020
let oldData = this . sortAndUpdate ( "pinnedDMs" ) ;
if ( oldData . length ) {
let id = this . generateID ( "dmCategories" ) . toString ( ) ;
BDFDB . DataUtils . save ( {
id : id ,
name : this . labels . header _pinneddms _text ,
dms : oldData ,
pos : 0 ,
collapsed : false
} , this , "dmCategories" , id ) ;
BDFDB . DataUtils . remove ( this , "pinnedDMs" ) ;
}
2019-01-26 22:45:19 +01:00
2019-10-22 18:55:25 +02:00
BDFDB . ModuleUtils . forceAllUpdates ( this ) ;
2018-10-11 10:21:26 +02:00
}
2019-11-01 10:14:50 +01:00
else console . error ( ` %c[ ${ this . getName ( ) } ]%c ` , "color: #3a71c1; font-weight: 700;" , "" , "Fatal Error: Could not load BD functions!" ) ;
2018-10-11 10:21:26 +02:00
}
stop ( ) {
2019-01-17 23:48:29 +01:00
if ( global . BDFDB && typeof BDFDB === "object" && BDFDB . loaded ) {
2019-10-22 11:37:23 +02:00
this . stopping = true ;
2019-11-21 14:56:53 +01:00
this . forceUpdateAll ( ) ;
let unreadDMsInstance = BDFDB . ReactUtils . findOwner ( document . querySelector ( BDFDB . dotCN . app ) , { name : "UnreadDMs" , unlimited : true } ) ;
if ( unreadDMsInstance ) {
delete unreadDMsInstance . props . pinnedPrivateChannelIds ;
unreadDMsInstance . props . unreadPrivateChannelIds = BDFDB . LibraryModules . DirectMessageUnreadStore . getUnreadPrivateChannelIds ( ) ;
BDFDB . ReactUtils . forceUpdate ( unreadDMsInstance ) ;
2018-11-26 23:36:18 +01:00
}
2019-01-26 22:45:19 +01:00
2019-10-22 18:55:25 +02:00
BDFDB . PluginUtils . clear ( this ) ;
2018-10-11 10:21:26 +02:00
}
}
2019-09-04 12:34:02 +02:00
2019-01-26 22:45:19 +01:00
2018-10-11 10:21:26 +02:00
// begin of own functions
2019-01-26 22:45:19 +01:00
2019-11-21 14:56:53 +01:00
onSettingsClosed ( instance , wrapper , returnvalue ) {
if ( this . SettingsUpdated ) {
delete this . SettingsUpdated ;
this . forceUpdateAll ( ) ;
}
}
onUserContextMenu ( e ) {
if ( e . instance . props . user ) {
let [ children , index ] = BDFDB . ReactUtils . findChildren ( e . returnvalue , { name : "UserCloseChatItem" } ) ;
2019-09-11 12:14:43 +02:00
if ( index > - 1 ) {
2019-11-21 14:56:53 +01:00
let id = BDFDB . LibraryModules . ChannelStore . getDMFromUserId ( e . instance . props . user . id ) ;
if ( id ) this . injectItem ( e . instance , id , children , index ) ;
2019-01-11 15:32:04 +01:00
}
2018-10-11 10:21:26 +02:00
}
2019-01-11 15:32:04 +01:00
}
2019-01-26 22:45:19 +01:00
2019-11-21 14:56:53 +01:00
onGroupDMContextMenu ( e ) {
if ( e . instance . props . channelId ) {
let [ children , index ] = BDFDB . ReactUtils . findChildren ( e . returnvalue , { name : "ChangeIcon" } ) ;
if ( index > - 1 ) this . injectItem ( e . instance , e . instance . props . channelId , children , index ) ;
2018-10-11 10:21:26 +02:00
}
2019-01-11 15:32:04 +01:00
}
2019-01-26 22:45:19 +01:00
2019-11-21 14:56:53 +01:00
injectItem ( instance , id , children , index ) {
let pinnedInGuild = this . isPinned ( id , "pinnedRecents" ) ;
2020-01-05 14:01:45 +01:00
let categories = this . sortAndUpdateCategories ( "dmCategories" , true ) ;
2020-01-05 17:53:26 +01:00
let currentCategory = this . getCategory ( id , "dmCategories" ) ;
2020-01-05 14:01:45 +01:00
2019-12-05 09:10:14 +01:00
children . splice ( index , 0 , BDFDB . ReactUtils . createElement ( BDFDB . LibraryComponents . ContextMenuItems . Sub , {
2019-11-21 14:56:53 +01:00
label : this . labels . context _pindm _text ,
2020-01-05 17:53:26 +01:00
render : [ BDFDB . ReactUtils . createElement ( BDFDB . LibraryComponents . ContextMenuItems . Sub , {
2020-01-05 14:01:45 +01:00
label : this . labels . context _pinchannel _text ,
render : [
BDFDB . ReactUtils . createElement ( BDFDB . LibraryComponents . ContextMenuItems . Group , {
2020-01-05 17:53:26 +01:00
children : currentCategory ? BDFDB . ReactUtils . createElement ( BDFDB . LibraryComponents . ContextMenuItems . Item , {
label : this . labels . context _unpinchannel _text ,
danger : true ,
action : _ => {
BDFDB . ContextMenuUtils . close ( instance ) ;
this . removeFromCategory ( id , currentCategory , "dmCategories" ) ;
}
} ) : BDFDB . ReactUtils . createElement ( BDFDB . LibraryComponents . ContextMenuItems . Item , {
2020-01-05 14:01:45 +01:00
label : this . labels . context _addtonewcategory _text ,
brand : true ,
action : _ => {
BDFDB . ContextMenuUtils . close ( instance ) ;
this . openCategorySettingsModal ( {
id : this . generateID ( "dmCategories" ) . toString ( ) ,
name : ` ${ this . labels . header _pinneddms _text } # ${ categories . length + 1 } ` ,
dms : [ id ] ,
pos : categories . length ,
collapsed : false
} , "dmCategories" , true ) ;
}
} )
} ) ,
categories . length ? BDFDB . ReactUtils . createElement ( BDFDB . LibraryComponents . ContextMenuItems . Group , {
2020-01-05 17:53:26 +01:00
children : categories . map ( category => currentCategory && currentCategory . id == category . id ? null : BDFDB . ReactUtils . createElement ( BDFDB . LibraryComponents . ContextMenuItems . Item , {
2020-01-05 14:01:45 +01:00
label : category . name || this . labels . header _pinneddms _text ,
action : _ => {
BDFDB . ContextMenuUtils . close ( instance ) ;
2020-01-05 17:53:26 +01:00
if ( currentCategory ) this . removeFromCategory ( id , currentCategory , "dmCategories" ) ;
2020-01-05 14:01:45 +01:00
this . addToCategory ( id , category , "dmCategories" ) ;
}
2020-01-05 17:53:26 +01:00
} ) ) . filter ( n => n )
2020-01-05 14:01:45 +01:00
} ) : null
] . filter ( n => n )
2019-11-21 14:56:53 +01:00
} ) ,
2019-12-05 09:10:14 +01:00
BDFDB . ReactUtils . createElement ( BDFDB . LibraryComponents . ContextMenuItems . Item , {
2019-11-21 14:56:53 +01:00
label : this . labels [ pinnedInGuild ? "context_unpinguild_text" : "context_pinguild_text" ] ,
danger : pinnedInGuild ,
action : _ => {
BDFDB . ContextMenuUtils . close ( instance ) ;
if ( ! pinnedInGuild ) this . addPin ( id , "pinnedRecents" ) ;
else this . removePin ( id , "pinnedRecents" ) ;
}
} )
]
2019-09-11 12:14:43 +02:00
} ) ) ;
2019-01-24 22:27:15 +01:00
}
2019-01-26 22:45:19 +01:00
2019-11-21 14:56:53 +01:00
processPrivateChannelsList ( e ) {
2020-01-05 14:01:45 +01:00
let categories = this . sortAndUpdateCategories ( "dmCategories" , true ) ;
if ( categories . length ) {
2020-01-07 12:05:44 +01:00
if ( this . draggedCategory && this . releasedCategory ) {
let draggedCategory = categories . find ( n => n . id == this . draggedCategory ) ;
let releasedCategory = categories . find ( n => n . id == this . releasedCategory ) ;
if ( draggedCategory && releasedCategory ) {
BDFDB . ArrayUtils . remove ( categories , draggedCategory , true ) ;
categories . splice ( categories . indexOf ( releasedCategory ) + 1 , 0 , draggedCategory ) ;
let newCategories = { } , newPos = 0 ;
for ( let category of [ ] . concat ( categories ) . reverse ( ) ) newCategories [ category . id ] = Object . assign ( category , { pos : newPos ++ } ) ;
BDFDB . DataUtils . save ( newCategories , this , "dmCategories" ) ;
}
delete this . draggedCategory ;
delete this . releasedCategory ;
}
2019-11-21 14:56:53 +01:00
e . instance . props . channels = Object . assign ( { } , e . instance . props . channels ) ;
e . instance . props . pinnedChannels = Object . assign ( { } , e . instance . props . pinnedChannels ) ;
2020-01-05 17:46:10 +01:00
e . instance . props . privateChannelIds = [ ] . concat ( e . instance . props . privateChannelIds ) . filter ( n => n ) ;
2020-01-06 20:53:06 +01:00
for ( let category of categories ) for ( let id of this . sortDMsByTime ( category . dms , "dmCategories" ) ) if ( e . instance . props . channels [ id ] ) {
2020-01-05 14:01:45 +01:00
e . instance . props . pinnedChannels [ id ] = e . instance . props . channels [ id ] ;
delete e . instance . props . channels [ id ] ;
2020-01-05 17:03:59 +01:00
BDFDB . ArrayUtils . remove ( e . instance . props . privateChannelIds , id , true ) ;
2020-01-05 17:46:10 +01:00
e . instance . props . privateChannelIds . unshift ( id ) ;
2019-11-21 14:56:53 +01:00
}
2020-01-05 14:01:45 +01:00
if ( e . returnvalue ) {
2019-11-21 14:56:53 +01:00
let [ children , index ] = BDFDB . ReactUtils . findChildren ( e . returnvalue , { name : "ListSectionItem" } ) ;
if ( index > - 1 ) {
if ( this . draggedChannel && this . releasedChannel ) {
2020-01-05 14:01:45 +01:00
let categoryId = this . releasedChannel . split ( "header_" ) [ 1 ] ;
let category = categories . find ( n => categoryId != undefined ? n . id == categoryId : n . dms . includes ( this . releasedChannel ) ) ;
if ( category ) {
BDFDB . ArrayUtils . remove ( category . dms , this . draggedChannel , true ) ;
category . dms . splice ( categoryId != undefined ? 0 : category . dms . indexOf ( this . releasedChannel ) + 1 , 0 , this . draggedChannel ) ;
BDFDB . DataUtils . save ( category , this , "dmCategories" , category . id ) ;
2019-11-21 14:56:53 +01:00
}
delete this . draggedChannel ;
delete this . releasedChannel ;
2019-02-05 14:23:34 +01:00
}
2020-01-05 14:01:45 +01:00
let showCategoryAmount = BDFDB . DataUtils . get ( this , "settings" , "showCategoryAmount" ) ;
2020-01-07 12:05:44 +01:00
for ( let category of categories ) if ( this . draggedCategory != category . id ) {
2020-01-05 14:01:45 +01:00
children . splice ( index ++ , 0 , BDFDB . ReactUtils . createElement ( "header" , {
className : BDFDB . DOMUtils . formatClassName ( BDFDB . disCN . dmchannelheader , BDFDB . disCN . _pindmspinnedchannelsheadercontainer , category . collapsed && BDFDB . disCN . _pindmspinnedchannelsheadercollapsed , BDFDB . disCN . namecontainernamecontainer ) ,
2020-01-07 12:05:44 +01:00
categoryId : category . id ,
onMouseDown : 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 ) ;
this . 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 hoveredCategory = categoryNode && categoryNode . getAttribute ( "categoryId" ) ;
let update = hoveredCategory != this . hoveredCategory ;
if ( hoveredCategory ) this . hoveredCategory = hoveredCategory ;
else delete this . hoveredCategory ;
if ( update ) this . updateContainer ( "dmCategories" ) ;
} ;
let releasing = event3 => {
BDFDB . DOMUtils . remove ( dragpreview ) ;
if ( this . hoveredCategory ) this . releasedCategory = this . hoveredCategory ;
else delete this . draggedCategory ;
delete this . hoveredCategory ;
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 ) ;
} ,
2020-01-05 14:01:45 +01:00
onClick : _ => {
if ( category . dms . length || ! category . collapsed ) {
category . collapsed = ! category . collapsed ;
BDFDB . DataUtils . save ( category , this , "dmCategories" , category . id ) ;
BDFDB . ReactUtils . forceUpdate ( e . instance ) ;
}
} ,
onContextMenu : event => {
BDFDB . ContextMenuUtils . open ( this , event , BDFDB . ReactUtils . createElement ( BDFDB . LibraryComponents . ContextMenuItems . Group , {
children : [
BDFDB . ReactUtils . createElement ( BDFDB . LibraryComponents . ContextMenuItems . Item , {
label : BDFDB . LanguageUtils . LanguageStrings . CATEGORY _SETTINGS ,
action : event2 => {
BDFDB . ContextMenuUtils . close ( BDFDB . DOMUtils . getParent ( BDFDB . dotCN . contextmenu , event2 . target ) ) ;
this . openCategorySettingsModal ( category , "dmCategories" ) ;
}
} ) ,
BDFDB . ReactUtils . createElement ( BDFDB . LibraryComponents . ContextMenuItems . Item , {
label : BDFDB . LanguageUtils . LanguageStrings . DELETE _CATEGORY ,
danger : true ,
action : event2 => {
BDFDB . ContextMenuUtils . close ( BDFDB . DOMUtils . getParent ( BDFDB . dotCN . contextmenu , event2 . target ) ) ;
BDFDB . DataUtils . remove ( this , "dmCategories" , category . id ) ;
this . updateContainer ( "dmCategories" ) ;
}
} )
]
} ) ) ;
} ,
children : [
BDFDB . ReactUtils . createElement ( "span" , {
className : BDFDB . disCN . dmchannelheadertext ,
children : category . name
} ) ,
showCategoryAmount ? BDFDB . ReactUtils . createElement ( BDFDB . LibraryComponents . BadgeComponents . NumberBadge , {
className : BDFDB . disCN . _pindmspinnedchannelsheaderamount ,
count : category . dms . 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 )
} ) ) ;
if ( this . hoveredChannel == "header_" + category . id ) children . splice ( index ++ , 0 , BDFDB . ReactUtils . createElement ( BDFDB . LibraryComponents . ListItem , {
className : BDFDB . disCNS . dmchannel + BDFDB . disCNS . _pindmsdmchannelpinned + BDFDB . disCN . _pindmsdmchannelplaceholder
} ) ) ;
2020-01-06 20:53:06 +01:00
for ( let id of this . sortDMsByTime ( category . dms , "dmCategories" ) ) {
2020-01-05 17:46:10 +01:00
if ( e . instance . props . pinnedChannels [ id ] && this . draggedChannel != id && ( ! category . collapsed || e . instance . props . selectedChannelId == id ) ) {
2020-01-05 17:03:59 +01:00
children . splice ( index ++ , 0 , e . instance . props . renderChannel ( e . instance . props . pinnedChannels [ id ] , e . instance . props . selectedChannelId == id ) ) ;
if ( this . hoveredChannel == id ) children . splice ( index ++ , 0 , BDFDB . ReactUtils . createElement ( BDFDB . LibraryComponents . ListItem , {
className : BDFDB . disCNS . dmchannel + BDFDB . disCNS . _pindmsdmchannelpinned + BDFDB . disCN . _pindmsdmchannelplaceholder
} ) ) ;
}
2020-01-05 17:46:10 +01:00
else BDFDB . ArrayUtils . remove ( e . instance . props . privateChannelIds , id , true ) ;
2019-11-21 14:56:53 +01:00
}
2020-01-07 12:05:44 +01:00
if ( this . hoveredCategory == category . id ) children . splice ( index ++ , 0 , BDFDB . ReactUtils . createElement ( "header" , {
className : BDFDB . disCNS . dmchannelheader + BDFDB . disCNS . _pindmspinnedchannelsheadercontainer + BDFDB . disCNS . _pindmsdmchannelplaceholder + BDFDB . disCN . namecontainernamecontainer
} ) ) ;
2019-01-24 22:27:15 +01:00
}
2019-05-29 17:39:43 +02:00
}
2019-01-24 22:27:15 +01:00
}
2018-10-11 10:21:26 +02:00
}
}
2019-01-26 22:45:19 +01:00
2019-11-21 14:56:53 +01: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 ) ;
2018-11-29 17:33:33 +01:00
}
2018-11-29 15:19:09 +01:00
}
2019-11-21 14:56:53 +01:00
e . instance . props . unreadPrivateChannelIds = e . instance . props . unreadPrivateChannelIds . concat ( BDFDB . LibraryModules . DirectMessageUnreadStore . getUnreadPrivateChannelIds ( ) ) ;
if ( e . returnvalue ) {
if ( this . draggedChannel && this . releasedChannel ) {
let pinnedPrivateChannelIds = [ ] . concat ( e . instance . props . pinnedPrivateChannelIds ) , newData = { } ;
BDFDB . ArrayUtils . remove ( pinnedPrivateChannelIds , this . draggedChannel , true ) ;
pinnedPrivateChannelIds . splice ( pinnedPrivateChannelIds . indexOf ( this . releasedChannel ) + 1 , 0 , this . draggedChannel ) ;
for ( let pos in pinnedPrivateChannelIds ) newData [ pinnedPrivateChannelIds [ pos ] ] = parseInt ( pos ) ;
BDFDB . DataUtils . save ( newData , this , "pinnedRecents" ) ;
delete this . draggedChannel ;
delete this . releasedChannel ;
BDFDB . ReactUtils . forceUpdate ( e . instance ) ;
2018-11-26 23:36:18 +01:00
}
2019-11-21 14:56:53 +01:00
if ( this . draggedChannel ) {
let [ children , index ] = BDFDB . ReactUtils . findChildren ( e . returnvalue , { filter : child => BDFDB . ReactUtils . getValue ( child , "props.channel.id" ) == this . draggedChannel } ) ;
children . splice ( index , 1 ) ;
}
if ( this . hoveredChannel ) {
let [ children , index ] = BDFDB . ReactUtils . findChildren ( e . returnvalue , { filter : child => BDFDB . ReactUtils . getValue ( 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 . DragPlaceholder , { } )
} )
} ) ) ;
2019-01-11 15:32:04 +01:00
}
2018-11-26 23:36:18 +01:00
}
2019-02-16 10:41:56 +01:00
}
2019-11-21 14:56:53 +01:00
else e . instance . props . unreadPrivateChannelIds = BDFDB . LibraryModules . DirectMessageUnreadStore . getUnreadPrivateChannelIds ( ) ;
2018-10-11 10:21:26 +02:00
}
2019-01-26 22:45:19 +01:00
2019-11-21 14:56:53 +01:00
processPrivateChannel ( e ) {
2020-01-05 14:01:45 +01:00
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 ) ;
2020-01-05 17:46:10 +01:00
if ( ! BDFDB . DataUtils . get ( this , "settings" , "sortInRecentOrder" ) ) {
e . node . setAttribute ( "draggable" , false ) ;
e . node . PinDMsMouseDownListener = event => {
if ( ! BDFDB . BdUtils . isPluginEnabled ( "PinDMs" ) ) e . node . removeEventListener ( "mousedown" , e . node . PinDMsMouseDownListener ) ;
else {
let mousemove = event2 => {
if ( Math . sqrt ( ( event . pageX - event2 . pageX ) * * 2 ) > 20 || Math . sqrt ( ( event . pageY - event2 . pageY ) * * 2 ) > 20 ) {
BDFDB . ListenerUtils . stopEvent ( event ) ;
this . 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 ) ;
2020-01-07 12:05:44 +01:00
let hoveredChannel = null ;
2020-01-05 17:46:10 +01:00
if ( BDFDB . DOMUtils . getParent ( BDFDB . dotCN . _pindmspinnedchannelsheadercontainer , event3 . target ) ) {
2020-01-07 12:05:44 +01:00
let hoveredCategoryId = BDFDB . ReactUtils . findValue ( event3 . target , "categoryId" , { up : true } ) ;
if ( hoveredCategoryId && hoveredCategoryId == category . id ) hoveredChannel = "header_" + category . id ;
2020-01-05 17:46:10 +01:00
}
else {
let placeholder = BDFDB . DOMUtils . getParent ( BDFDB . dotCN . _pindmsdmchannelplaceholder , event3 . target ) ;
hoveredChannel = ( BDFDB . ReactUtils . findValue ( BDFDB . DOMUtils . getParent ( BDFDB . dotCN . _pindmsdmchannelpinned , placeholder ? placeholder . previousSibling : event3 . target ) , "channel" , { up : true } ) || { } ) . id ;
let hoveredCategory = hoveredChannel && this . getCategory ( hoveredChannel , "dmCategories" ) ;
if ( ! hoveredCategory || hoveredCategory . id != category . id ) hoveredChannel = null ;
} ;
let update = hoveredChannel != this . hoveredChannel ;
if ( hoveredChannel ) this . hoveredChannel = hoveredChannel ;
else delete this . hoveredChannel ;
if ( update ) this . updateContainer ( "dmCategories" ) ;
} ;
let releasing = event3 => {
BDFDB . DOMUtils . remove ( dragpreview ) ;
if ( this . hoveredChannel ) this . releasedChannel = this . hoveredChannel ;
else delete this . draggedChannel ;
delete this . hoveredChannel ;
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
} )
} )
} )
] . concat ( e . returnvalue . props . children ) . flat ( 10 ) ;
}
}
}
}
processDirectMessage ( e ) {
if ( e . instance . props . channel ) {
if ( e . node ) {
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 ) ;
2020-01-06 20:53:06 +01:00
if ( ! BDFDB . DataUtils . get ( this , "settings" , "sortInRecentOrderGuild" ) ) {
2020-01-05 17:46:10 +01:00
for ( let child of e . node . querySelectorAll ( "a" ) ) child . setAttribute ( "draggable" , false ) ;
e . node . PinDMsMouseDownListener = event => {
2020-01-05 14:01:45 +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 ) ;
this . draggedChannel = e . instance . props . channel . id ;
2020-01-05 17:46:10 +01:00
BDFDB . ModuleUtils . forceAllUpdates ( this , "UnreadDMs" ) ;
2020-01-05 14:01:45 +01:00
let dragpreview = this . createDragPreview ( e . node , event2 ) ;
document . removeEventListener ( "mousemove" , mousemove ) ;
document . removeEventListener ( "mouseup" , mouseup ) ;
let dragging = event3 => {
this . updateDragPreview ( dragpreview , event3 ) ;
2020-01-05 17:46:10 +01:00
let placeholder = BDFDB . DOMUtils . getParent ( BDFDB . dotCN . _pindmsrecentplaceholder , event3 . target ) ;
let hoveredChannel = ( BDFDB . ReactUtils . findValue ( BDFDB . DOMUtils . getParent ( BDFDB . dotCN . _pindmsrecentpinned , placeholder ? placeholder . previousSibling : event3 . target ) , "channel" , { up : true } ) || { } ) . id ;
2020-01-05 14:01:45 +01:00
let update = hoveredChannel != this . hoveredChannel ;
if ( hoveredChannel ) this . hoveredChannel = hoveredChannel ;
else delete this . hoveredChannel ;
2020-01-05 17:46:10 +01:00
if ( update ) BDFDB . ModuleUtils . forceAllUpdates ( this , "UnreadDMs" ) ;
2020-01-05 14:01:45 +01:00
} ;
let releasing = event3 => {
BDFDB . DOMUtils . remove ( dragpreview ) ;
if ( this . hoveredChannel ) this . releasedChannel = this . hoveredChannel ;
else delete this . draggedChannel ;
delete this . hoveredChannel ;
2020-01-05 17:46:10 +01:00
BDFDB . ModuleUtils . forceAllUpdates ( this , "UnreadDMs" ) ;
2020-01-05 14:01:45 +01:00
document . removeEventListener ( "mousemove" , dragging ) ;
document . removeEventListener ( "mouseup" , releasing ) ;
} ;
document . addEventListener ( "mousemove" , dragging ) ;
document . addEventListener ( "mouseup" , releasing ) ;
}
2019-02-05 14:23:34 +01:00
} ;
2020-01-05 14:01:45 +01:00
let mouseup = _ => {
document . removeEventListener ( "mousemove" , mousemove ) ;
document . removeEventListener ( "mouseup" , mouseup ) ;
2019-02-05 14:23:34 +01:00
} ;
2020-01-05 14:01:45 +01:00
document . addEventListener ( "mousemove" , mousemove ) ;
document . addEventListener ( "mouseup" , mouseup ) ;
2019-11-21 14:56:53 +01:00
} ;
2020-01-05 17:46:10 +01:00
e . node . addEventListener ( "mousedown" , e . node . PinDMsMouseDownListener ) ;
}
2019-11-21 14:56:53 +01:00
}
}
2019-11-28 09:48:57 +01:00
if ( this . isPinned ( e . instance . props . channel . id , "pinnedRecents" ) && BDFDB . DataUtils . get ( this , "settings" , "showPinIcon" ) ) {
2019-11-21 14:56:53 +01:00
let [ children , index ] = BDFDB . ReactUtils . findChildren ( e . returnvalue , { name : "BlobMask" } ) ;
2019-11-28 09:48:57 +01:00
if ( index > - 1 ) children [ index ] . props . upperLeftBadge = BDFDB . ReactUtils . createElement ( BDFDB . LibraryComponents . BadgeComponents . IconBadge , {
2019-11-21 14:56:53 +01:00
className : BDFDB . disCN . guildbadgeiconbadge2 ,
name : BDFDB . LibraryComponents . SvgIcon . Names . NOVA _PIN ,
2019-11-28 09:48:57 +01:00
style : { backgroundColor : null , transform : "scale(-1, 1)" }
2019-11-21 14:56:53 +01:00
} ) ;
}
}
2019-02-05 14:23:34 +01:00
}
2020-01-05 14:01:45 +01: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 ;
}
addToCategory ( id , category , type ) {
if ( ! id || ! category || ! type ) return ;
let wasEmpty = ! 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 ) ;
}
removeFromCategory ( id , category , type ) {
if ( ! id || ! category || ! type ) return ;
BDFDB . ArrayUtils . remove ( category . dms , id , true ) ;
if ( ! category . dms . length ) category . collapsed = true ;
BDFDB . DataUtils . save ( category , this , type , category . id ) ;
this . updateContainer ( type ) ;
}
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 ;
}
sortAndUpdateCategories ( type , reverse ) {
let data = BDFDB . ObjectUtils . sort ( BDFDB . DataUtils . load ( this , type ) , "pos" ) , newData = { } ;
2020-01-06 12:23:12 +01:00
let sorted = [ ] , pos = 0 , sort = id => {
2020-01-05 14:01:45 +01:00
if ( sorted [ pos ] === undefined ) {
2020-01-06 12:23:12 +01:00
newData [ id ] = Object . assign ( { } , data [ id ] , { pos } ) ;
sorted [ pos ] = newData [ id ] ;
}
else {
pos ++ ;
sort ( id ) ;
2020-01-05 14:01:45 +01:00
}
} ;
2020-01-06 12:23:12 +01:00
for ( let id in data ) sort ( id ) ;
2020-01-05 14:01:45 +01:00
if ( ! BDFDB . equals ( data , newData ) ) BDFDB . DataUtils . save ( newData , this , type ) ;
2020-01-06 12:23:12 +01:00
return ( reverse ? sorted . reverse ( ) : sorted ) . filter ( n => n ) ;
2020-01-05 14:01:45 +01:00
}
2020-01-06 20:53:06 +01:00
sortDMsByTime ( dms , type ) {
if ( dms . length > 1 && BDFDB . DataUtils . get ( this , "settings" , type == "dmCategories" ? "sortInRecentOrder" : "sortInRecentOrderGuild" ) ) {
2020-01-05 17:46:10 +01:00
let timestamps = BDFDB . LibraryModules . DirectMessageStore . getPrivateChannelTimestamps ( ) ;
return [ ] . concat ( dms ) . sort ( function ( x , y ) { return timestamps [ x ] > timestamps [ y ] ? - 1 : timestamps [ x ] < timestamps [ y ] ? 1 : 0 ; } ) ;
}
else return dms ;
}
2020-01-05 14:01:45 +01:00
openCategorySettingsModal ( data , type , isNew ) {
if ( BDFDB . ObjectUtils . is ( data ) && type ) BDFDB . ModalUtils . open ( this , {
size : "SMALL" ,
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
} )
} )
] ,
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 ;
BDFDB . DataUtils . save ( data , this , type , data . id ) ;
this . updateContainer ( type ) ;
}
} ]
} ) ;
}
2019-11-21 14:56:53 +01: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 ) ;
2020-01-05 14:01:45 +01:00
this . updateContainer ( type ) ;
2019-02-05 14:23:34 +01:00
}
2019-11-21 14:56:53 +01:00
removePin ( id , type ) {
if ( ! id ) return ;
BDFDB . DataUtils . remove ( this , type , id ) ;
2020-01-05 14:01:45 +01:00
this . updateContainer ( type ) ;
2019-02-05 14:23:34 +01:00
}
2019-11-21 14:56:53 +01:00
isPinned ( id , type ) {
return BDFDB . DataUtils . load ( this , type , id ) != undefined ;
2019-01-24 22:27:15 +01:00
}
2019-11-21 14:56:53 +01:00
2020-01-05 14:01:45 +01:00
updateContainer ( type ) {
2019-11-21 14:56:53 +01:00
switch ( type ) {
2020-01-05 14:01:45 +01:00
case "dmCategories" :
BDFDB . ModuleUtils . forceAllUpdates ( this , "PrivateChannelsList" ) ;
break ;
case "pinnedRecents" :
BDFDB . ModuleUtils . forceAllUpdates ( this , "UnreadDMs" ) ;
break ;
2019-01-24 22:27:15 +01:00
}
}
2019-01-26 22:45:19 +01:00
2019-11-21 14:56:53 +01: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 ] ) ;
2019-01-24 22:27:15 +01:00
}
2019-11-21 14:56:53 +01:00
if ( ! BDFDB . equals ( data , newData ) ) BDFDB . DataUtils . save ( newData , this , type ) ;
2020-01-06 20:53:06 +01:00
return this . sortDMsByTime ( existingDMs , type ) ;
2019-01-24 22:27:15 +01:00
}
2019-01-26 22:45:19 +01:00
2019-11-21 14:56:53 +01:00
forceUpdateAll ( ) {
BDFDB . ReactUtils . forceUpdate ( BDFDB . ReactUtils . findOwner ( document . querySelector ( BDFDB . dotCN . app ) , { name : "FluxContainer(PrivateChannels)" , all : true , unlimited : true } ) ) ;
BDFDB . ModuleUtils . forceAllUpdates ( this ) ;
}
2019-09-04 12:34:02 +02:00
2019-11-21 14:56:53 +01: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
2019-11-21 14:56:53 +01: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" ) ;
2019-04-26 23:16:20 +02:00
}
2018-10-11 10:21:26 +02:00
setLabelsByLanguage ( ) {
2019-10-23 11:10:01 +02:00
switch ( BDFDB . LanguageUtils . getLanguage ( ) . id ) {
2018-10-11 10:21:26 +02:00
case "hr" : //croatian
return {
2018-11-06 22:48:28 +01:00
context _pindm _text : "Prikljucite Izravnu Poruku" ,
2019-01-24 22:27:15 +01:00
context _pinchannel _text : "Priložite popisu kanala" ,
context _unpinchannel _text : "Ukloni s popisa kanala" ,
2020-01-05 14:01:45 +01:00
context _addtonewcategory _text : "Dodavanje u novu kategoriju" ,
2019-01-24 22:27:15 +01:00
context _pinguild _text : "Priložite popisu poslužitelja" ,
context _unpinguild _text : "Ukloni s popisa poslužitelja" ,
2018-11-06 22:48:28 +01:00
header _pinneddms _text : "Prikvačene Izravne Poruke"
2018-10-11 10:21:26 +02:00
} ;
case "da" : //danish
return {
2018-11-06 22:48:28 +01:00
context _pindm _text : "Fastgør PB" ,
2019-01-24 22:27:15 +01:00
context _pinchannel _text : "Vedhæft til kanalliste" ,
context _unpinchannel _text : "Fjern fra kanalliste" ,
2020-01-05 14:01:45 +01:00
context _addtonewcategory _text : "Føj til ny kategori" ,
2019-01-24 22:27:15 +01:00
context _pinguild _text : "Vedhæft til serverliste" ,
context _unpinguild _text : "Fjern fra serverliste" ,
2018-10-11 10:21:26 +02:00
header _pinneddms _text : "Pinned Privat Beskeder"
} ;
case "de" : //german
return {
2018-11-06 22:48:28 +01:00
context _pindm _text : "Direktnachricht anheften" ,
2019-01-24 22:27:15 +01:00
context _pinchannel _text : "An Kanalliste anheften" ,
context _unpinchannel _text : "Von Kanalliste loslösen" ,
2020-01-05 14:01:45 +01:00
context _addtonewcategory _text : "Zur neuen Kategorie hinzufügen" ,
2019-01-24 22:27:15 +01:00
context _pinguild _text : "An Serverliste anheften" ,
context _unpinguild _text : "Von Serverliste loslösen" ,
2018-10-11 10:21:26 +02:00
header _pinneddms _text : "Gepinnte Direktnachrichten"
} ;
case "es" : //spanish
return {
2018-11-06 22:48:28 +01:00
context _pindm _text : "Anclar MD" ,
2019-01-24 22:27:15 +01:00
context _pinchannel _text : "Adjuntar a la lista de canales" ,
context _unpinchannel _text : "Deshazte de la lista de canales" ,
2020-01-05 14:01:45 +01:00
context _addtonewcategory _text : "Agregar a nueva categoría" ,
2019-01-24 22:27:15 +01:00
context _pinguild _text : "Adjuntar a la lista de servidores" ,
context _unpinguild _text : "Deshazte de la lista de servidores" ,
2018-10-11 10:21:26 +02:00
header _pinneddms _text : "Mensajes Directos Fijados"
} ;
case "fr" : //french
return {
context _pindm _text : "Épingler MP" ,
2019-12-02 20:43:01 +01:00
context _pinchannel _text : "Épingler à la liste des salons" ,
context _unpinchannel _text : "Détacher de la liste des salons" ,
2020-01-05 14:01:45 +01:00
context _addtonewcategory _text : "Ajouter à une nouvelle catégorie" ,
2019-01-24 22:27:15 +01:00
context _pinguild _text : "Épingler à la liste de serveurs" ,
context _unpinguild _text : "Détacher de la liste de serveurs" ,
2018-10-11 10:21:26 +02:00
header _pinneddms _text : "Messages Prives Épinglés"
} ;
case "it" : //italian
return {
2018-11-06 22:48:28 +01:00
context _pindm _text : "Fissa il messaggio diretto" ,
2019-01-24 22:27:15 +01:00
context _pinchannel _text : "Allega alla lista dei canali" ,
context _unpinchannel _text : "Rimuovi dalla lista dei canali" ,
2020-01-05 14:01:45 +01:00
context _addtonewcategory _text : "Aggiungi a nuova categoria" ,
2019-01-24 22:27:15 +01:00
context _pinguild _text : "Allega alla lista dei server" ,
context _unpinguild _text : "Rimuovi dalla lista dei server" ,
2018-10-11 10:21:26 +02:00
header _pinneddms _text : "Messaggi Diretti Aggiunti"
} ;
case "nl" : //dutch
return {
2018-11-06 22:48:28 +01:00
context _pindm _text : "PB pinnen" ,
2019-01-24 22:27:15 +01:00
context _pinchannel _text : "Pin naar de kanalenlijst" ,
context _unpinchannel _text : "Losmaken van kanalenlijst" ,
2020-01-05 14:01:45 +01:00
context _addtonewcategory _text : "Toevoegen aan nieuwe categorie" ,
2019-01-24 22:27:15 +01:00
context _pinguild _text : "Pin naar de serverlijst" ,
context _unpinguild _text : "Losmaken van serverlijst" ,
2018-10-11 10:21:26 +02:00
header _pinneddms _text : "Vastgezette Persoonluke Berichten"
} ;
case "no" : //norwegian
return {
2018-11-06 22:48:28 +01:00
context _pindm _text : "Fest DM" ,
2019-01-24 22:27:15 +01:00
context _pinchannel _text : "Fest på kanalliste" ,
context _unpinchannel _text : "Fjern fra kanalliste" ,
2020-01-05 14:01:45 +01:00
context _addtonewcategory _text : "Legg til i ny kategori" ,
2019-01-24 22:27:15 +01:00
context _pinguild _text : "Fest på serverliste" ,
context _unpinguild _text : "Fjern fra serverlisten" ,
2018-10-11 10:21:26 +02:00
header _pinneddms _text : "Pinned Direktemeldinger"
} ;
case "pl" : //polish
return {
context _pindm _text : "Przypnij PW" ,
2019-01-24 22:27:15 +01:00
context _pinchannel _text : "Dołącz do listy kanałów" ,
context _unpinchannel _text : "Usuń z listy kanałów" ,
2020-01-05 14:01:45 +01:00
context _addtonewcategory _text : "Dodaj do nowej kategorii" ,
2019-01-24 22:27:15 +01:00
context _pinguild _text : "Dołącz do listy serwerów" ,
context _unpinguild _text : "Usuń z listy serwerów" ,
2018-10-11 10:21:26 +02:00
header _pinneddms _text : "Prywatne Wiadomości Bezpośrednie"
} ;
case "pt-BR" : //portuguese (brazil)
return {
context _pindm _text : "Fixar MD" ,
2019-01-24 22:27:15 +01:00
context _pinchannel _text : "Anexar à lista de canais" ,
context _unpinchannel _text : "Remover da lista de canais" ,
2020-01-05 14:01:45 +01:00
context _addtonewcategory _text : "Lisää uuteen luokkaan" ,
2019-01-24 22:27:15 +01:00
context _pinguild _text : "Anexar à lista de servidores" ,
context _unpinguild _text : "Remover da lista de servidores" ,
2018-10-11 10:21:26 +02:00
header _pinneddms _text : "Mensagens diretas fixadas"
} ;
case "fi" : //finnish
return {
context _pindm _text : "Kiinnitä yksityisviestit" ,
2019-01-24 22:27:15 +01:00
context _pinchannel _text : "Liitä kanavaluetteloon" ,
context _unpinchannel _text : "Poista kanavaluettelosta" ,
2020-01-05 14:01:45 +01:00
context _addtonewcategory _text : "" ,
2019-01-24 22:27:15 +01:00
context _pinguild _text : "Liitä palvelinluetteloon" ,
context _unpinguild _text : "Poista palvelinluettelosta" ,
2018-10-11 10:21:26 +02:00
header _pinneddms _text : "Liitetyt yksityisviestit"
} ;
case "sv" : //swedish
return {
2018-11-06 22:48:28 +01:00
context _pindm _text : "Fäst DM" ,
2019-01-24 22:27:15 +01:00
context _pinchannel _text : "Fäst till kanallista" ,
context _unpinchannel _text : "Ta bort från kanallistan" ,
2020-01-05 14:01:45 +01:00
context _addtonewcategory _text : "Lägg till i ny kategori" ,
2019-01-24 22:27:15 +01:00
context _pinguild _text : "Fäst till servernlista" ,
context _unpinguild _text : "Ta bort från servernlista" ,
2018-10-11 10:21:26 +02:00
header _pinneddms _text : "Inlagda Direktmeddelanden"
} ;
case "tr" : //turkish
return {
context _pindm _text : "DM'yi Sabitle" ,
2019-01-24 22:27:15 +01:00
context _pinchannel _text : "Kanal listesine ekle" ,
context _unpinchannel _text : "Kanal listesinden kaldı r" ,
2020-01-05 14:01:45 +01:00
context _addtonewcategory _text : "Yeni kategoriye ekle" ,
2019-01-24 22:27:15 +01:00
context _pinguild _text : "Sunucu listesine ekle" ,
context _unpinguild _text : "Sunucu listesinden kaldı r" ,
2018-10-11 10:21:26 +02:00
header _pinneddms _text : "Direkt Mesajlar Sabitleyin"
} ;
case "cs" : //czech
return {
2018-11-06 22:48:28 +01:00
context _pindm _text : "Připnout PZ" ,
2019-01-24 22:27:15 +01:00
context _pinchannel _text : "Připojení k seznamu kanálů" ,
context _unpinchannel _text : "Odstranit ze seznamu kanálů" ,
2020-01-05 14:01:45 +01:00
context _addtonewcategory _text : "Přidat do nové kategorie" ,
2019-01-24 22:27:15 +01:00
context _pinguild _text : "Připojit ke seznamu serverů" ,
context _unpinguild _text : "Odstranit ze seznamu serverů" ,
2018-11-06 22:48:28 +01:00
header _pinneddms _text : "Připojené Přímá Zpráva"
2018-10-11 10:21:26 +02:00
} ;
case "bg" : //bulgarian
return {
2018-11-06 22:48:28 +01:00
context _pindm _text : "Закачени ДС" ,
2019-01-24 22:27:15 +01:00
context _pinchannel _text : "Прикачете към списъка с канали" ,
context _unpinchannel _text : "Премахване от списъка с канали" ,
2020-01-05 14:01:45 +01:00
context _addtonewcategory _text : "Добавяне към нова категория" ,
2019-01-24 22:27:15 +01:00
context _pinguild _text : "Прикачване към списъка със сървъри" ,
context _unpinguild _text : "Премахване от списъка със сървъри" ,
2018-10-11 10:21:26 +02:00
header _pinneddms _text : "Свързани директни съобщения"
} ;
case "ru" : //russian
return {
2018-11-06 22:48:28 +01:00
context _pindm _text : "Закрепить ЛС" ,
2019-01-24 22:27:15 +01:00
context _pinchannel _text : "Прикрепить к списку каналов" ,
context _unpinchannel _text : "Удалить из списка каналов" ,
2020-01-05 14:01:45 +01:00
context _addtonewcategory _text : "Добавить в новую категорию" ,
2019-01-24 22:27:15 +01:00
context _pinguild _text : "Присоединить к списку серверов" ,
context _unpinguild _text : "Удалить из списка серверов" ,
2018-11-06 22:48:28 +01:00
header _pinneddms _text : "Прикрепленные Личные Сообщения"
2018-10-11 10:21:26 +02:00
} ;
case "uk" : //ukrainian
return {
2018-11-06 22:48:28 +01:00
context _pindm _text : "Закріпити ОП" ,
2019-01-24 22:27:15 +01:00
context _pinchannel _text : "Додайте до списку каналів" ,
context _unpinchannel _text : "Видалити зі списку каналів" ,
2020-01-05 14:01:45 +01:00
context _addtonewcategory _text : "Додати до нової категорії" ,
2019-01-24 22:27:15 +01:00
context _pinguild _text : "Додайте до списку серверів" ,
context _unpinguild _text : "Видалити зі списку серверів" ,
2018-10-11 10:21:26 +02:00
header _pinneddms _text : "Прикріплені oс о б ис ті повідомлення"
} ;
case "ja" : //japanese
return {
2018-11-06 22:48:28 +01:00
context _pindm _text : "DMピン" ,
2019-01-24 22:27:15 +01:00
context _pinchannel _text : "チャンネルリストに添付" ,
context _unpinchannel _text : "チャンネルリストから削除" ,
2020-01-05 14:01:45 +01:00
context _addtonewcategory _text : "新しいカテゴリに追加" ,
2019-01-24 22:27:15 +01:00
context _pinguild _text : "サーバーリストに添付" ,
context _unpinguild _text : "サーバーリストから削除" ,
2018-10-11 10:21:26 +02:00
header _pinneddms _text : "固定された直接メッセージ"
} ;
case "zh-TW" : //chinese (traditional)
return {
2018-11-06 22:48:28 +01:00
context _pindm _text : "引腳直接留言" ,
2019-01-24 22:27:15 +01:00
context _pinchannel _text : "附加到頻道列表" ,
context _unpinchannel _text : "從頻道列表中刪除" ,
2020-01-05 14:01:45 +01:00
context _addtonewcategory _text : "添加到新類別" ,
2019-01-24 22:27:15 +01:00
context _pinguild _text : "附加到服務器列表" ,
context _unpinguild _text : "從服務器列表中刪除" ,
2018-10-11 10:21:26 +02:00
header _pinneddms _text : "固定私人信息"
} ;
case "ko" : //korean
return {
2018-11-06 22:48:28 +01:00
context _pindm _text : "비공개 메시지 고정" ,
2019-01-24 22:27:15 +01:00
context _pinchannel _text : "채널 목록에 첨부" ,
context _unpinchannel _text : "채널 목록에서 삭제" ,
2020-01-05 14:01:45 +01:00
context _addtonewcategory _text : "새 카테고리에 추가" ,
2019-01-24 22:27:15 +01:00
context _pinguild _text : "서버 목록에 첨부" ,
context _unpinguild _text : "서버 목록에서 제거" ,
2018-10-11 10:21:26 +02:00
header _pinneddms _text : "고정 된 비공개 메시지"
} ;
default : //default: english
return {
context _pindm _text : "Pin DM" ,
2019-01-24 22:27:15 +01:00
context _pinchannel _text : "Pin to Channellist" ,
context _unpinchannel _text : "Unpin from Channellist" ,
2020-01-05 14:01:45 +01:00
context _addtonewcategory _text : "Add to new Category" ,
2019-01-24 22:27:15 +01:00
context _pinguild _text : "Pin to Serverlist" ,
context _unpinguild _text : "Unpin from Serverlist" ,
2018-10-11 10:21:26 +02:00
header _pinneddms _text : "Pinned Direct Messages"
} ;
}
}
}