feat v13: Support pagination for fetching thread members (#9045)

* feat: support pagnation

* feat: support pagnation

* feat: fix tests

* fix: better fetch

* fix: tests

* Apply suggestions from code review

Co-authored-by: Aura Román <kyradiscord@gmail.com>

* fix: bad merge

---------

Co-authored-by: Aura Román <kyradiscord@gmail.com>
This commit is contained in:
Jaw0r3k
2023-04-17 15:59:25 +02:00
committed by GitHub
parent 71161518ca
commit 4f26ba7c2a
4 changed files with 163 additions and 28 deletions

50
typings/index.d.ts vendored
View File

@@ -2653,14 +2653,15 @@ export class ThreadChannel extends TextBasedChannelMixin(Channel, ['fetchWebhook
public unpin(reason?: string): Promise<ThreadChannel>;
}
export class ThreadMember extends Base {
private constructor(thread: ThreadChannel, data?: RawThreadMemberData);
export class ThreadMember<HasMemberData extends boolean = boolean> extends Base {
private constructor(thread: ThreadChannel, data?: RawThreadMemberData, extra?: unknown);
public flags: ThreadMemberFlags;
public readonly guildMember: GuildMember | null;
public readonly guildMember: HasMemberData extends true ? GuildMember : GuildMember | null;
public id: Snowflake;
public readonly joinedAt: Date | null;
public joinedTimestamp: number | null;
public readonly manageable: boolean;
private member: If<HasMemberData, GuildMember>;
public thread: ThreadChannel;
public readonly user: User | null;
public remove(reason?: string): Promise<ThreadMember>;
@@ -3641,9 +3642,26 @@ export class ThreadMemberManager extends CachedManager<Snowflake, ThreadMember,
public thread: ThreadChannel;
public get me(): ThreadMember | null;
public add(member: UserResolvable | '@me', reason?: string): Promise<Snowflake>;
public fetch(member?: UserResolvable, options?: BaseFetchOptions): Promise<ThreadMember>;
/** @deprecated Use `fetch(member, options)` instead. */
public fetch(cache?: boolean): Promise<Collection<Snowflake, ThreadMember>>;
public fetch(options?: FetchThreadMembersWithoutGuildMemberDataOptions): Promise<Collection<Snowflake, ThreadMember>>;
public fetch(
member: ThreadMember<true>,
options?: FetchMemberOptions
): Promise<ThreadMember<true>>;
public fetch(
member: Snowflake,
options: (FetchThreadMemberOptions & { withMember: true }),
): Promise<ThreadMember<true>>;
public fetch(
options: FetchThreadMembersWithGuildMemberDataOptions,
): Promise<Collection<Snowflake, ThreadMember<true>>>;
public fetch(member: UserResolvable, options?: FetchThreadMemberOptions): Promise<ThreadMember>;
/** @deprecated Use `fetch(options)` instead. */
public fetch(cache: boolean, options?: FetchThreadMembersOptions): Promise<Collection<Snowflake, ThreadMember>>;
public fetch(x: undefined, options: FetchThreadMembersWithGuildMemberDataOptions): Promise<Collection<Snowflake, ThreadMember<true>>>;
public fetch(x: undefined, options?: FetchThreadMembersWithoutGuildMemberDataOptions): Promise<Collection<Snowflake, ThreadMember>>;
public fetchMe(options?: BaseFetchOptions): Promise<ThreadMember>;
public remove(id: Snowflake | '@me', reason?: string): Promise<Snowflake>;
}
@@ -5083,6 +5101,26 @@ export interface FetchReactionUsersOptions {
after?: Snowflake;
}
export interface FetchThreadMemberOptions extends BaseFetchOptions {
withMember?: boolean;
}
export interface FetchThreadMembersWithGuildMemberDataOptions {
withMember: true;
after?: Snowflake;
limit?: number;
cache?: boolean;
}
export interface FetchThreadMembersWithoutGuildMemberDataOptions {
withMember?: false;
cache?: boolean;
}
export type FetchThreadMembersOptions =
| FetchThreadMembersWithGuildMemberDataOptions
| FetchThreadMembersWithoutGuildMemberDataOptions;
export interface FetchThreadsOptions {
archived?: FetchArchivedThreadOptions;
}

View File

@@ -98,6 +98,7 @@ import {
GuildBan,
GuildBanManager,
ForumChannel,
ThreadMemberManager,
} from '.';
import type { ApplicationCommandOptionTypes } from './enums';
import { expectAssignable, expectDeprecated, expectNotAssignable, expectNotType, expectType } from 'tsd';
@@ -898,7 +899,14 @@ declare const categoryChannel: CategoryChannel;
declare const guildChannelManager: GuildChannelManager;
{
type AnyChannel = TextChannel | VoiceChannel | CategoryChannel | NewsChannel | StoreChannel | StageChannel | ForumChannel;
type AnyChannel =
| TextChannel
| VoiceChannel
| CategoryChannel
| NewsChannel
| StoreChannel
| StageChannel
| ForumChannel;
expectType<Promise<TextChannel>>(guildChannelManager.create('name'));
expectType<Promise<TextChannel>>(guildChannelManager.create('name', {}));
@@ -1323,7 +1331,9 @@ declare const GuildBasedChannel: GuildBasedChannel;
declare const NonThreadGuildBasedChannel: NonThreadGuildBasedChannel;
declare const GuildTextBasedChannel: GuildTextBasedChannel;
expectType<DMChannel | PartialDMChannel | NewsChannel | TextChannel | ThreadChannel | VoiceChannel | StageChannel>(TextBasedChannel);
expectType<DMChannel | PartialDMChannel | NewsChannel | TextChannel | ThreadChannel | VoiceChannel | StageChannel>(
TextBasedChannel,
);
expectType<
| 'DM'
| 'GUILD_NEWS'
@@ -1335,10 +1345,42 @@ expectType<
| 'GUILD_STAGE_VOICE'
>(TextBasedChannelTypes);
expectType<StageChannel | VoiceChannel>(VoiceBasedChannel);
expectType<CategoryChannel | NewsChannel | StageChannel | StoreChannel | TextChannel | ThreadChannel | VoiceChannel | ForumChannel>(
GuildBasedChannel,
);
expectType<
| CategoryChannel
| NewsChannel
| StageChannel
| StoreChannel
| TextChannel
| ThreadChannel
| VoiceChannel
| ForumChannel
>(GuildBasedChannel);
expectType<CategoryChannel | NewsChannel | StageChannel | StoreChannel | TextChannel | VoiceChannel | ForumChannel>(
NonThreadGuildBasedChannel,
);
declare const threadMemberWithGuildMember: ThreadMember<true>;
declare const threadMemberManager: ThreadMemberManager;
{
expectType<Promise<ThreadMember>>(threadMemberManager.fetch('12345678'));
expectType<Promise<ThreadMember>>(threadMemberManager.fetch('12345678', { cache: false }));
expectType<Promise<ThreadMember>>(threadMemberManager.fetch('12345678', { force: true }));
expectType<Promise<ThreadMember<true>>>(threadMemberManager.fetch(threadMemberWithGuildMember));
expectType<Promise<ThreadMember<true>>>(threadMemberManager.fetch('12345678901234567', { withMember: true }));
expectType<Promise<Collection<Snowflake, ThreadMember>>>(threadMemberManager.fetch());
expectType<Promise<Collection<Snowflake, ThreadMember>>>(threadMemberManager.fetch({}));
expectType<Promise<Collection<Snowflake, ThreadMember<true>>>>(
threadMemberManager.fetch({ cache: true, limit: 50, withMember: true, after: '12345678901234567' }),
);
expectType<Promise<Collection<Snowflake, ThreadMember>>>(threadMemberManager.fetch(undefined, { cache: true }));
expectType<Promise<Collection<Snowflake, ThreadMember>>>(
threadMemberManager.fetch({ cache: true, withMember: false }),
);
// @ts-expect-error `withMember` needs to be `true` to receive paginated results.
threadMemberManager.fetch({ withMember: false, limit: 5, after: '12345678901234567' });
}
expectType<NewsChannel | TextChannel | ThreadChannel | VoiceChannel | StageChannel>(GuildTextBasedChannel);