Skip to content

Commit

Permalink
Make id Optional, custom impl Updateable
Browse files Browse the repository at this point in the history
  • Loading branch information
bitfl0wer committed Nov 14, 2023
1 parent 804b5c2 commit 7b3bb03
Showing 1 changed file with 15 additions and 3 deletions.
18 changes: 15 additions & 3 deletions src/types/entities/voice_state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,13 @@ use crate::types::{
utils::Snowflake,
};

/// The VoiceState struct. Note, that Discord does not have an `id` field for this, whereas Spacebar
/// does.
///
/// See <https://docs.spacebar.chat/routes/#cmp--schemas-voicestate>
#[derive(Serialize, Deserialize, Debug, Default, Clone)]
#[cfg_attr(feature = "sqlx", derive(sqlx::FromRow))]
#[cfg_attr(feature = "client", derive(Updateable, Composite))]
#[cfg_attr(feature = "client", derive(Composite))]
pub struct VoiceState {
pub guild_id: Option<Snowflake>,
pub guild: Option<Guild>,
Expand All @@ -38,6 +41,15 @@ pub struct VoiceState {
pub self_video: bool,
pub suppress: bool,
pub request_to_speak_timestamp: Option<DateTime<Utc>>,
#[serde(default = "Snowflake::generate")]
pub id: Snowflake, // Only exists on Spacebar
pub id: Option<Snowflake>, // Only exists on Spacebar
}

impl Updateable for VoiceState {
fn id(&self) -> Snowflake {
if let Some(id) = self.id {
id // ID exists: Only the case for Spacebar Server impls
} else {
self.user_id // ID doesn't exist: Discord does not have the ID field - ID is void
}
}
}

0 comments on commit 7b3bb03

Please sign in to comment.