Skip to content

Commit

Permalink
refactor(Message): remove stored edit history (#5155)
Browse files Browse the repository at this point in the history
  • Loading branch information
MattIPv4 authored Dec 30, 2020
1 parent 6a77453 commit 8c2e6b7
Show file tree
Hide file tree
Showing 4 changed files with 0 additions and 39 deletions.
7 changes: 0 additions & 7 deletions src/client/Client.js
Original file line number Diff line number Diff line change
Expand Up @@ -459,13 +459,6 @@ class Client extends BaseClient {
if (typeof options.messageSweepInterval !== 'number' || isNaN(options.messageSweepInterval)) {
throw new TypeError('CLIENT_INVALID_OPTION', 'messageSweepInterval', 'a number');
}
if (
typeof options.messageEditHistoryMaxSize !== 'number' ||
isNaN(options.messageEditHistoryMaxSize) ||
options.messageEditHistoryMaxSize < -1
) {
throw new TypeError('CLIENT_INVALID_OPTION', 'messageEditHistoryMaxSize', 'a number greater than or equal to -1');
}
if (typeof options.fetchAllMembers !== 'boolean') {
throw new TypeError('CLIENT_INVALID_OPTION', 'fetchAllMembers', 'a boolean');
}
Expand Down
24 changes: 0 additions & 24 deletions src/structures/Message.js
Original file line number Diff line number Diff line change
Expand Up @@ -185,13 +185,6 @@ class Message extends Base {
}
: null;

/**
* The previous versions of the message, sorted with the most recent first
* @type {Message[]}
* @private
*/
this._edits = [];

if (this.member && data.member) {
this.member._patch(data.member);
} else if (data.member && this.guild && this.author) {
Expand Down Expand Up @@ -246,11 +239,6 @@ class Message extends Base {
*/
patch(data) {
const clone = this._clone();
const { messageEditHistoryMaxSize } = this.client.options;
if (messageEditHistoryMaxSize !== 0) {
const editsLimit = messageEditHistoryMaxSize === -1 ? Infinity : messageEditHistoryMaxSize;
if (this._edits.unshift(clone) > editsLimit) this._edits.pop();
}

if ('edited_timestamp' in data) this.editedTimestamp = new Date(data.edited_timestamp).getTime();
if ('content' in data) this.content = data.content;
Expand Down Expand Up @@ -383,18 +371,6 @@ class Message extends Base {
});
}

/**
* An array of cached versions of the message, including the current version
* Sorted from latest (first) to oldest (last)
* @type {Message[]}
* @readonly
*/
get edits() {
const copy = this._edits.slice();
copy.unshift(this);
return copy;
}

/**
* Whether the message is editable by the client user
* @type {boolean}
Expand Down
3 changes: 0 additions & 3 deletions src/util/Constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@ const { Error, RangeError } = require('../errors');
* sweepable (in seconds, 0 for forever)
* @property {number} [messageSweepInterval=0] How frequently to remove messages from the cache that are older than
* the message cache lifetime (in seconds, 0 for never)
* @property {number} [messageEditHistoryMaxSize=-1] Maximum number of previous versions to hold for an edited message
* (-1 or Infinity for unlimited - don't do this without sweeping, otherwise memory usage may climb indefinitely.)
* @property {boolean} [fetchAllMembers=false] Whether to cache all guild members and users upon startup, as well as
* upon joining a guild (should be avoided whenever possible)
* @property {MessageMentionOptions} [allowedMentions] Default value for {@link MessageOptions#allowedMentions}
Expand All @@ -43,7 +41,6 @@ exports.DefaultOptions = {
messageCacheMaxSize: 200,
messageCacheLifetime: 0,
messageSweepInterval: 0,
messageEditHistoryMaxSize: -1,
fetchAllMembers: false,
partials: [],
restWsBridgeTimeout: 5000,
Expand Down
5 changes: 0 additions & 5 deletions typings/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -951,7 +951,6 @@ declare module 'discord.js' {

export class Message extends Base {
constructor(client: Client, data: object, channel: TextChannel | DMChannel | NewsChannel);
private _edits: Message[];
private patch(data: object): Message;

public activity: MessageActivity | null;
Expand All @@ -968,7 +967,6 @@ declare module 'discord.js' {
public readonly editable: boolean;
public readonly editedAt: Date | null;
public editedTimestamp: number | null;
public readonly edits: Message[];
public embeds: MessageEmbed[];
public readonly guild: Guild | null;
public id: Snowflake;
Expand Down Expand Up @@ -2332,7 +2330,6 @@ declare module 'discord.js' {
messageCacheMaxSize?: number;
messageCacheLifetime?: number;
messageSweepInterval?: number;
messageEditHistoryMaxSize?: number;
fetchAllMembers?: boolean;
allowedMentions?: MessageMentionOptions;
partials?: PartialTypes[];
Expand Down Expand Up @@ -3042,15 +3039,13 @@ declare module 'discord.js' {
| 'pinnable'
| 'url'
| 'flags'
| 'edits'
| 'embeds'
> {
attachments: Message['attachments'];
channel: Message['channel'];
readonly deletable: boolean;
readonly crosspostable: boolean;
readonly editable: boolean;
readonly edits: Message['edits'];
embeds: Message['embeds'];
flags: Message['flags'];
mentions: Message['mentions'];
Expand Down

0 comments on commit 8c2e6b7

Please sign in to comment.