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

@@ -76,26 +76,38 @@ class Presence extends Base {
}
_patch(data) {
/**
* The status of this presence
* @type {PresenceStatus}
*/
this.status = data.status ?? this.status ?? 'offline';
if ('status' in data) {
/**
* The status of this presence
* @type {PresenceStatus}
*/
this.status = data.status;
} else {
this.status ??= 'offline';
}
/**
* The activities of this presence
* @type {Activity[]}
*/
this.activities = data.activities?.map(activity => new Activity(this, activity)) ?? [];
if ('activities' in data) {
/**
* The activities of this presence
* @type {Activity[]}
*/
this.activities = data.activities.map(activity => new Activity(this, activity));
} else {
this.activities ??= [];
}
/**
* The devices this presence is on
* @type {?Object}
* @property {?ClientPresenceStatus} web The current presence in the web application
* @property {?ClientPresenceStatus} mobile The current presence in the mobile application
* @property {?ClientPresenceStatus} desktop The current presence in the desktop application
*/
this.clientStatus = data.client_status ?? null;
if ('client_status' in data) {
/**
* The devices this presence is on
* @type {?Object}
* @property {?ClientPresenceStatus} web The current presence in the web application
* @property {?ClientPresenceStatus} mobile The current presence in the mobile application
* @property {?ClientPresenceStatus} desktop The current presence in the desktop application
*/
this.clientStatus = data.client_status;
} else {
this.clientStatus ??= null;
}
return this;
}