-
-
Notifications
You must be signed in to change notification settings - Fork 132
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
base: next
Are you sure you want to change the base?
refactor!(model, cache, gateway): Make Presence::guild_id
an Option
#2125
Conversation
2f3a610
to
4680cf8
Compare
There was a problem hiding this 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()); |
There was a problem hiding this comment.
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}; | |||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@@ -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>>, |
There was a problem hiding this comment.
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?
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 twilightguild_id
s with presences as it's not required to.Secondly, is to work towards removing manually deserializers. See #1364