From afbd5db404c711fd966122a97ecf63493b35ff15 Mon Sep 17 00:00:00 2001 From: SpaceEEC Date: Mon, 5 Jul 2021 20:53:00 +0200 Subject: [PATCH] refactor(Presences): remove from User, nullable on GuildMember (#6055) as well as on Client#presenceUpdate --- src/client/actions/PresenceUpdate.js | 2 +- src/structures/GuildMember.js | 13 ++----------- src/structures/User.js | 13 ------------- typings/index.d.ts | 5 ++--- 4 files changed, 5 insertions(+), 28 deletions(-) diff --git a/src/client/actions/PresenceUpdate.js b/src/client/actions/PresenceUpdate.js index 989c08f78..5eb29a610 100644 --- a/src/client/actions/PresenceUpdate.js +++ b/src/client/actions/PresenceUpdate.js @@ -16,7 +16,7 @@ class PresenceUpdateAction extends Action { const guild = this.client.guilds.cache.get(data.guild_id); if (!guild) return; - const oldPresence = guild.presences.cache.get(user.id)?._clone(); + const oldPresence = guild.presences.cache.get(user.id)?._clone() ?? null; let member = guild.members.cache.get(user.id); if (!member && data.status !== 'offline') { member = guild.members.add({ diff --git a/src/structures/GuildMember.js b/src/structures/GuildMember.js index 86ce0cb05..c097b7b15 100644 --- a/src/structures/GuildMember.js +++ b/src/structures/GuildMember.js @@ -1,7 +1,6 @@ 'use strict'; const Base = require('./Base'); -const { Presence } = require('./Presence'); const VoiceState = require('./VoiceState'); const TextBasedChannel = require('./interfaces/TextBasedChannel'); const { Error } = require('../errors'); @@ -133,19 +132,11 @@ class GuildMember extends Base { /** * The presence of this guild member - * @type {Presence} + * @type {?Presence} * @readonly */ get presence() { - return ( - this.guild.presences.cache.get(this.id) ?? - new Presence(this.client, { - user: { - id: this.id, - }, - guild: this.guild, - }) - ); + return this.guild.presences.resolve(this.id); } /** diff --git a/src/structures/User.js b/src/structures/User.js index ca7dae392..66c39ad5d 100644 --- a/src/structures/User.js +++ b/src/structures/User.js @@ -1,7 +1,6 @@ 'use strict'; const Base = require('./Base'); -const { Presence } = require('./Presence'); const TextBasedChannel = require('./interfaces/TextBasedChannel'); const { Error } = require('../errors'); const SnowflakeUtil = require('../util/SnowflakeUtil'); @@ -122,18 +121,6 @@ class User extends Base { return new Date(this.createdTimestamp); } - /** - * The presence of this user - * @type {Presence} - * @readonly - */ - get presence() { - for (const guild of this.client.guilds.cache.values()) { - if (guild.presences.cache.has(this.id)) return guild.presences.cache.get(this.id); - } - return new Presence(this.client, { user: { id: this.id } }); - } - /** * A link to the user's avatar. * @param {ImageURLOptions} [options={}] Options for the Image URL diff --git a/typings/index.d.ts b/typings/index.d.ts index 0a6309383..c6c76cc4e 100644 --- a/typings/index.d.ts +++ b/typings/index.d.ts @@ -687,7 +687,7 @@ export class GuildMember extends PartialTextBasedChannel(Base) { public readonly permissions: Readonly; public readonly premiumSince: Date | null; public premiumSinceTimestamp: number | null; - public readonly presence: Presence; + public readonly presence: Presence | null; public readonly roles: GuildMemberRoleManager; public user: User; public readonly voice: VoiceState; @@ -1649,7 +1649,6 @@ export class User extends PartialTextBasedChannel(Base) { public flags: Readonly | null; public id: Snowflake; public readonly partial: false; - public readonly presence: Presence; public system: boolean; public readonly tag: string; public username: string; @@ -2932,7 +2931,7 @@ export interface ClientEvents { messageReactionAdd: [message: MessageReaction, user: User | PartialUser]; messageReactionRemove: [reaction: MessageReaction, user: User | PartialUser]; messageUpdate: [oldMessage: Message | PartialMessage, newMessage: Message | PartialMessage]; - presenceUpdate: [oldPresence: Presence | undefined, newPresence: Presence]; + presenceUpdate: [oldPresence: Presence | null, newPresence: Presence]; rateLimit: [rateLimitData: RateLimitData]; invalidRequestWarning: [invalidRequestWarningData: InvalidRequestWarningData]; ready: [];