Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(Presence): account for multiple activities everywhere #3703

Merged
merged 2 commits into from
Jan 19, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/structures/ClientPresence.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ class ClientPresence extends Presence {
};

if ((status || afk || since) && !activity) {
packet.game = this.activity;
packet.game = this.activities[0] || null;
}

if (packet.game) {
Expand Down
2 changes: 1 addition & 1 deletion src/structures/ClientUser.js
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ class ClientUser extends Structures.get('User') {
* @example
* // Set the client user's activity
* client.user.setActivity('discord.js', { type: 'WATCHING' })
* .then(presence => console.log(`Activity set to ${presence.activity.name}`))
* .then(presence => console.log(`Activity set to ${presence.activities[0].name}`))
* .catch(console.error);
*/
setActivity(name, options = {}) {
Expand Down
27 changes: 17 additions & 10 deletions src/structures/Presence.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,11 +85,17 @@ class Presence {
*/
this.status = data.status || this.status || 'offline';

/**
* The activities of this presence
* @type {Activity[]}
*/
this.activities = data.activities ? data.activities.map(activity => new Activity(this, activity)) : [];
if (data.activities) {
/**
* The activities of this presence
* @type {Activity[]}
*/
this.activities = data.activities.map(activity => new Activity(this, activity));
} else if (data.activity || data.game) {
this.activities = [new Activity(this, data.game || data.activity)];
} else {
this.activities = [];
}

/**
* The devices this presence is on
Expand All @@ -105,7 +111,7 @@ class Presence {

_clone() {
const clone = Object.assign(Object.create(this), this);
if (this.activity) clone.activity = this.activity._clone();
if (this.activities) clone.activities = this.activities.map(activity => activity._clone());
return clone;
}

Expand All @@ -118,10 +124,11 @@ class Presence {
return this === presence || (
presence &&
this.status === presence.status &&
this.activity ? this.activity.equals(presence.activity) : !presence.activity &&
this.clientStatus.web === presence.clientStatus.web &&
this.clientStatus.mobile === presence.clientStatus.mobile &&
this.clientStatus.desktop === presence.clientStatus.desktop
this.activities.length === presence.activities.length &&
this.activities.every((activity, index) => activity.equals(presence.activities[index])) &&
this.clientStatus.web === presence.clientStatus.web &&
this.clientStatus.mobile === presence.clientStatus.mobile &&
this.clientStatus.desktop === presence.clientStatus.desktop
);
}

Expand Down