BetterDiscordAddons/Plugins/RemoveBlockedUsers/RemoveBlockedUsers.plugin.js

492 lines
26 KiB
JavaScript
Raw Normal View History

2020-10-20 23:25:34 +02:00
/**
2021-07-11 18:46:40 +02:00
* @name RemoveBlockedUsers
2021-03-05 13:26:41 +01:00
* @author DevilBro
2020-10-20 23:25:34 +02:00
* @authorId 278543574059057154
2022-03-10 16:01:50 +01:00
* @version 1.4.0
2021-03-05 13:26:41 +01:00
* @description Removes blocked Messages/Users
2020-10-20 23:25:34 +02:00
* @invite Jx3TjNS
* @donate https://www.paypal.me/MircoWittrien
* @patreon https://www.patreon.com/MircoWittrien
2021-03-09 15:10:55 +01:00
* @website https://mwittrien.github.io/
2021-07-11 18:46:40 +02:00
* @source https://github.com/mwittrien/BetterDiscordAddons/tree/master/Plugins/RemoveBlockedUsers/
* @updateUrl https://mwittrien.github.io/BetterDiscordAddons/Plugins/RemoveBlockedUsers/RemoveBlockedUsers.plugin.js
2020-10-20 23:25:34 +02:00
*/
2020-02-04 10:22:02 +01:00
2020-09-19 20:49:33 +02:00
module.exports = (_ => {
2020-10-09 21:09:35 +02:00
const config = {
2020-09-19 20:49:33 +02:00
"info": {
2021-07-11 18:46:40 +02:00
"name": "RemoveBlockedUsers",
2020-09-19 20:49:33 +02:00
"author": "DevilBro",
2022-03-10 16:01:50 +01:00
"version": "1.4.0",
2021-03-05 11:21:21 +01:00
"description": "Removes blocked Messages/Users"
2021-11-24 01:03:16 +01:00
},
"changeLog": {
"fixed": {
2022-03-10 16:01:50 +01:00
"Offline List": "Fixed Issue where switching between servers would remove more and more users from the offline list if someone was blocked"
2021-11-24 01:03:16 +01:00
}
2020-02-04 10:22:02 +01:00
}
2020-09-19 20:49:33 +02:00
};
2020-11-13 19:47:44 +01:00
2022-02-05 21:14:17 +01:00
return !window.BDFDB_Global || (!window.BDFDB_Global.loaded && !window.BDFDB_Global.started) ? class {
2021-01-06 12:38:36 +01:00
getName () {return config.info.name;}
getAuthor () {return config.info.author;}
getVersion () {return config.info.version;}
2021-02-01 17:13:13 +01:00
getDescription () {return `The Library Plugin needed for ${config.info.name} is missing. Open the Plugin Settings to download it. \n\n${config.info.description}`;}
downloadLibrary () {
require("request").get("https://mwittrien.github.io/BetterDiscordAddons/Library/0BDFDB.plugin.js", (e, r, b) => {
2021-03-05 13:14:18 +01:00
if (!e && b && r.statusCode == 200) require("fs").writeFile(require("path").join(BdApi.Plugins.folder, "0BDFDB.plugin.js"), b, _ => BdApi.showToast("Finished downloading BDFDB Library", {type: "success"}));
2021-03-06 14:59:48 +01:00
else BdApi.alert("Error", "Could not download BDFDB Library Plugin. Try again later or download it manually from GitHub: https://mwittrien.github.io/downloader/?library");
2021-02-01 17:13:13 +01:00
});
}
2020-09-19 20:49:33 +02:00
2021-01-06 12:38:36 +01:00
load () {
2020-11-19 16:51:14 +01:00
if (!window.BDFDB_Global || !Array.isArray(window.BDFDB_Global.pluginQueue)) window.BDFDB_Global = Object.assign({}, window.BDFDB_Global, {pluginQueue: []});
2020-09-19 20:49:33 +02:00
if (!window.BDFDB_Global.downloadModal) {
window.BDFDB_Global.downloadModal = true;
2021-01-14 16:14:44 +01:00
BdApi.showConfirmationModal("Library Missing", `The Library Plugin needed for ${config.info.name} is missing. Please click "Download Now" to install it.`, {
2020-09-19 20:49:33 +02:00
confirmText: "Download Now",
cancelText: "Cancel",
onCancel: _ => {delete window.BDFDB_Global.downloadModal;},
2020-09-20 08:15:13 +02:00
onConfirm: _ => {
delete window.BDFDB_Global.downloadModal;
2021-02-01 17:13:13 +01:00
this.downloadLibrary();
2020-09-20 08:15:13 +02:00
}
2020-09-19 20:49:33 +02:00
});
2020-02-04 10:22:02 +01:00
}
2020-09-19 20:49:33 +02:00
if (!window.BDFDB_Global.pluginQueue.includes(config.info.name)) window.BDFDB_Global.pluginQueue.push(config.info.name);
2020-10-09 21:09:35 +02:00
}
2021-01-06 12:38:36 +01:00
start () {this.load();}
stop () {}
getSettingsPanel () {
2020-11-28 23:12:09 +01:00
let template = document.createElement("template");
2021-01-14 16:14:44 +01:00
template.innerHTML = `<div style="color: var(--header-primary); font-size: 16px; font-weight: 300; white-space: pre; line-height: 22px;">The Library Plugin needed for ${config.info.name} is missing.\nPlease click <a style="font-weight: 500;">Download Now</a> to install it.</div>`;
2021-02-01 17:13:13 +01:00
template.content.firstElementChild.querySelector("a").addEventListener("click", this.downloadLibrary);
2020-11-28 23:12:09 +01:00
return template.content.firstElementChild;
}
2020-10-09 21:09:35 +02:00
} : (([Plugin, BDFDB]) => {
2021-01-10 14:10:06 +01:00
var cachedChannelId, cachedReactions;
2020-10-06 09:40:54 +02:00
2021-07-11 18:46:40 +02:00
return class RemoveBlockedUsers extends Plugin {
2021-01-06 12:38:36 +01:00
onLoad () {
2020-11-28 20:27:04 +01:00
this.defaults = {
2021-05-04 19:33:36 +02:00
notifcations: {
messages: {value: true, description: "Messages Notifications"},
voiceChat: {value: true, description: "Voice Chat Notifications"},
},
places: {
messages: {value: true, description: "Messages"},
pins: {value: true, description: "Pinned Messages"},
inbox: {value: true, description: "Inbox Messages"},
replies: {value: true, description: "Replies"},
mentions: {value: true, description: "Mentions"},
reactions: {value: true, description: "Reactions"},
autocompletes: {value: true, description: "Autocomplete Entries"},
memberList: {value: true, description: "Members in List"},
voiceList: {value: true, description: "Members in Voice List"},
2021-06-09 17:52:32 +02:00
voiceChat: {value: true, description: "Members in Voice Chat"},
channelList: {value: true, description: "Channel/Group List"},
recentDms: {value: true, description: "Group Notifications"}
2020-11-28 20:27:04 +01:00
}
};
2020-09-19 20:49:33 +02:00
this.patchedModules = {
2020-10-06 09:40:54 +02:00
before: {
Message: "default",
2020-10-29 00:15:33 +01:00
ReactorsComponent: "render",
2020-10-15 14:34:57 +02:00
ChannelMembers: "render",
2020-10-15 19:14:17 +02:00
PrivateChannelRecipients: "default",
2020-10-06 09:40:54 +02:00
VoiceUsers: "render",
2020-10-15 19:14:17 +02:00
PrivateChannel: "render",
2020-10-06 09:40:54 +02:00
PrivateChannelCallParticipants: "render",
ChannelCall: "render",
UserSummaryItem: "render"
},
2020-09-19 20:49:33 +02:00
after: {
2020-11-20 16:52:10 +01:00
ChannelPins: "default",
RecentMentions: "default",
2020-10-06 09:40:54 +02:00
Messages: "type",
2021-01-10 14:10:06 +01:00
Reactions: "render",
2020-10-06 09:40:54 +02:00
MemberListItem: "render",
2020-10-15 19:14:17 +02:00
VoiceUser: "render",
2021-06-09 17:52:32 +02:00
DirectMessage: "render",
PrivateChannel: "render",
2021-02-24 17:32:17 +01:00
UserMention: "default",
RichUserMention: "UserMention"
2020-09-19 20:49:33 +02:00
}
};
2020-10-15 19:14:17 +02:00
2020-11-13 21:25:46 +01:00
this.patchPriority = 8;
2020-02-04 10:22:02 +01:00
}
2020-09-19 20:49:33 +02:00
2021-01-06 12:38:36 +01:00
onStart () {
2021-06-09 17:52:32 +02:00
BDFDB.PatchUtils.patch(this, BDFDB.LibraryModules.ChannelStore, "getChannel", {after: e => {
if (e.returnValue && e.returnValue.isGroupDM()) return new BDFDB.DiscordObjects.Channel(Object.assign({}, e.returnValue, {rawRecipients: e.returnValue.rawRecipients.filter(n => !n || !BDFDB.LibraryModules.RelationshipStore.isBlocked(n.id)), recipients: e.returnValue.recipients.filter(id => !id || !BDFDB.LibraryModules.RelationshipStore.isBlocked(id))}))
}});
2021-03-15 14:03:32 +01:00
BDFDB.PatchUtils.patch(this, BDFDB.LibraryModules.RelationshipUtils, "addRelationship", {after: e => {
if (e.methodArguments[2] == BDFDB.DiscordConstants.RelationshipTypes.BLOCKED) this.forceUpdateAll();
}});
BDFDB.PatchUtils.patch(this, BDFDB.LibraryModules.RelationshipUtils, "removeRelationship", {after: e => this.forceUpdateAll()});
2021-05-04 19:33:36 +02:00
BDFDB.PatchUtils.patch(this, BDFDB.LibraryModules.UnreadChannelUtils, "getUnreadCount", {after: e => {
if (e.returnValue && this.settings.notifcations.messages && e.returnValue < BDFDB.DiscordConstants.MAX_MESSAGES_PER_CHANNEL) {
let sub = 0, messages = [].concat(BDFDB.LibraryModules.MessageStore.getMessages(e.methodArguments[0])._array).reverse();
for (let i = 0; i < e.returnValue; i++) if (messages[i] && messages[i].blocked) sub++;
e.returnValue -= sub;
}
}});
2020-09-29 08:10:01 +02:00
BDFDB.PatchUtils.patch(this, BDFDB.LibraryModules.UnreadChannelUtils, "hasUnread", {after: e => {
2021-05-04 19:33:36 +02:00
if (e.returnValue && this.settings.notifcations.messages) {
2020-09-29 08:10:01 +02:00
let count = BDFDB.LibraryModules.UnreadChannelUtils.getUnreadCount(e.methodArguments[0]);
2021-12-22 22:09:03 +01:00
if (count > 0 && count < BDFDB.DiscordConstants.MAX_MESSAGES_PER_CHANNEL) {
2020-09-29 08:10:01 +02:00
let id = BDFDB.LibraryModules.UnreadChannelUtils.lastMessageId(e.methodArguments[0]);
let message = id && BDFDB.LibraryModules.MessageStore.getMessage(e.methodArguments[0], id);
if (message && message.blocked) {
let oldestId = BDFDB.LibraryModules.UnreadChannelUtils.getOldestUnreadMessageId(e.methodArguments[0]);
let messages = BDFDB.LibraryModules.MessageStore.getMessages(e.methodArguments[0]);
if (messages && oldestId) {
let index = messages._array.indexOf(messages._array.find(c => c.id == oldestId));
if (index > -1) return messages._array.slice(index).some(c => !c.blocked);
}
}
}
}
}});
2021-08-09 17:01:11 +02:00
BDFDB.PatchUtils.patch(this, BDFDB.LibraryModules.UnreadGuildUtils, "hasUnread", {after: e => {
2021-05-04 19:33:36 +02:00
if (e.returnValue && this.settings.notifcations.messages) {
2021-12-29 14:41:11 +01:00
return BDFDB.LibraryModules.GuildChannelStore.getChannels(e.methodArguments[0]).SELECTABLE.map(n => n.channel && n.channel.id).filter(n => n && n != "null").some(id => BDFDB.LibraryModules.UnreadChannelUtils.hasUnread(id));
2020-09-29 08:10:01 +02:00
}
}});
2020-09-29 08:10:27 +02:00
2020-10-15 19:14:17 +02:00
if (BDFDB.LibraryModules.AutocompleteOptions && BDFDB.LibraryModules.AutocompleteOptions.AUTOCOMPLETE_OPTIONS) BDFDB.PatchUtils.patch(this, BDFDB.LibraryModules.AutocompleteOptions.AUTOCOMPLETE_OPTIONS.MENTIONS, "queryResults", {after: e => {
2021-07-05 16:41:47 +02:00
if (this.settings.places.autocompletes && e.returnValue.results && e.returnValue.results.users) e.returnValue.results.users = e.returnValue.results.users.filter(n => !n.user || !BDFDB.LibraryModules.RelationshipStore.isBlocked(n.user.id));
2020-10-15 19:14:17 +02:00
}});
2020-11-13 21:25:46 +01:00
let muteTimeout;
let channelId = BDFDB.LibraryModules.CurrentVoiceUtils.getChannelId();
2021-03-15 13:52:24 +01:00
let connectedUsers = BDFDB.ObjectUtils.filter(BDFDB.LibraryModules.VoiceUtils.getVoiceStates(BDFDB.LibraryModules.CurrentVoiceUtils.getGuildId()), n => n && n.channelId == channelId && !BDFDB.LibraryModules.RelationshipStore.isBlocked(n.userId));
2020-11-13 21:25:46 +01:00
BDFDB.PatchUtils.patch(this, BDFDB.LibraryModules.SoundUtils, "playSound", {instead: e => {
let type = e.methodArguments[0];
2021-05-04 19:33:36 +02:00
if (this.settings.notifcations.voiceChat && type == "user_join" || type == "user_leave" || type == "user_moved") {
2020-11-13 21:25:46 +01:00
channelId = BDFDB.LibraryModules.CurrentVoiceUtils.getChannelId();
2020-11-21 17:58:52 +01:00
if (channelId) {
let allConnectedUsers = BDFDB.ObjectUtils.filter(BDFDB.LibraryModules.VoiceUtils.getVoiceStates(BDFDB.LibraryModules.CurrentVoiceUtils.getGuildId()), n => n && n.channelId == channelId);
2021-03-15 13:52:24 +01:00
let unblockedUsers = BDFDB.ObjectUtils.filter(allConnectedUsers, n => n && !BDFDB.LibraryModules.RelationshipStore.isBlocked(n.userId));
let unmutedBlockedUsers = BDFDB.ObjectUtils.toArray(allConnectedUsers).filter(n => n && BDFDB.LibraryModules.RelationshipStore.isBlocked(n.userId) && !BDFDB.LibraryModules.MediaDeviceUtils.isLocalMute(n.userId));
2020-11-21 17:58:52 +01:00
if (unmutedBlockedUsers.length) {
BDFDB.TimeUtils.clear(muteTimeout);
muteTimeout = BDFDB.TimeUtils.timeout(_ => {
while (unmutedBlockedUsers.length) BDFDB.LibraryModules.MediaDeviceSetUtils.toggleLocalMute(unmutedBlockedUsers.pop().userId);
}, 1000);
}
if (Object.keys(unblockedUsers).length == Object.keys(connectedUsers).length) {
e.stopOriginalMethodCall();
e.methodArguments[0] = null;
}
else e.callOriginalMethodAfterwards();
connectedUsers = unblockedUsers;
2020-11-13 21:25:46 +01:00
}
2020-11-16 17:02:03 +01:00
else e.callOriginalMethodAfterwards();
2020-11-13 21:25:46 +01:00
}
else e.callOriginalMethodAfterwards();
}});
2020-10-06 09:40:54 +02:00
this.forceUpdateAll();
2020-09-19 20:49:33 +02:00
}
2021-01-06 12:38:36 +01:00
onStop () {
2020-10-06 09:40:54 +02:00
this.forceUpdateAll();
}
getSettingsPanel (collapseStates = {}) {
2021-05-04 19:33:36 +02:00
let settingsPanel;
return settingsPanel = BDFDB.PluginUtils.createSettingsPanel(this, {
collapseStates: collapseStates,
children: _ => {
let settingsItems = [];
settingsItems.push(BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.SettingsPanelList, {
title: "Disable",
children: Object.keys(this.defaults.notifcations).map(key => BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.SettingsSaveItem, {
type: "Switch",
plugin: this,
keys: ["notifcations", key],
label: this.defaults.notifcations[key].description,
value: this.settings.notifcations[key]
}))
}));
settingsItems.push(BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.SettingsPanelList, {
title: "Remove",
children: Object.keys(this.defaults.places).map(key => BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.SettingsSaveItem, {
type: "Switch",
plugin: this,
keys: ["places", key],
label: this.defaults.places[key].description,
value: this.settings.places[key]
}))
}));
return settingsItems;
}
});
2020-10-06 09:40:54 +02:00
}
2021-01-06 12:38:36 +01:00
onSettingsClosed () {
2020-10-06 09:40:54 +02:00
if (this.SettingsUpdated) {
delete this.SettingsUpdated;
this.forceUpdateAll();
}
}
2021-05-04 19:33:36 +02:00
forceUpdateAll () {
2020-10-06 09:40:54 +02:00
BDFDB.PatchUtils.forceAllUpdates(this);
2020-08-15 14:24:48 +02:00
BDFDB.MessageUtils.rerenderAll();
2020-02-04 10:22:02 +01:00
}
2020-09-19 20:49:33 +02:00
processMessages (e) {
2021-05-04 19:33:36 +02:00
if (this.settings.places.messages) {
2020-10-06 09:40:54 +02:00
let messagesIns = e.returnvalue.props.children;
if (BDFDB.ArrayUtils.is(messagesIns.props.channelStream)) {
2020-11-13 21:25:46 +01:00
let oldStream = messagesIns.props.channelStream.filter(n => n.type != "MESSAGE_GROUP_BLOCKED"), newStream = [];
2020-10-06 09:40:54 +02:00
for (let i in oldStream) {
let next = parseInt(i)+1;
2020-11-13 21:25:46 +01:00
if (oldStream[i].type != "DIVIDER" || (oldStream[next] && oldStream[i].type == "DIVIDER" && oldStream[next].type != "DIVIDER" && oldStream.slice(next).some(nextStream => nextStream.type != "DIVIDER"))) newStream.push(oldStream[i]);
}
2020-11-17 19:04:03 +01:00
let groupId, author;
2020-11-13 21:25:46 +01:00
for (let i in newStream) {
2021-03-10 09:11:29 +01:00
if (newStream[i].type == "MESSAGE" && (newStream[i].content.type.type == BDFDB.DiscordConstants.MessageTypes.DEFAULT || newStream[i].content.type.type == BDFDB.DiscordConstants.MessageTypes.REPLY) && groupId != newStream[i].groupId) {
2020-11-17 19:04:03 +01:00
if (author && author.id == newStream[i].content.author.id && author.username == newStream[i].content.author.username) newStream[i] = Object.assign({}, newStream[i], {groupId: groupId});
author = newStream[i].content.author;
2020-11-13 21:25:46 +01:00
}
2020-11-17 19:04:03 +01:00
else author = null;;
2020-11-13 21:25:46 +01:00
groupId = newStream[i].groupId;
2020-10-06 09:40:54 +02:00
}
2020-11-13 21:25:46 +01:00
messagesIns.props.channelStream = newStream;
2020-10-06 09:40:54 +02:00
}
if (BDFDB.ObjectUtils.is(messagesIns.props.messages) && BDFDB.ArrayUtils.is(messagesIns.props.messages._array)) {
let messages = messagesIns.props.messages;
messagesIns.props.messages = new BDFDB.DiscordObjects.Messages(messages);
for (let key in messages) messagesIns.props.messages[key] = messages[key];
2021-03-15 13:52:24 +01:00
messagesIns.props.messages._array = [].concat(messagesIns.props.messages._array.filter(n => !n.author || !BDFDB.LibraryModules.RelationshipStore.isBlocked(n.author.id)));
2020-10-06 09:40:54 +02:00
if (messagesIns.props.oldestUnreadMessageId && messagesIns.props.messages._array.every(n => n.id != messagesIns.props.oldestUnreadMessageId)) messagesIns.props.oldestUnreadMessageId = null;
2020-09-19 20:49:33 +02:00
}
2020-09-16 16:20:38 +02:00
}
2020-02-04 10:22:02 +01:00
}
2020-10-06 09:40:54 +02:00
2020-11-21 17:55:42 +01:00
processMessage (e) {
2021-05-04 19:33:36 +02:00
if (this.settings.places.replies) {
2020-11-21 17:55:42 +01:00
let repliedMessage = e.instance.props.childrenRepliedMessage;
2021-03-15 13:52:24 +01:00
if (repliedMessage && repliedMessage.props && repliedMessage.props.children && repliedMessage.props.children.props && repliedMessage.props.children.props.referencedMessage && repliedMessage.props.children.props.referencedMessage.message && repliedMessage.props.children.props.referencedMessage.message.author && BDFDB.LibraryModules.RelationshipStore.isBlocked(repliedMessage.props.children.props.referencedMessage.message.author.id)) {
2020-11-21 17:55:42 +01:00
delete e.instance.props.childrenRepliedMessage;
let header = e.instance.props.childrenHeader;
if (header && header.props) {
delete header.props.referencedMessage;
delete header.props.referencedUsernameProfile;
delete header.props.replyReference;
header.props.message = new BDFDB.DiscordObjects.Message(Object.assign({}, header.props.message, {messageReference: null}));
}
}
}
}
2020-11-20 16:52:10 +01:00
processChannelPins (e) {
2021-05-04 19:33:36 +02:00
if (this.settings.places.pins && e.returnvalue.props && e.returnvalue.props.children && e.returnvalue.props.children.props && BDFDB.ArrayUtils.is(e.returnvalue.props.children.props.messages)) e.returnvalue.props.children.props.messages = e.returnvalue.props.children.props.messages.filter(n => !n || !n.author || !n.author.id || !BDFDB.LibraryModules.RelationshipStore.isBlocked(n.author.id));
2020-11-20 16:52:10 +01:00
}
2020-11-21 17:55:42 +01:00
2020-11-20 16:52:10 +01:00
processRecentMentions (e) {
2021-05-04 19:33:36 +02:00
if (this.settings.places.inbox && BDFDB.ArrayUtils.is(e.returnvalue.props.messages)) e.returnvalue.props.messages = e.returnvalue.props.messages.filter(n => !n || !n.author || !n.author.id || !BDFDB.LibraryModules.RelationshipStore.isBlocked(n.author.id));
2020-10-29 00:15:33 +01:00
}
2021-01-10 14:10:06 +01:00
processReactions (e) {
2022-03-02 19:22:13 +01:00
if (this.settings.places.reactions && e.returnvalue && e.returnvalue.props.children && BDFDB.ArrayUtils.is(e.returnvalue.props.children[0])) {
2021-03-15 13:52:24 +01:00
let updateTimeout, relationshipCount = BDFDB.LibraryModules.RelationshipStore.getRelationshipCount();
2021-01-10 14:10:06 +01:00
if (cachedChannelId != e.instance.props.message.channel_id) {
cachedReactions = {};
cachedChannelId = e.instance.props.message.channel_id;
}
if (!cachedReactions[e.instance.props.message.id]) cachedReactions[e.instance.props.message.id] = {};
for (let i in e.returnvalue.props.children[0]) {
let reaction = e.returnvalue.props.children[0][i];
let emojiId = reaction.props.emoji.name || reaction.props.emoji.id;
2021-06-18 20:33:15 +02:00
let oldCount = (reaction.props.message.reactions.find(n => n.emoji.name && n.emoji.name == emojiId || n.emoji.id == emojiId) || {}).count;
if (oldCount && oldCount < 10) {
if (cachedReactions[reaction.props.message.id][emojiId] && cachedReactions[reaction.props.message.id][emojiId].relationshipCount == relationshipCount && cachedReactions[reaction.props.message.id][emojiId].oldCount == oldCount) {
reaction.props.count = cachedReactions[reaction.props.message.id][emojiId].reactions.length;
if (reaction.props.count < 1) e.returnvalue.props.children[0][i] = null;
2021-02-09 18:56:44 +01:00
}
2021-06-18 20:33:15 +02:00
else BDFDB.LibraryModules.ReactionUtils.getReactions(reaction.props.message.channel_id, reaction.props.message.id, reaction.props.emoji).then(reactions => {
if (!reactions || !reactions.length) return;
let someBlocked = false;
let filteredReactions = reactions.filter(n => {
let isBlocked = n && BDFDB.LibraryModules.RelationshipStore.isBlocked(n.id);
someBlocked = someBlocked || isBlocked;
return !isBlocked;
});
if (someBlocked) {
reaction.props.reactions = filteredReactions;
reaction.props.count = reaction.props.reactions.length;
BDFDB.TimeUtils.clear(updateTimeout);
updateTimeout = BDFDB.TimeUtils.timeout(_ => BDFDB.ReactUtils.forceUpdate(e.instance), 1000);
}
if (cachedReactions && cachedReactions[reaction.props.message.id]) cachedReactions[reaction.props.message.id][emojiId] = {
blocked: someBlocked,
relationshipCount: relationshipCount,
oldCount: oldCount || 0,
reactions: reaction.props.reactions || reactions
};
});
}
2021-01-10 14:10:06 +01:00
}
if (!e.returnvalue.props.children[0].filter(n => n).length) return null;
}
}
2020-10-29 00:15:33 +01:00
processReactorsComponent (e) {
2021-05-04 19:33:36 +02:00
if (this.settings.places.reactions && BDFDB.ArrayUtils.is(e.instance.props.reactors)) e.instance.props.reactors = e.instance.props.reactors.filter(n => !n || !BDFDB.LibraryModules.RelationshipStore.isBlocked(n.id));
2020-10-19 10:38:04 +02:00
}
2020-10-15 14:34:57 +02:00
processChannelMembers (e) {
2021-05-05 06:37:08 +02:00
if (this.settings.places.memberList) {
2022-03-10 16:01:50 +01:00
let hiddenRows = 0, newRows = new Array(e.instance.props.rows.length), newGroups = new Array(e.instance.props.groups.length);
e.instance.props.groups = [].concat(e.instance.props.groups);
e.instance.props.rows = [].concat(e.instance.props.rows);
2020-10-15 14:34:57 +02:00
for (let i in e.instance.props.rows) {
let row = e.instance.props.rows[i];
2021-11-24 01:03:16 +01:00
if (!row || row.type != "MEMBER") newRows[i] = row;
else if (!row.user || !BDFDB.LibraryModules.RelationshipStore.isBlocked(row.user.id)) newRows[i] = row;
2020-10-15 14:34:57 +02:00
else {
2022-03-10 16:01:50 +01:00
hiddenRows++;
2020-10-17 14:47:13 +02:00
let found = false, rowIndex = i - 1;
while (!found && rowIndex > -1) {
if (newRows[rowIndex] && newRows[rowIndex].type == "GROUP") {
2020-10-15 14:34:57 +02:00
found = true;
2020-10-17 14:47:13 +02:00
let groupIndex = e.instance.props.groups.findIndex(r => r.id == newRows[rowIndex].id);
2020-11-25 19:19:30 +01:00
if (groupIndex > -1) {
2020-10-17 14:47:13 +02:00
e.instance.props.groups[groupIndex] = Object.assign({}, e.instance.props.groups[groupIndex], {count: e.instance.props.groups[groupIndex].count - 1});
newRows[rowIndex] = Object.assign({}, newRows[rowIndex], {count: e.instance.props.groups[groupIndex].count});
}
2020-10-15 14:34:57 +02:00
}
2020-10-17 14:47:13 +02:00
else rowIndex--;
2020-10-15 14:34:57 +02:00
}
}
}
2022-03-10 16:01:50 +01:00
if (hiddenRows) {
2022-03-02 19:22:13 +01:00
let indexSum = 0;
for (let i in e.instance.props.groups) {
newGroups[i] = Object.assign({}, e.instance.props.groups[i], {index: indexSum});
if (e.instance.props.groups[i].count > 0) indexSum += (e.instance.props.groups[i].count + 1);
}
for (let i in newRows) if (newRows[i] && newRows[i].type == "GROUP" && newRows[i].count <= 0) {
2022-03-10 16:01:50 +01:00
hiddenRows++;
2022-03-02 19:22:13 +01:00
newRows[i] = undefined;
}
const removeEmptyWithin = (array, filter) => {
let reversed = [].concat(array).reverse();
let prefixLength = 0, suffixLength = 0;
for (let i in array) if (array[i] !== undefined) {
prefixLength = parseInt(i);
break;
}
for (let i in reversed) if (reversed[i] !== undefined) {
suffixLength = parseInt(i);
break;
}
return [].concat(new Array(prefixLength), array.filter(filter), new Array(suffixLength))
};
e.instance.props.rows = removeEmptyWithin(newRows, n => n);
e.instance.props.groups = removeEmptyWithin(newGroups, g => g && g.count > 0);
2020-10-15 14:34:57 +02:00
}
}
2020-10-06 09:40:54 +02:00
}
2020-10-15 14:34:57 +02:00
2020-10-15 19:14:17 +02:00
processPrivateChannelRecipients (e) {
2021-05-04 19:33:36 +02:00
if (this.settings.places.voiceChat && e.instance.props.channel && e.instance.props.channel.isGroupDM()) e.instance.props.channel = new BDFDB.DiscordObjects.Channel(Object.assign({}, e.instance.props.channel, {rawRecipients: e.instance.props.channel.rawRecipients.filter(n => !n || !BDFDB.LibraryModules.RelationshipStore.isBlocked(n.id)), recipients: e.instance.props.channel.recipients.filter(id => !id || !BDFDB.LibraryModules.RelationshipStore.isBlocked(id))}));
2020-10-15 19:14:17 +02:00
}
2020-10-15 14:34:57 +02:00
processMemberListItem (e) {
2021-05-05 06:37:08 +02:00
if (this.settings.places.memberList && e.instance.props.user && BDFDB.LibraryModules.RelationshipStore.isBlocked(e.instance.props.user.id)) return null;
2020-10-06 09:40:54 +02:00
}
processVoiceUsers (e) {
2021-05-04 19:33:36 +02:00
if (this.settings.places.voiceList && BDFDB.ArrayUtils.is(e.instance.props.voiceStates)) e.instance.props.voiceStates = [].concat(e.instance.props.voiceStates).filter(n => !n.user || !BDFDB.LibraryModules.RelationshipStore.isBlocked(n.user.id));
2020-10-06 09:40:54 +02:00
}
2020-10-15 14:34:57 +02:00
processVoiceUser (e) {
2021-05-04 19:33:36 +02:00
if (this.settings.places.voiceList && e.instance.props.user && BDFDB.LibraryModules.RelationshipStore.isBlocked(e.instance.props.user.id)) return null;
2020-10-15 14:34:57 +02:00
}
2020-10-06 09:40:54 +02:00
2021-06-09 17:52:32 +02:00
processDirectMessage (e) {
if (e.instance.props.channel && !e.instance.props.channel.name && e.instance.props.channel.isGroupDM() && this.settings.places.recentDms) {
let tooltip = BDFDB.ReactUtils.findChild(e.returnvalue, {name: "ListItemTooltip"});
if (tooltip) tooltip.props.text = this.getGroupName(e.instance.props.channel.id);
}
}
2020-10-15 19:14:17 +02:00
processPrivateChannel (e) {
2021-06-09 17:52:32 +02:00
if (this.settings.places.channelList && e.instance.props.channel && e.instance.props.channel.isGroupDM()) {
if (!e.returnvalue) {
e.instance.props.channel = new BDFDB.DiscordObjects.Channel(Object.assign({}, e.instance.props.channel, {rawRecipients: e.instance.props.channel.rawRecipients.filter(n => !n || !BDFDB.LibraryModules.RelationshipStore.isBlocked(n.id)), recipients: e.instance.props.channel.recipients.filter(id => !id || !BDFDB.LibraryModules.RelationshipStore.isBlocked(id))}));
}
else {
2021-11-12 16:30:05 +01:00
if (!e.instance.props.channel.name) {
2022-02-25 16:12:53 +01:00
let wrapper = e.returnvalue && e.returnvalue.props.children && e.returnvalue.props.children.props && typeof e.returnvalue.props.children.props.children == "function" ? e.returnvalue.props.children : e.returnvalue;
if (typeof wrapper.props.children == "function") {
let childrenRender = wrapper.props.children;
wrapper.props.children = BDFDB.TimeUtils.suppress((...args) => {
2021-11-12 16:30:05 +01:00
let children = childrenRender(...args);
children.props.name = BDFDB.ReactUtils.createElement("span", {children: this.getGroupName(e.instance.props.channel.id)});
return children;
}, "", this);
}
2022-02-25 16:12:53 +01:00
else wrapper.props.name = BDFDB.ReactUtils.createElement("span", {children: this.getGroupName(e.instance.props.channel.id)});
2021-11-12 16:30:05 +01:00
}
2021-06-09 17:52:32 +02:00
}
}
2020-10-15 19:14:17 +02:00
}
2020-10-06 09:40:54 +02:00
processPrivateChannelCallParticipants (e) {
2021-07-19 09:00:02 +02:00
if (this.settings.places.voiceChat) {
if (BDFDB.ArrayUtils.is(e.instance.props.participants)) e.instance.props.participants = [].concat(e.instance.props.participants).filter(n => !n.user || !BDFDB.LibraryModules.RelationshipStore.isBlocked(n.user.id));
if (BDFDB.ArrayUtils.is(e.instance.props.filteredParticipants)) e.instance.props.filteredParticipants = [].concat(e.instance.props.filteredParticipants).filter(n => !n.user || !BDFDB.LibraryModules.RelationshipStore.isBlocked(n.user.id));
}
2020-10-06 09:40:54 +02:00
}
processChannelCall (e) {
2021-07-19 09:00:02 +02:00
if (this.settings.places.voiceChat) {
if (BDFDB.ArrayUtils.is(e.instance.props.participants)) e.instance.props.participants = [].concat(e.instance.props.participants).filter(n => !n.user || !BDFDB.LibraryModules.RelationshipStore.isBlocked(n.user.id));
if (BDFDB.ArrayUtils.is(e.instance.props.filteredParticipants)) e.instance.props.filteredParticipants = [].concat(e.instance.props.filteredParticipants).filter(n => !n.user || !BDFDB.LibraryModules.RelationshipStore.isBlocked(n.user.id));
}
2020-10-06 09:40:54 +02:00
}
processUserSummaryItem (e) {
2021-05-05 06:37:08 +02:00
if (this.settings.places.memberList && BDFDB.ArrayUtils.is(e.instance.props.users)) e.instance.props.users = [].concat(e.instance.props.users).filter(n => !n || !BDFDB.LibraryModules.RelationshipStore.isBlocked(n.id));
2020-10-06 09:40:54 +02:00
}
2020-10-15 19:14:17 +02:00
2021-02-24 17:32:17 +01:00
processUserMention (e) {
2021-05-04 19:33:36 +02:00
if (e.instance.props.userId && this.settings.places.mentions && BDFDB.LibraryModules.RelationshipStore.isBlocked(e.instance.props.userId)) return BDFDB.ReactUtils.createElement("span", {
2021-02-24 17:32:17 +01:00
className: BDFDB.DOMUtils.formatClassName(BDFDB.disCN.mention, BDFDB.disCN.mentionwrapper, e.instance.props.className),
children: ["@" + BDFDB.LanguageUtils.LanguageStrings.UNKNOWN_USER]
});
}
processRichUserMention (e) {
2021-05-04 19:33:36 +02:00
if (e.instance.props.id && this.settings.places.mentions && BDFDB.LibraryModules.RelationshipStore.isBlocked(e.instance.props.id)) return BDFDB.ReactUtils.createElement("span", {
2021-02-24 17:32:17 +01:00
className: BDFDB.DOMUtils.formatClassName(BDFDB.disCN.mention, BDFDB.disCN.mentionwrapper, e.instance.props.className),
2021-01-10 14:10:06 +01:00
children: ["@" + BDFDB.LanguageUtils.LanguageStrings.UNKNOWN_USER]
2020-10-15 19:14:17 +02:00
});
}
2021-06-09 17:52:32 +02:00
getGroupName (channelId) {
let channel = BDFDB.LibraryModules.ChannelStore.getChannel(channelId);
if (channel.name) return channel.name;
let recipients = channel.recipients.map(BDFDB.LibraryModules.UserStore.getUser).filter(n => n && !BDFDB.LibraryModules.RelationshipStore.isBlocked(n.id));
return recipients.length > 0 ? recipients.map(u => u.toString()).join(", ") : BDFDB.LanguageUtils.LanguageStrings.UNNAMED;
}
2020-09-19 20:49:33 +02:00
};
2020-10-09 21:09:35 +02:00
})(window.BDFDB_Global.PluginUtils.buildPlugin(config));
2021-02-07 22:48:32 +01:00
})();