Skip to content

Commit

Permalink
fix(GuildChannel): improve empty overwrite handling for permissionsLo…
Browse files Browse the repository at this point in the history
…cked (#5821)
  • Loading branch information
MattIPv4 authored Jun 11, 2021
1 parent 9e5106d commit 6df3623
Showing 1 changed file with 26 additions and 6 deletions.
32 changes: 26 additions & 6 deletions src/structures/GuildChannel.js
Original file line number Diff line number Diff line change
Expand Up @@ -95,13 +95,33 @@ class GuildChannel extends Channel {
*/
get permissionsLocked() {
if (!this.parent) return null;
if (this.permissionOverwrites.size !== this.parent.permissionOverwrites.size) return false;
return this.permissionOverwrites.every((value, key) => {
const testVal = this.parent.permissionOverwrites.get(key);

// Get all overwrites
const overwriteIds = new Set([...this.permissionOverwrites.keys(), ...this.parent.permissionOverwrites.keys()]);

// Compare all overwrites
return [...overwriteIds].every(key => {
const channelVal = this.permissionOverwrites.get(key);
const parentVal = this.parent.permissionOverwrites.get(key);

// Handle empty overwrite
if (
(channelVal === undefined &&
parentVal.deny.bitfield === Permissions.defaultBit &&
parentVal.allow.bitfield === Permissions.defaultBit) ||
(parentVal === undefined &&
channelVal.deny.bitfield === Permissions.defaultBit &&
channelVal.allow.bitfield === Permissions.defaultBit)
) {
return true;
}

// Compare overwrites
return (
testVal !== undefined &&
testVal.deny.bitfield === value.deny.bitfield &&
testVal.allow.bitfield === value.allow.bitfield
channelVal !== undefined &&
parentVal !== undefined &&
channelVal.deny.bitfield === parentVal.deny.bitfield &&
channelVal.allow.bitfield === parentVal.allow.bitfield
);
});
}
Expand Down

0 comments on commit 6df3623

Please sign in to comment.