From 226719b36e040ec15bbeceaf139dc73ff5e4c05f Mon Sep 17 00:00:00 2001 From: Samuel Elliott Date: Sun, 10 Mar 2019 17:45:20 +0000 Subject: [PATCH] Rerender messages after loading emotes --- client/src/builtin/BuiltinModule.js | 8 ++++---- client/src/builtin/E2EE.js | 2 ++ client/src/builtin/EmoteModule.js | 4 +++- client/src/modules/reactcomponents.js | 7 ++++--- 4 files changed, 13 insertions(+), 8 deletions(-) diff --git a/client/src/builtin/BuiltinModule.js b/client/src/builtin/BuiltinModule.js index 28d26794..330f685a 100644 --- a/client/src/builtin/BuiltinModule.js +++ b/client/src/builtin/BuiltinModule.js @@ -22,10 +22,10 @@ export default class BuiltinModule { this.patch = this.patch.bind(this); } - init() { + async init() { this.setting.on('setting-updated', this._settingUpdated); if (this.setting.value) { - if (this.enabled) this.enabled(); + if (this.enabled) await this.enabled(); if (this.applyPatches) this.applyPatches(); } } @@ -38,10 +38,10 @@ export default class BuiltinModule { return Patcher.getPatchesByCaller(`BD:${this.moduleName}`); } - _settingUpdated(e) { + async _settingUpdated(e) { const { value } = e; if (value === true) { - if (this.enabled) this.enabled(e); + if (this.enabled) await this.enabled(e); if (this.applyPatches) this.applyPatches(); return; } diff --git a/client/src/builtin/E2EE.js b/client/src/builtin/E2EE.js index a620013c..82e1a363 100644 --- a/client/src/builtin/E2EE.js +++ b/client/src/builtin/E2EE.js @@ -239,9 +239,11 @@ export default new class E2EE extends BuiltinModule { const MessageContent = await ReactComponents.getComponent('MessageContent'); this.patch(MessageContent.component.prototype, 'render', this.beforeRenderMessageContent, 'before'); this.patch(MessageContent.component.prototype, 'render', this.afterRenderMessageContent); + MessageContent.forceUpdateAll(); const ImageWrapper = await ReactComponents.getComponent('ImageWrapper'); this.patch(ImageWrapper.component.prototype, 'render', this.beforeRenderImageWrapper, 'before'); + ImageWrapper.forceUpdateAll(); } beforeRenderMessageContent(component) { diff --git a/client/src/builtin/EmoteModule.js b/client/src/builtin/EmoteModule.js index 9839d5c2..581fcc97 100644 --- a/client/src/builtin/EmoteModule.js +++ b/client/src/builtin/EmoteModule.js @@ -12,7 +12,7 @@ import BuiltinModule from './BuiltinModule'; import path from 'path'; import { request } from 'vendor'; -import { Utils, FileUtils } from 'common'; +import { Utils, FileUtils, ClientLogger as Logger } from 'common'; import { DiscordApi, Settings, Globals, Reflection, ReactComponents, Database } from 'modules'; import { DiscordContextMenu } from 'ui'; @@ -131,6 +131,8 @@ export default new class EmoteModule extends BuiltinModule { this.database.set(id, { id: emote.value.id || value, type }); } + + Logger.log('EmoteModule', ['Loaded emote database']); } async loadUserData() { diff --git a/client/src/modules/reactcomponents.js b/client/src/modules/reactcomponents.js index e591a885..d856c28c 100644 --- a/client/src/modules/reactcomponents.js +++ b/client/src/modules/reactcomponents.js @@ -397,8 +397,10 @@ export class ReactAutoPatcher { } static async patchImageWrapper() { + ReactComponents.componentAliases.ImageWrapper = 'Image'; + const { selector } = Reflection.resolve('imageWrapper'); - this.ImageWrapper = await ReactComponents.getComponent('ImageWrapper', {selector}); + this.ImageWrapper = await ReactComponents.getComponent('ImageWrapper', {selector}, c => typeof c.defaultProps.children === 'function'); } static async patchChannelMember() { @@ -541,8 +543,7 @@ export class ReactAutoPatcher { this.UserPopout = await ReactComponents.getComponent('UserPopout', {selector}, c => c.prototype.renderHeader); this.unpatchUserPopout = MonkeyPatch('BD:ReactComponents', this.UserPopout.component.prototype).after('render', (component, args, retVal) => { - Logger.log('ReactComponents', ['Rendering UserPopout', component, args, retVal]); - const root = retVal.props.children[0] || retVal.props.children; + const root = retVal.props.children[0] || retVal.props.children; const { user, guild, guildMember } = component.props; if (!user) return; root.props['data-user-id'] = user.id;