From 1caf8e9ba2d2b43ae513b64d1b33b544295e1195 Mon Sep 17 00:00:00 2001 From: bitfl0wer Date: Tue, 14 Nov 2023 16:10:37 +0100 Subject: [PATCH 1/4] bump version --- Cargo.lock | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index edb7696..576f2ec 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -177,7 +177,7 @@ checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" [[package]] name = "chorus" -version = "0.10.1" +version = "0.11.0" dependencies = [ "async-trait", "base64 0.21.3", @@ -2338,9 +2338,9 @@ dependencies = [ [[package]] name = "tokio-tungstenite" -version = "0.20.0" +version = "0.20.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2b2dbec703c26b00d74844519606ef15d09a7d6857860f84ad223dec002ddea2" +checksum = "212d5dcb2a1ce06d81107c3d0ffa3121fe974b73f068c8282cb1c32328113b6c" dependencies = [ "futures-util", "log", From 2ee421d57efc91af57e589f0ce4a9bef59c75174 Mon Sep 17 00:00:00 2001 From: bitfl0wer Date: Tue, 14 Nov 2023 16:55:23 +0100 Subject: [PATCH 2/4] 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 3/4] 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 4/4] 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 + } + } }