Fix emotes

This commit is contained in:
Samuel Elliott 2018-08-01 19:58:52 +01:00
parent a20473d718
commit 331b2b396a
No known key found for this signature in database
GPG Key ID: 8420C7CDE43DC4D6
1 changed files with 10 additions and 13 deletions

View File

@ -48,7 +48,7 @@ export default new class EmoteModule {
try { try {
await Promise.all([ await Promise.all([
this.patchMessage(), this.patchMessageContent(),
this.patchChannelTextArea() this.patchChannelTextArea()
]); ]);
} catch (err) { } catch (err) {
@ -194,38 +194,35 @@ export default new class EmoteModule {
return matching; return matching;
} }
async patchMessage() { async patchMessageContent() {
const Message = await ReactComponents.getComponent('Message'); const selector = '.' + WebpackModules.getClassName('container', 'containerCozy', 'containerCompact', 'edited');
const MessageContent = await ReactComponents.getComponent('MessageContent', {selector});
this.unpatchRender = MonkeyPatch('BD:EmoteModule', Message.component.prototype).after('render', (component, args, retVal) => { this.unpatchRender = MonkeyPatch('BD:EmoteModule', MessageContent.component.prototype).after('render', (component, args, retVal) => {
try { try {
// First child has all the actual text content, second is the edited timestamp // First child has all the actual text content, second is the edited timestamp
const markup = this.findByProp(retVal, 'className', 'markup'); const markup = retVal.props.children[1].props;
if (!markup || !this.enabledSetting.value) return; if (!markup || !this.enabledSetting.value) return;
markup.children[0] = this.processMarkup(markup.children[0], component.props.message.editedTimestamp || component.props.message.timestamp); markup.children[1] = this.processMarkup(markup.children[1], component.props.message.editedTimestamp || component.props.message.timestamp);
} catch (err) { } catch (err) {
Logger.err('EmoteModule', err); Logger.err('EmoteModule', err);
} }
}); });
for (const message of document.querySelectorAll('.message')) { MessageContent.forceUpdateAll();
Reflection(message).forceUpdate();
}
} }
async patchChannelTextArea() { async patchChannelTextArea() {
const selector = '.' + WebpackModules.getClassName('channelTextArea', 'emojiButton'); const selector = '.' + WebpackModules.getClassName('channelTextArea', 'emojiButton');
const ChannelTextArea = await ReactComponents.getComponent('ChannelTextArea', {selector}); const ChannelTextArea = await ReactComponents.getComponent('ChannelTextArea', {selector});
this.unpatchChannelTextArea = MonkeyPatch('BD:ReactComponents', ChannelTextArea.component.prototype).after('render', (component, args, retVal) => { this.unpatchChannelTextArea = MonkeyPatch('BD:EmoteModule', ChannelTextArea.component.prototype).after('render', (component, args, retVal) => {
if (!(retVal.props.children instanceof Array)) retVal.props.children = [retVal.props.children]; if (!(retVal.props.children instanceof Array)) retVal.props.children = [retVal.props.children];
retVal.props.children.splice(0, 0, VueInjector.createReactElement(Autocomplete, {}, true)); retVal.props.children.splice(0, 0, VueInjector.createReactElement(Autocomplete, {}, true));
}); });
for (const e of document.querySelectorAll(selector)) { ChannelTextArea.forceUpdateAll();
Reflection(e).forceUpdate();
}
} }
} }