From e0c7af0d45afe88d97d2024a4794553c464035f8 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 e7642969..74db9496 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 804b5c253f5d098918714d210966b3a72fa01ae0 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 74db9496..8d14264c 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 7b3bb037e75a8f8a89f58fb7ca86648d456bc8d4 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 8d14264c..6bc45e25 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 + } + } }