Skip to content

Commit

Permalink
refactor(Presences): remove from User, nullable on GuildMember (#6055)
Browse files Browse the repository at this point in the history
as well as on Client#presenceUpdate
  • Loading branch information
SpaceEEC committed Jul 5, 2021
1 parent 8d9ab74 commit afbd5db
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 28 deletions.
2 changes: 1 addition & 1 deletion src/client/actions/PresenceUpdate.js
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand Down
13 changes: 2 additions & 11 deletions src/structures/GuildMember.js
Original file line number Diff line number Diff line change
@@ -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');
Expand Down Expand Up @@ -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);
}

/**
Expand Down
13 changes: 0 additions & 13 deletions src/structures/User.js
Original file line number Diff line number Diff line change
@@ -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');
Expand Down Expand Up @@ -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
Expand Down
5 changes: 2 additions & 3 deletions typings/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -687,7 +687,7 @@ export class GuildMember extends PartialTextBasedChannel(Base) {
public readonly permissions: Readonly<Permissions>;
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;
Expand Down Expand Up @@ -1649,7 +1649,6 @@ export class User extends PartialTextBasedChannel(Base) {
public flags: Readonly<UserFlags> | null;
public id: Snowflake;
public readonly partial: false;
public readonly presence: Presence;
public system: boolean;
public readonly tag: string;
public username: string;
Expand Down Expand Up @@ -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: [];
Expand Down

0 comments on commit afbd5db

Please sign in to comment.