Skip to content

Commit

Permalink
refactor: remove lastMessage properties from User and `GuildMembe…
Browse files Browse the repository at this point in the history
…r` (#6046)
  • Loading branch information
kyranet committed Jul 5, 2021
1 parent 676118a commit 1a27f57
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 62 deletions.
10 changes: 0 additions & 10 deletions src/client/actions/MessageCreate.js
Expand Up @@ -13,17 +13,7 @@ class MessageCreateAction extends Action {
const existing = channel.messages.cache.get(data.id);
if (existing) return { message: existing };
const message = channel.messages.add(data);
const user = message.author;
const member = message.member;
channel.lastMessageId = data.id;
if (user) {
user.lastMessageId = data.id;
user.lastMessageChannelId = channel.id;
}
if (member) {
member.lastMessageId = data.id;
member.lastMessageChannelId = channel.id;
}

/**
* Emitted whenever a message is created.
Expand Down
25 changes: 0 additions & 25 deletions src/structures/GuildMember.js
Expand Up @@ -34,18 +34,6 @@ class GuildMember extends Base {
*/
this.joinedTimestamp = null;

/**
* The member's last message id, if one was sent
* @type {?Snowflake}
*/
this.lastMessageId = null;

/**
* The id of the channel for the last message sent by the member in their guild, if one was sent
* @type {?Snowflake}
*/
this.lastMessageChannelId = null;

/**
* The timestamp of when the member used their Nitro boost on the guild, if it was used
* @type {?number}
Expand Down Expand Up @@ -116,15 +104,6 @@ class GuildMember extends Base {
return new GuildMemberRoleManager(this);
}

/**
* The Message object of the last message sent by the member in their guild, if one was sent
* @type {?Message}
* @readonly
*/
get lastMessage() {
return this.guild.channels.resolve(this.lastMessageChannelId)?.messages.resolve(this.lastMessageId) ?? null;
}

/**
* The voice state of this member
* @type {VoiceState}
Expand Down Expand Up @@ -352,8 +331,6 @@ class GuildMember extends Base {
this.partial === member.partial &&
this.guild.id === member.guild.id &&
this.joinedTimestamp === member.joinedTimestamp &&
this.lastMessageId === member.lastMessageId &&
this.lastMessageChannelId === member.lastMessageChannelId &&
this.nickname === member.nickname &&
this.pending === member.pending &&
(this._roles === member._roles ||
Expand All @@ -377,8 +354,6 @@ class GuildMember extends Base {
guild: 'guildId',
user: 'userId',
displayName: true,
lastMessage: false,
lastMessageId: false,
roles: true,
});
}
Expand Down
23 changes: 0 additions & 23 deletions src/structures/User.js
Expand Up @@ -32,18 +32,6 @@ class User extends Base {

this.flags = null;

/**
* The user's last message id, if one was sent
* @type {?Snowflake}
*/
this.lastMessageId = null;

/**
* The channel in which the last message was sent by the user, if one was sent
* @type {?Snowflake}
*/
this.lastMessageChannelId = null;

this._patch(data);
}

Expand Down Expand Up @@ -134,15 +122,6 @@ class User extends Base {
return new Date(this.createdTimestamp);
}

/**
* The Message object of the last message sent by the user, if one was sent
* @type {?Message}
* @readonly
*/
get lastMessage() {
return this.client.channels.resolve(this.lastMessageChannelId)?.messages.resolve(this.lastMessageId) ?? null;
}

/**
* The presence of this user
* @type {Presence}
Expand Down Expand Up @@ -316,8 +295,6 @@ class User extends Base {
createdTimestamp: true,
defaultAvatarURL: true,
tag: true,
lastMessage: false,
lastMessageId: false,
},
...props,
);
Expand Down
6 changes: 2 additions & 4 deletions typings/index.d.ts
Expand Up @@ -681,7 +681,6 @@ export class GuildMember extends PartialTextBasedChannel(Base) {
public readonly joinedAt: Date | null;
public joinedTimestamp: number | null;
public readonly kickable: boolean;
public lastMessageChannelId: Snowflake | null;
public readonly manageable: boolean;
public nickname: string | null;
public readonly partial: false;
Expand Down Expand Up @@ -1646,7 +1645,6 @@ export class User extends PartialTextBasedChannel(Base) {
public readonly dmChannel: DMChannel | null;
public flags: Readonly<UserFlags> | null;
public id: Snowflake;
public lastMessageId: Snowflake | null;
public readonly partial: false;
public readonly presence: Presence;
public system: boolean;
Expand Down Expand Up @@ -2531,13 +2529,13 @@ export function TextBasedChannel<T, I extends keyof TextBasedChannelFields = nev
): Constructable<T & Omit<TextBasedChannelFields, I>>;

export interface PartialTextBasedChannelFields {
lastMessageId: Snowflake | null;
readonly lastMessage: Message | null;
send(options: string | MessagePayload | MessageOptions): Promise<Message>;
}

export interface TextBasedChannelFields extends PartialTextBasedChannelFields {
_typing: Map<string, TypingData>;
lastMessageId: Snowflake | null;
readonly lastMessage: Message | null;
lastPinTimestamp: number | null;
readonly lastPinAt: Date | null;
typing: boolean;
Expand Down
32 changes: 32 additions & 0 deletions typings/index.ts
@@ -1,17 +1,25 @@
import {
Client,
Collection,
DMChannel,
GuildMember,
Intents,
Message,
MessageActionRow,
MessageAttachment,
MessageButton,
MessageEmbed,
NewsChannel,
Options,
PartialTextBasedChannelFields,
Permissions,
Serialized,
ShardClientUtil,
ShardingManager,
TextBasedChannelFields,
TextChannel,
ThreadChannel,
User,
} from '..';

const client: Client = new Client({
Expand Down Expand Up @@ -455,3 +463,27 @@ assertType<Promise<number[]>>(shardingManager.broadcastEval(() => 1));
assertType<Promise<number[]>>(shardClientUtil.broadcastEval(() => 1));
assertType<Promise<number[]>>(shardingManager.broadcastEval(async () => 1));
assertType<Promise<number[]>>(shardClientUtil.broadcastEval(async () => 1));

declare const dmChannel: DMChannel;
declare const threadChannel: ThreadChannel;
declare const newsChannel: NewsChannel;
declare const textChannel: TextChannel;
declare const user: User;
declare const guildMember: GuildMember;

// Test whether the structures implement send
assertType<TextBasedChannelFields['send']>(dmChannel.send);
assertType<TextBasedChannelFields>(threadChannel);
assertType<TextBasedChannelFields>(newsChannel);
assertType<TextBasedChannelFields>(textChannel);
assertType<PartialTextBasedChannelFields>(user);
assertType<PartialTextBasedChannelFields>(guildMember);

assertType<Message | null>(dmChannel.lastMessage);
assertType<Message | null>(threadChannel.lastMessage);
assertType<Message | null>(newsChannel.lastMessage);
assertType<Message | null>(textChannel.lastMessage);
// @ts-expect-error
assertType<never>(user.lastMessage);
// @ts-expect-error
assertType<never>(guildMember.lastMessage);

0 comments on commit 1a27f57

Please sign in to comment.