Skip to content

Commit

Permalink
mark info
Browse files Browse the repository at this point in the history
  • Loading branch information
jcs090218 committed Jun 15, 2024
1 parent 969312f commit 9b542dc
Showing 1 changed file with 27 additions and 14 deletions.
41 changes: 27 additions & 14 deletions src/handler/file.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,32 @@ pub mod update {
return;
}

let relative_path = file.unwrap().relative_path(&room);

let file = room.get_file_mut(&addr, &path);
let file = file.unwrap();

file.update(&add_or_delete, beg, end, &contents);

// Get the peers that are in the file.
let peers = room.peers_by_file(&room, &relative_path);

let params = &serde_json::json!({
"method": METHOD,
"file": relative_path,
"add_or_delete": add_or_delete,
"beg": beg,
"end": end,
"contents": contents,
"status": "success",
});

for (_addr, _sender) in peers.iter() {
if *_addr == addr {
continue;
}
let _ = _sender.send(params.to_string());
}
}
}

Expand Down Expand Up @@ -149,7 +171,7 @@ pub mod info {
use std::sync::Arc;
use tokio::sync::Mutex;

const METHOD: &str = "file::users";
const METHOD: &str = "file::info";

/// Return a list of user in file.
///
Expand Down Expand Up @@ -203,30 +225,21 @@ pub mod info {
let room = room.lock().await;
let client = room.get_client(addr).unwrap();

let file = data_str(json, "file").unwrap();
let file = room.get_file(&addr, &file);
//let file = data_str(json, "file").unwrap();
//let file = room.get_file(&addr, &file);

if !check_entered(channel, &client, METHOD).await {
return;
}

if file.is_none() {
return;
}

let file = file.unwrap();

let file_path = file.relative_path(&room);
let contents = file.contents();

let users = get_users(&room, &client);
let users = serde_json::to_string(&users).unwrap();

channel
.send_json(&serde_json::json!({
"method": METHOD,
"file": file_path,
"contents": contents,
//"file": file_path,
//"contents": contents,
"clients": users,
"status": "success",
}))
Expand Down

0 comments on commit 9b542dc

Please sign in to comment.