diff --git a/src/client.rs b/src/client.rs index 1e2cee7..fdd0884 100644 --- a/src/client.rs +++ b/src/client.rs @@ -51,6 +51,20 @@ impl Client { self.user.as_mut() } + /// Return the user relative path. + pub fn user_relative_path(&self) -> Option { + let user = self.user.clone(); + if user.is_none() { + return None; + } + let path = user.unwrap().path; + if path.is_none() { + return None; + } + let path = path.unwrap(); + Some(path.replace(&self.path, "")) + } + /// Return project path pub fn get_path(&self) -> &String { &self.path diff --git a/src/handler/file.rs b/src/handler/file.rs index 6803837..8adbfc1 100644 --- a/src/handler/file.rs +++ b/src/handler/file.rs @@ -31,10 +31,6 @@ pub mod users { let room = room.lock().await; let client = room.get_client(addr).unwrap(); - // XXX: Get this early to avoid borrow errors. - let file_path = data_str(json, "file").unwrap(); - let local_path = to_room_path(addr, &room, &file_path); - if !check_entered(channel, &client, METHOD).await { return; } @@ -69,7 +65,7 @@ pub mod users { } // Ignore if not in the same file. - if local_path != user.path.clone().unwrap() { + if client.user_relative_path() != _client.user_relative_path() { continue; }