Fix Message component selection and add bd-isGuildOwner and bd-isGuildMember classes
This commit is contained in:
parent
331b2b396a
commit
0c8279311e
|
@ -11,7 +11,7 @@
|
|||
*/
|
||||
|
||||
import { Reflection } from 'ui';
|
||||
import { Filters, ClientLogger as Logger } from 'common';
|
||||
import { Utils, Filters, ClientLogger as Logger } from 'common';
|
||||
import { MonkeyPatch } from './patcher';
|
||||
import { WebpackModules } from './webpackmodules';
|
||||
import DiscordApi from './discordapi';
|
||||
|
@ -322,7 +322,8 @@ export class ReactAutoPatcher {
|
|||
}
|
||||
|
||||
static async patchMessage() {
|
||||
this.Message = await ReactComponents.getComponent('Message', { selector: '.message' }, m => m.prototype.renderContent);
|
||||
const selector = '.' + WebpackModules.getClassName('message', 'messageCozy', 'messageCompact');
|
||||
this.Message = await ReactComponents.getComponent('Message', {selector}, m => m.prototype && m.prototype.renderCozy);
|
||||
|
||||
this.unpatchMessageRender = MonkeyPatch('BD:ReactComponents', this.Message.component.prototype).after('render', (component, args, retVal) => {
|
||||
const { message, jumpSequenceId, canFlash } = component.props;
|
||||
|
@ -335,11 +336,13 @@ export class ReactAutoPatcher {
|
|||
if (attachments && attachments.length) retVal.props.className += ' bd-hasAttachments';
|
||||
if (embeds && embeds.length) retVal.props.className += ' bd-hasEmbeds';
|
||||
if (author && author.id === DiscordApi.currentUser.id) retVal.props.className += ' bd-isCurrentUser';
|
||||
|
||||
const dapiMessage = DiscordApi.Message.from(message);
|
||||
if (dapiMessage.guild && author.id === dapiMessage.guild.ownerId) retVal.props.className += ' bd-isGuildOwner';
|
||||
if (dapiMessage.guild && dapiMessage.guild.isMember(author.id)) retVal.props.className += ' bd-isGuildMember';
|
||||
});
|
||||
|
||||
for (const e of document.querySelectorAll('.message')) {
|
||||
Reflection(e).forceUpdate();
|
||||
}
|
||||
this.Message.forceUpdateAll();
|
||||
}
|
||||
|
||||
static async patchMessageGroup() {
|
||||
|
|
|
@ -54,9 +54,6 @@ export default class extends Module {
|
|||
});
|
||||
|
||||
// Rerender all messages
|
||||
for (const message of document.querySelectorAll('.message')) {
|
||||
Reflection(message).forceUpdate();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -80,11 +77,7 @@ export default class extends Module {
|
|||
|
||||
// Rerender all channel members
|
||||
if (this.PatchedNameTag) {
|
||||
const selector = '.' + WebpackModules.getClassName('member', 'memberInner', 'activity');
|
||||
|
||||
for (const channelMember of document.querySelectorAll(selector)) {
|
||||
Reflection(channelMember).forceUpdate();
|
||||
}
|
||||
ChannelMember.forceUpdateAll();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -95,7 +88,7 @@ export default class extends Module {
|
|||
if (this.PatchedNameTag) return this.PatchedNameTag;
|
||||
|
||||
const selector = '.' + WebpackModules.getClassName('nameTag', 'username', 'discriminator', 'ownerIcon');
|
||||
const NameTag = await ReactComponents.getComponent('NameTag', { selector });
|
||||
const NameTag = await ReactComponents.getComponent('NameTag', {selector});
|
||||
|
||||
this.PatchedNameTag = class extends NameTag.component {
|
||||
render() {
|
||||
|
@ -121,11 +114,8 @@ export default class extends Module {
|
|||
|
||||
// Rerender all channel members
|
||||
if (this.unpatchChannelMemberRender) {
|
||||
const selector = '.' + WebpackModules.getClassName('member', 'memberInner', 'activity');
|
||||
|
||||
for (const channelMember of document.querySelectorAll(selector)) {
|
||||
Reflection(channelMember).forceUpdate();
|
||||
}
|
||||
const ChannelMember = await ReactComponents.getComponent('ChannelMember');
|
||||
ChannelMember.forceUpdateAll();
|
||||
}
|
||||
|
||||
return this.PatchedNameTag;
|
||||
|
@ -135,9 +125,9 @@ export default class extends Module {
|
|||
* Patches UserProfileModal to render profile badges.
|
||||
*/
|
||||
async patchUserProfileModal() {
|
||||
this.UserProfileModal = await ReactComponents.getComponent('UserProfileModal');
|
||||
const UserProfileModal = await ReactComponents.getComponent('UserProfileModal');
|
||||
|
||||
this.unpatchUserProfileModal = MonkeyPatch('ProfileBadges', this.UserProfileModal.component.prototype).after('renderBadges', (component, args, retVal, setRetVal) => {
|
||||
this.unpatchUserProfileModal = MonkeyPatch('ProfileBadges', UserProfileModal.component.prototype).after('renderBadges', (component, args, retVal, setRetVal) => {
|
||||
const user = ReactHelpers.findProp(component, 'user');
|
||||
if (!user) return;
|
||||
const contributor = contributors.find(c => c.id === user.id);
|
||||
|
@ -155,6 +145,8 @@ export default class extends Module {
|
|||
}));
|
||||
} else retVal.props.children.splice(0, 0, element);
|
||||
});
|
||||
|
||||
UserProfileModal.forceUpdateAll();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue