From b751156cd73788221e45f47515d5f2864ae1db41 Mon Sep 17 00:00:00 2001 From: Antonio Scandurra Date: Fri, 20 May 2022 17:35:00 +0200 Subject: [PATCH] Rename `first_connection` to `connected_once` Co-Authored-By: Nathan Sobo --- .../20220518151305_add_invites_to_users.sql | 2 +- crates/collab/src/db.rs | 20 ++++++++----------- crates/collab/src/rpc.rs | 4 ++-- 3 files changed, 11 insertions(+), 15 deletions(-) diff --git a/crates/collab/migrations/20220518151305_add_invites_to_users.sql b/crates/collab/migrations/20220518151305_add_invites_to_users.sql index e2a22f3420..46239f2833 100644 --- a/crates/collab/migrations/20220518151305_add_invites_to_users.sql +++ b/crates/collab/migrations/20220518151305_add_invites_to_users.sql @@ -2,7 +2,7 @@ ALTER TABLE users ADD invite_code VARCHAR(64), ADD invite_count INTEGER NOT NULL DEFAULT 0, ADD inviter_id INTEGER REFERENCES users (id), -ADD first_connection BOOLEAN NOT NULL DEFAULT true, +ADD connected_once BOOLEAN NOT NULL DEFAULT false, ADD created_at TIMESTAMP NOT NULL DEFAULT NOW(); CREATE UNIQUE INDEX "index_invite_code_users" ON "users" ("invite_code"); diff --git a/crates/collab/src/db.rs b/crates/collab/src/db.rs index b05ff3c9ec..7474fe44c0 100644 --- a/crates/collab/src/db.rs +++ b/crates/collab/src/db.rs @@ -18,7 +18,7 @@ pub trait Db: Send + Sync { async fn get_users_by_ids(&self, ids: Vec) -> Result>; async fn get_user_by_github_login(&self, github_login: &str) -> Result>; async fn set_user_is_admin(&self, id: UserId, is_admin: bool) -> Result<()>; - async fn set_user_first_connection(&self, id: UserId, first_connection: bool) -> Result<()>; + async fn set_user_connected_once(&self, id: UserId, connected_once: bool) -> Result<()>; async fn destroy_user(&self, id: UserId) -> Result<()>; async fn set_invite_count(&self, id: UserId, count: u32) -> Result<()>; @@ -183,10 +183,10 @@ impl Db for PostgresDb { .map(drop)?) } - async fn set_user_first_connection(&self, id: UserId, first_connection: bool) -> Result<()> { - let query = "UPDATE users SET first_connection = $1 WHERE id = $2"; + async fn set_user_connected_once(&self, id: UserId, connected_once: bool) -> Result<()> { + let query = "UPDATE users SET connected_once = $1 WHERE id = $2"; Ok(sqlx::query(query) - .bind(first_connection) + .bind(connected_once) .bind(id.0) .execute(&self.pool) .await @@ -858,7 +858,7 @@ pub struct User { pub admin: bool, pub invite_code: Option, pub invite_count: i32, - pub first_connection: bool, + pub connected_once: bool, } id_type!(OrgId); @@ -1613,7 +1613,7 @@ pub mod tests { admin, invite_code: None, invite_count: 0, - first_connection: true, + connected_once: false, }, ); Ok(user_id) @@ -1651,17 +1651,13 @@ pub mod tests { unimplemented!() } - async fn set_user_first_connection( - &self, - id: UserId, - first_connection: bool, - ) -> Result<()> { + async fn set_user_connected_once(&self, id: UserId, connected_once: bool) -> Result<()> { self.background.simulate_random_delay().await; let mut users = self.users.lock(); let mut user = users .get_mut(&id) .ok_or_else(|| anyhow!("user not found"))?; - user.first_connection = first_connection; + user.connected_once = connected_once; Ok(()) } diff --git a/crates/collab/src/rpc.rs b/crates/collab/src/rpc.rs index b902ded619..576a6e1db2 100644 --- a/crates/collab/src/rpc.rs +++ b/crates/collab/src/rpc.rs @@ -280,9 +280,9 @@ impl Server { let _ = send_connection_id.send(connection_id).await; } - if user.first_connection { + if !user.connected_once { this.peer.send(connection_id, proto::ShowContacts {})?; - this.app_state.db.set_user_first_connection(user_id, false).await?; + this.app_state.db.set_user_connected_once(user_id, true).await?; } let (contacts, invite_code) = future::try_join(