Skip to content

Commit

Permalink
refactor: use collection to store snapshots
Browse files Browse the repository at this point in the history
  • Loading branch information
TAEMBO committed Sep 4, 2024
1 parent 3e6051f commit 057e2c1
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
13 changes: 8 additions & 5 deletions packages/discord.js/src/structures/Message.js
Original file line number Diff line number Diff line change
Expand Up @@ -452,9 +452,9 @@ class Message extends Base {
if (data.message_snapshots) {
/**
* The message associated with the message reference
* @type {Array<Message>}
* @type {Collection<Snowflake, Message>}
*/
this.messageSnapshots = data.message_snapshots.map(snapshot => {
this.messageSnapshots = data.message_snapshots.reduce((coll, snapshot) => {
const channel = this.client.channels.resolve(this.reference.channelId);
const snapshotData = {
...snapshot.message,
Expand All @@ -463,10 +463,13 @@ class Message extends Base {
guild_id: this.reference.guildId,
};

return channel ? channel.messages._add(snapshotData) : new this.constructor(snapshotData);
});
return coll.set(
this.reference.messageId,
channel ? channel.messages._add(snapshotData) : new this.constructor(this.client, snapshotData),
);
}, new Collection());
} else {
this.messageSnapshots = this.messageSnapshots?.slice() ?? [];
this.messageSnapshots ??= new Collection();
}

/**
Expand Down
2 changes: 1 addition & 1 deletion packages/discord.js/typings/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2185,7 +2185,7 @@ export class Message<InGuild extends boolean = boolean> extends Base {
public webhookId: Snowflake | null;
public flags: Readonly<MessageFlagsBitField>;
public reference: MessageReference | null;
public messageSnapshots: MessageSnapshot[];
public messageSnapshots: Collection<Snowflake, MessageSnapshot>;
public awaitMessageComponent<ComponentType extends MessageComponentType>(
options?: AwaitMessageCollectorOptionsParams<ComponentType, InGuild>,
): Promise<MappedInteractionTypes<InGuild>[ComponentType]>;
Expand Down

0 comments on commit 057e2c1

Please sign in to comment.