From 2ee421d57efc91af57e589f0ce4a9bef59c75174 Mon Sep 17 00:00:00 2001 From: bitfl0wer Date: Tue, 14 Nov 2023 16:55:23 +0100 Subject: [PATCH 1/3] Generate snowflake if not exists --- src/types/entities/voice_state.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/types/entities/voice_state.rs b/src/types/entities/voice_state.rs index e764296..74db949 100644 --- a/src/types/entities/voice_state.rs +++ b/src/types/entities/voice_state.rs @@ -38,5 +38,6 @@ pub struct VoiceState { pub self_video: bool, pub suppress: bool, pub request_to_speak_timestamp: Option>, - pub id: Snowflake, + #[serde(default = "Snowflake::generate")] + pub id: Snowflake, // Only exists on Spacebar } From 2bff2cb8cf453a58e686405a8abb4495ad439e7d Mon Sep 17 00:00:00 2001 From: kozabrada123 <59031733+kozabrada123@users.noreply.github.com> Date: Tue, 14 Nov 2023 17:08:46 +0100 Subject: [PATCH 2/3] fix: Voice State session id is a string, not a snowflake --- src/types/entities/voice_state.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/types/entities/voice_state.rs b/src/types/entities/voice_state.rs index 74db949..8d14264 100644 --- a/src/types/entities/voice_state.rs +++ b/src/types/entities/voice_state.rs @@ -28,7 +28,7 @@ pub struct VoiceState { pub channel_id: Option, pub user_id: Snowflake, pub member: Option>>, - pub session_id: Snowflake, + pub session_id: String, pub token: Option, pub deaf: bool, pub mute: bool, From b4193e2c2e0bbd06d67eee7770e5dac5055967fd Mon Sep 17 00:00:00 2001 From: bitfl0wer Date: Tue, 14 Nov 2023 17:31:07 +0100 Subject: [PATCH 3/3] Make id Optional, custom impl Updateable --- src/types/entities/voice_state.rs | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/src/types/entities/voice_state.rs b/src/types/entities/voice_state.rs index 8d14264..6bc45e2 100644 --- a/src/types/entities/voice_state.rs +++ b/src/types/entities/voice_state.rs @@ -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 #[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, pub guild: Option, @@ -38,6 +41,15 @@ pub struct VoiceState { pub self_video: bool, pub suppress: bool, pub request_to_speak_timestamp: Option>, - #[serde(default = "Snowflake::generate")] - pub id: Snowflake, // Only exists on Spacebar + pub id: Option, // 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 + } + } }