diff --git a/client/src/builtin/ColoredText.js b/client/src/builtin/ColoredText.js index 290eaf6a..f7aef90c 100644 --- a/client/src/builtin/ColoredText.js +++ b/client/src/builtin/ColoredText.js @@ -50,7 +50,7 @@ export default new class ColoredText extends BuiltinModule { /* Patches */ async applyPatches() { if (this.patches.length) return; - this.MessageContent = await ReactComponents.getComponent('MessageContent', { selector: Reflection.resolve('container', 'containerCozy', 'containerCompact', 'edited').selector }, m => m.defaultProps && m.defaultProps.hasOwnProperty('disableButtons')); + this.MessageContent = await ReactComponents.getComponent('MessageContent'); this.patch(this.MessageContent.component.prototype, 'render', this.injectColoredText); this.MessageContent.forceUpdateAll(); } diff --git a/client/src/builtin/E2EE.js b/client/src/builtin/E2EE.js index e85b5bad..a620013c 100644 --- a/client/src/builtin/E2EE.js +++ b/client/src/builtin/E2EE.js @@ -172,7 +172,7 @@ export default new class E2EE extends BuiltinModule { this.patch(Dispatcher, 'dispatch', this.dispatcherPatch, 'before'); this.patchMessageContent(); - const ChannelTextArea = await ReactComponents.getComponent('ChannelTextArea', { selector: Reflection.resolve('channelTextArea', 'emojiButton').selector }); + const ChannelTextArea = await ReactComponents.getComponent('ChannelTextArea'); this.patchChannelTextArea(ChannelTextArea); this.patchChannelTextAreaSubmit(ChannelTextArea); ChannelTextArea.forceUpdateAll(); @@ -236,11 +236,11 @@ export default new class E2EE extends BuiltinModule { } async patchMessageContent() { - const MessageContent = await ReactComponents.getComponent('MessageContent', { selector: Reflection.resolve('container', 'containerCozy', 'containerCompact', 'edited').selector }, m => m.defaultProps && m.defaultProps.hasOwnProperty('disableButtons')); + const MessageContent = await ReactComponents.getComponent('MessageContent'); this.patch(MessageContent.component.prototype, 'render', this.beforeRenderMessageContent, 'before'); this.patch(MessageContent.component.prototype, 'render', this.afterRenderMessageContent); - const ImageWrapper = await ReactComponents.getComponent('ImageWrapper', { selector: Reflection.resolve('imageWrapper').selector }); + const ImageWrapper = await ReactComponents.getComponent('ImageWrapper'); this.patch(ImageWrapper.component.prototype, 'render', this.beforeRenderImageWrapper, 'before'); } diff --git a/client/src/builtin/EmoteModule.js b/client/src/builtin/EmoteModule.js index aa2f927d..9839d5c2 100644 --- a/client/src/builtin/EmoteModule.js +++ b/client/src/builtin/EmoteModule.js @@ -218,7 +218,7 @@ export default new class EmoteModule extends BuiltinModule { async applyPatches() { this.patchMessageContent(); this.patchSendAndEdit(); - const ImageWrapper = await ReactComponents.getComponent('ImageWrapper', { selector: Reflection.resolve('imageWrapper').selector }); + const ImageWrapper = await ReactComponents.getComponent('ImageWrapper'); this.patch(ImageWrapper.component.prototype, 'render', this.beforeRenderImageWrapper, 'before'); } @@ -226,7 +226,7 @@ export default new class EmoteModule extends BuiltinModule { * Patches MessageContent render method */ async patchMessageContent() { - const MessageContent = await ReactComponents.getComponent('MessageContent', { selector: Reflection.resolve('container', 'containerCozy', 'containerCompact', 'edited').selector }, m => m.defaultProps && m.defaultProps.hasOwnProperty('disableButtons')); + const MessageContent = await ReactComponents.getComponent('MessageContent'); this.childPatch(MessageContent.component.prototype, 'render', ['props', 'children'], this.afterRenderMessageContent); MessageContent.forceUpdateAll(); } diff --git a/client/src/modules/packageinstaller.js b/client/src/modules/packageinstaller.js index 9d20e802..e3ab8454 100644 --- a/client/src/modules/packageinstaller.js +++ b/client/src/modules/packageinstaller.js @@ -10,7 +10,6 @@ import { Utils } from 'common'; import PluginManager from './pluginmanager'; import Globals from './globals'; import Security from './security'; -import { ReactComponents } from './reactcomponents'; import Reflection from './reflection'; import DiscordApi from './discordapi'; import ThemeManager from './thememanager'; @@ -136,12 +135,10 @@ export default class PackageInstaller { /** * Patches Discord upload area for .bd files */ - static async uploadAreaPatch() { - const { selector } = Reflection.resolve('uploadArea'); - this.UploadArea = await ReactComponents.getComponent('UploadArea', { selector }); + static async uploadAreaPatch(UploadArea) { + const reflect = Reflection.DOM(UploadArea.important.selector); + const stateNode = reflect.getComponentStateNode(UploadArea); - const reflect = Reflection.DOM(selector); - const stateNode = reflect.getComponentStateNode(this.UploadArea); const callback = async function (e) { if (!e.dataTransfer.files.length || !e.dataTransfer.files[0].name.endsWith('.bd')) return; e.preventDefault(); diff --git a/client/src/modules/reactcomponents.js b/client/src/modules/reactcomponents.js index 36bd416d..e591a885 100644 --- a/client/src/modules/reactcomponents.js +++ b/client/src/modules/reactcomponents.js @@ -373,6 +373,11 @@ export class ReactAutoPatcher { this.Message.forceUpdateAll(); } + static async patchMessageContent() { + const { selector } = Reflection.resolve('container', 'containerCozy', 'containerCompact', 'edited'); + this.MessageContent = await ReactComponents.getComponent('MessageContent', {selector}, c => c.defaultProps && c.defaultProps.hasOwnProperty('disableButtons')); + } + static async patchMessageGroup() { const { selector } = Reflection.resolve('container', 'message', 'messageCozy'); this.MessageGroup = await ReactComponents.getComponent('MessageGroup', {selector}); @@ -391,6 +396,11 @@ export class ReactAutoPatcher { this.MessageGroup.forceUpdateAll(); } + static async patchImageWrapper() { + const { selector } = Reflection.resolve('imageWrapper'); + this.ImageWrapper = await ReactComponents.getComponent('ImageWrapper', {selector}); + } + static async patchChannelMember() { ReactComponents.componentAliases.ChannelMember = 'MemberListItem'; @@ -409,6 +419,11 @@ export class ReactAutoPatcher { this.ChannelMember.forceUpdateAll(); } + static async patchNameTag() { + const { selector } = Reflection.resolve('nameTag', 'username', 'discriminator', 'ownerIcon'); + this.NameTag = await ReactComponents.getComponent('NameTag', {selector}); + } + static async patchGuild() { const selector = `div.${Reflection.resolve('container', 'guildIcon', 'selected', 'unread').className}:not(:first-child)`; this.Guild = await ReactComponents.getComponent('Guild', {selector}, m => m.prototype.renderBadge); @@ -443,6 +458,11 @@ export class ReactAutoPatcher { this.Channel.forceUpdateAll(); } + static async patchChannelTextArea() { + const { selector } = Reflection.resolve('channelTextArea', 'emojiButton'); + this.ChannelTextArea = await ReactComponents.getComponent('ChannelTextArea', {selector}); + } + /** * The GuildTextChannel component represents a text channel in the guild channel list. */ @@ -538,6 +558,9 @@ export class ReactAutoPatcher { } static async patchUploadArea() { - PackageInstaller.uploadAreaPatch(); + const { selector } = Reflection.resolve('uploadArea'); + this.UploadArea = await ReactComponents.getComponent('UploadArea', {selector}); + + PackageInstaller.uploadAreaPatch(this.UploadArea); } } diff --git a/client/src/ui/autocomplete.js b/client/src/ui/autocomplete.js index 1150e820..2e76656e 100644 --- a/client/src/ui/autocomplete.js +++ b/client/src/ui/autocomplete.js @@ -11,7 +11,7 @@ export default new class Autocomplete { } async init() { - this.cta = await ReactComponents.getComponent('ChannelTextArea', { selector: Reflection.resolve('channelTextArea', 'emojiButton').selector }); + this.cta = await ReactComponents.getComponent('ChannelTextArea'); MonkeyPatch('BD:Autocomplete', this.cta.component.prototype).after('render', this.channelTextAreaAfterRender.bind(this)); this.initialized = true; } diff --git a/client/src/ui/contextmenus.js b/client/src/ui/contextmenus.js index b199626c..0c53af8f 100644 --- a/client/src/ui/contextmenus.js +++ b/client/src/ui/contextmenus.js @@ -9,7 +9,7 @@ */ import { Utils, ClientLogger as Logger } from 'common'; -import { ReactComponents, Reflection, MonkeyPatch } from 'modules'; +import { Reflection, MonkeyPatch } from 'modules'; import { VueInjector, Toasts } from 'ui'; import CMGroup from './components/contextmenu/Group.vue'; diff --git a/client/src/ui/profilebadges.js b/client/src/ui/profilebadges.js index 400d2299..900b96db 100644 --- a/client/src/ui/profilebadges.js +++ b/client/src/ui/profilebadges.js @@ -87,8 +87,7 @@ export default class extends Module { async patchNameTag() { if (this.PatchedNameTag) return this.PatchedNameTag; - const selector = Reflection.resolve('nameTag', 'username', 'discriminator', 'ownerIcon').selector; - const NameTag = await ReactComponents.getComponent('NameTag', {selector}); + const NameTag = await ReactComponents.getComponent('NameTag'); this.PatchedNameTag = class extends NameTag.component { render() {