From 0e156b98977b5fea4e125dfaf67ee5d218adf606 Mon Sep 17 00:00:00 2001 From: bitfl0wer Date: Tue, 29 Aug 2023 00:05:16 +0200 Subject: [PATCH] Make ChorusUser `Clone` --- src/instance.rs | 8 ++++---- src/types/schema/auth.rs | 6 +++--- tests/common/mod.rs | 2 +- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/instance.rs b/src/instance.rs index 08a7f82..a3b5325 100644 --- a/src/instance.rs +++ b/src/instance.rs @@ -84,7 +84,7 @@ impl fmt::Display for Token { } } -#[derive(Debug)] +#[derive(Debug, Clone)] /// A ChorusUser is a representation of an authenticated user on an [Instance]. /// It is used for most authenticated actions on a Spacebar server. /// It also has its own [Gateway] connection. @@ -94,7 +94,7 @@ pub struct ChorusUser { pub limits: Option>, pub settings: Arc>, pub object: Arc>, - pub gateway: GatewayHandle, + pub gateway: Arc, // TODO: Can this be an Arc? That way we could have Clone implemented on ChorusUser } impl ChorusUser { @@ -117,7 +117,7 @@ impl ChorusUser { limits: Option>, settings: Arc>, object: Arc>, - gateway: GatewayHandle, + gateway: Arc, ) -> ChorusUser { ChorusUser { belongs_to, @@ -139,7 +139,7 @@ impl ChorusUser { let object = Arc::new(RwLock::new(User::default())); let wss_url = instance.read().unwrap().urls.wss.clone(); // Dummy gateway object - let gateway = Gateway::new(wss_url).await.unwrap(); + let gateway = Arc::new(Gateway::new(wss_url).await.unwrap()); ChorusUser { token, belongs_to: instance.clone(), diff --git a/src/types/schema/auth.rs b/src/types/schema/auth.rs index 9a3b9d6..60e23a4 100644 --- a/src/types/schema/auth.rs +++ b/src/types/schema/auth.rs @@ -1,6 +1,6 @@ use serde::{Deserialize, Serialize}; -#[derive(Debug, Default, Serialize, Deserialize, PartialEq, Eq)] +#[derive(Debug, Clone, Default, Serialize, Deserialize, PartialEq, Eq)] #[serde(rename_all = "snake_case")] pub struct RegisterSchema { pub username: String, @@ -15,7 +15,7 @@ pub struct RegisterSchema { pub promotional_email_opt_in: Option, } -#[derive(Debug, Serialize, Deserialize, PartialEq, Eq)] +#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] #[serde(rename_all = "snake_case")] pub struct LoginSchema { /// For Discord, usernames must be between 2 and 32 characters, @@ -30,7 +30,7 @@ pub struct LoginSchema { pub gift_code_sku_id: Option, } -#[derive(Debug, Serialize, Deserialize)] +#[derive(Debug, Clone, Default, PartialEq, Eq, Serialize, Deserialize)] #[serde(rename_all = "snake_case")] pub struct TotpSchema { code: String, diff --git a/tests/common/mod.rs b/tests/common/mod.rs index a7b9d5d..19c6509 100644 --- a/tests/common/mod.rs +++ b/tests/common/mod.rs @@ -42,7 +42,7 @@ impl TestBundle { limits: self.user.limits.clone(), settings: self.user.settings.clone(), object: self.user.object.clone(), - gateway: Gateway::new(self.instance.urls.wss.clone()).await.unwrap(), + gateway: Arc::new(Gateway::new(self.instance.urls.wss.clone()).await.unwrap()), } } }