mirror of
https://github.com/discordjs/discord.js.git
synced 2026-03-10 00:23:30 +01:00
refactor: use guild-wide route for fetching active threads (#6193)
Co-authored-by: SpaceEEC <24881032+SpaceEEC@users.noreply.github.com>
This commit is contained in:
@@ -220,7 +220,7 @@ class ThreadManager extends CachedManager {
|
||||
const raw = await path.threads
|
||||
.archived(type)
|
||||
.get({ query: { before: type === 'private' && !fetchAll ? id : timestamp, limit } });
|
||||
return this._mapThreads(raw, cache);
|
||||
return this.constructor._mapThreads(raw, this.client, { parent: this.channel, cache });
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -229,20 +229,21 @@ class ThreadManager extends CachedManager {
|
||||
* @returns {Promise<FetchedThreads>}
|
||||
*/
|
||||
async fetchActive(cache = true) {
|
||||
const raw = await this.client.api.channels(this.channel.id).threads.active.get();
|
||||
return this._mapThreads(raw, cache);
|
||||
const raw = await this.client.api.guilds(this.channel.guild.id).threads.active.get();
|
||||
return this.constructor._mapThreads(raw, this.client, { parent: this.channel, cache });
|
||||
}
|
||||
|
||||
_mapThreads(rawThreads, cache) {
|
||||
static _mapThreads(rawThreads, client, { parent, guild, cache }) {
|
||||
const threads = rawThreads.threads.reduce((coll, raw) => {
|
||||
const thread = this.client.channels._add(raw, null, { cache });
|
||||
const thread = client.channels._add(raw, guild ?? parent?.guild, { cache });
|
||||
if (parent && thread.parentId !== parent.id) return coll;
|
||||
return coll.set(thread.id, thread);
|
||||
}, new Collection());
|
||||
// Discord sends the thread id as id in this object
|
||||
for (const rawMember of rawThreads.members) threads.get(rawMember.id)?.members._add(rawMember);
|
||||
for (const rawMember of rawThreads.members) client.channels.cache.get(rawMember.id)?.members._add(rawMember);
|
||||
return {
|
||||
threads,
|
||||
hasMore: rawThreads.has_more,
|
||||
hasMore: rawThreads.has_more ?? false,
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user