Update PinDMs.plugin.js
This commit is contained in:
parent
b5ea4e0903
commit
4c9e5f1d27
|
@ -14,8 +14,13 @@ module.exports = (_ => {
|
|||
"info": {
|
||||
"name": "PinDMs",
|
||||
"author": "DevilBro",
|
||||
"version": "1.7.6",
|
||||
"version": "1.7.7",
|
||||
"description": "Allow you to pin DMs, making them appear at the top of your DMs/Server-List"
|
||||
},
|
||||
"changeLog": {
|
||||
"fixed": {
|
||||
"Works again": "Some of you really need to learn how to be a little bit more patient and give plugin devs some time to fix their stuff if discord breaks it..."
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -182,7 +187,6 @@ module.exports = (_ => {
|
|||
}));
|
||||
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: _ => {
|
||||
|
@ -335,41 +339,92 @@ module.exports = (_ => {
|
|||
}
|
||||
}
|
||||
else {
|
||||
e.returnvalue.props.sections = [];
|
||||
e.returnvalue.props.sections.push(e.instance.state.preRenderedChildren);
|
||||
let shownPinnedIds = BDFDB.ObjectUtils.toArray(e.instance.props.pinnedChannelIds).reverse();
|
||||
for (let ids of shownPinnedIds) e.returnvalue.props.sections.push(ids.length || 1);
|
||||
e.returnvalue.props.sections.push(e.instance.props.privateChannelIds.length - shownPinnedIds.flat().length);
|
||||
if (typeof e.returnvalue.props.children == "function") {
|
||||
let childrenRender = e.returnvalue.props.children;
|
||||
e.returnvalue.props.children = (...args) => {
|
||||
let children = childrenRender(...args);
|
||||
this.injectCategories(e.instance, children, categories);
|
||||
return children;
|
||||
};
|
||||
}
|
||||
else this.injectCategories(e.instance, e.returnvalue, categories);
|
||||
}
|
||||
|
||||
let sectionHeight = e.returnvalue.props.sectionHeight;
|
||||
let pinnedIds = BDFDB.ObjectUtils.toArray(e.instance.props.pinnedChannelIds).reverse();
|
||||
BDFDB.PatchUtils.unpatch(this, e.instance, "renderDM");
|
||||
BDFDB.PatchUtils.patch(this, e.instance, "renderDM", {before: e2 => {
|
||||
if (e2.methodArguments[0] != 0) e2.methodArguments[1] += pinnedIds.slice(0, e2.methodArguments[0] - 1).flat().length;
|
||||
}, after: e2 => {
|
||||
if (e2.methodArguments[0] != 0) {
|
||||
let id = e.instance.props.privateChannelIds[e2.methodArguments[1]];
|
||||
e2.returnValue = e.instance.props.channels[id] ? BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.PrivateChannelItems[e.instance.props.channels[id].isMultiUserDM() ? "GroupDM" : "DirectMessage"], Object.assign({
|
||||
key: id,
|
||||
channel: e.instance.props.channels[id],
|
||||
selected: e.instance.props.selectedChannelId == id
|
||||
}, (e.instance.props.navigator || e.instance.props.listNavigator).getItemProps({
|
||||
index: e2.methodArguments[2]
|
||||
}))) : null;
|
||||
|
||||
let category = categories[e2.methodArguments[0] - 1];
|
||||
if (category) {
|
||||
if (!id || (category.collapsed && e.instance.props.selectedChannelId != id) || !category.dms.includes(id) || draggedCategory == category.id || draggedChannel == id) e2.returnValue = null;
|
||||
else if (hoveredCategory == category.id && [].concat(category.dms).reverse()[0] == id) e2.returnValue = [
|
||||
e2.returnValue,
|
||||
BDFDB.ReactUtils.createElement("h2", {
|
||||
className: BDFDB.disCNS.dmchannelheadercontainer + BDFDB.disCNS._pindmspinnedchannelsheadercontainer + BDFDB.disCNS._pindmsdmchannelplaceholder + BDFDB.disCN.namecontainernamecontainer
|
||||
})
|
||||
].filter(n => n);
|
||||
else if (hoveredChannel == id) e2.returnValue = [
|
||||
e2.returnValue,
|
||||
BDFDB.ReactUtils.createElement("div", {
|
||||
className: BDFDB.disCNS.dmchannel + BDFDB.disCNS._pindmsdmchannelpinned + BDFDB.disCNS._pindmsdmchannelplaceholder + BDFDB.disCN.namecontainernamecontainer,
|
||||
children: BDFDB.ReactUtils.createElement("div", {
|
||||
className: BDFDB.disCN.namecontainerlayout
|
||||
})
|
||||
})
|
||||
].filter(n => n);
|
||||
}
|
||||
}
|
||||
}}, {force: true, noCache: true});
|
||||
}
|
||||
}
|
||||
|
||||
injectCategories (instance, returnvalue, categories) {
|
||||
returnvalue.props.sections = [];
|
||||
returnvalue.props.sections.push(instance.state.preRenderedChildren);
|
||||
let shownPinnedIds = BDFDB.ObjectUtils.toArray(instance.props.pinnedChannelIds).reverse();
|
||||
for (let ids of shownPinnedIds) returnvalue.props.sections.push(ids.length || 1);
|
||||
returnvalue.props.sections.push(instance.props.privateChannelIds.length - shownPinnedIds.flat().length);
|
||||
|
||||
let sectionHeight = returnvalue.props.sectionHeight;
|
||||
let sectionHeightFunc = typeof sectionHeight != "function" ? _ => sectionHeight : sectionHeight;
|
||||
e.returnvalue.props.sectionHeight = (...args) => {
|
||||
if (args[0] != 0 && args[0] != e.returnvalue.props.sections.length - 1) {
|
||||
returnvalue.props.sectionHeight = (...args) => {
|
||||
if (args[0] != 0 && args[0] != returnvalue.props.sections.length - 1) {
|
||||
let category = categories[args[0] - 1];
|
||||
if (category) return 40;
|
||||
}
|
||||
return sectionHeightFunc(...args);
|
||||
};
|
||||
|
||||
let rowHeight = e.returnvalue.props.rowHeight;
|
||||
let rowHeight = returnvalue.props.rowHeight;
|
||||
let rowHeightFunc = typeof rowHeight != "function" ? _ => rowHeight : rowHeight;
|
||||
e.returnvalue.props.rowHeight = (...args) => {
|
||||
if (args[0] != 0 && args[0] != e.returnvalue.props.sections.length - 1) {
|
||||
returnvalue.props.rowHeight = (...args) => {
|
||||
if (args[0] != 0 && args[0] != returnvalue.props.sections.length - 1) {
|
||||
let category = categories[args[0] - 1];
|
||||
if (category && (category.collapsed || category.id == draggedCategory)) return 0;
|
||||
}
|
||||
return rowHeightFunc(...args);
|
||||
};
|
||||
|
||||
let renderRow = e.returnvalue.props.renderRow;
|
||||
e.returnvalue.props.renderRow = (...args) => {
|
||||
let renderRow = returnvalue.props.renderRow;
|
||||
returnvalue.props.renderRow = (...args) => {
|
||||
let row = renderRow(...args);
|
||||
return row && row.key == "no-private-channels" ? null : row;
|
||||
};
|
||||
|
||||
let renderSection = e.returnvalue.props.renderSection;
|
||||
e.returnvalue.props.renderSection = (...args) => {
|
||||
if (args[0].section != 0 && args[0].section != e.returnvalue.props.sections.length - 1) {
|
||||
let renderSection = returnvalue.props.renderSection;
|
||||
returnvalue.props.renderSection = (...args) => {
|
||||
if (args[0].section != 0 && args[0].section != returnvalue.props.sections.length - 1) {
|
||||
let category = categories[args[0].section - 1];
|
||||
if (category && draggedCategory != category.id) {
|
||||
let color = BDFDB.ColorUtils.convert(category.color, "RGBA");
|
||||
|
@ -495,45 +550,6 @@ module.exports = (_ => {
|
|||
};
|
||||
}
|
||||
|
||||
let pinnedIds = BDFDB.ObjectUtils.toArray(e.instance.props.pinnedChannelIds).reverse();
|
||||
BDFDB.PatchUtils.unpatch(this, e.instance, "renderDM");
|
||||
BDFDB.PatchUtils.patch(this, e.instance, "renderDM", {before: e2 => {
|
||||
if (e2.methodArguments[0] != 0) e2.methodArguments[1] += pinnedIds.slice(0, e2.methodArguments[0] - 1).flat().length;
|
||||
}, after: e2 => {
|
||||
if (e2.methodArguments[0] != 0) {
|
||||
let id = e.instance.props.privateChannelIds[e2.methodArguments[1]];
|
||||
e2.returnValue = e.instance.props.channels[id] ? BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.PrivateChannelItems[e.instance.props.channels[id].isMultiUserDM() ? "GroupDM" : "DirectMessage"], Object.assign({
|
||||
key: id,
|
||||
channel: e.instance.props.channels[id],
|
||||
selected: e.instance.props.selectedChannelId == id
|
||||
}, (e.instance.props.navigator || e.instance.props.listNavigator).getItemProps({
|
||||
index: e2.methodArguments[2]
|
||||
}))) : null;
|
||||
|
||||
let category = categories[e2.methodArguments[0] - 1];
|
||||
if (category) {
|
||||
if (!id || (category.collapsed && e.instance.props.selectedChannelId != id) || !category.dms.includes(id) || draggedCategory == category.id || draggedChannel == id) e2.returnValue = null;
|
||||
else if (hoveredCategory == category.id && [].concat(category.dms).reverse()[0] == id) e2.returnValue = [
|
||||
e2.returnValue,
|
||||
BDFDB.ReactUtils.createElement("h2", {
|
||||
className: BDFDB.disCNS.dmchannelheadercontainer + BDFDB.disCNS._pindmspinnedchannelsheadercontainer + BDFDB.disCNS._pindmsdmchannelplaceholder + BDFDB.disCN.namecontainernamecontainer
|
||||
})
|
||||
].filter(n => n);
|
||||
else if (hoveredChannel == id) e2.returnValue = [
|
||||
e2.returnValue,
|
||||
BDFDB.ReactUtils.createElement("div", {
|
||||
className: BDFDB.disCNS.dmchannel + BDFDB.disCNS._pindmsdmchannelpinned + BDFDB.disCNS._pindmsdmchannelplaceholder + BDFDB.disCN.namecontainernamecontainer,
|
||||
children: BDFDB.ReactUtils.createElement("div", {
|
||||
className: BDFDB.disCN.namecontainerlayout
|
||||
})
|
||||
})
|
||||
].filter(n => n);
|
||||
}
|
||||
}
|
||||
}}, {force: true, noCache: true});
|
||||
}
|
||||
}
|
||||
|
||||
processUnreadDMs (e) {
|
||||
e.instance.props.pinnedPrivateChannelIds = [];
|
||||
let sortedRecents = this.sortAndUpdate("pinnedRecents");
|
||||
|
|
Loading…
Reference in New Issue