From 54c7fcc51f7c33a382887414dd8d24385dd36831 Mon Sep 17 00:00:00 2001 From: Mirco Wittrien Date: Thu, 29 Nov 2018 15:19:09 +0100 Subject: [PATCH] Update PinDMs.plugin.js --- Plugins/PinDMs/PinDMs.plugin.js | 50 +++++++++++---------------------- 1 file changed, 17 insertions(+), 33 deletions(-) diff --git a/Plugins/PinDMs/PinDMs.plugin.js b/Plugins/PinDMs/PinDMs.plugin.js index 340861a50b..6cda08383e 100644 --- a/Plugins/PinDMs/PinDMs.plugin.js +++ b/Plugins/PinDMs/PinDMs.plugin.js @@ -19,7 +19,7 @@ class PinDMs { getDescription () {return "Allows you to pin DMs, making them appear at the top of your DM-list.";} - getVersion () {return "1.1.9";} + getVersion () {return "1.2.0";} getAuthor () {return "DevilBro";} @@ -79,7 +79,7 @@ class PinDMs { } }); - setTimeout(() => {this.onSwitch();},1000); + setTimeout(() => {this.patchDMsScroller();},1000); } else { console.error(this.getName() + ": Fatal Error: Could not load BD functions!"); @@ -110,12 +110,6 @@ class PinDMs { } } - onSwitch () { - if (!document.querySelector(BDFDB.dotCNS.guildselected + BDFDB.dotCN.friendsicon)) return; - - this.patchDMsScroller(); - } - // begin of own functions @@ -177,33 +171,23 @@ class PinDMs { } patchDMsScroller () { + let addAllDMs = (dmsarray) => { + let sortedDMs = this.sortAndUpdate(); + if (sortedDMs.length > 0) { + let insertpoint = this.getInsertPoint(dmsarray); + for (let pos in sortedDMs) this.addPinnedDM(sortedDMs[pos], dmsarray, insertpoint); + } + }; + this.patchCancels.push(BDFDB.WebModules.monkeyPatch(BDFDB.WebModules.findByName("LazyScroller").prototype, "render", {before: (e) => { + if (e.thisObject._reactInternalFiber.return.memoizedProps.privateChannelIds && !e.thisObject.props.PinDMsPatched) { + e.thisObject.props.PinDMsPatched = true; + addAllDMs(e.thisObject.props.children); + } + }})); let dmsscroller = document.querySelector(BDFDB.dotCNS.dmchannels + BDFDB.dotCN.scroller); if (dmsscroller) { - if (!this.lazyScrollerWasPatched) { - let addAllDMs = (dmsarray) => { - let sortedDMs = this.sortAndUpdate(); - if (sortedDMs.length > 0) { - let insertpoint = this.getInsertPoint(dmsarray); - for (let pos in sortedDMs) this.addPinnedDM(sortedDMs[pos], dmsarray, insertpoint); - } - }; - this.lazyScrollerWasPatched = true; - let lazyScrollerDMsInstance = BDFDB.getOwnerInstance({"node":dmsscroller, "props":["createComputer","getSubscriptions"], "up":true}); - let lazyScrollerDMsWrap = lazyScrollerDMsInstance._reactInternalFiber.type; - this.patchCancels.push(BDFDB.WebModules.monkeyPatch(lazyScrollerDMsWrap.prototype, "componentDidMount", {before: (e) => { - e.thisObject.props.patched = true; - addAllDMs(e.thisObject.props.children); - }})); - this.patchCancels.push(BDFDB.WebModules.monkeyPatch(lazyScrollerDMsWrap.prototype, "componentDidUpdate", {before: (e) => { - if (!e.thisObject.props.patched) { - e.thisObject.props.patched = true; - addAllDMs(e.thisObject.props.children); - this.forceUpdateScroller(document.querySelector(BDFDB.dotCNS.dmchannels + BDFDB.dotCN.scroller)); - } - }})); - addAllDMs(BDFDB.getReactInstance(dmsscroller).return.return.return.memoizedProps.children); - this.forceUpdateScroller(dmsscroller); - } + addAllDMs(BDFDB.getReactInstance(dmsscroller).return.return.return.memoizedProps.children); + this.forceUpdateScroller(dmsscroller); } }