Update PinDMs.plugin.js

This commit is contained in:
Mirco Wittrien 2022-11-01 11:08:18 +01:00
parent b304b28029
commit b5e451f495
1 changed files with 139 additions and 143 deletions

View File

@ -336,7 +336,7 @@ module.exports = (_ => {
processPrivateChannelsList (e) {
let categories = this.sortAndUpdateCategories("channelList", true);
if (categories.length) {
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);
@ -377,8 +377,7 @@ module.exports = (_ => {
}
}
}
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 => {
@ -415,6 +414,7 @@ module.exports = (_ => {
}
}
}}, {noCache: true});
this.injectCategories(e.instance, e.returnvalue, categories);
}
}
@ -429,32 +429,32 @@ 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) {
@ -590,7 +590,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 +598,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,13 +607,13 @@ module.exports = (_ => {
}
processPrivateChannel (e) {
if (e.instance.props.channel && !this.getPredefinedCategory(e.instance.props.channel.id)) {
if (!e.instance.props.channel || this.getPredefinedCategory(e.instance.props.channel.id)) return;
let category = this.getChannelListCategory(e.instance.props.channel.id);
if (category) {
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) {
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);
@ -669,24 +669,8 @@ module.exports = (_ => {
};
e.node.addEventListener("mousedown", e.node.PinDMsMouseDownListener);
}
}
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);
}
}
}
}
_processPrivateChannel (instance, returnvalue, category) {
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,
@ -694,7 +678,7 @@ module.exports = (_ => {
className: BDFDB.disCN._pindmsunpinbutton,
onClick: event => {
BDFDB.ListenerUtils.stopEvent(event);
this.removeFromCategory(instance.props.channel.id, category, "channelList");
this.removeFromCategory(e.instance.props.channel.id, category, "channelList");
},
children: BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.SvgIcon, {
className: BDFDB.disCN._pindmsunpinicon,
@ -702,6 +686,18 @@ module.exports = (_ => {
})
})
}));
};
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);
}
}
processDirectMessage (e) {
@ -911,7 +907,7 @@ module.exports = (_ => {
updateContainer (type) {
switch (type) {
case "channelList":
BDFDB.PatchUtils.forceAllUpdates(this, "PrivateChannelsList");
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":