fix: don't patch missing properties from partial payloads (#5796)

* fix: don't patch missing properties from partial payloads

* fix(GuildChannel): initialize permissionOverwrites in the constructor

* refactor(GuildChannel): remove redundant if
This commit is contained in:
SpaceEEC
2021-06-10 18:42:45 +02:00
committed by GitHub
parent ffabec3a5e
commit 097c7b9cdd
5 changed files with 87 additions and 64 deletions

View File

@@ -35,35 +35,44 @@ class GuildChannel extends Channel {
* @type {Guild}
*/
this.guild = guild;
this.parentID = null;
this.permissionOverwrites = new Collection();
}
_patch(data) {
super._patch(data);
/**
* The name of the guild channel
* @type {string}
*/
this.name = data.name;
if ('name' in data) {
/**
* The name of the guild channel
* @type {string}
*/
this.name = data.name;
}
/**
* The raw position of the channel from discord
* @type {number}
*/
this.rawPosition = data.position;
if ('position' in data) {
/**
* The raw position of the channel from discord
* @type {number}
*/
this.rawPosition = data.position;
}
/**
* The ID of the category parent of this channel
* @type {?Snowflake}
*/
this.parentID = data.parent_id || null;
if ('parent_id' in data) {
/**
* The ID of the category parent of this channel
* @type {?Snowflake}
*/
this.parentID = data.parent_id;
}
/**
* A map of permission overwrites in this channel for roles and users
* @type {Collection<Snowflake, PermissionOverwrites>}
*/
this.permissionOverwrites = new Collection();
if (data.permission_overwrites) {
if ('permission_overwrites' in data) {
/**
* A map of permission overwrites in this channel for roles and users
* @type {Collection<Snowflake, PermissionOverwrites>}
*/
this.permissionOverwrites = new Collection();
for (const overwrite of data.permission_overwrites) {
this.permissionOverwrites.set(overwrite.id, new PermissionOverwrites(this, overwrite));
}