From 3de9fb47dec11ce0ce4e4e4a62619c0d8a70343c Mon Sep 17 00:00:00 2001 From: Mirco Wittrien Date: Mon, 5 Jul 2021 21:50:35 +0200 Subject: [PATCH] stuff --- Library/_res/BDFDB.data.json | 2 +- .../ShowConnections/ShowConnections.plugin.js | 157 +++++++++--------- 2 files changed, 81 insertions(+), 78 deletions(-) diff --git a/Library/_res/BDFDB.data.json b/Library/_res/BDFDB.data.json index e488f91a4e..c53b8f0151 100644 --- a/Library/_res/BDFDB.data.json +++ b/Library/_res/BDFDB.data.json @@ -5006,7 +5006,7 @@ "798499176220327966": {"active": true, "tier": "t2", "text": "", "color": "", "id": ".void (DsOp)"}, "89482511343702016": {"active": true, "tier": "t3", "text": "", "color": "#0080ff", "id": "AzukiPuddles"}, "222808775722008587": {"active": true, "tier": "t2", "text": "", "color": "", "id": "Riyshin (AbÖz)"}, - "464865517354614805": {"active": true, "tier": "t2", "text": "", "color": "", "id": "Zammu (ScQu)"}, + "464865517354614805": {"active": false, "tier": "t2", "text": "", "color": "", "id": "Zammu (ScQu)"}, "467514600934604801": {"active": true, "tier": "t3", "text": "", "color": "", "id": "star (adria)"}, "446396928092274720": {"active": true, "tier": "t3", "text": "Existing...", "color": "", "id": "Sayori (SaySa)"}, "760784464560914452": {"active": true, "tier": "t3", "text": "Keyra", "color": "", "id": "Keyra (PaCu)"}, diff --git a/Plugins/ShowConnections/ShowConnections.plugin.js b/Plugins/ShowConnections/ShowConnections.plugin.js index 02cebcf0c9..e2e787a5eb 100644 --- a/Plugins/ShowConnections/ShowConnections.plugin.js +++ b/Plugins/ShowConnections/ShowConnections.plugin.js @@ -2,7 +2,7 @@ * @name ShowConnections * @author DevilBro * @authorId 278543574059057154 - * @version 1.0.5 + * @version 1.0.6 * @description Shows the connected Accounts of a User in the UserPopout * @invite Jx3TjNS * @donate https://www.paypal.me/MircoWittrien @@ -17,12 +17,12 @@ module.exports = (_ => { "info": { "name": "ShowConnections", "author": "DevilBro", - "version": "1.0.5", + "version": "1.0.6", "description": "Shows the connected Accounts of a User in the UserPopout" }, "changeLog": { - "fixed": { - "User Popout": "Fixing Stuff for the User Popout Update, thanks Discord" + "improved": { + "Performance": "" } } }; @@ -73,13 +73,18 @@ module.exports = (_ => { return template.content.firstElementChild; } } : (([Plugin, BDFDB]) => { - var loadedUsers = {}, fetchTimeout, currentPopout; + var _this; + var loadedUsers, requestedUsers, queuedInstances; return class ShowConnections extends Plugin { onLoad () { + _this = this; + loadedUsers = {}; + requestedUsers = {}; + queuedInstances = {}; + this.patchedModules = { after: { - AnalyticsContext: "render", UserPopoutBody: "default" } }; @@ -125,11 +130,11 @@ module.exports = (_ => { onStart () { BDFDB.PatchUtils.patch(this, BDFDB.LibraryModules.DispatchApiUtils, "dispatch", {after: e => { if (BDFDB.ObjectUtils.is(e.methodArguments[0]) && e.methodArguments[0].type == BDFDB.DiscordConstants.ActionTypes.USER_PROFILE_FETCH_SUCCESS && e.methodArguments[0].user && e.methodArguments[0].connected_accounts) { - loadedUsers[e.methodArguments[0].user.id] = e.methodArguments[0].connected_accounts; - if (currentPopout && currentPopout.user.id == e.methodArguments[0].user.id) { - BDFDB.ReactUtils.forceUpdate(currentPopout.instance); - currentPopout = null; - } + const user = e.methodArguments[0].user; + delete requestedUsers[user.id]; + loadedUsers[user.id] = e.methodArguments[0].connected_accounts; + BDFDB.ReactUtils.forceUpdate(queuedInstances[user.id]); + delete queuedInstances[user.id]; } }}); @@ -175,76 +180,74 @@ module.exports = (_ => { }); } - processAnalyticsContext (e) { - if (e.instance.props.section != BDFDB.DiscordConstants.AnalyticsSections.PROFILE_POPOUT) return; - const user = BDFDB.ReactUtils.findValue(e.instance, "user"); - if (!user) return; - currentPopout = {user: user, instance: e.instance}; - } - processUserPopoutBody (e) { - if (!e.instance.props.user || e.instance.props.user.bot || e.instance.props.user.discriminator == "0000") return; - if (loadedUsers[e.instance.props.user.id]) { - let connections = loadedUsers[e.instance.props.user.id].filter(c => this.settings.connections[c.type]); - if (!connections.length) return; - let isLightTheme = BDFDB.DiscordUtils.getTheme() == BDFDB.disCN.themelight; - let bodyInner = BDFDB.ReactUtils.findChild(e.returnvalue, {props: [["className", BDFDB.disCN.userpopoutbodyinnerwrapper]]}); - if (bodyInner) bodyInner.props.children.splice(this.settings.general.placeAtTop ? 1 : bodyInner.props.children.length - 2, 0, BDFDB.ReactUtils.createElement(BDFDB.ReactUtils.Fragment, { - children: [ - BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.Header, { - className: BDFDB.disCN.userpopoutbodytitle, - size: BDFDB.LibraryComponents.Header.Sizes.SIZE_12, - muted: true, - uppercase: true, - children: BDFDB.LanguageUtils.LanguageStrings.CONNECTIONS - }), - BDFDB.ReactUtils.createElement("div", { - className: BDFDB.disCN._showconnectionsconnections, - children: connections.map(c => { - let provider = BDFDB.LibraryModules.ConnectionProviderUtils.get(c.type); - let url = this.settings.general.openWebpage && provider.getPlatformUserUrl && provider.getPlatformUserUrl(c); - return BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.TooltipContainer, { - text: `${provider.name}: ${c.name}`, - tooltipConfig: {backgroundColor: this.settings.general.useColoredTooltips && BDFDB.ColorUtils.change(provider.color, -0.3), color: !this.settings.general.useColoredTooltips || !provider.color ? "black" : null}, - children: BDFDB.ReactUtils.createElement(!url ? "div" : BDFDB.LibraryComponents.Anchor, Object.assign(!url ? {} : { - href: url - }, { - className: BDFDB.DOMUtils.formatClassName(BDFDB.disCN._showconnectionsconnection, url && BDFDB.disCN.cursorpointer), - children: [ - BDFDB.ReactUtils.createElement("img", { - className: BDFDB.disCN._showconnectionsicon, - alt: BDFDB.LanguageUtils.LanguageStringsFormat("IMG_ALT_LOGO", provider.name), - src: provider.icon[this.settings.general.useColoredIcons ? "color" : "white"] - }), - this.settings.general.showVerifiedBadge && c.verified && BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.TooltipContainer, { - text: BDFDB.LanguageUtils.LanguageStrings.CONNECTION_VERIFIED, - tooltipConfig: {color: "brand", type: "bottom"}, - children: BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.FlowerStar, { - className: BDFDB.disCN._showconnectionsverifiedbadge, - size: "50%", - color: isLightTheme ? BDFDB.DiscordConstants.Colors.STATUS_GREY_200 : BDFDB.DiscordConstants.Colors.PRIMARY_DARK, - children: BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.SvgIcon, { - name: BDFDB.LibraryComponents.SvgIcon.Names.CHECKMARK, - width: "70%", - height: "70%", - color: isLightTheme ? BDFDB.DiscordConstants.Colors.STATUS_GREY_500 : BDFDB.DiscordConstants.Colors.WHITE + if (!e.instance.props.user || e.instance.props.user.isNonUserBot()) return; + if (!loadedUsers[e.instance.props.user.id] && !requestedUsers[e.instance.props.user.id]) { + requestedUsers[e.instance.props.user.id] = true; + queuedInstances[e.instance.props.user.id] = [].concat(queuedInstances[e.instance.props.user.id]).filter(n => n); + BDFDB.LibraryModules.UserProfileUtils.fetchProfile(e.instance.props.user.id); + } + let bodyInner = BDFDB.ReactUtils.findChild(e.returnvalue, {props: [["className", BDFDB.disCN.userpopoutbodyinnerwrapper]]}); + if (bodyInner) bodyInner.props.children.splice(this.settings.general.placeAtTop ? 1 : bodyInner.props.children.length - 2, 0, BDFDB.ReactUtils.createElement(class extends BDFDB.ReactUtils.Component { + render() { + if (!loadedUsers[e.instance.props.user.id]) { + if (queuedInstances[e.instance.props.user.id].indexOf(this) == -1) queuedInstances[e.instance.props.user.id].push(this); + return null; + } + else { + let connections = loadedUsers[e.instance.props.user.id].filter(c => _this.settings.connections[c.type]); + if (!connections.length) return null; + let isLightTheme = BDFDB.DiscordUtils.getTheme() == BDFDB.disCN.themelight; + return [ + BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.Header, { + className: BDFDB.disCN.userpopoutbodytitle, + size: BDFDB.LibraryComponents.Header.Sizes.SIZE_12, + muted: true, + uppercase: true, + children: BDFDB.LanguageUtils.LanguageStrings.CONNECTIONS + }), + BDFDB.ReactUtils.createElement("div", { + className: BDFDB.disCN._showconnectionsconnections, + children: connections.map(c => { + let provider = BDFDB.LibraryModules.ConnectionProviderUtils.get(c.type); + let url = _this.settings.general.openWebpage && provider.getPlatformUserUrl && provider.getPlatformUserUrl(c); + return BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.TooltipContainer, { + text: `${provider.name}: ${c.name}`, + tooltipConfig: {backgroundColor: _this.settings.general.useColoredTooltips && BDFDB.ColorUtils.change(provider.color, -0.3), color: !_this.settings.general.useColoredTooltips || !provider.color ? "black" : null}, + children: BDFDB.ReactUtils.createElement(!url ? "div" : BDFDB.LibraryComponents.Anchor, Object.assign(!url ? {} : { + href: url + }, { + className: BDFDB.DOMUtils.formatClassName(BDFDB.disCN._showconnectionsconnection, url && BDFDB.disCN.cursorpointer), + children: [ + BDFDB.ReactUtils.createElement("img", { + className: BDFDB.disCN._showconnectionsicon, + alt: BDFDB.LanguageUtils.LanguageStringsFormat("IMG_ALT_LOGO", provider.name), + src: provider.icon[_this.settings.general.useColoredIcons ? "color" : "white"] + }), + _this.settings.general.showVerifiedBadge && c.verified && BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.TooltipContainer, { + text: BDFDB.LanguageUtils.LanguageStrings.CONNECTION_VERIFIED, + tooltipConfig: {color: "brand", type: "bottom"}, + children: BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.FlowerStar, { + className: BDFDB.disCN._showconnectionsverifiedbadge, + size: "50%", + color: isLightTheme ? BDFDB.DiscordConstants.Colors.STATUS_GREY_200 : BDFDB.DiscordConstants.Colors.PRIMARY_DARK, + children: BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.SvgIcon, { + name: BDFDB.LibraryComponents.SvgIcon.Names.CHECKMARK, + width: "70%", + height: "70%", + color: isLightTheme ? BDFDB.DiscordConstants.Colors.STATUS_GREY_500 : BDFDB.DiscordConstants.Colors.WHITE + }) }) }) - }) - ] - })) - }); + ] + })) + }); + }) }) - }) - ] - })); - } - else { - BDFDB.TimeUtils.clear(fetchTimeout); - fetchTimeout = BDFDB.TimeUtils.timeout(_ => { - if (!loadedUsers[e.instance.props.user.id]) BDFDB.LibraryModules.UserProfileUtils.fetchProfile(e.instance.props.user.id); - }, 1000); - } + ]; + } + } + })); } }; })(window.BDFDB_Global.PluginUtils.buildPlugin(config));