2018-08-21 05:42:34 +02:00
|
|
|
/**
|
|
|
|
* BetterDiscord Blocked Messages Module
|
|
|
|
* Copyright (c) 2015-present Jiiks/JsSucks - https://github.com/Jiiks / https://github.com/JsSucks
|
|
|
|
* All rights reserved.
|
|
|
|
* https://betterdiscord.net
|
|
|
|
*
|
|
|
|
* This source code is licensed under the MIT license found in the
|
|
|
|
* LICENSE file in the root directory of this source tree.
|
|
|
|
*/
|
|
|
|
|
|
|
|
import BuiltinModule from './BuiltinModule';
|
2018-08-25 15:02:42 +02:00
|
|
|
import { Reflection } from 'modules';
|
2018-08-21 05:42:34 +02:00
|
|
|
|
|
|
|
export default new class BlockedMessages extends BuiltinModule {
|
|
|
|
|
2018-08-25 15:12:33 +02:00
|
|
|
/* Getters */
|
2018-08-25 15:02:42 +02:00
|
|
|
get moduleName() { return 'BlockedMessages' }
|
2018-08-21 05:42:34 +02:00
|
|
|
|
2018-08-25 15:12:33 +02:00
|
|
|
get settingPath() { return ['ui', 'default', 'blocked-messages'] }
|
|
|
|
|
2018-08-21 05:42:34 +02:00
|
|
|
async enabled(e) {
|
2018-08-24 18:05:27 +02:00
|
|
|
const MessageListComponents = Reflection.module.byProps('BlockedMessageGroup');
|
2018-08-21 05:42:34 +02:00
|
|
|
MessageListComponents.OriginalBlockedMessageGroup = MessageListComponents.BlockedMessageGroup;
|
2018-08-25 15:02:42 +02:00
|
|
|
MessageListComponents.BlockedMessageGroup = () => { return null; };
|
2018-08-21 05:42:34 +02:00
|
|
|
this.cancelBlockedMessages = () => {
|
|
|
|
MessageListComponents.BlockedMessageGroup = MessageListComponents.OriginalBlockedMessageGroup;
|
|
|
|
delete MessageListComponents.OriginalBlockedMessageGroup;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
disabled(e) {
|
|
|
|
if (this.cancelBlockedMessages) this.cancelBlockedMessages();
|
|
|
|
}
|
|
|
|
|
2018-08-25 15:12:33 +02:00
|
|
|
/* Methods */
|
2018-08-25 15:02:42 +02:00
|
|
|
static isBlocked(id) {
|
|
|
|
const { RelationshipStore } = Reflection.modules;
|
|
|
|
return RelationshipStore.isBlocked(id);
|
|
|
|
}
|
|
|
|
|
2018-08-25 15:12:33 +02:00
|
|
|
/* Patches */
|
2018-08-25 15:02:42 +02:00
|
|
|
applyPatches() {
|
|
|
|
if (this.patches.length) return;
|
|
|
|
const { MessageActions } = Reflection.modules;
|
|
|
|
this.patch(MessageActions, 'receiveMessage', this.processMessage, 'instead');
|
|
|
|
}
|
|
|
|
|
2018-08-25 15:12:33 +02:00
|
|
|
/**
|
|
|
|
* Ignore blocked messages completely
|
|
|
|
*/
|
2018-08-25 15:02:42 +02:00
|
|
|
processMessage(that, args, originalFunction) {
|
|
|
|
if (args[1] && args[1].author && args[1].author.id && BlockedMessages.isBlocked(args[1].author.id)) return;
|
|
|
|
return originalFunction(...args);
|
|
|
|
}
|
|
|
|
|
2018-08-21 05:42:34 +02:00
|
|
|
}
|