Code at the speed of thought – Zed is a high-performance, multiplayer code editor from the creators of Atom and Tree-sitter.
Add users to mailing list when using an invite link
Joseph T. Lyonsc3b102f5a82e
diff --git a/crates/collab/src/api.rs b/crates/collab/src/api.rsindex 921b4189e82..235ed664244 100644--- a/crates/collab/src/api.rs+++ b/crates/collab/src/api.rs@@ -353,6 +353,8 @@ pub struct CreateInviteFromCodeParams {invite_code: String,email_address: String,device_id: Option<String>,+ #[serde(default)]+ added_to_mailing_list: bool,}async fn create_invite_from_code(@@ -365,6 +367,7 @@ async fn create_invite_from_code(¶ms.invite_code,¶ms.email_address,params.device_id.as_deref(),+ params.added_to_mailing_list,).await?,))diff --git a/crates/collab/src/db.rs b/crates/collab/src/db.rsindex 1bbfac85d3d..63ea7fdd9e1 100644--- a/crates/collab/src/db.rs+++ b/crates/collab/src/db.rs@@ -882,6 +882,7 @@ impl Database {code: &str,email_address: &str,device_id: Option<&str>,+ added_to_mailing_list: bool,) -> Result<Invite> {self.transaction(|tx| async move {let existing_user = user::Entity::find()@@ -933,6 +934,7 @@ impl Database {platform_windows: ActiveValue::set(false),platform_unknown: ActiveValue::set(true),device_id: ActiveValue::set(device_id.map(|device_id| device_id.into())),+ added_to_mailing_list: ActiveValue::set(added_to_mailing_list),..Default::default()}).on_conflict(diff --git a/crates/collab/src/db/tests.rs b/crates/collab/src/db/tests.rsindex 9d42c11f8bb..1e271675458 100644--- a/crates/collab/src/db/tests.rs+++ b/crates/collab/src/db/tests.rs@@ -567,7 +567,12 @@ async fn test_invite_codes() {// User 2 redeems the invite code and becomes a contact of user 1.let user2_invite = db- .create_invite_from_code(&invite_code, "[email protected]", Some("user-2-device-id"))+ .create_invite_from_code(+ &invite_code,+ "[email protected]",+ Some("user-2-device-id"),+ true,+ ).await.unwrap();let NewUserResult {@@ -617,7 +622,7 @@ async fn test_invite_codes() {// User 3 redeems the invite code and becomes a contact of user 1.let user3_invite = db- .create_invite_from_code(&invite_code, "[email protected]", None)+ .create_invite_from_code(&invite_code, "[email protected]", None, true).await.unwrap();let NewUserResult {@@ -672,9 +677,14 @@ async fn test_invite_codes() {);// Trying to reedem the code for the third time results in an error.- db.create_invite_from_code(&invite_code, "[email protected]", Some("user-4-device-id"))- .await- .unwrap_err();+ db.create_invite_from_code(+ &invite_code,+ "[email protected]",+ Some("user-4-device-id"),+ true,+ )+ .await+ .unwrap_err();// Invite count can be updated after the code has been created.db.set_invite_count_for_user(user1, 2).await.unwrap();@@ -684,7 +694,12 @@ async fn test_invite_codes() {// User 4 can now redeem the invite code and becomes a contact of user 1.let user4_invite = db- .create_invite_from_code(&invite_code, "[email protected]", Some("user-4-device-id"))+ .create_invite_from_code(+ &invite_code,+ "[email protected]",+ Some("user-4-device-id"),+ true,+ ).await.unwrap();let user4 = db@@ -739,9 +754,14 @@ async fn test_invite_codes() {);// An existing user cannot redeem invite codes.- db.create_invite_from_code(&invite_code, "[email protected]", Some("user-2-device-id"))- .await- .unwrap_err();+ db.create_invite_from_code(+ &invite_code,+ "[email protected]",+ Some("user-2-device-id"),+ true,+ )+ .await+ .unwrap_err();let (_, invite_count) = db.get_invite_code_for_user(user1).await.unwrap().unwrap();assert_eq!(invite_count, 1);@@ -763,7 +783,7 @@ async fn test_invite_codes() {db.set_invite_count_for_user(user5, 5).await.unwrap();let (user5_invite_code, _) = db.get_invite_code_for_user(user5).await.unwrap().unwrap();let user5_invite_to_user1 = db- .create_invite_from_code(&user5_invite_code, "[email protected]", None)+ .create_invite_from_code(&user5_invite_code, "[email protected]", None, true).await.unwrap();let user1_2 = db