Update RemoveBlockedMessages.plugin.js

This commit is contained in:
Mirco Wittrien 2020-10-15 14:34:57 +02:00
parent 494e52bbeb
commit 31dff42d93
1 changed files with 39 additions and 11 deletions

View File

@ -5,15 +5,13 @@ module.exports = (_ => {
"info": { "info": {
"name": "RemoveBlockedMessages", "name": "RemoveBlockedMessages",
"author": "DevilBro", "author": "DevilBro",
"version": "1.0.7", "version": "1.0.8",
"description": "Completely removes blocked messages." "description": "Completely removes blocked messages."
}, },
"changeLog": { "changeLog": {
"added": { "fixed": {
"Hide Users": "Added option to hide blocked users completely (hide them in memberlist, channelist, calls)" "Hide Users": "Also hides user icons in the voice channel overview",
}, "Role Group Count": "Fixes role group count for hidden banned users"
"improved": {
"Settings": "You can now disable certain features of the plugin"
} }
} }
}; };
@ -59,6 +57,7 @@ module.exports = (_ => {
this.patchedModules = { this.patchedModules = {
before: { before: {
ChannelMembers: "render",
VoiceUsers: "render", VoiceUsers: "render",
PrivateChannelCallParticipants: "render", PrivateChannelCallParticipants: "render",
ChannelCall: "render", ChannelCall: "render",
@ -153,11 +152,36 @@ module.exports = (_ => {
} }
} }
processMemberListItem (e) { processChannelMembers (e) {
if (settings.removeUsers && e.instance.props.user && BDFDB.LibraryModules.FriendUtils.isBlocked(e.instance.props.user.id)) return null; if (settings.removeUsers) {
e.instance.props.groups = [].concat(e.instance.props.groups);
let newRows = [];
for (let i in e.instance.props.rows) {
let row = e.instance.props.rows[i];
if (row.type != "MEMBER") newRows.push(row);
else if (!row.user || !BDFDB.LibraryModules.FriendUtils.isBlocked(row.user.id)) newRows.push(row);
else {
let found = false, checkIndex = i - 1;
while (!found && checkIndex > -1) {
if (newRows[checkIndex].type == "GROUP") {
found = true;
newRows[checkIndex] = Object.assign({}, newRows[checkIndex], {count: newRows[checkIndex].count - 1});
}
else checkIndex--;
}
}
}
let indexSum = 0;
for (let i in e.instance.props.groups) {
let row = newRows.find(r => r.type == "GROUP" && r.id == e.instance.props.groups[i].id);
e.instance.props.groups[i] = Object.assign({}, e.instance.props.groups[i], {index: indexSum, count: row ? row.count : e.instance.props.groups[i].count});
indexSum += (e.instance.props.groups[i].count + 1);
}
e.instance.props.rows = newRows;
}
} }
processVoiceUser (e) { processMemberListItem (e) {
if (settings.removeUsers && e.instance.props.user && BDFDB.LibraryModules.FriendUtils.isBlocked(e.instance.props.user.id)) return null; if (settings.removeUsers && e.instance.props.user && BDFDB.LibraryModules.FriendUtils.isBlocked(e.instance.props.user.id)) return null;
} }
@ -165,6 +189,10 @@ module.exports = (_ => {
if (settings.removeUsers && BDFDB.ArrayUtils.is(e.instance.props.voiceStates)) e.instance.props.voiceStates = [].concat(e.instance.props.voiceStates).filter(n => !n.user || !BDFDB.LibraryModules.FriendUtils.isBlocked(n.user.id)); if (settings.removeUsers && BDFDB.ArrayUtils.is(e.instance.props.voiceStates)) e.instance.props.voiceStates = [].concat(e.instance.props.voiceStates).filter(n => !n.user || !BDFDB.LibraryModules.FriendUtils.isBlocked(n.user.id));
} }
processVoiceUser (e) {
if (settings.removeUsers && e.instance.props.user && BDFDB.LibraryModules.FriendUtils.isBlocked(e.instance.props.user.id)) return null;
}
processPrivateChannelCallParticipants (e) { processPrivateChannelCallParticipants (e) {
if (settings.removeUsers && BDFDB.ArrayUtils.is(e.instance.props.participants)) e.instance.props.participants = [].concat(e.instance.props.participants).filter(n => !n.user || !BDFDB.LibraryModules.FriendUtils.isBlocked(n.user.id)); if (settings.removeUsers && BDFDB.ArrayUtils.is(e.instance.props.participants)) e.instance.props.participants = [].concat(e.instance.props.participants).filter(n => !n.user || !BDFDB.LibraryModules.FriendUtils.isBlocked(n.user.id));
} }
@ -174,7 +202,7 @@ module.exports = (_ => {
} }
processUserSummaryItem (e) { processUserSummaryItem (e) {
if (settings.removeUsers && BDFDB.ArrayUtils.is(e.instance.props.users)) e.instance.props.users = [].concat(e.instance.props.users).filter(n => !n.user || !BDFDB.LibraryModules.FriendUtils.isBlocked(n.user.id)); if (settings.removeUsers && BDFDB.ArrayUtils.is(e.instance.props.users)) e.instance.props.users = [].concat(e.instance.props.users).filter(n => !n || !BDFDB.LibraryModules.FriendUtils.isBlocked(n.id));
} }
}; };
})(window.BDFDB_Global.PluginUtils.buildPlugin(config)); })(window.BDFDB_Global.PluginUtils.buildPlugin(config));