Skip to content

Commit

Permalink
refactor(PresenceManager): have Presence extend Base and simplify add (
Browse files Browse the repository at this point in the history
…#6056)

* refactor(PresenceManager): have Presence extend Base and simplify add

* style(Presence): add empty line after super call

Co-authored-by: Noel <buechler.noel@outlook.com>

Co-authored-by: Noel <buechler.noel@outlook.com>
  • Loading branch information
SpaceEEC and iCrawl authored Jul 5, 2021
1 parent afbd5db commit ded93fe
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 15 deletions.
3 changes: 1 addition & 2 deletions src/managers/PresenceManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,7 @@ class PresenceManager extends CachedManager {
*/

add(data, cache) {
const existing = this.cache.get(data.user.id);
return existing ? existing.patch(data) : super.add(data, cache, { id: data.user.id });
return super.add(data, cache, { id: data.user.id });
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/structures/ClientPresence.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class ClientPresence extends Presence {

set(presence) {
const packet = this._parse(presence);
this.patch(packet);
this._patch(packet);
if (typeof presence.shardId === 'undefined') {
this.client.ws.broadcast({ op: OPCodes.STATUS_UPDATE, d: packet });
} else if (Array.isArray(presence.shardId)) {
Expand Down
17 changes: 7 additions & 10 deletions src/structures/Presence.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
'use strict';

const Base = require('./Base');
const Emoji = require('./Emoji');
const ActivityFlags = require('../util/ActivityFlags');
const { ActivityTypes } = require('../util/Constants');
Expand Down Expand Up @@ -31,20 +32,16 @@ const Util = require('../util/Util');

/**
* Represents a user's presence.
* @extends {Base}
*/
class Presence {
class Presence extends Base {
/**
* @param {Client} client The instantiating client
* @param {APIPresence} [data={}] The data for the presence
*/
constructor(client, data = {}) {
/**
* The client that instantiated this
* @name Presence#client
* @type {Client}
* @readonly
*/
Object.defineProperty(this, 'client', { value: client });
super(client);

/**
* The presence's user id
* @type {Snowflake}
Expand All @@ -57,7 +54,7 @@ class Presence {
*/
this.guild = data.guild ?? null;

this.patch(data);
this._patch(data);
}

/**
Expand All @@ -78,7 +75,7 @@ class Presence {
return this.guild.members.resolve(this.userId);
}

patch(data) {
_patch(data) {
/**
* The status of this presence
* @type {PresenceStatus}
Expand Down
3 changes: 1 addition & 2 deletions typings/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1273,10 +1273,9 @@ export class Permissions extends BitField<PermissionString, bigint> {
public static resolve(permission?: PermissionResolvable): bigint;
}

export class Presence {
export class Presence extends Base {
public constructor(client: Client, data?: unknown);
public activities: Activity[];
public readonly client: Client;
public clientStatus: ClientPresenceStatusData | null;
public guild: Guild | null;
public readonly member: GuildMember | null;
Expand Down

0 comments on commit ded93fe

Please sign in to comment.