From 7053ad0fe2a65bf872243125b722a3c3bce05fe7 Mon Sep 17 00:00:00 2001 From: JenChieh Date: Sat, 15 Jun 2024 20:45:41 -0700 Subject: [PATCH] fix: Rename room users to info --- src/handler/mod.rs | 2 +- src/handler/room.rs | 7 ++++--- src/util.rs | 15 +++++++++++++++ 3 files changed, 20 insertions(+), 4 deletions(-) diff --git a/src/handler/mod.rs b/src/handler/mod.rs index 02ac80b..185ad5a 100644 --- a/src/handler/mod.rs +++ b/src/handler/mod.rs @@ -36,7 +36,7 @@ pub async fn handle(channel: &mut Channel, room: &Arc>, json: &str) "room::exit" => room::exit::handle(channel, room, &val).await, "room::kick" => room::kick::handle(channel, room, &val).await, "room::broadcast" => room::broadcast::handle(channel, room, &val).await, - "room::users" => room::users::handle(channel, room, &val).await, + "room::info" => room::info::handle(channel, room, &val).await, "room::sync" => room::sync::handle(channel, room, &val).await, "room::update_client" => room::update_client::handle(channel, room, &val).await, "file::update" => file::update::handle(channel, room, &val).await, diff --git a/src/handler/room.rs b/src/handler/room.rs index 9eafecb..87e5d48 100644 --- a/src/handler/room.rs +++ b/src/handler/room.rs @@ -291,6 +291,7 @@ pub mod update_client { } let path = data_str(json, "path"); + let path = no_client_path(&client, &path); let point = data_u64(json, "point"); let region_beg = data_u64(json, "region_beg"); let region_end = data_u64(json, "region_end"); @@ -301,17 +302,17 @@ pub mod update_client { } } -/// Room Users +/// Room Information /// /// Return a list of users in room. -pub mod users { +pub mod info { use crate::channel::*; use crate::handler::room::*; use serde_json::Value; use std::sync::Arc; use tokio::sync::Mutex; - const METHOD: &str = "room::users"; + const METHOD: &str = "room::info"; pub async fn handle(channel: &mut Channel, room: &Arc>, json: &Value) { let addr = &channel.get_connection().addr; diff --git a/src/util.rs b/src/util.rs index 89bb783..0bdb4a4 100644 --- a/src/util.rs +++ b/src/util.rs @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ +use crate::client::*; use crate::room::*; use crate::user::*; use path_slash::PathBufExt as _; @@ -107,6 +108,20 @@ pub fn no_room_path(room: &Room, path: &str) -> String { path.replace(&room_path, "") } +/// Remove client path. +/// +/// # Arguments +/// +/// * `room` - Room object. +/// * `path` - Path we want to remove room path. +pub fn no_client_path(client: &Client, path: &Option) -> Option { + if path.is_none() { + return None; + } + let path = path.clone().unwrap(); + Some(path.replace(client.get_path(), "")) +} + /// Convert backslash to slash. /// /// # Arguments