This commit is contained in:
poslop
2022-11-04 11:13:13 -05:00
parent 623a84748b
commit a81ed41ae7
25 changed files with 1909 additions and 2385 deletions

View File

@@ -2,7 +2,7 @@
* @name PinDMs
* @author DevilBro
* @authorId 278543574059057154
* @version 1.9.3
* @version 1.9.7
* @description Allows you to pin DMs, making them appear at the top of your DMs/ServerList
* @invite Jx3TjNS
* @donate https://www.paypal.me/MircoWittrien
@@ -13,20 +13,16 @@
*/
module.exports = (_ => {
const config = {
"info": {
"name": "PinDMs",
"author": "DevilBro",
"version": "1.9.3",
"description": "Allows you to pin DMs, making them appear at the top of your DMs/ServerList"
}
const changeLog = {
};
return !window.BDFDB_Global || (!window.BDFDB_Global.loaded && !window.BDFDB_Global.started) ? class {
getName () {return config.info.name;}
getAuthor () {return config.info.author;}
getVersion () {return config.info.version;}
getDescription () {return `The Library Plugin needed for ${config.info.name} is missing. Open the Plugin Settings to download it. \n\n${config.info.description}`;}
constructor (meta) {for (let key in meta) this[key] = meta[key];}
getName () {return this.name;}
getAuthor () {return this.author;}
getVersion () {return this.version;}
getDescription () {return `The Library Plugin needed for ${this.name} is missing. Open the Plugin Settings to download it. \n\n${this.description}`;}
downloadLibrary () {
require("request").get("https://mwittrien.github.io/BetterDiscordAddons/Library/0BDFDB.plugin.js", (e, r, b) => {
@@ -39,7 +35,7 @@ module.exports = (_ => {
if (!window.BDFDB_Global || !Array.isArray(window.BDFDB_Global.pluginQueue)) window.BDFDB_Global = Object.assign({}, window.BDFDB_Global, {pluginQueue: []});
if (!window.BDFDB_Global.downloadModal) {
window.BDFDB_Global.downloadModal = true;
BdApi.showConfirmationModal("Library Missing", `The Library Plugin needed for ${config.info.name} is missing. Please click "Download Now" to install it.`, {
BdApi.showConfirmationModal("Library Missing", `The Library Plugin needed for ${this.name} is missing. Please click "Download Now" to install it.`, {
confirmText: "Download Now",
cancelText: "Cancel",
onCancel: _ => {delete window.BDFDB_Global.downloadModal;},
@@ -49,13 +45,13 @@ module.exports = (_ => {
}
});
}
if (!window.BDFDB_Global.pluginQueue.includes(config.info.name)) window.BDFDB_Global.pluginQueue.push(config.info.name);
if (!window.BDFDB_Global.pluginQueue.includes(this.name)) window.BDFDB_Global.pluginQueue.push(this.name);
}
start () {this.load();}
stop () {}
getSettingsPanel () {
let template = document.createElement("template");
template.innerHTML = `<div style="color: var(--header-primary); font-size: 16px; font-weight: 300; white-space: pre; line-height: 22px;">The Library Plugin needed for ${config.info.name} is missing.\nPlease click <a style="font-weight: 500;">Download Now</a> to install it.</div>`;
template.innerHTML = `<div style="color: var(--header-primary); font-size: 16px; font-weight: 300; white-space: pre; line-height: 22px;">The Library Plugin needed for ${this.name} is missing.\nPlease click <a style="font-weight: 500;">Download Now</a> to install it.</div>`;
template.content.firstElementChild.querySelector("a").addEventListener("click", this.downloadLibrary);
return template.content.firstElementChild;
}
@@ -83,15 +79,22 @@ module.exports = (_ => {
}
};
this.patchedModules = {
before: {
PrivateChannelsList: "render"
},
after: {
PrivateChannelsList: "render",
PrivateChannel: ["render", "componentDidMount"],
DirectMessage: ["render", "componentDidMount", "componentWillUnmount"]
}
this.modulePatches = {
before: [
"PrivateChannelsList"
],
after: [
"DirectMessage",
"PrivateChannel",
"PrivateChannelsList"
],
componentDidMount: [
"DirectMessage",
"PrivateChannel"
],
componentWillUnmount: [
"DirectMessage"
]
};
this.css = `
@@ -159,7 +162,7 @@ module.exports = (_ => {
}
onStart () {
BDFDB.PatchUtils.patch(this, BDFDB.LibraryModules.DirectMessageUnreadStore, "getUnreadPrivateChannelIds", {after: e => {
BDFDB.PatchUtils.patch(this, BDFDB.LibraryStores.PrivateChannelReadStateStore, "getUnreadPrivateChannelIds", {after: e => {
let sortedRecents = this.sortAndUpdate("guildList");
if (sortedRecents.length) {
const dms = [];
@@ -254,13 +257,18 @@ module.exports = (_ => {
}
onUserContextMenu (e) {
if (e.instance.props.channel && !e.instance.props.channel.guild_id && e.subType == "useCloseDMItem") e.returnvalue.unshift(this.createItem(e.instance.props.channel.id));
if (e.instance.props.channel && !e.instance.props.channel.guild_id) {
let [children, index] = BDFDB.ContextMenuUtils.findItem(e.returnvalue, {id: "close-dm"});
children.splice(index > -1 ? index : children.length, 0, this.createItem(e.instance.props.channel.id));
}
}
onChannelContextMenu (e) {
if (e.instance.props.channel && !e.instance.props.channel.guild_id && e.instance.props.channel.isGroupDM() && e.subType == "useChannelMarkAsReadItem") {
if (e.returnvalue.length > 0) e.returnvalue.push(BDFDB.ContextMenuUtils.createItem(BDFDB.LibraryComponents.MenuItems.MenuSeparator, {}));
e.returnvalue.push(this.createItem(e.instance.props.channel.id));
onGroupDMContextMenu (e) {
if (e.instance.props.channel) {
let [children, index] = BDFDB.ContextMenuUtils.findItem(e.returnvalue, {id: "change-icon", group: true});
children.splice(index > -1 ? index + 1 : children.length, 0, BDFDB.ContextMenuUtils.createItem(BDFDB.LibraryComponents.MenuItems.MenuGroup, {
children: this.createItem(e.instance.props.channel.id)
}));
}
}
@@ -278,33 +286,25 @@ module.exports = (_ => {
BDFDB.ContextMenuUtils.createItem(BDFDB.LibraryComponents.MenuItems.MenuItem, {
label: this.labels.context_pinchannel,
id: BDFDB.ContextMenuUtils.createItemId(this.name, "submenu-channelist"),
children: this.getPredefinedCategory(id) ? BDFDB.ContextMenuUtils.createItem(BDFDB.LibraryComponents.MenuItems.MenuItem, {
label: this.labels.context_inpredefined,
id: BDFDB.ContextMenuUtils.createItemId(this.name, "in-predefined"),
disabled: true
}) : [
children: [
BDFDB.ContextMenuUtils.createItem(BDFDB.LibraryComponents.MenuItems.MenuGroup, {
children: currentCategory ? BDFDB.ContextMenuUtils.createItem(BDFDB.LibraryComponents.MenuItems.MenuItem, {
label: this.labels.context_unpinchannel,
id: BDFDB.ContextMenuUtils.createItemId(this.name, "unpin-channellist"),
color: BDFDB.LibraryComponents.MenuItems.Colors.DANGER,
action: _ => {
this.removeFromCategory(id, currentCategory, "channelList");
}
color: BDFDB.DiscordConstants.MenuItemColors.DANGER,
action: _ => this.removeFromCategory(id, currentCategory, "channelList")
}) : BDFDB.ContextMenuUtils.createItem(BDFDB.LibraryComponents.MenuItems.MenuItem, {
label: this.labels.context_addtonewcategory,
id: BDFDB.ContextMenuUtils.createItemId(this.name, "new-channellist"),
color: BDFDB.LibraryComponents.MenuItems.Colors.BRAND,
action: _ => {
this.openCategorySettingsModal({
id: this.generateID("channelList").toString(),
name: `${this.labels.header_pinneddms} #${categories.length + 1}`,
dms: [id],
pos: categories.length,
collapsed: false,
color: null
}, "channelList", true);
}
color: BDFDB.DiscordConstants.MenuItemColors.BRAND,
action: _ => this.openCategorySettingsModal({
id: this.generateId("channelList"),
name: `${this.labels.header_pinneddms} #${categories.length + 1}`,
dms: [id],
pos: categories.length,
collapsed: false,
color: null
}, "channelList", true)
})
}),
categories.length ? BDFDB.ContextMenuUtils.createItem(BDFDB.LibraryComponents.MenuItems.MenuGroup, {
@@ -322,7 +322,7 @@ module.exports = (_ => {
BDFDB.ContextMenuUtils.createItem(BDFDB.LibraryComponents.MenuItems.MenuItem, {
label: this.labels[pinnedInGuild ? "context_unpinguild" : "context_pinguild"],
id: BDFDB.ContextMenuUtils.createItemId(this.name, pinnedInGuild ? "unpin-serverlist" : "pin-serverlist"),
color: pinnedInGuild ? BDFDB.LibraryComponents.MenuItems.Colors.DANGER : BDFDB.LibraryComponents.MenuItems.Colors.DEFAULT,
color: pinnedInGuild ? BDFDB.DiscordConstants.MenuItemColors.DANGER : BDFDB.DiscordConstants.MenuItemColors.DEFAULT,
action: _ => {
if (!pinnedInGuild) this.addPin(id, "guildList");
else this.removePin(id, "guildList");
@@ -334,49 +334,46 @@ module.exports = (_ => {
processPrivateChannelsList (e) {
let categories = this.sortAndUpdateCategories("channelList", true);
if (categories.length) {
e.instance.props.channels = Object.assign({}, e.instance.props.channels);
e.instance.props.privateChannelIds = [].concat(e.instance.props.privateChannelIds || []);
e.instance.props.pinnedChannelIds = Object.assign({}, e.instance.props.pinnedChannelIds);
if (!e.returnvalue) {
if (draggedChannel && releasedChannel) {
let categoryId = releasedChannel.split("header_")[1];
let category = categories.find(n => categoryId != undefined ? n.id == categoryId : n.dms.includes(releasedChannel));
if (category) {
BDFDB.ArrayUtils.remove(category.dms, draggedChannel, true);
category.dms.splice(categoryId != undefined ? 0 : category.dms.indexOf(releasedChannel) + 1, 0, draggedChannel);
this.savePinnedChannels(Object.assign({}, this.getPinnedChannels("channelList"), {[category.id]: category}), "channelList");
}
draggedChannel = null;
releasedChannel = null;
if (!categories.length) return;
e.instance.props.channels = Object.assign({}, e.instance.props.channels);
e.instance.props.privateChannelIds = [].concat(e.instance.props.privateChannelIds || []);
e.instance.props.pinnedChannelIds = Object.assign({}, e.instance.props.pinnedChannelIds);
if (!e.returnvalue) {
if (draggedChannel && releasedChannel) {
let categoryId = releasedChannel.split("header_")[1];
let category = categories.find(n => categoryId != undefined ? n.id == categoryId : n.dms.includes(releasedChannel));
if (category) {
BDFDB.ArrayUtils.remove(category.dms, draggedChannel, true);
category.dms.splice(categoryId != undefined ? 0 : category.dms.indexOf(releasedChannel) + 1, 0, draggedChannel);
this.savePinnedChannels(Object.assign({}, this.getPinnedChannels("channelList"), {[category.id]: category}), "channelList");
}
if (draggedCategory && releasedCategory) {
let maybedDraggedCategory = categories.find(n => n.id == draggedCategory);
let maybedReleasedCategory = categories.find(n => n.id == releasedCategory);
if (maybedDraggedCategory && maybedReleasedCategory) {
BDFDB.ArrayUtils.remove(categories, maybedDraggedCategory, true);
categories.splice(categories.indexOf(maybedReleasedCategory) + 1, 0, maybedDraggedCategory);
let newCategories = {}, newPos = 0;
for (let category of [].concat(categories).reverse()) if (!category.predefined) newCategories[category.id] = Object.assign(category, {pos: newPos++});
this.savePinnedChannels(newCategories, "channelList");
}
draggedCategory = null;
releasedCategory = null;
draggedChannel = null;
releasedChannel = null;
}
if (draggedCategory && releasedCategory) {
let maybedDraggedCategory = categories.find(n => n.id == draggedCategory);
let maybedReleasedCategory = categories.find(n => n.id == releasedCategory);
if (maybedDraggedCategory && maybedReleasedCategory) {
BDFDB.ArrayUtils.remove(categories, maybedDraggedCategory, true);
categories.splice(categories.indexOf(maybedReleasedCategory) + 1, 0, maybedDraggedCategory);
let newCategories = {}, newPos = 0;
for (let category of [].concat(categories).reverse()) if (!category.predefined) newCategories[category.id] = Object.assign(category, {pos: newPos++});
this.savePinnedChannels(newCategories, "channelList");
}
e.instance.props.pinnedChannelIds = {};
for (let category of [].concat(categories).reverse()) {
e.instance.props.pinnedChannelIds[category.id] = [];
for (let id of this.sortDMsByTime(this.filterDMs(category.dms, !category.predefined), "channelList").reverse()) {
BDFDB.ArrayUtils.remove(e.instance.props.privateChannelIds, id, true);
if (!category.collapsed || e.instance.props.selectedChannelId == id) {
e.instance.props.privateChannelIds.unshift(id);
e.instance.props.pinnedChannelIds[category.id].push(id);
}
}
draggedCategory = null;
releasedCategory = null;
}
e.instance.props.pinnedChannelIds = {};
for (let category of [].concat(categories).reverse()) {
e.instance.props.pinnedChannelIds[category.id] = [];
for (let id of this.sortDMsByTime(this.filterDMs(category.dms, !category.predefined), "channelList").reverse()) {
BDFDB.ArrayUtils.remove(e.instance.props.privateChannelIds, id, true);
e.instance.props.privateChannelIds.unshift(id);
e.instance.props.pinnedChannelIds[category.id].push(id);
}
}
else this.injectCategories(e.instance, e.returnvalue, categories);
}
else {
let pinnedIds = BDFDB.ObjectUtils.toArray(e.instance.props.pinnedChannelIds).reverse();
BDFDB.PatchUtils.unpatch(this, e.instance, "renderDM");
BDFDB.PatchUtils.patch(this, e.instance, "renderDM", {before: e2 => {
@@ -392,9 +389,9 @@ module.exports = (_ => {
index: e2.methodArguments[2]
}))) : null;
let category = categories[e2.methodArguments[0] - 1]; // WRONG
let category = categories[e2.methodArguments[0] - 1];
if (category) {
if (!id || (category.collapsed && e.instance.props.selectedChannelId != id) || !this.filterDMs(category.dms, !category.predefined).includes(id) || draggedCategory == category.id || draggedChannel == id) e2.returnValue = null;
if (!id || (category.collapsed && e.instance.props.selectedChannelId != id) || !this.filterDMs(category.dms, !category.predefined).includes(id) || draggedCategory == category.id || draggedChannel == id) e2.returnValue = null;
else if (hoveredCategory == category.id && [].concat(category.dms).reverse()[0] == id) e2.returnValue = [
e2.returnValue,
BDFDB.ReactUtils.createElement("h2", {
@@ -412,7 +409,8 @@ module.exports = (_ => {
].filter(n => n);
}
}
}}, {force: true, noCache: true});
}}, {noCache: true});
this.injectCategories(e.instance, e.returnvalue, categories);
}
}
@@ -427,38 +425,38 @@ module.exports = (_ => {
let sectionHeight = returnvalue.props.sectionHeight;
let sectionHeightFunc = typeof sectionHeight != "function" ? _ => sectionHeight : sectionHeight;
returnvalue.props.sectionHeight = (...args) => {
returnvalue.props.sectionHeight = BDFDB.TimeUtils.suppress((...args) => {
if (args[0] != 0 && args[0] != returnvalue.props.sections.length - 1) {
let category = categories[args[0] - 1];
if (category) return 40;
}
return sectionHeightFunc(...args);
};
}, "Error in sectionHeight of PrivateChannelsList!", this);
let rowHeight = returnvalue.props.rowHeight;
let rowHeightFunc = typeof rowHeight != "function" ? _ => rowHeight : rowHeight;
returnvalue.props.rowHeight = (...args) => {
returnvalue.props.rowHeight = BDFDB.TimeUtils.suppress((...args) => {
if (args[0] != 0 && args[0] != returnvalue.props.sections.length - 1) {
let category = categories[args[0] - 1];
if (category && (category.collapsed || category.id == draggedCategory)) return 0;
}
return rowHeightFunc(...args);
};
}, "Error in rowHeight of PrivateChannelsList!", this);
let renderRow = returnvalue.props.renderRow;
returnvalue.props.renderRow = (...args) => {
returnvalue.props.renderRow = BDFDB.TimeUtils.suppress((...args) => {
let row = renderRow(...args);
return row && row.key == "no-private-channels" ? null : row;
};
}, "Error in renderRow of PrivateChannelsList!", this);
let renderSection = returnvalue.props.renderSection;
returnvalue.props.renderSection = (...args) => {
returnvalue.props.renderSection = BDFDB.TimeUtils.suppress((...args) => {
if (args[0].section != 0 && args[0].section != returnvalue.props.sections.length - 1) {
let category = categories[args[0].section - 1];
if (category && draggedCategory != category.id) {
let color = BDFDB.ColorUtils.convert(category.color, "RGBA");
let foundDMs = this.filterDMs(category.dms, !category.predefined);
let unreadAmount = this.settings.general.unreadAmount && BDFDB.ArrayUtils.sum(foundDMs.map(id => BDFDB.LibraryModules.UnreadChannelUtils.getMentionCount(id)));
let unreadAmount = this.settings.general.unreadAmount && BDFDB.ArrayUtils.sum(foundDMs.map(id => BDFDB.LibraryStores.ReadStateStore.getMentionCount(id)));
return category.predefined && foundDMs.length < 1 ? null : [
BDFDB.ReactUtils.createElement("h2", {
className: BDFDB.DOMUtils.formatClassName(BDFDB.disCN.dmchannelheadercontainer, BDFDB.disCN._pindmspinnedchannelsheadercontainer, category.collapsed && BDFDB.disCN._pindmspinnedchannelsheadercollapsed, color && BDFDB.disCN._pindmspinnedchannelsheadercolored, BDFDB.disCN.namecontainernamecontainer),
@@ -530,14 +528,12 @@ module.exports = (_ => {
BDFDB.ContextMenuUtils.createItem(BDFDB.LibraryComponents.MenuItems.MenuItem, {
label: BDFDB.LanguageUtils.LanguageStrings.CATEGORY_SETTINGS,
id: BDFDB.ContextMenuUtils.createItemId(this.name, "category-settings"),
action: _ => {
this.openCategorySettingsModal(category, "channelList");
}
action: _ => this.openCategorySettingsModal(category, "channelList")
}),
BDFDB.ContextMenuUtils.createItem(BDFDB.LibraryComponents.MenuItems.MenuItem, {
label: BDFDB.LanguageUtils.LanguageStrings.DELETE_CATEGORY,
id: BDFDB.ContextMenuUtils.createItemId(this.name, "remove-category"),
color: BDFDB.LibraryComponents.MenuItems.Colors.DANGER,
color: BDFDB.DiscordConstants.MenuItemColors.DANGER,
action: _ => {
let newData = this.getPinnedChannels("channelList");
delete newData[category.id];
@@ -590,7 +586,7 @@ module.exports = (_ => {
else return null;
}
else return renderSection(...args);
};
}, "Error in renderSection of PrivateChannelsList!", this);
}
else if (typeof returnvalue.props.children == "function") {
let childrenRender = returnvalue.props.children;
@@ -598,7 +594,7 @@ module.exports = (_ => {
let children = childrenRender(...args);
this.injectCategories(instance, children, categories);
return children;
}, "Error in Children Render of PrivateChannelList!", this);
}, "Error in Children Render of PrivateChannelsList!", this);
}
else if (BDFDB.ArrayUtils.is(returnvalue)) {
for (let child of returnvalue) this.injectCategories(instance, child, categories);
@@ -607,101 +603,97 @@ module.exports = (_ => {
}
processPrivateChannel (e) {
if (e.instance.props.channel && !this.getPredefinedCategory(e.instance.props.channel.id)) {
let category = this.getChannelListCategory(e.instance.props.channel.id);
if (category) {
if (e.node) {
BDFDB.DOMUtils.addClass(e.node, BDFDB.disCN._pindmsdmchannelpinned);
e.node.removeEventListener("mousedown", e.node.PinDMsMouseDownListener);
if (!this.settings.recentOrder.channelList) {
e.node.setAttribute("draggable", false);
e.node.PinDMsMouseDownListener = event => {
if (!this.started) e.node.removeEventListener("mousedown", e.node.PinDMsMouseDownListener);
else {
event = event.nativeEvent || event;
let mouseMove = event2 => {
if (Math.sqrt((event.pageX - event2.pageX)**2) > 20 || Math.sqrt((event.pageY - event2.pageY)**2) > 20) {
BDFDB.ListenerUtils.stopEvent(event);
draggedChannel = e.instance.props.channel.id;
this.updateContainer("channelList");
let dragPreview = this.createDragPreview(e.node, event2);
document.removeEventListener("mousemove", mouseMove);
document.removeEventListener("mouseup", mouseUp);
let dragging = event3 => {
this.updateDragPreview(dragPreview, event3);
let maybeHoveredChannel = null;
let categoryNode = BDFDB.DOMUtils.getParent(BDFDB.dotCN._pindmspinnedchannelsheadercontainer, event3.target);
if (categoryNode) {
let hoveredCategoryId = categoryNode.getAttribute("categoryid");
if (hoveredCategoryId && hoveredCategoryId == category.id) maybeHoveredChannel = "header_" + category.id;
}
else {
let placeholder = BDFDB.DOMUtils.getParent(BDFDB.dotCN._pindmsdmchannelplaceholder, event3.target);
maybeHoveredChannel = (BDFDB.ReactUtils.findValue(BDFDB.DOMUtils.getParent(BDFDB.dotCN._pindmsdmchannelpinned, placeholder ? placeholder.previousSibling : event3.target), "channel", {up: true}) || {}).id;
let maybeHoveredCategory = maybeHoveredChannel && this.getChannelListCategory(maybeHoveredChannel);
if (!maybeHoveredCategory || maybeHoveredCategory.id != category.id) maybeHoveredChannel = null;
};
let update = maybeHoveredChannel != hoveredChannel;
if (maybeHoveredChannel) hoveredChannel = maybeHoveredChannel;
else hoveredChannel = null;
if (update) this.updateContainer("channelList");
};
let releasing = event3 => {
BDFDB.DOMUtils.remove(dragPreview);
if (hoveredChannel) releasedChannel = hoveredChannel;
else draggedChannel = null;
hoveredChannel = null;
this.updateContainer("channelList");
document.removeEventListener("mousemove", dragging);
document.removeEventListener("mouseup", releasing);
};
document.addEventListener("mousemove", dragging);
document.addEventListener("mouseup", releasing);
}
if (!e.instance.props.channel || this.getPredefinedCategory(e.instance.props.channel.id)) return;
let category = this.getChannelListCategory(e.instance.props.channel.id);
if (!category) return;
if (e.node) {
BDFDB.DOMUtils.addClass(e.node, BDFDB.disCN._pindmsdmchannelpinned);
e.node.removeEventListener("mousedown", e.node.PinDMsMouseDownListener);
if (this.settings.recentOrder.channelList) return;
e.node.setAttribute("draggable", false);
e.node.PinDMsMouseDownListener = event => {
if (!this.started) e.node.removeEventListener("mousedown", e.node.PinDMsMouseDownListener);
else {
event = event.nativeEvent || event;
let mouseMove = event2 => {
if (Math.sqrt((event.pageX - event2.pageX)**2) > 20 || Math.sqrt((event.pageY - event2.pageY)**2) > 20) {
BDFDB.ListenerUtils.stopEvent(event);
draggedChannel = e.instance.props.channel.id;
this.updateContainer("channelList");
let dragPreview = this.createDragPreview(e.node, event2);
document.removeEventListener("mousemove", mouseMove);
document.removeEventListener("mouseup", mouseUp);
let dragging = event3 => {
this.updateDragPreview(dragPreview, event3);
let maybeHoveredChannel = null;
let categoryNode = BDFDB.DOMUtils.getParent(BDFDB.dotCN._pindmspinnedchannelsheadercontainer, event3.target);
if (categoryNode) {
let hoveredCategoryId = categoryNode.getAttribute("categoryid");
if (hoveredCategoryId && hoveredCategoryId == category.id) maybeHoveredChannel = "header_" + category.id;
}
else {
let placeholder = BDFDB.DOMUtils.getParent(BDFDB.dotCN._pindmsdmchannelplaceholder, event3.target);
maybeHoveredChannel = (BDFDB.ReactUtils.findValue(BDFDB.DOMUtils.getParent(BDFDB.dotCN._pindmsdmchannelpinned, placeholder ? placeholder.previousSibling : event3.target), "channel", {up: true}) || {}).id;
let maybeHoveredCategory = maybeHoveredChannel && this.getChannelListCategory(maybeHoveredChannel);
if (!maybeHoveredCategory || maybeHoveredCategory.id != category.id) maybeHoveredChannel = null;
};
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);
}
let update = maybeHoveredChannel != hoveredChannel;
if (maybeHoveredChannel) hoveredChannel = maybeHoveredChannel;
else hoveredChannel = null;
if (update) this.updateContainer("channelList");
};
let releasing = event3 => {
BDFDB.DOMUtils.remove(dragPreview);
if (hoveredChannel) releasedChannel = hoveredChannel;
else draggedChannel = null;
hoveredChannel = null;
this.updateContainer("channelList");
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);
}
if (e.returnvalue) {
let wrapper = e.returnvalue && e.returnvalue.props.children && e.returnvalue.props.children.props && typeof e.returnvalue.props.children.props.children == "function" ? e.returnvalue.props.children : e.returnvalue;
if (typeof wrapper.props.children == "function") {
let childrenRender = wrapper.props.children;
wrapper.props.children = BDFDB.TimeUtils.suppress((...args) => {
let children = childrenRender(...args);
this._processPrivateChannel(e.instance, children, category);
return children;
}, "Error in Children Render of PrivateChannel!", this);
}
else this._processPrivateChannel(e.instance, wrapper, category);
}
}
};
e.node.addEventListener("mousedown", e.node.PinDMsMouseDownListener);
}
if (e.returnvalue) {
let process = returnvalue => {
let [children, index] = BDFDB.ReactUtils.findParent(returnvalue, {name: "CloseButton"});
if (index > -1) children.splice(index, 0, 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, "channelList");
},
children: BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.SvgIcon, {
className: BDFDB.disCN._pindmsunpinicon,
name: BDFDB.LibraryComponents.SvgIcon.Names.PIN
})
})
}));
};
let wrapper = e.returnvalue && e.returnvalue.props.children && e.returnvalue.props.children.props && typeof e.returnvalue.props.children.props.children == "function" ? e.returnvalue.props.children : e.returnvalue;
if (typeof wrapper.props.children == "function") {
let childrenRender = wrapper.props.children;
wrapper.props.children = BDFDB.TimeUtils.suppress((...args) => {
let children = childrenRender(...args);
process(children);
return children;
}, "Error in Children Render of PrivateChannel!", this);
}
else process(wrapper);
}
}
_processPrivateChannel (instance, returnvalue, category) {
let [children, index] = BDFDB.ReactUtils.findParent(returnvalue, {name: "CloseButton"});
if (index > -1) children.splice(index, 0, 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(instance.props.channel.id, category, "channelList");
},
children: BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.SvgIcon, {
className: BDFDB.disCN._pindmsunpinicon,
name: BDFDB.LibraryComponents.SvgIcon.Names.PIN
})
})
}));
}
processDirectMessage (e) {
@@ -742,15 +734,15 @@ module.exports = (_ => {
else BDFDB.DataUtils.remove(this, "pinned", BDFDB.UserUtils.me.id);
}
generateID (type) {
generateId (type) {
if (!type) return null;
let categories = this.getPinnedChannels(type);
let id = Math.round(Math.random() * 10000000000000000);
return categories[id] ? this.generateID() : id;
return categories[id] ? this.generateId() : id.toString();
}
filterDMs (dms, removePredefined) {
return dms.filter(id => BDFDB.LibraryModules.ChannelStore.getChannel(id) && !(removePredefined && this.getPredefinedCategory(id)));
return dms.filter(id => BDFDB.LibraryStores.ChannelStore.getChannel(id) && !(removePredefined && this.getPredefinedCategory(id)));
}
addToCategory (id, category, type) {
@@ -778,12 +770,12 @@ module.exports = (_ => {
}
getPredefinedCategory (id) {
if (!id) return "";
let channel = BDFDB.LibraryModules.ChannelStore.getChannel(id);
if (!id || this.getChannelListCategory(id)) return "";
let channel = BDFDB.LibraryStores.ChannelStore.getChannel(id);
if (!channel) return "";
else if (this.settings.preCategories.friends.enabled && channel.isDM() && BDFDB.LibraryModules.RelationshipStore.isFriend(channel.recipients[0])) return "friends";
else if (this.settings.preCategories.blocked.enabled && channel.isDM() && BDFDB.LibraryModules.RelationshipStore.isBlocked(channel.recipients[0])) return "blocked";
else if (this.settings.preCategories.bots.enabled && channel.isDM() && (BDFDB.LibraryModules.UserStore.getUser(channel.recipients[0]) || {}).bot) return "bots";
else if (this.settings.preCategories.friends.enabled && channel.isDM() && BDFDB.LibraryStores.RelationshipStore.isFriend(channel.recipients[0])) return "friends";
else if (this.settings.preCategories.blocked.enabled && channel.isDM() && BDFDB.LibraryStores.RelationshipStore.isBlocked(channel.recipients[0])) return "blocked";
else if (this.settings.preCategories.bots.enabled && channel.isDM() && (BDFDB.LibraryStores.UserStore.getUser(channel.recipients[0]) || {}).bot) return "bots";
else if (this.settings.preCategories.groups.enabled && channel.isGroupDM()) return "groups";
return "";
}
@@ -804,7 +796,7 @@ module.exports = (_ => {
if (!BDFDB.equals(data, newData)) this.savePinnedChannels(newData, type);
if (type == "channelList" && Object.keys(this.settings.preCategories).some(type => this.settings.preCategories[type].enabled)) {
let predefinedDMs = {};
for (let channelId of BDFDB.LibraryModules.DirectMessageStore.getPrivateChannelIds()) {
for (let channelId of BDFDB.LibraryStores.PrivateChannelSortStore.getPrivateChannelIds()) {
let category = this.getPredefinedCategory(channelId);
if (category) {
if (!predefinedDMs[category]) predefinedDMs[category] = [];
@@ -825,7 +817,7 @@ module.exports = (_ => {
sortDMsByTime (dms, type) {
if (dms.length > 1 && this.settings.recentOrder[type]) {
let timestamps = BDFDB.LibraryModules.DirectMessageStore.getPrivateChannelIds().reduce((newObj, channelId) => (newObj[channelId] = BDFDB.LibraryModules.UnreadChannelUtils.lastMessageId(channelId), newObj), {});
let timestamps = BDFDB.LibraryStores.PrivateChannelSortStore.getPrivateChannelIds().reduce((newObj, channelId) => (newObj[channelId] = BDFDB.LibraryStores.ReadStateStore.lastMessageId(channelId), newObj), {});
return [].concat(dms).sort(function (x, y) {
const xT = parseFloat(timestamps[x]), yT = parseFloat(timestamps[y]);
return xT > yT ? -1 : xT < yT ? 1 : 0;
@@ -910,12 +902,12 @@ module.exports = (_ => {
updateContainer (type) {
switch (type) {
case "channelList":
BDFDB.PatchUtils.forceAllUpdates(this, "PrivateChannelsList");
case "channelList":
BDFDB.PatchUtils.forceAllUpdates(this, "PrivateChannelsList"); /* DOES NOT WORK */
if (!Object.keys(this.settings.preCategories).every(type => this.settings.preCategories[type].enabled) && BDFDB.ObjectUtils.isEmpty(this.getPinnedChannels(type))) this.forceUpdateAll();
break;
case "guildList":
BDFDB.GuildUtils.rerenderAll(true);
case "guildList":
BDFDB.DiscordUtils.rerenderAll(true);
break;
}
}
@@ -932,7 +924,7 @@ module.exports = (_ => {
sortedDMs = sortedDMs.filter(n => n);
for (let pos in sortedDMs) {
newData[sortedDMs[pos]] = parseInt(pos);
if (BDFDB.LibraryModules.ChannelStore.getChannel(sortedDMs[pos])) existingDMs.push(sortedDMs[pos]);
if (BDFDB.LibraryStores.ChannelStore.getChannel(sortedDMs[pos])) existingDMs.push(sortedDMs[pos]);
}
if (!BDFDB.equals(data, newData)) this.savePinnedChannels(newData, this);
return this.sortDMsByTime(existingDMs, type);
@@ -966,7 +958,6 @@ module.exports = (_ => {
return {
context_addtonewcategory: "Добавяне към нова категория",
context_disablepredefined: "Деактивирайте предварително определена категория",
context_inpredefined: "Фиксирано в предварително дефинирана категория",
context_pinchannel: "Фиксиране към списъка с канали",
context_pindm: "Закачете директно съобщение",
context_pinguild: "Фиксиране към списъка със сървъри",
@@ -979,7 +970,6 @@ module.exports = (_ => {
return {
context_addtonewcategory: "Přidat do nové kategorie",
context_disablepredefined: "Deaktivovat předdefinovanou kategorii",
context_inpredefined: "Připnuté v předdefinované katrgorii",
context_pinchannel: "Připnout do seznamu kanálů",
context_pindm: "Připnout do PZ",
context_pinguild: "Připnout do seznamu serverů",
@@ -992,7 +982,6 @@ module.exports = (_ => {
return {
context_addtonewcategory: "Føj til ny kategori",
context_disablepredefined: "Deaktiver foruddefineret kategori",
context_inpredefined: "Fastgjort i en foruddefineret kategori",
context_pinchannel: "Fastgør til kanallisten",
context_pindm: "Pin direkte besked",
context_pinguild: "Fastgør til serverlisten",
@@ -1005,7 +994,6 @@ module.exports = (_ => {
return {
context_addtonewcategory: "Zur neuen Kategorie hinzufügen",
context_disablepredefined: "Vordefinierte Kategorie deaktivieren",
context_inpredefined: "In vordefinierter Kategorie angeheftet",
context_pinchannel: "An Kanalliste anheften",
context_pindm: "Direktnachricht anheften",
context_pinguild: "An Serverliste anheften",
@@ -1018,7 +1006,6 @@ module.exports = (_ => {
return {
context_addtonewcategory: "Προσθήκη σε νέα κατηγορία",
context_disablepredefined: "Απενεργοποίηση προκαθορισμένης κατηγορίας",
context_inpredefined: "Καρφιτσώθηκε σε μια προκαθορισμένη κατηγορία",
context_pinchannel: "Καρφίτσωμα στη λίστα καναλιών",
context_pindm: "Καρφιτσώστε το άμεσο μήνυμα",
context_pinguild: "Καρφίτσωμα στη λίστα διακομιστών",
@@ -1031,7 +1018,6 @@ module.exports = (_ => {
return {
context_addtonewcategory: "Agregar a una nueva categoría",
context_disablepredefined: "Desactivar categoría predefinida",
context_inpredefined: "Anclado en una categoría predefinida",
context_pinchannel: "Anclar a la lista de canales",
context_pindm: "Pin de mensaje directo",
context_pinguild: "Anclar a la lista de servidores",
@@ -1044,7 +1030,6 @@ module.exports = (_ => {
return {
context_addtonewcategory: "Lisää uuteen luokkaan",
context_disablepredefined: "Poista ennalta määritetty luokka käytöstä",
context_inpredefined: "Kiinnitetty ennalta määritettyyn luokkaan",
context_pinchannel: "Kiinnitä kanavaluetteloon",
context_pindm: "Kiinnitä suora viesti",
context_pinguild: "Kiinnitä palvelinluetteloon",
@@ -1057,7 +1042,6 @@ module.exports = (_ => {
return {
context_addtonewcategory: "Ajouter à une nouvelle catégorie",
context_disablepredefined: "Désactiver la catégorie prédéfinie",
context_inpredefined: "Épinglé dans une catégorie prédéfinie",
context_pinchannel: "Épingler à la liste des salons",
context_pindm: "Épingler le message privé",
context_pinguild: "Épingler à la liste des serveurs",
@@ -1070,7 +1054,6 @@ module.exports = (_ => {
return {
context_addtonewcategory: "नई श्रेणी में जोड़ें",
context_disablepredefined: "पूर्वनिर्धारित श्रेणी को निष्क्रिय करें",
context_inpredefined: "एक पूर्वनिर्धारित श्रेणी में पिन किया गया",
context_pinchannel: "चैनल सूची में पिन करें",
context_pindm: "पिन डीएम",
context_pinguild: "सर्वर सूची में पिन करें",
@@ -1083,7 +1066,6 @@ module.exports = (_ => {
return {
context_addtonewcategory: "Dodaj u novu kategoriju",
context_disablepredefined: "Deaktivirajte unaprijed definiranu kategoriju",
context_inpredefined: "Prikvačeno u unaprijed definiranoj kategoriji",
context_pinchannel: "Prikvači na popis kanala",
context_pindm: "Prikvači izravnu poruku",
context_pinguild: "Prikvači na popis poslužitelja",
@@ -1096,7 +1078,6 @@ module.exports = (_ => {
return {
context_addtonewcategory: "Hozzáadás új kategóriához",
context_disablepredefined: "Deaktiválja az előre definiált kategóriát",
context_inpredefined: "Előre meghatározott kategóriában rögzítve",
context_pinchannel: "Rögzítés a csatornalistához",
context_pindm: "Közvetlen üzenet rögzítése",
context_pinguild: "Rögzítés a kiszolgáló listához",
@@ -1109,7 +1090,6 @@ module.exports = (_ => {
return {
context_addtonewcategory: "Aggiungi a una nuova categoria",
context_disablepredefined: "Disattiva la categoria predefinita",
context_inpredefined: "Bloccato in una categoria predefinita",
context_pinchannel: "Fissa all'elenco dei canali",
context_pindm: "Metti il messaggio diretto",
context_pinguild: "Aggiungi all'elenco dei server",
@@ -1122,7 +1102,6 @@ module.exports = (_ => {
return {
context_addtonewcategory: "新しいカテゴリに追加",
context_disablepredefined: "事前定義されたカテゴリを非アクティブ化",
context_inpredefined: "事前定義されたカテゴリに固定",
context_pinchannel: "チャネルリストに固定",
context_pindm: "ダイレクトメッセージを固定する",
context_pinguild: "サーバーリストに固定する",
@@ -1135,7 +1114,6 @@ module.exports = (_ => {
return {
context_addtonewcategory: "새 카테고리에 추가",
context_disablepredefined: "사전 정의 된 카테고리 비활성화",
context_inpredefined: "사전 정의 된 카테고리에 고정됨",
context_pinchannel: "채널 목록에 고정",
context_pindm: "개인 메시지 고정",
context_pinguild: "서버 목록에 고정",
@@ -1148,7 +1126,6 @@ module.exports = (_ => {
return {
context_addtonewcategory: "Pridėti prie naujos kategorijos",
context_disablepredefined: "Išjunkite iš anksto nustatytą kategoriją",
context_inpredefined: "Prisegta iš anksto nustatytoje kategorijoje",
context_pinchannel: "Prisegti prie kanalų sąrašo",
context_pindm: "Prisegti tiesioginį pranešimą",
context_pinguild: "Prisegti prie serverio sąrašo",
@@ -1161,7 +1138,6 @@ module.exports = (_ => {
return {
context_addtonewcategory: "Toevoegen aan nieuwe categorie",
context_disablepredefined: "Schakel de voorgedefinieerde categorie uit",
context_inpredefined: "Vastgezet in een vooraf gedefinieerde categorie",
context_pinchannel: "Vastzetten op kanalenlijst",
context_pindm: "Direct bericht vastzetten",
context_pinguild: "Vastzetten op serverlijst",
@@ -1174,7 +1150,6 @@ module.exports = (_ => {
return {
context_addtonewcategory: "Legg til i ny kategori",
context_disablepredefined: "Deaktiver forhåndsdefinert kategori",
context_inpredefined: "Festet i en forhåndsdefinert kategori",
context_pinchannel: "Fest til kanallisten",
context_pindm: "Fest direkte melding",
context_pinguild: "Fest til serverlisten",
@@ -1187,7 +1162,6 @@ module.exports = (_ => {
return {
context_addtonewcategory: "Dodaj do nowej kategorii",
context_disablepredefined: "Dezaktywuj predefiniowaną kategorię",
context_inpredefined: "Przypięty w predefiniowanej kategorii",
context_pinchannel: "Przypnij do listy kanałów",
context_pindm: "Przypnij bezpośrednią wiadomość",
context_pinguild: "Przypnij do listy serwerów",
@@ -1200,7 +1174,6 @@ module.exports = (_ => {
return {
context_addtonewcategory: "Adicionar à nova categoria",
context_disablepredefined: "Desativar categoria predefinida",
context_inpredefined: "Fixado em uma categoria predefinida",
context_pinchannel: "Fixar na lista de canais",
context_pindm: "Fixar mensagem direta",
context_pinguild: "Fixar na lista de servidores",
@@ -1213,7 +1186,6 @@ module.exports = (_ => {
return {
context_addtonewcategory: "Adăugați la o nouă categorie",
context_disablepredefined: "Dezactivați categoria predefinită",
context_inpredefined: "Fixat într-o categorie predefinită",
context_pinchannel: "Fixați în lista de canale",
context_pindm: "Fixați mesajul direct",
context_pinguild: "Fixați pe lista serverului",
@@ -1226,7 +1198,6 @@ module.exports = (_ => {
return {
context_addtonewcategory: "Добавить в новую категорию",
context_disablepredefined: "Отключить предопределенную категорию",
context_inpredefined: "Закреплено в предопределенной категории",
context_pinchannel: "Закрепить в списке каналов",
context_pindm: "Закрепить прямую переписку",
context_pinguild: "Закрепить в списке серверов",
@@ -1239,7 +1210,6 @@ module.exports = (_ => {
return {
context_addtonewcategory: "Lägg till i ny kategori",
context_disablepredefined: "Inaktivera fördefinierad kategori",
context_inpredefined: "Fästs i en fördefinierad kategori",
context_pinchannel: "Fäst i kanallistan",
context_pindm: "Fäst direktmeddelande",
context_pinguild: "Fäst i serverlistan",
@@ -1252,7 +1222,6 @@ module.exports = (_ => {
return {
context_addtonewcategory: "เพิ่มในหมวดหมู่ใหม่",
context_disablepredefined: "ปิดใช้งานหมวดหมู่ที่กำหนดไว้ล่วงหน้า",
context_inpredefined: "ตรึงไว้ในหมวดหมู่ที่กำหนดไว้ล่วงหน้า",
context_pinchannel: "ตรึงในรายการช่อง",
context_pindm: "ตรึงข้อความโดยตรง",
context_pinguild: "ปักหมุดรายการเซิร์ฟเวอร์",
@@ -1265,7 +1234,6 @@ module.exports = (_ => {
return {
context_addtonewcategory: "Yeni kategoriye ekle",
context_disablepredefined: "Önceden tanımlanmış kategoriyi devre dışı bırakın",
context_inpredefined: "Önceden tanımlanmış bir kategoriye sabitlenmiş",
context_pinchannel: "Kanal listesine sabitle",
context_pindm: "Doğrudan mesajı sabitle",
context_pinguild: "Sunucu listesine sabitle",
@@ -1278,7 +1246,6 @@ module.exports = (_ => {
return {
context_addtonewcategory: "Додати до нової категорії",
context_disablepredefined: "Вимкнути заздалегідь визначену категорію",
context_inpredefined: "Закріплено в наперед визначеній категорії",
context_pinchannel: "Закріпити в списку каналів",
context_pindm: "Закріпити пряме повідомлення",
context_pinguild: "Закріпити на списку серверів",
@@ -1291,7 +1258,6 @@ module.exports = (_ => {
return {
context_addtonewcategory: "Thêm vào danh mục mới",
context_disablepredefined: "Hủy kích hoạt danh mục xác định trước",
context_inpredefined: "Được ghim trong một danh mục xác định trước",
context_pinchannel: "Ghim vào danh sách kênh",
context_pindm: "Ghim tin nhắn trực tiếp",
context_pinguild: "Ghim vào danh sách máy chủ",
@@ -1304,7 +1270,6 @@ module.exports = (_ => {
return {
context_addtonewcategory: "添加到新类别",
context_disablepredefined: "停用预定义类别",
context_inpredefined: "固定在预定义的类别中",
context_pinchannel: "固定到频道列表",
context_pindm: "固定直接讯息",
context_pinguild: "固定到服务器列表",
@@ -1317,7 +1282,6 @@ module.exports = (_ => {
return {
context_addtonewcategory: "添加到新類別",
context_disablepredefined: "停用預定義類別",
context_inpredefined: "固定在預定義的類別中",
context_pinchannel: "固定到頻道列表",
context_pindm: "固定直接訊息",
context_pinguild: "固定到服務器列表",
@@ -1330,7 +1294,6 @@ module.exports = (_ => {
return {
context_addtonewcategory: "Add to new Category",
context_disablepredefined: "Deactivate predefined Category",
context_inpredefined: "Pinned in a predefined Category",
context_pinchannel: "Pin to Channel List",
context_pindm: "Pin DM",
context_pinguild: "Pin to Server List",
@@ -1342,5 +1305,5 @@ module.exports = (_ => {
}
}
};
})(window.BDFDB_Global.PluginUtils.buildPlugin(config));
})(window.BDFDB_Global.PluginUtils.buildPlugin(changeLog));
})();