fix: don't patch set data with undefined (#6694)

This commit is contained in:
Rodry
2021-10-03 13:59:52 +01:00
committed by GitHub
parent 8b4456e0aa
commit 9eb9591473
33 changed files with 1211 additions and 795 deletions

View File

@@ -27,58 +27,104 @@ class VoiceState extends Base {
}
_patch(data) {
/**
* Whether this member is deafened server-wide
* @type {?boolean}
*/
this.serverDeaf = data.deaf ?? null;
/**
* Whether this member is muted server-wide
* @type {?boolean}
*/
this.serverMute = data.mute ?? null;
/**
* Whether this member is self-deafened
* @type {?boolean}
*/
this.selfDeaf = data.self_deaf ?? null;
/**
* Whether this member is self-muted
* @type {?boolean}
*/
this.selfMute = data.self_mute ?? null;
/**
* Whether this member's camera is enabled
* @type {?boolean}
*/
this.selfVideo = data.self_video ?? null;
/**
* The session id for this member's connection
* @type {?string}
*/
this.sessionId = data.session_id ?? null;
/**
* Whether this member is streaming using "Screen Share"
* @type {boolean}
*/
this.streaming = data.self_stream ?? false;
/**
* The {@link VoiceChannel} or {@link StageChannel} id the member is in
* @type {?Snowflake}
*/
this.channelId = data.channel_id ?? null;
/**
* Whether this member is suppressed from speaking. This property is specific to stage channels only.
* @type {boolean}
*/
this.suppress = data.suppress;
/**
* The time at which the member requested to speak. This property is specific to stage channels only.
* @type {?number}
*/
this.requestToSpeakTimestamp = data.request_to_speak_timestamp
? new Date(data.request_to_speak_timestamp).getTime()
: null;
if ('deaf' in data) {
/**
* Whether this member is deafened server-wide
* @type {?boolean}
*/
this.serverDeaf = data.deaf;
} else {
this.serverDeaf ??= null;
}
if ('mute' in data) {
/**
* Whether this member is muted server-wide
* @type {?boolean}
*/
this.serverMute = data.mute;
} else {
this.serverMute ??= null;
}
if ('self_deaf' in data) {
/**
* Whether this member is self-deafened
* @type {?boolean}
*/
this.selfDeaf = data.self_deaf;
} else {
this.selfDeaf ??= null;
}
if ('self_mute' in data) {
/**
* Whether this member is self-muted
* @type {?boolean}
*/
this.selfMute = data.self_mute;
} else {
this.selfMute ??= null;
}
if ('self_video' in data) {
/**
* Whether this member's camera is enabled
* @type {?boolean}
*/
this.selfVideo = data.self_video;
} else {
this.selfVideo ??= null;
}
if ('session_id' in data) {
/**
* The session id for this member's connection
* @type {?string}
*/
this.sessionId = data.session_id;
} else {
this.sessionId ??= null;
}
if ('self_streaming' in data) {
/**
* Whether this member is streaming using "Screen Share"
* @type {boolean}
*/
this.streaming = data.self_stream ?? false;
} else {
this.streaming ??= null;
}
if ('channel_id' in data) {
/**
* The {@link VoiceChannel} or {@link StageChannel} id the member is in
* @type {?Snowflake}
*/
this.channelId = data.channel_id;
} else {
this.channelId ??= null;
}
if ('suppress' in data) {
/**
* Whether this member is suppressed from speaking. This property is specific to stage channels only.
* @type {boolean}
*/
this.suppress = data.suppress;
}
if ('request_to_speak_timestamp' in data) {
/**
* The time at which the member requested to speak. This property is specific to stage channels only.
* @type {?number}
*/
this.requestToSpeakTimestamp = new Date(data.request_to_speak_timestamp).getTime();
} else {
this.requestToSpeakTimestamp ??= null;
}
return this;
}