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(Typing): cache member object #10786

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

Pavel-Boyazov
Copy link

Please describe the changes this PR makes and why it should be merged:
Discord API provides member object with TYPING_START event in guild. We can use this for cache update and getting value without getter

Status and versioning classification:

  • Code changes have been tested against the Discord API, or there are no code changes
  • I know how to update typings and have done so, or typings don't need updating

@Pavel-Boyazov Pavel-Boyazov requested a review from a team as a code owner March 1, 2025 21:38
Copy link

vercel bot commented Mar 1, 2025

The latest updates on your projects. Learn more about Vercel for Git ↗︎

2 Skipped Deployments
Name Status Preview Comments Updated (UTC)
discord-js ⬜️ Ignored (Inspect) Visit Preview Mar 1, 2025 11:18pm
discord-js-guide ⬜️ Ignored (Inspect) Visit Preview Mar 1, 2025 11:18pm

Comment on lines 37 to 43
if ('member' in data) {
/**
* The member that this guild typing instance represents
* @type {?GuildMember}
*/
this.member = this.channel.guild.members._add(data.member, true);
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This PR makes the member only set when its provided, otherwise it will be undefined (not null). Either we keep the getter and add the caching logic in too, or we define a fallback that is the getter

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This can be done without getters. If the member property was not set when the object was created, then there can be no conditions when it will be set later (except manually). I can use the ternary operator to set null if there is no data.
What do you think?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

const user = this.getUserFromMember(data);
already adds the member to cache, so this is redundant. The getter was fine as is.

@Pavel-Boyazov Pavel-Boyazov requested a review from vladfrangu March 1, 2025 23:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: Review in Progress
Development

Successfully merging this pull request may close these issues.

3 participants