mirror of
https://github.com/discordjs/discord.js.git
synced 2026-03-16 11:33:30 +01:00
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:
@@ -35,35 +35,44 @@ class GuildChannel extends Channel {
|
|||||||
* @type {Guild}
|
* @type {Guild}
|
||||||
*/
|
*/
|
||||||
this.guild = guild;
|
this.guild = guild;
|
||||||
|
|
||||||
|
this.parentID = null;
|
||||||
|
this.permissionOverwrites = new Collection();
|
||||||
}
|
}
|
||||||
|
|
||||||
_patch(data) {
|
_patch(data) {
|
||||||
super._patch(data);
|
super._patch(data);
|
||||||
|
|
||||||
/**
|
if ('name' in data) {
|
||||||
* The name of the guild channel
|
/**
|
||||||
* @type {string}
|
* The name of the guild channel
|
||||||
*/
|
* @type {string}
|
||||||
this.name = data.name;
|
*/
|
||||||
|
this.name = data.name;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
if ('position' in data) {
|
||||||
* The raw position of the channel from discord
|
/**
|
||||||
* @type {number}
|
* The raw position of the channel from discord
|
||||||
*/
|
* @type {number}
|
||||||
this.rawPosition = data.position;
|
*/
|
||||||
|
this.rawPosition = data.position;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
if ('parent_id' in data) {
|
||||||
* The ID of the category parent of this channel
|
/**
|
||||||
* @type {?Snowflake}
|
* The ID of the category parent of this channel
|
||||||
*/
|
* @type {?Snowflake}
|
||||||
this.parentID = data.parent_id || null;
|
*/
|
||||||
|
this.parentID = data.parent_id;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
if ('permission_overwrites' in data) {
|
||||||
* A map of permission overwrites in this channel for roles and users
|
/**
|
||||||
* @type {Collection<Snowflake, PermissionOverwrites>}
|
* A map of permission overwrites in this channel for roles and users
|
||||||
*/
|
* @type {Collection<Snowflake, PermissionOverwrites>}
|
||||||
this.permissionOverwrites = new Collection();
|
*/
|
||||||
if (data.permission_overwrites) {
|
this.permissionOverwrites = new Collection();
|
||||||
for (const overwrite of data.permission_overwrites) {
|
for (const overwrite of data.permission_overwrites) {
|
||||||
this.permissionOverwrites.set(overwrite.id, new PermissionOverwrites(this, overwrite));
|
this.permissionOverwrites.set(overwrite.id, new PermissionOverwrites(this, overwrite));
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -10,11 +10,13 @@ class StageChannel extends BaseGuildVoiceChannel {
|
|||||||
_patch(data) {
|
_patch(data) {
|
||||||
super._patch(data);
|
super._patch(data);
|
||||||
|
|
||||||
/**
|
if ('topic' in data) {
|
||||||
* The topic of the stage channel
|
/**
|
||||||
* @type {?string}
|
* The topic of the stage channel
|
||||||
*/
|
* @type {?string}
|
||||||
this.topic = data.topic;
|
*/
|
||||||
|
this.topic = data.topic;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -17,7 +17,6 @@ class StoreChannel extends GuildChannel {
|
|||||||
/**
|
/**
|
||||||
* If the guild considers this channel NSFW
|
* If the guild considers this channel NSFW
|
||||||
* @type {boolean}
|
* @type {boolean}
|
||||||
* @readonly
|
|
||||||
*/
|
*/
|
||||||
this.nsfw = Boolean(data.nsfw);
|
this.nsfw = Boolean(data.nsfw);
|
||||||
}
|
}
|
||||||
@@ -25,7 +24,9 @@ class StoreChannel extends GuildChannel {
|
|||||||
_patch(data) {
|
_patch(data) {
|
||||||
super._patch(data);
|
super._patch(data);
|
||||||
|
|
||||||
if (typeof data.nsfw !== 'undefined') this.nsfw = Boolean(data.nsfw);
|
if ('nsfw' in data) {
|
||||||
|
this.nsfw = Boolean(data.nsfw);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -28,7 +28,6 @@ class TextChannel extends GuildChannel {
|
|||||||
/**
|
/**
|
||||||
* If the guild considers this channel NSFW
|
* If the guild considers this channel NSFW
|
||||||
* @type {boolean}
|
* @type {boolean}
|
||||||
* @readonly
|
|
||||||
*/
|
*/
|
||||||
this.nsfw = Boolean(data.nsfw);
|
this.nsfw = Boolean(data.nsfw);
|
||||||
this._typing = new Map();
|
this._typing = new Map();
|
||||||
@@ -37,34 +36,46 @@ class TextChannel extends GuildChannel {
|
|||||||
_patch(data) {
|
_patch(data) {
|
||||||
super._patch(data);
|
super._patch(data);
|
||||||
|
|
||||||
/**
|
if ('topic' in data) {
|
||||||
* The topic of the text channel
|
/**
|
||||||
* @type {?string}
|
* The topic of the text channel
|
||||||
*/
|
* @type {?string}
|
||||||
this.topic = data.topic;
|
*/
|
||||||
|
this.topic = data.topic;
|
||||||
|
}
|
||||||
|
|
||||||
if (typeof data.nsfw !== 'undefined') this.nsfw = Boolean(data.nsfw);
|
if ('nsfw' in data) {
|
||||||
|
this.nsfw = Boolean(data.nsfw);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
if ('last_message_id' in data) {
|
||||||
* The ID of the last message sent in this channel, if one was sent
|
/**
|
||||||
* @type {?Snowflake}
|
* The ID of the last message sent in this channel, if one was sent
|
||||||
*/
|
* @type {?Snowflake}
|
||||||
this.lastMessageID = data.last_message_id;
|
*/
|
||||||
|
this.lastMessageID = data.last_message_id;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
if ('rate_limit_per_user' in data) {
|
||||||
* The ratelimit per user for this channel in seconds
|
/**
|
||||||
* <warn>It is not currently possible to set a rate limit per user on a `NewsChannel`.</warn>
|
* The ratelimit per user for this channel in seconds
|
||||||
* @type {number}
|
* <warn>It is not currently possible to set a rate limit per user on a `NewsChannel`.</warn>
|
||||||
*/
|
* @type {number}
|
||||||
this.rateLimitPerUser = data.rate_limit_per_user || 0;
|
*/
|
||||||
|
this.rateLimitPerUser = data.rate_limit_per_user;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
if ('last_pin_timestamp' in data) {
|
||||||
* The timestamp when the last pinned message was pinned, if there was one
|
/**
|
||||||
* @type {?number}
|
* The timestamp when the last pinned message was pinned, if there was one
|
||||||
*/
|
* @type {?number}
|
||||||
this.lastPinTimestamp = data.last_pin_timestamp ? new Date(data.last_pin_timestamp).getTime() : null;
|
*/
|
||||||
|
this.lastPinTimestamp = data.last_pin_timestamp ? new Date(data.last_pin_timestamp).getTime() : null;
|
||||||
|
}
|
||||||
|
|
||||||
if (data.messages) for (const message of data.messages) this.messages.add(message);
|
if ('messages' in data) {
|
||||||
|
for (const message of data.messages) this.messages.add(message);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -30,6 +30,18 @@ class User extends Base {
|
|||||||
this.system = null;
|
this.system = null;
|
||||||
this.flags = null;
|
this.flags = null;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The ID of the last message sent by the user, if one was sent
|
||||||
|
* @type {?Snowflake}
|
||||||
|
*/
|
||||||
|
this.lastMessageID = null;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The ID of the channel for the last message sent by the user, if one was sent
|
||||||
|
* @type {?Snowflake}
|
||||||
|
*/
|
||||||
|
this.lastMessageChannelID = null;
|
||||||
|
|
||||||
this._patch(data);
|
this._patch(data);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -87,18 +99,6 @@ class User extends Base {
|
|||||||
*/
|
*/
|
||||||
this.flags = new UserFlags(data.public_flags);
|
this.flags = new UserFlags(data.public_flags);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* The ID of the last message sent by the user, if one was sent
|
|
||||||
* @type {?Snowflake}
|
|
||||||
*/
|
|
||||||
this.lastMessageID = null;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The ID of the channel for the last message sent by the user, if one was sent
|
|
||||||
* @type {?Snowflake}
|
|
||||||
*/
|
|
||||||
this.lastMessageChannelID = null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
Reference in New Issue
Block a user