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

feat(ThreadMemberManager): Support pagination fetching #9035

Merged
merged 24 commits into from
Feb 17, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
ed9458c
feat: initial commit
Jiralite Jan 9, 2023
48dc043
fix: `query`
Jiralite Jan 9, 2023
ee1679b
fix: `GuildMember` for `member`
Jiralite Jan 9, 2023
f9153e3
types(ThreadMember): constructor types
Jiralite Jan 9, 2023
25c3aec
fix: send API properties correctly
Jiralite Jan 9, 2023
b71f4c5
docs(FetchThreadMembersOptions): update `cache` description
Jiralite Jan 9, 2023
f2f09aa
fix: retrieve from option
Jiralite Jan 9, 2023
0b258e0
Merge branch 'feat/thread-member-pagination' of https://github.com/Ji…
Jiralite Jan 9, 2023
e03f79f
fix: fix fetch many
Jiralite Jan 9, 2023
5e8c12d
types(FetchThreadMembersOptions): add `withMember`
Jiralite Jan 9, 2023
867c24f
types: stricter types
Jiralite Jan 9, 2023
aaacbbe
types: infer possible guild member
Jiralite Jan 9, 2023
a3560b9
chore: reference member in getter
Jiralite Jan 9, 2023
cda695f
types: remove `<false>`
Jiralite Jan 9, 2023
5fc1fa2
style: remove line
Jiralite Jan 9, 2023
7d5c327
chore: markdown
Jiralite Jan 9, 2023
e88f05c
types: remove `?`
Jiralite Jan 9, 2023
f1090ea
docs: remove irrelevant part
Jiralite Jan 9, 2023
978c25b
fix: prevent crash
Jiralite Jan 9, 2023
7d0629f
refactor: make `member` `@private`
Jiralite Jan 11, 2023
0c0973f
Merge branch 'main' into feat/thread-member-pagination
Jiralite Jan 13, 2023
5419804
Merge branch 'main' into feat/thread-member-pagination
Jiralite Jan 18, 2023
135cdfa
Merge branch 'main' into feat/thread-member-pagination
Jiralite Feb 17, 2023
de25cea
Merge branch 'main' into feat/thread-member-pagination
kodiakhq[bot] Feb 17, 2023
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
11 changes: 7 additions & 4 deletions packages/discord.js/src/managers/ThreadMemberManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -114,10 +114,13 @@ class ThreadMemberManager extends CachedManager {
/**
* @typedef {BaseFetchOptions} FetchThreadMemberOptions
* @property {ThreadMemberResolvable} member The thread member to fetch
* @property {boolean} [withMember] Whether to also return the guild member associated with this thread member
*/

/**
* @typedef {Object} FetchThreadMembersOptions
* @property {Snowflake} [after] Consider only thread members after this id
* @property {number} [limit] The maximum number of thread members to return
* @property {boolean} [cache] Whether to cache the fetched thread members
*/

Expand All @@ -130,19 +133,19 @@ class ThreadMemberManager extends CachedManager {
*/
fetch(options) {
if (!options) return this._fetchMany();
const { member, cache, force } = options;
const { member, withMember, cache, force } = options;
const resolvedMember = this.resolveId(member ?? options);
if (resolvedMember) return this._fetchSingle({ member: resolvedMember, cache, force });
if (resolvedMember) return this._fetchSingle({ member: resolvedMember, withMember, cache, force });
return this._fetchMany(options);
}

async _fetchSingle({ member, cache, force = false }) {
async _fetchSingle({ member, withMember, cache, force = false }) {
if (!force) {
const existing = this.cache.get(member);
if (existing) return existing;
}

const data = await this.client.rest.get(Routes.threadMembers(this.thread.id, member));
const data = await this.client.rest.get(Routes.threadMembers(this.thread.id, member), { body: { withMember } });
return this._add(data, cache);
}

Expand Down
10 changes: 10 additions & 0 deletions packages/discord.js/src/structures/ThreadMember.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,16 @@ class ThreadMember extends Base {
_patch(data) {
if ('join_timestamp' in data) this.joinedTimestamp = Date.parse(data.join_timestamp);
if ('flags' in data) this.flags = new ThreadMemberFlagsBitField(data.flags).freeze();

/**
* The guild member associated with this thread member.
* @type {?GuildMember}
*/
if ('member' in data) {
Jiralite marked this conversation as resolved.
Show resolved Hide resolved
this.member = data.member;
Jiralite marked this conversation as resolved.
Show resolved Hide resolved
} else {
this.member ??= null;
}
}

/**
Expand Down
4 changes: 4 additions & 0 deletions packages/discord.js/typings/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2964,6 +2964,7 @@ export class ThreadChannel<Forum extends boolean = boolean> extends TextBasedCha
export class ThreadMember extends Base {
private constructor(thread: ThreadChannel, data?: RawThreadMemberData);
public flags: ThreadMemberFlagsBitField;
public member: GuildMember | null;
public get guildMember(): GuildMember | null;
public id: Snowflake;
public get joinedAt(): Date | null;
Expand Down Expand Up @@ -5185,9 +5186,12 @@ export interface FetchReactionUsersOptions {

export interface FetchThreadMemberOptions extends BaseFetchOptions {
member: ThreadMemberResolvable;
withMember?: boolean;
}

export interface FetchThreadMembersOptions {
after?: Snowflake;
limit?: number;
cache?: boolean;
}

Expand Down