refactor(PresenceManager): have Presence extend Base and simplify add (#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>
This commit is contained in:
SpaceEEC
2021-07-05 20:53:15 +02:00
committed by GitHub
parent afbd5db404
commit ded93feb57
4 changed files with 10 additions and 15 deletions

View File

@@ -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 });
}
/**

View File

@@ -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)) {

View File

@@ -1,5 +1,6 @@
'use strict';
const Base = require('./Base');
const Emoji = require('./Emoji');
const ActivityFlags = require('../util/ActivityFlags');
const { ActivityTypes } = require('../util/Constants');
@@ -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}
@@ -57,7 +54,7 @@ class Presence {
*/
this.guild = data.guild ?? null;
this.patch(data);
this._patch(data);
}
/**
@@ -78,7 +75,7 @@ class Presence {
return this.guild.members.resolve(this.userId);
}
patch(data) {
_patch(data) {
/**
* The status of this presence
* @type {PresenceStatus}

3
typings/index.d.ts vendored
View File

@@ -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;