fix(ThreadChannel): better property handling (#6172)

This commit is contained in:
ckohen
2021-07-27 17:29:06 -07:00
committed by GitHub
parent 30a58dc801
commit 9679b90872
8 changed files with 64 additions and 33 deletions

View File

@@ -19,10 +19,10 @@ class ChannelManager extends CachedManager {
* @name ChannelManager#cache
*/
_add(data, guild, cache = true, allowUnknownGuild = false) {
_add(data, guild, { cache = true, allowUnknownGuild = false, fromInteraction = false } = {}) {
const existing = this.cache.get(data.id);
if (existing) {
if (cache) existing._patch(data);
if (cache) existing._patch(data, fromInteraction);
guild?.channels?._add(existing);
if (ThreadChannelTypes.includes(existing.type)) {
existing.parent?.threads?._add(existing);
@@ -30,7 +30,7 @@ class ChannelManager extends CachedManager {
return existing;
}
const channel = Channel.create(this.client, data, guild, allowUnknownGuild);
const channel = Channel.create(this.client, data, guild, { allowUnknownGuild, fromInteraction });
if (!channel) {
this.client.emit(Events.DEBUG, `Failed to find guild, or unknown type for channel ${data.id} ${data.type}`);
@@ -99,7 +99,7 @@ class ChannelManager extends CachedManager {
}
const data = await this.client.api.channels(id).get();
return this._add(data, null, cache, allowUnknownGuild);
return this._add(data, null, { cache, allowUnknownGuild });
}
}

View File

@@ -169,12 +169,12 @@ class GuildChannelManager extends CachedManager {
const data = await this.client.api.channels(id).get();
// Since this is the guild manager, throw if on a different guild
if (this.guild.id !== data.guild_id) throw new Error('GUILD_CHANNEL_UNOWNED');
return this.client.channels._add(data, this.guild, cache);
return this.client.channels._add(data, this.guild, { cache });
}
const data = await this.client.api.guilds(this.guild.id).channels.get();
const channels = new Collection();
for (const channel of data) channels.set(channel.id, this.client.channels._add(channel, this.guild, cache));
for (const channel of data) channels.set(channel.id, this.client.channels._add(channel, this.guild, { cache }));
return channels;
}
}

View File

@@ -235,7 +235,7 @@ class ThreadManager extends CachedManager {
_mapThreads(rawThreads, cache) {
const threads = rawThreads.threads.reduce((coll, raw) => {
const thread = this.client.channels._add(raw, null, cache);
const thread = this.client.channels._add(raw, null, { cache });
return coll.set(thread.id, thread);
}, new Collection());
// Discord sends the thread id as id in this object