Skip to content

Commit

Permalink
Get relative path
Browse files Browse the repository at this point in the history
  • Loading branch information
jcs090218 committed Jun 10, 2024
1 parent 80ad638 commit 343dd78
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 5 deletions.
14 changes: 14 additions & 0 deletions src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,20 @@ impl Client {
self.user.as_mut()
}

/// Return the user relative path.
pub fn user_relative_path(&self) -> Option<String> {
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
Expand Down
6 changes: 1 addition & 5 deletions src/handler/file.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down Expand Up @@ -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;
}

Expand Down

0 comments on commit 343dd78

Please sign in to comment.