codemp/src/api/event.rs

28 lines
809 B
Rust
Raw Normal View History

use codemp_proto::workspace::workspace_event::Event as WorkspaceEventInner;
2024-08-15 20:15:37 +02:00
#[derive(Debug, Clone)]
#[cfg_attr(feature = "python", pyo3::pyclass)]
pub enum Event {
FileTreeUpdated(String),
UserJoin(String),
UserLeave(String),
}
2024-08-22 00:57:24 +02:00
impl From<WorkspaceEventInner> for Event {
fn from(event: WorkspaceEventInner) -> Self {
match event {
2024-08-22 00:57:24 +02:00
WorkspaceEventInner::Join(e) => Self::UserJoin(e.user.name),
WorkspaceEventInner::Leave(e) => Self::UserLeave(e.user.name),
WorkspaceEventInner::Create(e) => Self::FileTreeUpdated(e.path),
WorkspaceEventInner::Delete(e) => Self::FileTreeUpdated(e.path),
WorkspaceEventInner::Rename(e) => Self::FileTreeUpdated(e.after),
}
}
}
2024-08-22 00:57:24 +02:00
impl From<&WorkspaceEventInner> for Event {
fn from(event: &WorkspaceEventInner) -> Self {
Self::from(event.clone())
}
}