From 47af7a5da6ec8fe4e4ea6ef1992b5759b0e23637 Mon Sep 17 00:00:00 2001 From: Jiiks Date: Sat, 25 Aug 2018 16:02:42 +0300 Subject: [PATCH] Blocked messages refactor to use new builtin base --- client/src/builtin/BlockedMessages.js | 40 +++++++++++++-------------- 1 file changed, 20 insertions(+), 20 deletions(-) diff --git a/client/src/builtin/BlockedMessages.js b/client/src/builtin/BlockedMessages.js index 4431119e..4b2205b5 100644 --- a/client/src/builtin/BlockedMessages.js +++ b/client/src/builtin/BlockedMessages.js @@ -9,12 +9,25 @@ */ import BuiltinModule from './BuiltinModule'; -import { Patcher, MonkeyPatch, Reflection, ReactComponents } from 'modules'; +import { Reflection } from 'modules'; export default new class BlockedMessages extends BuiltinModule { - get settingPath() { - return ['ui', 'default', 'blocked-messages']; + get settingPath() { return ['ui', 'default', 'blocked-messages'] } + get moduleName() { return 'BlockedMessages' } + + async enabled(e) { + const MessageListComponents = Reflection.module.byProps('BlockedMessageGroup'); + MessageListComponents.OriginalBlockedMessageGroup = MessageListComponents.BlockedMessageGroup; + MessageListComponents.BlockedMessageGroup = () => { return null; }; + this.cancelBlockedMessages = () => { + MessageListComponents.BlockedMessageGroup = MessageListComponents.OriginalBlockedMessageGroup; + delete MessageListComponents.OriginalBlockedMessageGroup; + } + } + + disabled(e) { + if (this.cancelBlockedMessages) this.cancelBlockedMessages(); } static isBlocked(id) { @@ -22,28 +35,15 @@ export default new class BlockedMessages extends BuiltinModule { return RelationshipStore.isBlocked(id); } - async enabled(e) { - if (Patcher.getPatchesByCaller('BD:BlockedMessages').length) return; + applyPatches() { + if (this.patches.length) return; const { MessageActions } = Reflection.modules; - MonkeyPatch('BD:BlockedMessages', MessageActions).instead('receiveMessage', this.processMessage); - - const MessageListComponents = Reflection.module.byProps('BlockedMessageGroup'); - MessageListComponents.OriginalBlockedMessageGroup = MessageListComponents.BlockedMessageGroup; - MessageListComponents.BlockedMessageGroup = () => {return null;}; - this.cancelBlockedMessages = () => { - MessageListComponents.BlockedMessageGroup = MessageListComponents.OriginalBlockedMessageGroup; - delete MessageListComponents.OriginalBlockedMessageGroup; - } + this.patch(MessageActions, 'receiveMessage', this.processMessage, 'instead'); } - processMessage(thisObject, args, originalFunction) { + processMessage(that, args, originalFunction) { if (args[1] && args[1].author && args[1].author.id && BlockedMessages.isBlocked(args[1].author.id)) return; return originalFunction(...args); } - disabled(e) { - Patcher.unpatchAll('BD:BlockedMessages'); - if (this.cancelBlockedMessages) this.cancelBlockedMessages(); - } - }