Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(ThreadManager): Ensure fetchActive() only returns active threads in a channel #9568

Merged
merged 5 commits into from
May 25, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions packages/discord.js/src/managers/GuildChannelManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -468,8 +468,17 @@ class GuildChannelManager extends CachedManager {
* .catch(console.error);
*/
async fetchActiveThreads(cache = true) {
const raw = await this.client.rest.get(Routes.guildActiveThreads(this.guild.id));
return GuildTextThreadManager._mapThreads(raw, this.client, { guild: this.guild, cache });
const data = await this.rawFetchGuildActiveThreads();
return GuildTextThreadManager._mapThreads(data, this.client, { guild: this.guild, cache });
}

/**
* `GET /guilds/{guild.id}/threads/active`
* @private
* @returns {Promise<RESTGetAPIGuildThreadsResult>}
*/
rawFetchGuildActiveThreads() {
return this.client.rest.get(Routes.guildActiveThreads(this.guild.id));
}

/**
Expand Down
8 changes: 4 additions & 4 deletions packages/discord.js/src/managers/ThreadManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -171,13 +171,13 @@ class ThreadManager extends CachedManager {
}

/**
* Obtains all active thread channels in the guild.
* This internally calls {@link GuildChannelManager#fetchActiveThreads}.
* Obtains all active threads in the channel.
* @param {boolean} [cache=true] Whether to cache the fetched data
* @returns {Promise<FetchedThreads>}
*/
fetchActive(cache = true) {
return this.channel.guild.channels.fetchActiveThreads(cache);
async fetchActive(cache = true) {
const data = await this.channel.guild.channels.rawFetchGuildActiveThreads();
return this.constructor._mapThreads(data, this.client, { parent: this.channel, cache });
}

static _mapThreads(rawThreads, client, { parent, guild, cache }) {
Expand Down
5 changes: 5 additions & 0 deletions packages/discord.js/src/util/APITypes.js
Original file line number Diff line number Diff line change
Expand Up @@ -400,6 +400,11 @@
* @see {@link https://discord-api-types.dev/api/discord-api-types-payloads/common#PermissionFlagsBits}
*/

/**
* @external RESTGetAPIGuildThreadsResult
* @see {@link https://discord-api-types.dev/api/discord-api-types-v10#RESTGetAPIGuildThreadsResult}
*/

/**
* @external RESTJSONErrorCodes
* @see {@link https://discord-api-types.dev/api/discord-api-types-rest/common/enum/RESTJSONErrorCodes}
Expand Down
2 changes: 2 additions & 0 deletions packages/discord.js/typings/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,7 @@ import {
APIApplicationRoleConnectionMetadata,
ImageFormat,
GuildMemberFlags,
RESTGetAPIGuildThreadsResult,
} from 'discord-api-types/v10';
import { ChildProcess } from 'node:child_process';
import { EventEmitter } from 'node:events';
Expand Down Expand Up @@ -3860,6 +3861,7 @@ export class GuildChannelManager extends CachedManager<Snowflake, GuildBasedChan
): Promise<GuildChannel>;
public setPositions(channelPositions: readonly ChannelPosition[]): Promise<Guild>;
public fetchActiveThreads(cache?: boolean): Promise<FetchedThreads>;
private rawFetchGuildActiveThreads(): Promise<RESTGetAPIGuildThreadsResult>;
public delete(channel: GuildChannelResolvable, reason?: string): Promise<void>;
}

Expand Down