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

refactor!(model, cache, gateway): Make Presence::guild_id an Option #2125

Open
wants to merge 3 commits into
base: next
Choose a base branch
from

Conversation

suneettipirneni
Copy link
Member

As outlined in discord, this PR makes Presence::guild_id an option. This is being done for various reasons.

The first reason is for future-proofing against API changes. Presence isn't an explicitly defined structure in the API, but rather something that is the return value of a gateway event. Despite this, it does show up in other areas of the API. As of making this PR there isn't any situations where we receive a presence and have no knowledge of the guild id. However, as the field itself isn't always required to be sent with presences, the API may not always give twilight guild_ids with presences as it's not required to.

Secondly, is to work towards removing manually deserializers. See #1364

@github-actions github-actions bot added c-cache Affects the cache crate c-model Affects the model crate labels Feb 6, 2023
@suneettipirneni suneettipirneni marked this pull request as draft February 6, 2023 18:00
@zeylahellyer zeylahellyer self-requested a review February 7, 2023 01:07
@suneettipirneni suneettipirneni force-pushed the refactor/make-presence-guild-id-option branch from 2f3a610 to 4680cf8 Compare February 8, 2023 02:40
@suneettipirneni suneettipirneni marked this pull request as ready for review February 8, 2023 02:40
@suneettipirneni suneettipirneni changed the base branch from main to next February 8, 2023 02:50
@vilgotf vilgotf self-requested a review April 2, 2023 14:49
Copy link
Member

@vilgotf vilgotf left a comment

Choose a reason for hiding this comment

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

Looks good, as you've pointed out but I only now understand, the injection of presences' guild ID inside of the guild deserializer is necessary for the cache to work. Need to keep that in mind if we ever want to replace the manual guild deserializer with a derived one.

@@ -34,7 +34,9 @@ impl UpdateCache for PresenceUpdate {

let presence = CachedPresence::from_model(self.0.clone());
Copy link
Member

Choose a reason for hiding this comment

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

Let's move this allocation inside of the if statement

@@ -1,188 +1,28 @@
use serde::{Deserialize, Serialize};

Copy link
Member

Choose a reason for hiding this comment

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

Suggested change

@@ -14,7 +14,7 @@ use twilight_model::{
pub struct CachedPresence {
pub(crate) activities: Vec<Activity>,
pub(crate) client_status: ClientStatus,
pub(crate) guild_id: Id<GuildMarker>,
pub(crate) guild_id: Option<Id<GuildMarker>>,
Copy link
Member

Choose a reason for hiding this comment

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

Actually I do not see a reason for this change. Except that the from_model would need to require another arg for the guild_id. But since the cache_presence method requires a guild_id anyways, this shouldn't be a huge problem, no?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
c-cache Affects the cache crate c-model Affects the model crate
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants