collab: Remove unused invite code handlers (#46048)

Marshall Bowers created

This PR removes some unused invite code RPC handlers, as well as the
`UpdateInviteInfo` RPC message.

Release Notes:

- N/A

Change summary

crates/client/src/user.rs             | 22 ------------
crates/collab/src/db/queries/users.rs |  2 -
crates/collab/src/db/tables/user.rs   |  2 -
crates/collab/src/rpc.rs              | 51 -----------------------------
crates/proto/proto/app.proto          |  5 --
crates/proto/proto/zed.proto          |  2 
crates/proto/src/proto.rs             |  1 
7 files changed, 1 insertion(+), 84 deletions(-)

Detailed changes

crates/client/src/user.rs 🔗

@@ -116,7 +116,6 @@ pub struct UserStore {
     incoming_contact_requests: Vec<Arc<User>>,
     outgoing_contact_requests: Vec<Arc<User>>,
     pending_contact_requests: HashMap<u64, usize>,
-    invite_info: Option<InviteInfo>,
     client: Weak<Client>,
     _maintain_contacts: Task<()>,
     _maintain_current_user: Task<Result<()>>,
@@ -173,7 +172,6 @@ impl UserStore {
         let (update_contacts_tx, mut update_contacts_rx) = mpsc::unbounded();
         let rpc_subscriptions = vec![
             client.add_message_handler(cx.weak_entity(), Self::handle_update_contacts),
-            client.add_message_handler(cx.weak_entity(), Self::handle_update_invite_info),
             client.add_message_handler(cx.weak_entity(), Self::handle_show_contacts),
         ];
 
@@ -193,7 +191,6 @@ impl UserStore {
             incoming_contact_requests: Default::default(),
             participant_indices: Default::default(),
             outgoing_contact_requests: Default::default(),
-            invite_info: None,
             client: Arc::downgrade(&client),
             update_contacts_tx,
             _maintain_contacts: cx.spawn(async move |this, cx| {
@@ -297,21 +294,6 @@ impl UserStore {
         self.by_github_login.clear();
     }
 
-    async fn handle_update_invite_info(
-        this: Entity<Self>,
-        message: TypedEnvelope<proto::UpdateInviteInfo>,
-        mut cx: AsyncApp,
-    ) -> Result<()> {
-        this.update(&mut cx, |this, cx| {
-            this.invite_info = Some(InviteInfo {
-                url: Arc::from(message.payload.url),
-                count: message.payload.count,
-            });
-            cx.notify();
-        })?;
-        Ok(())
-    }
-
     async fn handle_show_contacts(
         this: Entity<Self>,
         _: TypedEnvelope<proto::ShowContacts>,
@@ -321,10 +303,6 @@ impl UserStore {
         Ok(())
     }
 
-    pub fn invite_info(&self) -> Option<&InviteInfo> {
-        self.invite_info.as_ref()
-    }
-
     async fn handle_update_contacts(
         this: Entity<Self>,
         message: TypedEnvelope<proto::UpdateContacts>,

crates/collab/src/db/queries/users.rs 🔗

@@ -136,8 +136,6 @@ impl Database {
                 github_user_id: ActiveValue::set(github_user_id),
                 github_user_created_at: ActiveValue::set(Some(github_user_created_at)),
                 admin: ActiveValue::set(false),
-                invite_count: ActiveValue::set(0),
-                invite_code: ActiveValue::set(None),
                 metrics_id: ActiveValue::set(Uuid::new_v4()),
                 ..Default::default()
             })

crates/collab/src/db/tables/user.rs 🔗

@@ -15,8 +15,6 @@ pub struct Model {
     pub email_address: Option<String>,
     pub name: Option<String>,
     pub admin: bool,
-    pub invite_code: Option<String>,
-    pub invite_count: i32,
     pub connected_once: bool,
     pub metrics_id: Uuid,
     pub created_at: NaiveDateTime,

crates/collab/src/rpc.rs 🔗

@@ -982,57 +982,6 @@ impl Server {
         Ok(())
     }
 
-    pub async fn invite_code_redeemed(
-        self: &Arc<Self>,
-        inviter_id: UserId,
-        invitee_id: UserId,
-    ) -> Result<()> {
-        if let Some(user) = self.app_state.db.get_user_by_id(inviter_id).await?
-            && let Some(code) = &user.invite_code
-        {
-            let pool = self.connection_pool.lock();
-            let invitee_contact = contact_for_user(invitee_id, false, &pool);
-            for connection_id in pool.user_connection_ids(inviter_id) {
-                self.peer.send(
-                    connection_id,
-                    proto::UpdateContacts {
-                        contacts: vec![invitee_contact.clone()],
-                        ..Default::default()
-                    },
-                )?;
-                self.peer.send(
-                    connection_id,
-                    proto::UpdateInviteInfo {
-                        url: format!("{}{}", self.app_state.config.invite_link_prefix, &code),
-                        count: user.invite_count as u32,
-                    },
-                )?;
-            }
-        }
-        Ok(())
-    }
-
-    pub async fn invite_count_updated(self: &Arc<Self>, user_id: UserId) -> Result<()> {
-        if let Some(user) = self.app_state.db.get_user_by_id(user_id).await?
-            && let Some(invite_code) = &user.invite_code
-        {
-            let pool = self.connection_pool.lock();
-            for connection_id in pool.user_connection_ids(user_id) {
-                self.peer.send(
-                    connection_id,
-                    proto::UpdateInviteInfo {
-                        url: format!(
-                            "{}{}",
-                            self.app_state.config.invite_link_prefix, invite_code
-                        ),
-                        count: user.invite_count as u32,
-                    },
-                )?;
-            }
-        }
-        Ok(())
-    }
-
     pub async fn snapshot(self: &Arc<Self>) -> ServerSnapshot<'_> {
         ServerSnapshot {
             connection_pool: ConnectionPoolGuard {

crates/proto/proto/app.proto 🔗

@@ -1,11 +1,6 @@
 syntax = "proto3";
 package zed.messages;
 
-message UpdateInviteInfo {
-    string url = 1;
-    uint32 count = 2;
-}
-
 message ShutdownRemoteServer {}
 
 message Toast {

crates/proto/proto/zed.proto 🔗

@@ -122,7 +122,6 @@ message Envelope {
         PerformRenameResponse perform_rename_response = 86;
 
         UpdateContacts update_contacts = 89;
-        UpdateInviteInfo update_invite_info = 90;
         ShowContacts show_contacts = 91;
 
         GetUsers get_users = 92;
@@ -452,6 +451,7 @@ message Envelope {
     }
 
     reserved 87 to 88, 396;
+    reserved 90;
     reserved 102 to 103;
     reserved 158 to 161;
     reserved 164;

crates/proto/src/proto.rs 🔗

@@ -274,7 +274,6 @@ messages!(
     (UpdateDiffBases, Foreground),
     (UpdateFollowers, Foreground),
     (UpdateGitBranch, Background),
-    (UpdateInviteInfo, Foreground),
     (UpdateLanguageServer, Foreground),
     (UpdateNotification, Foreground),
     (UpdateParticipantLocation, Foreground),