Update PinDMs.plugin.js

This commit is contained in:
Mirco Wittrien 2020-01-05 14:01:45 +01:00
parent 3df173f82c
commit 0983fe1989
1 changed files with 328 additions and 111 deletions

View File

@ -3,7 +3,7 @@
class PinDMs { class PinDMs {
getName () {return "PinDMs";} getName () {return "PinDMs";}
getVersion () {return "1.5.1";} getVersion () {return "1.5.2";}
getAuthor () {return "DevilBro";} getAuthor () {return "DevilBro";}
@ -11,7 +11,7 @@ class PinDMs {
constructor () { constructor () {
this.changelog = { this.changelog = {
"improved":[["New Library Structure & React","Restructured my Library and switched to React rendering instead of DOM manipulation"]] "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"]]
}; };
this.patchedModules = { this.patchedModules = {
@ -36,6 +36,28 @@ class PinDMs {
${BDFDB.dotCN.dmchannel}:hover ${BDFDB.dotCN._pindmsunpinbutton} { ${BDFDB.dotCN.dmchannel}:hover ${BDFDB.dotCN._pindmsunpinbutton} {
display: block; display: block;
} }
${BDFDB.dotCN._pindmspinnedchannelsheadercontainer} {
display: flex;
cursor: pointer;
}
${BDFDB.dotCNS._pindmspinnedchannelsheadercontainer + BDFDB.dotCN.dmchannelheadertext} {
margin-right: 6px;
}
${BDFDB.dotCNS._pindmspinnedchannelsheadercontainer + BDFDB.dotCN._pindmspinnedchannelsheaderamount} {
position: relative;
top: -1px;
margin-right: 6px;
}
${BDFDB.dotCN._pindmspinnedchannelsheaderarrow} {
flex: 0;
width: 16px;
height: 16px;
margin-left: 0;
margin-right: 2px;
}
${BDFDB.dotCNS._pindmspinnedchannelsheadercollapsed + BDFDB.dotCN._pindmspinnedchannelsheaderarrow + BDFDB.dotCN.channelheadericonwrapper} {
transform: rotate(-90deg);
}
${BDFDB.dotCN._pindmsunpinbutton} { ${BDFDB.dotCN._pindmsunpinbutton} {
display: none; display: none;
width: 16px; width: 16px;
@ -64,7 +86,8 @@ class PinDMs {
this.defaults = { this.defaults = {
settings: { settings: {
showPinIcon: {value:true, description:"Shows a little 'Pin' icon for pinned DMs in the server list:"} showPinIcon: {value:true, description:"Shows a little 'Pin' icon for pinned DMs in the server list:"},
showCategoryAmount: {value:true, description:"Shows the amount of pinned DMs in a category in the channel list:"}
} }
}; };
} }
@ -89,7 +112,7 @@ class PinDMs {
label: "Unpin all pinned DMs", label: "Unpin all pinned DMs",
onClick: _ => { onClick: _ => {
BDFDB.ModalUtils.confirm(this, "Are you sure you want to unpin all pinned DMs?", () => { BDFDB.ModalUtils.confirm(this, "Are you sure you want to unpin all pinned DMs?", () => {
BDFDB.DataUtils.remove(this, "pinnedDMs"); BDFDB.DataUtils.remove(this, "dmCategories");
BDFDB.DataUtils.remove(this, "pinnedRecents"); BDFDB.DataUtils.remove(this, "pinnedRecents");
}); });
}, },
@ -127,6 +150,21 @@ class PinDMs {
if (global.BDFDB && typeof BDFDB === "object" && BDFDB.loaded) { if (global.BDFDB && typeof BDFDB === "object" && BDFDB.loaded) {
if (this.started) return; if (this.started) return;
BDFDB.PluginUtils.init(this); BDFDB.PluginUtils.init(this);
// 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");
}
BDFDB.ModuleUtils.forceAllUpdates(this); BDFDB.ModuleUtils.forceAllUpdates(this);
} }
@ -178,19 +216,50 @@ class PinDMs {
} }
injectItem (instance, id, children, index) { injectItem (instance, id, children, index) {
let pinnedInChannel = this.isPinned(id, "pinnedDMs");
let pinnedInGuild = this.isPinned(id, "pinnedRecents"); let pinnedInGuild = this.isPinned(id, "pinnedRecents");
let categories = this.sortAndUpdateCategories("dmCategories", true);
let category = this.getCategory(id, "dmCategories");
children.splice(index, 0, BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.ContextMenuItems.Sub, { children.splice(index, 0, BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.ContextMenuItems.Sub, {
label: this.labels.context_pindm_text, label: this.labels.context_pindm_text,
render: [ render: [
BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.ContextMenuItems.Item, { category ? BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.ContextMenuItems.Item, {
label: this.labels[pinnedInChannel ? "context_unpinchannel_text" : "context_pinchannel_text"], label: this.labels.context_unpinchannel_text,
danger: pinnedInChannel, danger: true,
action: _ => { action: _ => {
BDFDB.ContextMenuUtils.close(instance); BDFDB.ContextMenuUtils.close(instance);
if (!pinnedInChannel) this.addPin(id, "pinnedDMs"); this.removeFromCategory(id, category, "dmCategories");
else this.removePin(id, "pinnedDMs");
} }
}) : BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.ContextMenuItems.Sub, {
label: this.labels.context_pinchannel_text,
render: [
BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.ContextMenuItems.Group, {
children: BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.ContextMenuItems.Item, {
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, {
children: categories.map((category, i) => BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.ContextMenuItems.Item, {
label: category.name || this.labels.header_pinneddms_text,
action: _ => {
BDFDB.ContextMenuUtils.close(instance);
this.addToCategory(id, category, "dmCategories");
}
}))
}) : null
].filter(n => n)
}), }),
BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.ContextMenuItems.Item, { BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.ContextMenuItems.Item, {
label: this.labels[pinnedInGuild ? "context_unpinguild_text" : "context_pinguild_text"], label: this.labels[pinnedInGuild ? "context_unpinguild_text" : "context_pinguild_text"],
@ -206,48 +275,87 @@ class PinDMs {
} }
processPrivateChannelsList (e) { processPrivateChannelsList (e) {
let sortedDMs = this.sortAndUpdate("pinnedDMs"); let categories = this.sortAndUpdateCategories("dmCategories", true);
if (sortedDMs.length) { if (categories.length) {
e.instance.props.channels = Object.assign({}, e.instance.props.channels); e.instance.props.channels = Object.assign({}, e.instance.props.channels);
e.instance.props.pinnedChannels = Object.assign({}, e.instance.props.pinnedChannels); e.instance.props.pinnedChannels = Object.assign({}, e.instance.props.pinnedChannels);
for (let pos in sortedDMs) { for (let category of categories) for (let id of category.dms) if (e.instance.props.channels[id]) {
let id = sortedDMs[pos]; e.instance.props.pinnedChannels[id] = e.instance.props.channels[id];
if (e.instance.props.channels[id]) { delete e.instance.props.channels[id];
e.instance.props.pinnedChannels[id] = e.instance.props.channels[id];
BDFDB.ArrayUtils.remove(e.instance.props.privateChannelIds, id, true);
delete e.instance.props.channels[id];
}
} }
if (e.returnvalue && !BDFDB.ObjectUtils.isEmpty(e.instance.props.pinnedChannels)) { if (e.returnvalue) {
let [children, index] = BDFDB.ReactUtils.findChildren(e.returnvalue, {name: "ListSectionItem"}); let [children, index] = BDFDB.ReactUtils.findChildren(e.returnvalue, {name: "ListSectionItem"});
if (index > -1) { if (index > -1) {
if (this.draggedChannel && this.releasedChannel) { if (this.draggedChannel && this.releasedChannel) {
let ids = Object.keys(e.instance.props.pinnedChannels), pinnedChannels = {}, newData = {}; let categoryId = this.releasedChannel.split("header_")[1];
BDFDB.ArrayUtils.remove(ids, this.draggedChannel, true); let category = categories.find(n => categoryId != undefined ? n.id == categoryId : n.dms.includes(this.releasedChannel));
ids.splice(this.releasedChannel == "header" ? 0 : ids.indexOf(this.releasedChannel) + 1, 0, this.draggedChannel); if (category) {
for (let pos in ids) { BDFDB.ArrayUtils.remove(category.dms, this.draggedChannel, true);
let id = ids[pos]; category.dms.splice(categoryId != undefined ? 0 : category.dms.indexOf(this.releasedChannel) + 1, 0, this.draggedChannel);
pinnedChannels[id] = e.instance.props.pinnedChannels[id]; BDFDB.DataUtils.save(category, this, "dmCategories", category.id);
newData[id] = parseInt(pos);
} }
e.instance.props.pinnedChannels = pinnedChannels;
BDFDB.DataUtils.save(newData, this, "pinnedDMs");
delete this.draggedChannel; delete this.draggedChannel;
delete this.releasedChannel; delete this.releasedChannel;
} }
children.splice(index++, 0, BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.ListHeader, { let showCategoryAmount = BDFDB.DataUtils.get(this, "settings", "showCategoryAmount");
className: BDFDB.disCNS.dmchannelheader + BDFDB.disCN._pindmspinnedchannelsheadercontainer, for (let category of categories) {
children: this.labels.header_pinneddms_text 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),
if (this.hoveredChannel == "header") children.splice(index++, 0, BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.ListItem, { category: category,
className: BDFDB.disCNS.dmchannel + BDFDB.disCNS._pindmsdmchannelpinned + BDFDB.disCN._pindmsdmchannelplaceholder onClick: _ => {
})); if (category.dms.length || !category.collapsed) {
for (let id in e.instance.props.pinnedChannels) if (e.instance.props.pinnedChannels[id]) { category.collapsed = !category.collapsed;
if (!e.instance.props.privateChannelIds.includes(id)) e.instance.props.privateChannelIds.unshift(id); BDFDB.DataUtils.save(category, this, "dmCategories", category.id);
if (this.draggedChannel != id) { BDFDB.ReactUtils.forceUpdate(e.instance);
let channel = e.instance.props.renderChannel(e.instance.props.pinnedChannels[id], e.instance.props.selectedChannelId == id); }
channel.props.pinned = true; },
children.splice(index++, 0, channel); 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
}));
if (!category.collapsed) for (let id of category.dms) if (e.instance.props.pinnedChannels[id] && this.draggedChannel != id) {
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, { if (this.hoveredChannel == id) children.splice(index++, 0, BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.ListItem, {
className: BDFDB.disCNS.dmchannel + BDFDB.disCNS._pindmsdmchannelpinned + BDFDB.disCN._pindmsdmchannelplaceholder className: BDFDB.disCNS.dmchannel + BDFDB.disCNS._pindmsdmchannelpinned + BDFDB.disCN._pindmsdmchannelplaceholder
})); }));
@ -301,71 +409,82 @@ class PinDMs {
} }
processPrivateChannel (e) { processPrivateChannel (e) {
if (e.instance.props.channel && e.instance.props.pinned) { if (e.instance.props.channel) {
if (e.node) { let category = this.getCategory(e.instance.props.channel.id, "dmCategories");
BDFDB.DOMUtils.addClass(e.node, BDFDB.disCN._pindmsdmchannelpinned); if (category) {
e.node.setAttribute("draggable", false); if (e.node) {
e.node.removeEventListener("mousedown", e.node.PinDMsMouseDownListener); BDFDB.DOMUtils.addClass(e.node, BDFDB.disCN._pindmsdmchannelpinned);
e.node.PinDMsMouseDownListener = event => { e.node.setAttribute("draggable", false);
let mousemove = event2 => { e.node.removeEventListener("mousedown", e.node.PinDMsMouseDownListener);
if (Math.sqrt((event.pageX - event2.pageX)**2) > 20 || Math.sqrt((event.pageY - event2.pageY)**2) > 20) { e.node.PinDMsMouseDownListener = event => {
BDFDB.ListenerUtils.stopEvent(event); if (!BDFDB.BdUtils.isPluginEnabled("PinDMs")) e.node.removeEventListener("mousedown", e.node.PinDMsMouseDownListener);
this.draggedChannel = e.instance.props.channel.id; else {
BDFDB.ModuleUtils.forceAllUpdates(this, "PrivateChannelsList"); let mousemove = event2 => {
let dragpreview = this.createDragPreview(e.node, event2); if (Math.sqrt((event.pageX - event2.pageX)**2) > 20 || Math.sqrt((event.pageY - event2.pageY)**2) > 20) {
document.removeEventListener("mousemove", mousemove); BDFDB.ListenerUtils.stopEvent(event);
document.removeEventListener("mouseup", mouseup); this.draggedChannel = e.instance.props.channel.id;
let dragging = event3 => { this.updateContainer("dmCategories");
this.updateDragPreview(dragpreview, event3); let dragpreview = this.createDragPreview(e.node, event2);
let hoveredChannel = null; document.removeEventListener("mousemove", mousemove);
if (BDFDB.DOMUtils.getParent(BDFDB.dotCN._pindmspinnedchannelsheadercontainer, event3.target)) hoveredChannel = "header"; document.removeEventListener("mouseup", mouseup);
else { let dragging = event3 => {
let placeholder = BDFDB.DOMUtils.getParent(BDFDB.dotCN._pindmsdmchannelplaceholder, event3.target); this.updateDragPreview(dragpreview, event3);
hoveredChannel = (BDFDB.ReactUtils.findValue(BDFDB.DOMUtils.getParent(BDFDB.dotCN._pindmsdmchannelpinned, placeholder ? placeholder.previousSibling : event3.target), "channel", {up: true}) || {}).id; let hoveredChannel = null;
}; if (BDFDB.DOMUtils.getParent(BDFDB.dotCN._pindmspinnedchannelsheadercontainer, event3.target)) {
let update = hoveredChannel != this.hoveredChannel; let hoveredCategory = BDFDB.ReactUtils.findValue(event3.target, "category", {up: true});
if (hoveredChannel) this.hoveredChannel = hoveredChannel; if (hoveredCategory && hoveredCategory.id == category.id) hoveredChannel = "header_" + category.id;
else delete this.hoveredChannel; }
if (update) BDFDB.ModuleUtils.forceAllUpdates(this, "PrivateChannelsList"); 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 releasing = event3 => { let mouseup = _ => {
BDFDB.DOMUtils.remove(dragpreview); document.removeEventListener("mousemove", mousemove);
if (this.hoveredChannel) this.releasedChannel = this.hoveredChannel; document.removeEventListener("mouseup", mouseup);
else delete this.draggedChannel;
delete this.hoveredChannel;
BDFDB.ModuleUtils.forceAllUpdates(this, "PrivateChannelsList");
document.removeEventListener("mousemove", dragging);
document.removeEventListener("mouseup", releasing);
}; };
document.addEventListener("mousemove", dragging); document.addEventListener("mousemove", mousemove);
document.addEventListener("mouseup", releasing); document.addEventListener("mouseup", mouseup);
} }
}; };
let mouseup = _ => { e.node.addEventListener("mousedown", e.node.PinDMsMouseDownListener);
document.removeEventListener("mousemove", mousemove); }
document.removeEventListener("mouseup", mouseup); if (e.returnvalue) e.returnvalue.props.children = [
}; BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.TooltipContainer, {
document.addEventListener("mousemove", mousemove); text: BDFDB.LanguageUtils.LanguageStrings.UNPIN,
document.addEventListener("mouseup", mouseup); children: BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.Clickable, {
}; className: BDFDB.disCN._pindmsunpinbutton,
e.node.addEventListener("mousedown", e.node.PinDMsMouseDownListener); onClick: event => {
} BDFDB.ListenerUtils.stopEvent(event);
if (e.returnvalue) e.returnvalue.props.children = [ this.removeFromCategory(e.instance.props.channel.id, category, "dmCategories");
BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.TooltipContainer, { },
text: BDFDB.LanguageUtils.LanguageStrings.UNPIN, children: BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.SvgIcon, {
children: BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.Clickable, { className: BDFDB.disCN._pindmsunpinicon,
className: BDFDB.disCN._pindmsunpinbutton, name: BDFDB.LibraryComponents.SvgIcon.Names.PIN
onClick: event => { })
BDFDB.ListenerUtils.stopEvent(event);
this.removePin(e.instance.props.channel.id, "pinnedDMs");
},
children: BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.SvgIcon, {
className: BDFDB.disCN._pindmsunpinicon,
name: BDFDB.LibraryComponents.SvgIcon.Names.PIN
}) })
}) })
}) ].concat(e.returnvalue.props.children).flat(10);
].concat(e.returnvalue.props.children).flat(10); }
} }
} }
@ -432,34 +551,111 @@ class PinDMs {
} }
} }
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 = {};
let sorted = [], sort = (id, pos) => {
if (sorted[pos] === undefined) {
data[id].pos = pos;
sorted[pos] = data[id];
newData[id] = data[id];
}
else sort(id, pos + 1);
};
sorted = sorted.filter(n => n);
for (let id in data) sort(id, data[id].pos);
if (!BDFDB.equals(data, newData)) BDFDB.DataUtils.save(newData, this, type);
return reverse ? sorted.reverse() : sorted;
}
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);
}
}]
});
}
addPin (newid, type) { addPin (newid, type) {
if (!newid) return; if (!newid) return;
let container = this.getContainer(type);
if (!container) return;
let pinnedDMs = BDFDB.DataUtils.load(this, type); let pinnedDMs = BDFDB.DataUtils.load(this, type);
for (let id in pinnedDMs) pinnedDMs[id] = pinnedDMs[id] + 1; for (let id in pinnedDMs) pinnedDMs[id] = pinnedDMs[id] + 1;
pinnedDMs[newid] = 0; pinnedDMs[newid] = 0;
BDFDB.DataUtils.save(pinnedDMs, this, type); BDFDB.DataUtils.save(pinnedDMs, this, type);
BDFDB.ModuleUtils.forceAllUpdates(this, container); this.updateContainer(type);
} }
removePin (id, type) { removePin (id, type) {
if (!id) return; if (!id) return;
let container = this.getContainer(type);
if (!container) return;
BDFDB.DataUtils.remove(this, type, id); BDFDB.DataUtils.remove(this, type, id);
BDFDB.ModuleUtils.forceAllUpdates(this, container); this.updateContainer(type);
} }
isPinned (id, type) { isPinned (id, type) {
return BDFDB.DataUtils.load(this, type, id) != undefined; return BDFDB.DataUtils.load(this, type, id) != undefined;
} }
getContainer (type) { updateContainer (type) {
switch (type) { switch (type) {
case "pinnedDMs": return "PrivateChannelsList"; case "dmCategories":
case "pinnedRecents": return "UnreadDMs"; BDFDB.ModuleUtils.forceAllUpdates(this, "PrivateChannelsList");
default: return null; break;
case "pinnedRecents":
BDFDB.ModuleUtils.forceAllUpdates(this, "UnreadDMs");
break;
} }
} }
@ -515,6 +711,7 @@ class PinDMs {
context_pindm_text: "Prikljucite Izravnu Poruku", context_pindm_text: "Prikljucite Izravnu Poruku",
context_pinchannel_text: "Priložite popisu kanala", context_pinchannel_text: "Priložite popisu kanala",
context_unpinchannel_text: "Ukloni s popisa kanala", context_unpinchannel_text: "Ukloni s popisa kanala",
context_addtonewcategory_text: "Dodavanje u novu kategoriju",
context_pinguild_text: "Priložite popisu poslužitelja", context_pinguild_text: "Priložite popisu poslužitelja",
context_unpinguild_text: "Ukloni s popisa poslužitelja", context_unpinguild_text: "Ukloni s popisa poslužitelja",
header_pinneddms_text: "Prikvačene Izravne Poruke" header_pinneddms_text: "Prikvačene Izravne Poruke"
@ -524,6 +721,7 @@ class PinDMs {
context_pindm_text: "Fastgør PB", context_pindm_text: "Fastgør PB",
context_pinchannel_text: "Vedhæft til kanalliste", context_pinchannel_text: "Vedhæft til kanalliste",
context_unpinchannel_text: "Fjern fra kanalliste", context_unpinchannel_text: "Fjern fra kanalliste",
context_addtonewcategory_text: "Føj til ny kategori",
context_pinguild_text: "Vedhæft til serverliste", context_pinguild_text: "Vedhæft til serverliste",
context_unpinguild_text: "Fjern fra serverliste", context_unpinguild_text: "Fjern fra serverliste",
header_pinneddms_text: "Pinned Privat Beskeder" header_pinneddms_text: "Pinned Privat Beskeder"
@ -533,6 +731,7 @@ class PinDMs {
context_pindm_text: "Direktnachricht anheften", context_pindm_text: "Direktnachricht anheften",
context_pinchannel_text: "An Kanalliste anheften", context_pinchannel_text: "An Kanalliste anheften",
context_unpinchannel_text: "Von Kanalliste loslösen", context_unpinchannel_text: "Von Kanalliste loslösen",
context_addtonewcategory_text: "Zur neuen Kategorie hinzufügen",
context_pinguild_text: "An Serverliste anheften", context_pinguild_text: "An Serverliste anheften",
context_unpinguild_text: "Von Serverliste loslösen", context_unpinguild_text: "Von Serverliste loslösen",
header_pinneddms_text: "Gepinnte Direktnachrichten" header_pinneddms_text: "Gepinnte Direktnachrichten"
@ -542,6 +741,7 @@ class PinDMs {
context_pindm_text: "Anclar MD", context_pindm_text: "Anclar MD",
context_pinchannel_text: "Adjuntar a la lista de canales", context_pinchannel_text: "Adjuntar a la lista de canales",
context_unpinchannel_text: "Deshazte de 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_pinguild_text: "Adjuntar a la lista de servidores",
context_unpinguild_text: "Deshazte de la lista de servidores", context_unpinguild_text: "Deshazte de la lista de servidores",
header_pinneddms_text: "Mensajes Directos Fijados" header_pinneddms_text: "Mensajes Directos Fijados"
@ -551,6 +751,7 @@ class PinDMs {
context_pindm_text: "Épingler MP", context_pindm_text: "Épingler MP",
context_pinchannel_text: "Épingler à la liste des salons", context_pinchannel_text: "Épingler à la liste des salons",
context_unpinchannel_text: "Détacher de 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_pinguild_text: "Épingler à la liste de serveurs",
context_unpinguild_text: "Détacher de la liste de serveurs", context_unpinguild_text: "Détacher de la liste de serveurs",
header_pinneddms_text: "Messages Prives Épinglés" header_pinneddms_text: "Messages Prives Épinglés"
@ -560,6 +761,7 @@ class PinDMs {
context_pindm_text: "Fissa il messaggio diretto", context_pindm_text: "Fissa il messaggio diretto",
context_pinchannel_text: "Allega alla lista dei canali", context_pinchannel_text: "Allega alla lista dei canali",
context_unpinchannel_text: "Rimuovi dalla 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_pinguild_text: "Allega alla lista dei server",
context_unpinguild_text: "Rimuovi dalla lista dei server", context_unpinguild_text: "Rimuovi dalla lista dei server",
header_pinneddms_text: "Messaggi Diretti Aggiunti" header_pinneddms_text: "Messaggi Diretti Aggiunti"
@ -569,6 +771,7 @@ class PinDMs {
context_pindm_text: "PB pinnen", context_pindm_text: "PB pinnen",
context_pinchannel_text: "Pin naar de kanalenlijst", context_pinchannel_text: "Pin naar de kanalenlijst",
context_unpinchannel_text: "Losmaken van kanalenlijst", context_unpinchannel_text: "Losmaken van kanalenlijst",
context_addtonewcategory_text: "Toevoegen aan nieuwe categorie",
context_pinguild_text: "Pin naar de serverlijst", context_pinguild_text: "Pin naar de serverlijst",
context_unpinguild_text: "Losmaken van serverlijst", context_unpinguild_text: "Losmaken van serverlijst",
header_pinneddms_text: "Vastgezette Persoonluke Berichten" header_pinneddms_text: "Vastgezette Persoonluke Berichten"
@ -578,6 +781,7 @@ class PinDMs {
context_pindm_text: "Fest DM", context_pindm_text: "Fest DM",
context_pinchannel_text: "Fest på kanalliste", context_pinchannel_text: "Fest på kanalliste",
context_unpinchannel_text: "Fjern fra kanalliste", context_unpinchannel_text: "Fjern fra kanalliste",
context_addtonewcategory_text: "Legg til i ny kategori",
context_pinguild_text: "Fest på serverliste", context_pinguild_text: "Fest på serverliste",
context_unpinguild_text: "Fjern fra serverlisten", context_unpinguild_text: "Fjern fra serverlisten",
header_pinneddms_text: "Pinned Direktemeldinger" header_pinneddms_text: "Pinned Direktemeldinger"
@ -587,6 +791,7 @@ class PinDMs {
context_pindm_text: "Przypnij PW", context_pindm_text: "Przypnij PW",
context_pinchannel_text: "Dołącz do listy kanałów", context_pinchannel_text: "Dołącz do listy kanałów",
context_unpinchannel_text: "Usuń z 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_pinguild_text: "Dołącz do listy serwerów",
context_unpinguild_text: "Usuń z listy serwerów", context_unpinguild_text: "Usuń z listy serwerów",
header_pinneddms_text: "Prywatne Wiadomości Bezpośrednie" header_pinneddms_text: "Prywatne Wiadomości Bezpośrednie"
@ -596,6 +801,7 @@ class PinDMs {
context_pindm_text: "Fixar MD", context_pindm_text: "Fixar MD",
context_pinchannel_text: "Anexar à lista de canais", context_pinchannel_text: "Anexar à lista de canais",
context_unpinchannel_text: "Remover da lista de canais", context_unpinchannel_text: "Remover da lista de canais",
context_addtonewcategory_text: "Lisää uuteen luokkaan",
context_pinguild_text: "Anexar à lista de servidores", context_pinguild_text: "Anexar à lista de servidores",
context_unpinguild_text: "Remover da lista de servidores", context_unpinguild_text: "Remover da lista de servidores",
header_pinneddms_text: "Mensagens diretas fixadas" header_pinneddms_text: "Mensagens diretas fixadas"
@ -605,6 +811,7 @@ class PinDMs {
context_pindm_text: "Kiinnitä yksityisviestit", context_pindm_text: "Kiinnitä yksityisviestit",
context_pinchannel_text: "Liitä kanavaluetteloon", context_pinchannel_text: "Liitä kanavaluetteloon",
context_unpinchannel_text: "Poista kanavaluettelosta", context_unpinchannel_text: "Poista kanavaluettelosta",
context_addtonewcategory_text: "",
context_pinguild_text: "Liitä palvelinluetteloon", context_pinguild_text: "Liitä palvelinluetteloon",
context_unpinguild_text: "Poista palvelinluettelosta", context_unpinguild_text: "Poista palvelinluettelosta",
header_pinneddms_text: "Liitetyt yksityisviestit" header_pinneddms_text: "Liitetyt yksityisviestit"
@ -614,6 +821,7 @@ class PinDMs {
context_pindm_text: "Fäst DM", context_pindm_text: "Fäst DM",
context_pinchannel_text: "Fäst till kanallista", context_pinchannel_text: "Fäst till kanallista",
context_unpinchannel_text: "Ta bort från kanallistan", 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_pinguild_text: "Fäst till servernlista",
context_unpinguild_text: "Ta bort från servernlista", context_unpinguild_text: "Ta bort från servernlista",
header_pinneddms_text: "Inlagda Direktmeddelanden" header_pinneddms_text: "Inlagda Direktmeddelanden"
@ -623,6 +831,7 @@ class PinDMs {
context_pindm_text: "DM'yi Sabitle", context_pindm_text: "DM'yi Sabitle",
context_pinchannel_text: "Kanal listesine ekle", context_pinchannel_text: "Kanal listesine ekle",
context_unpinchannel_text: "Kanal listesinden kaldır", context_unpinchannel_text: "Kanal listesinden kaldır",
context_addtonewcategory_text: "Yeni kategoriye ekle",
context_pinguild_text: "Sunucu listesine ekle", context_pinguild_text: "Sunucu listesine ekle",
context_unpinguild_text: "Sunucu listesinden kaldır", context_unpinguild_text: "Sunucu listesinden kaldır",
header_pinneddms_text: "Direkt Mesajlar Sabitleyin" header_pinneddms_text: "Direkt Mesajlar Sabitleyin"
@ -632,6 +841,7 @@ class PinDMs {
context_pindm_text: "Připnout PZ", context_pindm_text: "Připnout PZ",
context_pinchannel_text: "Připojení k seznamu kanálů", context_pinchannel_text: "Připojení k seznamu kanálů",
context_unpinchannel_text: "Odstranit ze 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_pinguild_text: "Připojit ke seznamu serverů",
context_unpinguild_text: "Odstranit ze seznamu serverů", context_unpinguild_text: "Odstranit ze seznamu serverů",
header_pinneddms_text: "Připojené Přímá Zpráva" header_pinneddms_text: "Připojené Přímá Zpráva"
@ -641,6 +851,7 @@ class PinDMs {
context_pindm_text: "Закачени ДС", context_pindm_text: "Закачени ДС",
context_pinchannel_text: "Прикачете към списъка с канали", context_pinchannel_text: "Прикачете към списъка с канали",
context_unpinchannel_text: "Премахване от списъка с канали", context_unpinchannel_text: "Премахване от списъка с канали",
context_addtonewcategory_text: "Добавяне към нова категория",
context_pinguild_text: "Прикачване към списъка със сървъри", context_pinguild_text: "Прикачване към списъка със сървъри",
context_unpinguild_text: "Премахване от списъка със сървъри", context_unpinguild_text: "Премахване от списъка със сървъри",
header_pinneddms_text: "Свързани директни съобщения" header_pinneddms_text: "Свързани директни съобщения"
@ -650,6 +861,7 @@ class PinDMs {
context_pindm_text: "Закрепить ЛС", context_pindm_text: "Закрепить ЛС",
context_pinchannel_text: "Прикрепить к списку каналов", context_pinchannel_text: "Прикрепить к списку каналов",
context_unpinchannel_text: "Удалить из списка каналов", context_unpinchannel_text: "Удалить из списка каналов",
context_addtonewcategory_text: "Добавить в новую категорию",
context_pinguild_text: "Присоединить к списку серверов", context_pinguild_text: "Присоединить к списку серверов",
context_unpinguild_text: "Удалить из списка серверов", context_unpinguild_text: "Удалить из списка серверов",
header_pinneddms_text: "Прикрепленные Личные Сообщения" header_pinneddms_text: "Прикрепленные Личные Сообщения"
@ -659,6 +871,7 @@ class PinDMs {
context_pindm_text: "Закріпити ОП", context_pindm_text: "Закріпити ОП",
context_pinchannel_text: "Додайте до списку каналів", context_pinchannel_text: "Додайте до списку каналів",
context_unpinchannel_text: "Видалити зі списку каналів", context_unpinchannel_text: "Видалити зі списку каналів",
context_addtonewcategory_text: "Додати до нової категорії",
context_pinguild_text: "Додайте до списку серверів", context_pinguild_text: "Додайте до списку серверів",
context_unpinguild_text: "Видалити зі списку серверів", context_unpinguild_text: "Видалити зі списку серверів",
header_pinneddms_text: "Прикріплені oсобисті повідомлення" header_pinneddms_text: "Прикріплені oсобисті повідомлення"
@ -668,6 +881,7 @@ class PinDMs {
context_pindm_text: "DMピン", context_pindm_text: "DMピン",
context_pinchannel_text: "チャンネルリストに添付", context_pinchannel_text: "チャンネルリストに添付",
context_unpinchannel_text: "チャンネルリストから削除", context_unpinchannel_text: "チャンネルリストから削除",
context_addtonewcategory_text: "新しいカテゴリに追加",
context_pinguild_text: "サーバーリストに添付", context_pinguild_text: "サーバーリストに添付",
context_unpinguild_text: "サーバーリストから削除", context_unpinguild_text: "サーバーリストから削除",
header_pinneddms_text: "固定された直接メッセージ" header_pinneddms_text: "固定された直接メッセージ"
@ -677,6 +891,7 @@ class PinDMs {
context_pindm_text: "引腳直接留言", context_pindm_text: "引腳直接留言",
context_pinchannel_text: "附加到頻道列表", context_pinchannel_text: "附加到頻道列表",
context_unpinchannel_text: "從頻道列表中刪除", context_unpinchannel_text: "從頻道列表中刪除",
context_addtonewcategory_text: "添加到新類別",
context_pinguild_text: "附加到服務器列表", context_pinguild_text: "附加到服務器列表",
context_unpinguild_text: "從服務器列表中刪除", context_unpinguild_text: "從服務器列表中刪除",
header_pinneddms_text: "固定私人信息" header_pinneddms_text: "固定私人信息"
@ -686,6 +901,7 @@ class PinDMs {
context_pindm_text: "비공개 메시지 고정", context_pindm_text: "비공개 메시지 고정",
context_pinchannel_text: "채널 목록에 첨부", context_pinchannel_text: "채널 목록에 첨부",
context_unpinchannel_text: "채널 목록에서 삭제", context_unpinchannel_text: "채널 목록에서 삭제",
context_addtonewcategory_text: "새 카테고리에 추가",
context_pinguild_text: "서버 목록에 첨부", context_pinguild_text: "서버 목록에 첨부",
context_unpinguild_text: "서버 목록에서 제거", context_unpinguild_text: "서버 목록에서 제거",
header_pinneddms_text: "고정 된 비공개 메시지" header_pinneddms_text: "고정 된 비공개 메시지"
@ -695,6 +911,7 @@ class PinDMs {
context_pindm_text: "Pin DM", context_pindm_text: "Pin DM",
context_pinchannel_text: "Pin to Channellist", context_pinchannel_text: "Pin to Channellist",
context_unpinchannel_text: "Unpin from Channellist", context_unpinchannel_text: "Unpin from Channellist",
context_addtonewcategory_text: "Add to new Category",
context_pinguild_text: "Pin to Serverlist", context_pinguild_text: "Pin to Serverlist",
context_unpinguild_text: "Unpin from Serverlist", context_unpinguild_text: "Unpin from Serverlist",
header_pinneddms_text: "Pinned Direct Messages" header_pinneddms_text: "Pinned Direct Messages"