client: Add CloudUserStore (#35370)

This PR adds a new `CloudUserStore` for storing information about the
user retrieved from Cloud instead of Collab.

Release Notes:

- N/A
This commit is contained in:
Marshall Bowers 2025-07-30 18:43:10 -04:00 committed by GitHub
parent 289f420504
commit bb1a7ccbba
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
7 changed files with 68 additions and 4 deletions

View file

@ -1,6 +1,7 @@
#[cfg(any(test, feature = "test-support"))]
pub mod test;
mod cloud;
mod proxy;
pub mod telemetry;
pub mod user;
@ -52,6 +53,7 @@ use tokio::net::TcpStream;
use url::Url;
use util::{ConnectionResult, ResultExt};
pub use cloud::*;
pub use rpc::*;
pub use telemetry_events::Event;
pub use user::*;
@ -621,6 +623,10 @@ impl Client {
self.http.clone()
}
pub fn cloud_client(&self) -> Arc<CloudApiClient> {
self.cloud_client.clone()
}
pub fn set_id(&self, id: u64) -> &Self {
self.id.store(id, Ordering::SeqCst);
self

View file

@ -0,0 +1,3 @@
mod user_store;
pub use user_store::*;

View file

@ -0,0 +1,41 @@
use std::sync::Arc;
use std::time::Duration;
use anyhow::Context as _;
use cloud_api_client::{AuthenticatedUser, CloudApiClient};
use gpui::{Context, Task};
use util::{ResultExt as _, maybe};
pub struct CloudUserStore {
authenticated_user: Option<AuthenticatedUser>,
_fetch_authenticated_user_task: Task<()>,
}
impl CloudUserStore {
pub fn new(cloud_client: Arc<CloudApiClient>, cx: &mut Context<Self>) -> Self {
Self {
authenticated_user: None,
_fetch_authenticated_user_task: cx.spawn(async move |this, cx| {
maybe!(async move {
loop {
if cloud_client.has_credentials() {
break;
}
cx.background_executor()
.timer(Duration::from_millis(100))
.await;
}
let response = cloud_client.get_authenticated_user().await?;
this.update(cx, |this, _cx| {
this.authenticated_user = Some(response.user);
})
})
.await
.context("failed to fetch authenticated user")
.log_err();
}),
}
}
}