mirror of
https://github.com/discordjs/discord.js.git
synced 2026-03-10 16:43:31 +01:00
refactor(Message): remove stored edit history (#5155)
This commit is contained in:
committed by
GitHub
parent
6a77453532
commit
8c2e6b70b8
@@ -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');
|
||||
}
|
||||
|
||||
@@ -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) {
|
||||
@@ -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;
|
||||
@@ -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}
|
||||
|
||||
@@ -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}
|
||||
@@ -43,7 +41,6 @@ exports.DefaultOptions = {
|
||||
messageCacheMaxSize: 200,
|
||||
messageCacheLifetime: 0,
|
||||
messageSweepInterval: 0,
|
||||
messageEditHistoryMaxSize: -1,
|
||||
fetchAllMembers: false,
|
||||
partials: [],
|
||||
restWsBridgeTimeout: 5000,
|
||||
|
||||
5
typings/index.d.ts
vendored
5
typings/index.d.ts
vendored
@@ -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;
|
||||
@@ -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;
|
||||
@@ -2332,7 +2330,6 @@ declare module 'discord.js' {
|
||||
messageCacheMaxSize?: number;
|
||||
messageCacheLifetime?: number;
|
||||
messageSweepInterval?: number;
|
||||
messageEditHistoryMaxSize?: number;
|
||||
fetchAllMembers?: boolean;
|
||||
allowedMentions?: MessageMentionOptions;
|
||||
partials?: PartialTypes[];
|
||||
@@ -3042,7 +3039,6 @@ declare module 'discord.js' {
|
||||
| 'pinnable'
|
||||
| 'url'
|
||||
| 'flags'
|
||||
| 'edits'
|
||||
| 'embeds'
|
||||
> {
|
||||
attachments: Message['attachments'];
|
||||
@@ -3050,7 +3046,6 @@ declare module 'discord.js' {
|
||||
readonly deletable: boolean;
|
||||
readonly crosspostable: boolean;
|
||||
readonly editable: boolean;
|
||||
readonly edits: Message['edits'];
|
||||
embeds: Message['embeds'];
|
||||
flags: Message['flags'];
|
||||
mentions: Message['mentions'];
|
||||
|
||||
Reference in New Issue
Block a user