chore: de-arced a bit

Co-authored-by: zaaarf <me@zaaarf.foo>
This commit is contained in:
əlemi 2024-08-08 00:25:22 +02:00
parent ffa8d8ea82
commit 4de09cb164
Signed by: alemi
GPG key ID: A4895B84D311642C
2 changed files with 32 additions and 31 deletions

View file

@ -33,8 +33,8 @@ use crate::{
/// can be used to interact with server /// can be used to interact with server
pub struct Client { pub struct Client {
user_id: Uuid, user_id: Uuid,
workspaces: DashMap<String, Workspace>,
token_tx: Arc<tokio::sync::watch::Sender<Token>>, token_tx: Arc<tokio::sync::watch::Sender<Token>>,
workspaces: Arc<DashMap<String, Workspace>>,
services: Arc<Services> services: Arc<Services>
} }
@ -93,8 +93,8 @@ impl Client {
Ok(Client { Ok(Client {
user_id, user_id,
workspaces: DashMap::default(),
token_tx: Arc::new(token_tx), token_tx: Arc::new(token_tx),
workspaces: Arc::new(DashMap::default()),
services: Arc::new(Services { workspace, buffer, cursor, auth }) services: Arc::new(Services { workspace, buffer, cursor, auth })
}) })
} }
@ -129,8 +129,8 @@ impl Client {
let ws = Workspace::new( let ws = Workspace::new(
workspace.to_string(), workspace.to_string(),
self.user_id, self.user_id,
self.token_tx.clone(),
controller, controller,
self.token_tx.clone(),
self.services.clone() self.services.clone()
); );

View file

@ -1,5 +1,5 @@
use crate::{ use crate::{
api::controller::ControllerWorker, api::{Controller, controller::ControllerWorker},
buffer::{self, worker::BufferWorker}, buffer::{self, worker::BufferWorker},
client::Services, client::Services,
cursor, cursor,
@ -39,12 +39,12 @@ pub struct Workspace(Arc<WorkspaceInner>);
struct WorkspaceInner { struct WorkspaceInner {
id: String, id: String,
user_id: Uuid, // reference to global user id user_id: Uuid, // reference to global user id
token: Arc<tokio::sync::watch::Sender<Token>>,
cursor: cursor::Controller, cursor: cursor::Controller,
buffers: Arc<DashMap<String, buffer::Controller>>, buffers: DashMap<String, buffer::Controller>,
pub(crate) filetree: Arc<DashSet<String>>, filetree: DashSet<String>,
pub(crate) users: Arc<DashMap<Uuid, UserInfo>>, users: DashMap<Uuid, UserInfo>,
services: Arc<Services>, token: Arc<tokio::sync::watch::Sender<Token>>, // shared
services: Arc<Services>, // shared
} }
impl Workspace { impl Workspace {
@ -52,8 +52,8 @@ impl Workspace {
pub(crate) fn new( pub(crate) fn new(
id: String, id: String,
user_id: Uuid, user_id: Uuid,
token: Arc<tokio::sync::watch::Sender<Token>>,
cursor: cursor::Controller, cursor: cursor::Controller,
token: Arc<tokio::sync::watch::Sender<Token>>,
services: Arc<Services>, services: Arc<Services>,
) -> Self { ) -> Self {
Self(Arc::new(WorkspaceInner { Self(Arc::new(WorkspaceInner {
@ -61,16 +61,15 @@ impl Workspace {
user_id, user_id,
token, token,
cursor, cursor,
buffers: Arc::new(DashMap::default()), buffers: DashMap::default(),
filetree: Arc::new(DashSet::default()), filetree: DashSet::default(),
users: Arc::new(DashMap::default()), users: DashMap::default(),
services, services,
})) }))
} }
pub(crate) fn run_actor(&self, mut stream: Streaming<WorkspaceEvent>) { pub(crate) fn run_actor(&self, mut stream: Streaming<WorkspaceEvent>) {
let users = self.0.users.clone(); let inner = self.0.clone();
let filetree = self.0.filetree.clone();
let name = self.id(); let name = self.id();
tokio::spawn(async move { tokio::spawn(async move {
loop { loop {
@ -80,22 +79,24 @@ impl Workspace {
Ok(Some(WorkspaceEvent { event: None })) => { Ok(Some(WorkspaceEvent { event: None })) => {
tracing::warn!("workspace {} received empty event", name) tracing::warn!("workspace {} received empty event", name)
} }
Ok(Some(WorkspaceEvent { event: Some(ev) })) => match ev { Ok(Some(WorkspaceEvent { event: Some(ev) })) => {
WorkspaceEventInner::Join(UserJoin { user }) => { match ev {
users.insert(user.clone().into(), UserInfo { uuid: user.into() }); WorkspaceEventInner::Join(UserJoin { user }) => {
} inner.users.insert(user.clone().into(), UserInfo { uuid: user.into() });
WorkspaceEventInner::Leave(UserLeave { user }) => { }
users.remove(&user.into()); WorkspaceEventInner::Leave(UserLeave { user }) => {
} inner.users.remove(&user.into());
WorkspaceEventInner::Create(FileCreate { path }) => { }
filetree.insert(path); WorkspaceEventInner::Create(FileCreate { path }) => {
} inner.filetree.insert(path);
WorkspaceEventInner::Rename(FileRename { before, after }) => { }
filetree.remove(&before); WorkspaceEventInner::Rename(FileRename { before, after }) => {
filetree.insert(after); inner.filetree.remove(&before);
} inner.filetree.insert(after);
WorkspaceEventInner::Delete(FileDelete { path }) => { }
filetree.remove(&path); WorkspaceEventInner::Delete(FileDelete { path }) => {
inner.filetree.remove(&path);
}
} }
}, },
} }