feat: api struct for event

Co-authored-by: zaaarf <me@zaaarf.foo>
This commit is contained in:
əlemi 2024-08-09 00:40:33 +02:00
parent 07dd964466
commit a8b4eab445
Signed by: alemi
GPG key ID: A4895B84D311642C
2 changed files with 24 additions and 0 deletions

20
src/api/event.rs Normal file
View file

@ -0,0 +1,20 @@
use codemp_proto::workspace::workspace_event::Event as WorkspaceEventInner;
pub enum Event {
FileTreeUpdated,
UserJoin(String),
UserLeave(String),
}
impl From<&WorkspaceEventInner> for Event {
fn from(event: &WorkspaceEventInner) -> Self {
match event {
WorkspaceEventInner::Join(e) => Self::UserJoin(e.user.id.clone()),
WorkspaceEventInner::Leave(e) => Self::UserLeave(e.user.id.clone()),
WorkspaceEventInner::Create(_)
| WorkspaceEventInner::Rename(_)
| WorkspaceEventInner::Delete(_)
=> Self::FileTreeUpdated,
}
}
}

View file

@ -13,6 +13,9 @@ pub mod change;
/// representation for an user's cursor /// representation for an user's cursor
pub mod cursor; pub mod cursor;
/// workspace events
pub mod event;
/// data structure for service users /// data structure for service users
pub mod user; pub mod user;
@ -20,4 +23,5 @@ pub use controller::Controller;
pub use change::TextChange; pub use change::TextChange;
pub use change::Op; pub use change::Op;
pub use cursor::Cursor; pub use cursor::Cursor;
pub use event::Event;
pub use user::User; pub use user::User;