mirror of
https://github.com/discordjs/discord.js.git
synced 2026-03-12 09:33:32 +01:00
Partials (#3070)
* Remove GroupDMChannels they sparked no joy * Start partials for message deletion * MessageUpdate partials * Add partials as an opt-in client option * Add fetch() to Message * Message.author should never be undefined * Fix channels being the wrong type * Allow fetching channels * Refactor and add reaction add partials * Reaction remove partials * Check for emoji first * fix message fetching janky * User partials in audit logs * refactor overwrite code * guild member partials * partials as a whitelist * document GuildMember#fetch * fix: check whether a structure is a partial, not whether cache is true * typings: Updated for latest commit (#3075) * partials: fix messageUpdate behaviour (now "old" message can be partial) * partials: add warnings and docs * partials: add partials to index.yml * partials: tighten "partial" definitions * partials: fix embed-only messages counting as partials
This commit is contained in:
@@ -40,6 +40,7 @@ class MessageStore extends DataStore {
|
||||
* <info>The returned Collection does not contain reaction users of the messages if they were not cached.
|
||||
* Those need to be fetched separately in such a case.</info>
|
||||
* @param {Snowflake|ChannelLogsQueryOptions} [message] The ID of the message to fetch, or query parameters.
|
||||
* @param {boolean} [cache=true] Whether to cache the message(s)
|
||||
* @returns {Promise<Message>|Promise<Collection<Snowflake, Message>>}
|
||||
* @example
|
||||
* // Get message
|
||||
@@ -57,8 +58,8 @@ class MessageStore extends DataStore {
|
||||
* .then(messages => console.log(`${messages.filter(m => m.author.id === '84484653687267328').size} messages`))
|
||||
* .catch(console.error);
|
||||
*/
|
||||
fetch(message) {
|
||||
return typeof message === 'string' ? this._fetchId(message) : this._fetchMany(message);
|
||||
fetch(message, cache = true) {
|
||||
return typeof message === 'string' ? this._fetchId(message, cache) : this._fetchMany(message, cache);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -80,15 +81,17 @@ class MessageStore extends DataStore {
|
||||
});
|
||||
}
|
||||
|
||||
async _fetchId(messageID) {
|
||||
async _fetchId(messageID, cache) {
|
||||
const existing = this.get(messageID);
|
||||
if (existing && !existing.partial) return existing;
|
||||
const data = await this.client.api.channels[this.channel.id].messages[messageID].get();
|
||||
return this.add(data);
|
||||
return this.add(data, cache);
|
||||
}
|
||||
|
||||
async _fetchMany(options = {}) {
|
||||
async _fetchMany(options = {}, cache) {
|
||||
const data = await this.client.api.channels[this.channel.id].messages.get({ query: options });
|
||||
const messages = new Collection();
|
||||
for (const message of data) messages.set(message.id, this.add(message));
|
||||
for (const message of data) messages.set(message.id, this.add(message, cache));
|
||||
return messages;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user