From 0b0b164c01ce40715ee850bc29e092f79e03e04f Mon Sep 17 00:00:00 2001 From: Piyush Mishra Date: Thu, 13 May 2021 10:08:45 +0530 Subject: [PATCH] bug fix and arranged --- src/broker_messages/pind.rs | 36 +++--- src/broker_messages/sansad.rs | 78 ++++++------ src/chat_pinnd/message.rs | 2 +- src/chat_pinnd/mod.rs | 2 +- src/chat_pinnd/user.rs | 10 +- src/validator.rs | 2 +- src/ws_sansad/handlers.rs | 218 +++++++++++++++++----------------- src/ws_sansad/messages.rs | 80 +++++++------ src/ws_sansad/users.rs | 200 ++++++++++++++++--------------- static/js/app.js | 1 + 10 files changed, 322 insertions(+), 307 deletions(-) diff --git a/src/broker_messages/pind.rs b/src/broker_messages/pind.rs index 467f6dc..16dea37 100644 --- a/src/broker_messages/pind.rs +++ b/src/broker_messages/pind.rs @@ -42,7 +42,7 @@ pub struct JoinRandom { pub name: String, pub tags: Vec, } -/// Request to connect Random vayakti +/// Request to connect Random Next vayakti #[derive(Clone, Message)] #[rtype(result = "Resp")] pub struct JoinRandomNext { @@ -50,6 +50,22 @@ pub struct JoinRandomNext { pub kunjika: String } +// Request to send list of users +#[derive(Clone, Message)] +#[rtype(result = "String")] +pub struct List { + pub kaksh_kunjika: String +} + +/// Request to leave kaksh +#[derive(Clone, Message)] +#[rtype(result = "()")] +pub struct LeaveVayakti { + pub kaksh_kunjika: Option, + pub kunjika: String, + pub addr: Addr +} + /// Request to send text #[derive(Clone, Message)] #[rtype(result = "()")] @@ -96,7 +112,7 @@ pub struct DeleteMsg { pub msg_id: Vec } -// Request to delete messages +// Request to edit messages #[derive(Clone, Message)] #[rtype(result = "()")] pub struct EditMsg { @@ -105,19 +121,3 @@ pub struct EditMsg { pub text: String, pub msg_id: String } - -// Request to send list of users -#[derive(Clone, Message)] -#[rtype(result = "String")] -pub struct List { - pub kaksh_kunjika: String -} - -/// Request to leave kaksh -#[derive(Clone, Message)] -#[rtype(result = "()")] -pub struct LeaveUser { - pub kaksh_kunjika: Option, - pub kunjika: String, - pub addr: Addr -} \ No newline at end of file diff --git a/src/broker_messages/sansad.rs b/src/broker_messages/sansad.rs index a747caa..67f6ceb 100644 --- a/src/broker_messages/sansad.rs +++ b/src/broker_messages/sansad.rs @@ -19,12 +19,48 @@ use super::*; //################################################## For WsSansad ################################################## // Request to send own kunjika hash + +// Notify Someone connected +#[derive(Clone, Message)] +#[rtype(result = "()")] +pub struct WsConnected { + pub name: String, + pub kunjika: String +} + +// Got connected to random vayakti +#[derive(Clone, Message)] +#[rtype(result = "()")] +pub struct WsConnectedRandom { + pub name: String, + pub kunjika: String, + pub kaksh_kunjika: String +} + +// Request to send hash calculated of kunjika #[derive(Clone, Message)] #[rtype(result = "()")] pub struct WsKunjikaHash { pub kunjika: String } -// Request to send transfer text + +// Request to send list +#[derive(Clone, Message)] +#[rtype(result = "()")] +pub struct WsList { + pub json: String +} + +// Notify someone disconnected +#[derive(Clone, Message)] +#[rtype(result = "()")] +pub struct WsDisconnected { + pub kunjika: String, + pub name: String +} + + +// Request to send Text #[derive(Clone, Message)] #[rtype(result = "()")] pub struct WsText { @@ -34,7 +70,7 @@ pub struct WsText { pub msg_id: u128 } -// Request to send transfer Image +// Request to send Image #[derive(Clone, Message)] #[rtype(result = "()")] pub struct WsImage { @@ -42,7 +78,7 @@ pub struct WsImage { pub sender_kunjika: String, pub msg_id: u128 } -// Request to send REaction +// Request to send Reaction #[derive(Clone, Message)] #[rtype(result = "()")] pub struct WsReaction { @@ -52,7 +88,7 @@ pub struct WsReaction { } -// Request to send transfer status +// Request to send Status #[derive(Clone, Message)] #[rtype(result = "()")] pub struct WsStatus { @@ -68,7 +104,7 @@ pub struct WsDeleteMsg { pub sender_kunjika: String } -// Request to delete messages +// Request to edit messages #[derive(Clone, Message)] #[rtype(result = "()")] pub struct WsEditMsg { @@ -77,29 +113,6 @@ pub struct WsEditMsg { pub msg_id: String } -// Request to send transfer text -#[derive(Clone, Message)] -#[rtype(result = "()")] -pub struct WsList { - pub json: String -} - -// Notify Someone connected -#[derive(Clone, Message)] -#[rtype(result = "()")] -pub struct WsConnected { - pub name: String, - pub kunjika: String -} - -// Notify someone disconnected -#[derive(Clone, Message)] -#[rtype(result = "()")] -pub struct WsDisconnected { - pub kunjika: String, - pub name: String -} - // Give response message #[derive(Clone, Message)] #[rtype(result = "()")] @@ -107,12 +120,3 @@ pub struct WsResponse { pub result: String, pub message: String } - -// Got connected to random vayakti -#[derive(Clone, Message)] -#[rtype(result = "()")] -pub struct WsConnectedRandom { - pub name: String, - pub kunjika: String, - pub kaksh_kunjika: String -} diff --git a/src/chat_pinnd/message.rs b/src/chat_pinnd/message.rs index 3618c66..7485768 100644 --- a/src/chat_pinnd/message.rs +++ b/src/chat_pinnd/message.rs @@ -109,7 +109,7 @@ impl Handler for ChatPinnd { } -/// send delete messages for everyone +/// send edit messages for everyone impl Handler for ChatPinnd { type Result = (); diff --git a/src/chat_pinnd/mod.rs b/src/chat_pinnd/mod.rs index 800773b..5182faa 100644 --- a/src/chat_pinnd/mod.rs +++ b/src/chat_pinnd/mod.rs @@ -69,7 +69,7 @@ impl Actor for ChatPinnd { self.subscribe_system_async::(ctx); self.subscribe_system_async::(ctx); self.subscribe_system_async::(ctx); - self.subscribe_system_async::(ctx); + self.subscribe_system_async::(ctx); } } diff --git a/src/chat_pinnd/user.rs b/src/chat_pinnd/user.rs index 95510cc..4ef47af 100644 --- a/src/chat_pinnd/user.rs +++ b/src/chat_pinnd/user.rs @@ -152,7 +152,7 @@ impl Handler for ChatPinnd { } } -/// Next Random user +/// Next Random next vayakti impl Handler for ChatPinnd { type Result = Resp; fn handle(&mut self, msg: ms::pind::JoinRandomNext, _: &mut Self::Context) -> Self::Result { @@ -258,7 +258,7 @@ impl Handler for ChatPinnd { } } -/// send list of users +/// send list of vayakti impl Handler for ChatPinnd { type Result = String; @@ -275,11 +275,11 @@ impl Handler for ChatPinnd { } } -/// Notifiy a user disconnected and trim kaksh -impl Handler for ChatPinnd { +/// Notifiy a vayakti disconnected and trim kaksh +impl Handler for ChatPinnd { type Result = (); - fn handle(&mut self, msg: ms::pind::LeaveUser, _: &mut Self::Context) -> Self::Result { + fn handle(&mut self, msg: ms::pind::LeaveVayakti, _: &mut Self::Context) -> Self::Result { if let Some(kaksh_kunjika) = &msg.kaksh_kunjika { if let Some(kaksh) = self.kaksh.get_mut(kaksh_kunjika) { let name = if let Some(i) = kaksh.loog.iter().position(|x| x.addr == msg.addr) { diff --git a/src/validator.rs b/src/validator.rs index 663217e..a22f195 100644 --- a/src/validator.rs +++ b/src/validator.rs @@ -40,7 +40,7 @@ pub fn validate(val: Vec, dat: &str, entry_name: &str) -> Option Option { - if dat.len() > 0 { + if dat.len() > 0 || dat != "" { None } else { Some(format!("{} is Required", entry_name)) diff --git a/src/ws_sansad/handlers.rs b/src/ws_sansad/handlers.rs index 7509d3b..2a9bfeb 100644 --- a/src/ws_sansad/handlers.rs +++ b/src/ws_sansad/handlers.rs @@ -17,96 +17,29 @@ use super::*; -/// send text message -impl Handler for WsSansad { + +/// notify someone got connected +impl Handler for WsSansad { type Result = (); - fn handle(&mut self, msg: ms::sansad::WsText, ctx: &mut Self::Context) -> Self::Result { + fn handle(&mut self, msg: ms::sansad::WsConnected, ctx: &mut Self::Context) -> Self::Result { let json = json!({ - "cmd": "text", - "text": msg.text, - "reply": msg.reply, - "kunjika": msg.sender_kunjika, // Sender's kunjuka - "msg_id": msg.msg_id.to_string() + "cmd": "connected", + "name": msg.name, + "kunjika": msg.kunjika }); ctx.text(json.to_string()); } } -/// send image message -impl Handler for WsSansad { +/// notify got connected as random person +impl Handler for WsSansad { type Result = (); - fn handle(&mut self, msg: ms::sansad::WsImage, ctx: &mut Self::Context) -> Self::Result { + fn handle(&mut self, msg: ms::sansad::WsConnectedRandom, ctx: &mut Self::Context) -> Self::Result { + self.isthiti = Isthiti::Kaksh(msg.kaksh_kunjika); let json = json!({ - "cmd": "img", - "src": msg.src, - "kunjika": msg.sender_kunjika, // Sender's kunjuka - "msg_id": msg.msg_id.to_string() - }); - ctx.text(json.to_string()); - } -} - -/// send image message -impl Handler for WsSansad { - type Result = (); - fn handle(&mut self, msg: ms::sansad::WsReaction, ctx: &mut Self::Context) -> Self::Result { - let json = json!({ - "cmd": "react", - "emoji": msg.emoji, - "kunjika": msg.sender_kunjika, // Sender's kunjuka - "msg_id": msg.msg_id.to_string() - }); - ctx.text(json.to_string()); - } -} - -/// send text status -impl Handler for WsSansad { - type Result = (); - fn handle(&mut self, msg: ms::sansad::WsStatus, ctx: &mut Self::Context) -> Self::Result { - let json = json!({ - "cmd": "status", - "status": msg.status, - "kunjika": msg.sender_kunjika // Sender's kunjuka - }); - ctx.text(json.to_string()); - } -} - -/// delete messages -impl Handler for WsSansad { - type Result = (); - fn handle(&mut self, msg: ms::sansad::WsDeleteMsg, ctx: &mut Self::Context) -> Self::Result { - let json = json!({ - "cmd": "del", - "msg_id": msg.msg_id, - "kunjika": msg.sender_kunjika // Sender's kunjuka - }); - ctx.text(json.to_string()); - } -} - -/// delete messages -impl Handler for WsSansad { - type Result = (); - fn handle(&mut self, msg: ms::sansad::WsEditMsg, ctx: &mut Self::Context) -> Self::Result { - let json = json!({ - "cmd": "edit", - "msg_id": msg.msg_id, - "text": msg.text, - "kunjika": msg.sender_kunjika // Sender's kunjuka - }); - ctx.text(json.to_string()); - } -} - -/// List Vayakti -impl Handler for WsSansad { - type Result = (); - fn handle(&mut self, msg: ms::sansad::WsList, ctx: &mut Self::Context) -> Self::Result { - let json = json!({ - "cmd": "list", - "vayakti": msg.json + "cmd": "random", + "name": msg.name, + "kunjika": msg.kunjika }); ctx.text(json.to_string()); } @@ -124,33 +57,19 @@ impl Handler for WsSansad { } } -/// send response ok, error -impl Handler for WsSansad { +/// List Vayakti +impl Handler for WsSansad { type Result = (); - fn handle(&mut self, msg: ms::sansad::WsResponse, ctx: &mut Self::Context) -> Self::Result { + fn handle(&mut self, msg: ms::sansad::WsList, ctx: &mut Self::Context) -> Self::Result { let json = json!({ - "cmd": "resp", - "result": msg.result, - "message": msg.message + "cmd": "list", + "vayakti": msg.json }); ctx.text(json.to_string()); } } -/// notify someone got connected -impl Handler for WsSansad { - type Result = (); - fn handle(&mut self, msg: ms::sansad::WsConnected, ctx: &mut Self::Context) -> Self::Result { - let json = json!({ - "cmd": "connected", - "name": msg.name, - "kunjika": msg.kunjika - }); - ctx.text(json.to_string()); - } -} - -/// notify someone got disconnected +/// Notify someone got disconnected impl Handler for WsSansad { type Result = (); fn handle(&mut self, msg: ms::sansad::WsDisconnected, ctx: &mut Self::Context) -> Self::Result { @@ -163,16 +82,99 @@ impl Handler for WsSansad { } } -/// notify got connected to random person -impl Handler for WsSansad { +/// Send text message +impl Handler for WsSansad { type Result = (); - fn handle(&mut self, msg: ms::sansad::WsConnectedRandom, ctx: &mut Self::Context) -> Self::Result { - self.isthiti = Isthiti::Kaksh(msg.kaksh_kunjika); + fn handle(&mut self, msg: ms::sansad::WsText, ctx: &mut Self::Context) -> Self::Result { let json = json!({ - "cmd": "random", - "name": msg.name, - "kunjika": msg.kunjika + "cmd": "text", + "text": msg.text, + "reply": msg.reply, + "kunjika": msg.sender_kunjika, // Sender's kunjuka + "msg_id": msg.msg_id.to_string() }); ctx.text(json.to_string()); } } + +/// Send image message +impl Handler for WsSansad { + type Result = (); + fn handle(&mut self, msg: ms::sansad::WsImage, ctx: &mut Self::Context) -> Self::Result { + let json = json!({ + "cmd": "img", + "src": msg.src, + "kunjika": msg.sender_kunjika, // Sender's kunjuka + "msg_id": msg.msg_id.to_string() + }); + ctx.text(json.to_string()); + } +} + +/// Send reaction message +impl Handler for WsSansad { + type Result = (); + fn handle(&mut self, msg: ms::sansad::WsReaction, ctx: &mut Self::Context) -> Self::Result { + let json = json!({ + "cmd": "react", + "emoji": msg.emoji, + "kunjika": msg.sender_kunjika, // Sender's kunjuka + "msg_id": msg.msg_id.to_string() + }); + ctx.text(json.to_string()); + } +} + +/// Send status status +impl Handler for WsSansad { + type Result = (); + fn handle(&mut self, msg: ms::sansad::WsStatus, ctx: &mut Self::Context) -> Self::Result { + let json = json!({ + "cmd": "status", + "status": msg.status, + "kunjika": msg.sender_kunjika // Sender's kunjuka + }); + ctx.text(json.to_string()); + } +} + +/// Delete messages +impl Handler for WsSansad { + type Result = (); + fn handle(&mut self, msg: ms::sansad::WsDeleteMsg, ctx: &mut Self::Context) -> Self::Result { + let json = json!({ + "cmd": "del", + "msg_id": msg.msg_id, + "kunjika": msg.sender_kunjika // Sender's kunjuka + }); + ctx.text(json.to_string()); + } +} + +/// Edit messages +impl Handler for WsSansad { + type Result = (); + fn handle(&mut self, msg: ms::sansad::WsEditMsg, ctx: &mut Self::Context) -> Self::Result { + let json = json!({ + "cmd": "edit", + "msg_id": msg.msg_id, + "text": msg.text, + "kunjika": msg.sender_kunjika // Sender's kunjuka + }); + ctx.text(json.to_string()); + } +} + +/// Send response ok, error +impl Handler for WsSansad { + type Result = (); + fn handle(&mut self, msg: ms::sansad::WsResponse, ctx: &mut Self::Context) -> Self::Result { + let json = json!({ + "cmd": "resp", + "result": msg.result, + "message": msg.message + }); + ctx.text(json.to_string()); + } +} + diff --git a/src/ws_sansad/messages.rs b/src/ws_sansad/messages.rs index 5a76c8b..ffd44a6 100644 --- a/src/ws_sansad/messages.rs +++ b/src/ws_sansad/messages.rs @@ -65,44 +65,6 @@ impl WsSansad { }); } - /// send status to vayakti in kaksh - pub async fn send_status(&mut self, val: Value) { - // check if vayakti exist - if let Isthiti::None = self.isthiti { - self.send_err_response("Not in any Kaksh"); - return; - } - - // check if connected to any kaksh - match self.isthiti { - Isthiti::Kaksh(_) => (), - _ => { - self.send_err_response("Kaksh not connected"); - return; - } - } - - // sent status - let status = match val.get("status") { - Some(val) => val, - None => { - self.send_err_response("Invalid request"); - return; - } - }.as_str().unwrap().to_owned(); - let kaksh_kunjika = match &self.isthiti { - Isthiti::Kaksh(kaksh_kunjika) => { - kaksh_kunjika.to_owned() - }, _ => { - return; - } - }; - Broker::::issue_async(ms::pind::SendStatus { - kaksh_kunjika, - kunjika: self.kunjika.to_owned(), - status - }); - } /// send image to vayakti in kaksh pub async fn send_image(&mut self, val: Value) { @@ -144,6 +106,7 @@ impl WsSansad { }); } + /// send reaction to vayakti in kaksh pub async fn send_reaction(&mut self, val: Value) { // check if vayakti exist @@ -194,6 +157,45 @@ impl WsSansad { }); } + /// send status to vayakti in kaksh + pub async fn send_status(&mut self, val: Value) { + // check if vayakti exist + if let Isthiti::None = self.isthiti { + self.send_err_response("Not in any Kaksh"); + return; + } + + // check if connected to any kaksh + match self.isthiti { + Isthiti::Kaksh(_) => (), + _ => { + self.send_err_response("Kaksh not connected"); + return; + } + } + + // sent status + let status = match val.get("status") { + Some(val) => val, + None => { + self.send_err_response("Invalid request"); + return; + } + }.as_str().unwrap().to_owned(); + let kaksh_kunjika = match &self.isthiti { + Isthiti::Kaksh(kaksh_kunjika) => { + kaksh_kunjika.to_owned() + }, _ => { + return; + } + }; + Broker::::issue_async(ms::pind::SendStatus { + kaksh_kunjika, + kunjika: self.kunjika.to_owned(), + status + }); + } + /// delete text to vayakti in kaksh pub async fn delete_msg(&mut self, val: Value) { // check if vayakti exist @@ -242,7 +244,7 @@ impl WsSansad { }); } - /// send text to vayakti in kaksh + /// edit text to vayakti in kaksh pub async fn edit_msg(&mut self, val: Value) { // check if vayakti exist if let Isthiti::None = self.isthiti { diff --git a/src/ws_sansad/users.rs b/src/ws_sansad/users.rs index 7b50f97..473a9f5 100644 --- a/src/ws_sansad/users.rs +++ b/src/ws_sansad/users.rs @@ -18,6 +18,94 @@ use super::*; impl WsSansad { + /// Request to join to kaksh + pub async fn join_kaksh(&mut self, val: Value) { + // Check is already joined + match self.isthiti { + Isthiti::None => (), + _ => return + } + + // is vayakti in watch list + if let Isthiti::VraktigatWaitlist = self.isthiti { + self.send_ok_response("watchlist"); + return; + } + + // Kunjika + let kunjika = match val.get("kunjika") { + Some(val ) => val.as_str().unwrap().to_owned(), + None => { + self.send_err_response("Invalid request"); + return; + } + }; + if let Some(val ) = validate(vec![vl::NonEmpty, vl::NoSpace, vl::NoHashtag, vl::NoAndOrQuestion], &kunjika, "Kunjika") { + self.send_err_response(&val); + return; + } + let mut m = sha1::Sha1::new(); + m.update(format!("{}{}",kunjika, + crate::SALT.to_owned()).as_bytes()); + let kunjika = base64::encode(m.digest().bytes())[..8].to_owned(); + + // Name + let name = match val.get("name") { + Some(val ) => val.as_str().unwrap().to_owned(), + None => { + self.send_err_response("Invalid request"); + return; + } + }; + if let Some(val ) = validate(vec![vl::NonEmpty, vl::NoAndOrQuestion], &name, "Name") { + self.send_err_response(&val); + return; + } + + // Kaksh Kunjika + let kaksh_kunjika = match val.get("kaksh_kunjika") { + Some(val ) => val.as_str().unwrap().to_owned(), + None => { + self.send_err_response("Invalid request"); + return; + } + }; + if let Some(val ) = validate(vec![vl::NonEmpty, vl::NoGupt, vl::NoSpace, vl::NoAndOrQuestion], &kaksh_kunjika, "Kaksh Kunjika") { + self.send_err_response(&val); + return; + } + + // Length + let length: Option = match val.get("length") { + Some(val) => match val.as_i64(){ + Some(val) => Some(val as usize), + None => None + }, + None => None + }; + + // request + let result: Resp = ChatPinnd::from_registry().send(ms::pind::JoinKaksh { + kaksh_kunjika: kaksh_kunjika.to_owned(), + length, + addr: self.addr.clone().unwrap(), + kunjika: kunjika.to_owned(), + name + }).await.unwrap(); + + + match result { + Resp::Err(err) => self.send_err_response(&err), + Resp::Ok => { + self.isthiti = Isthiti::Kaksh(kaksh_kunjika); + self.addr.clone().unwrap().do_send(ms::sansad::WsKunjikaHash{ kunjika: kunjika.clone() }); + self.kunjika = kunjika; + self.send_ok_response("joined") + } + _ => () + } + } + /// Request for joining to random person pub async fn join_random(&mut self, val: Value) { // Check is already joined @@ -29,6 +117,7 @@ impl WsSansad { }, Isthiti::Kaksh(_) => return } + // Kunjika let kunjika = match val.get("kunjika") { Some(val ) => val.as_str().unwrap().to_owned(), None => { @@ -36,12 +125,16 @@ impl WsSansad { return; } }; - // kunjika to hash and base64 + if let Some(val ) = validate(vec![vl::NonEmpty, vl::NoSpace, vl::NoHashtag, vl::NoAndOrQuestion], &kunjika, "Kunjika") { + self.send_err_response(&val); + return; + } let mut m = sha1::Sha1::new(); m.update(format!("{}{}",kunjika, crate::SALT.to_owned()).as_bytes()); let kunjika = base64::encode(m.digest().bytes())[..8].to_owned(); + // Name let name = match val.get("name") { Some(val ) => val.as_str().unwrap().to_owned(), None => { @@ -49,6 +142,12 @@ impl WsSansad { return; } }; + if let Some(val ) = validate(vec![vl::NonEmpty, vl::NoAndOrQuestion], &name, "Name") { + self.send_err_response(&val); + return; + } + + // Tags let tags = match val.get("tags") { Some(val ) => { let mut v = Vec::new(); @@ -62,15 +161,6 @@ impl WsSansad { } }; - // Validate - if let Some(val ) = validate(vec![vl::NonEmpty, vl::NoSpace, vl::NoHashtag, vl::NoAndOrQuestion], &kunjika, "Kunjika") { - self.send_err_response(&val); - return; - } else if let Some(val ) = validate(vec![vl::NonEmpty, vl::NoAndOrQuestion], &name, "Name") { - self.send_err_response(&val); - return; - } - // request let result: Resp = ChatPinnd::from_registry().send(ms::pind::JoinRandom{ addr: self.addr.clone().unwrap(), @@ -97,7 +187,7 @@ impl WsSansad { } } - /// Request for joining to random person + /// Request for joining to next random person pub async fn join_random_next(&mut self) { // Check is already joined let kaksh_kunjika = match &self.isthiti { @@ -132,91 +222,7 @@ impl WsSansad { } } - /// Request to join to kaksh - pub async fn join_kaksh(&mut self, val: Value) { - // Check is already joined - match self.isthiti { - Isthiti::None => (), - _ => return - } - - // is vayakti in watch list - if let Isthiti::VraktigatWaitlist = self.isthiti { - self.send_ok_response("watchlist"); - return; - } - - let kunjika = match val.get("kunjika") { - Some(val ) => val.as_str().unwrap().to_owned(), - None => { - self.send_err_response("Invalid request"); - return; - } - }; - // kunjika to hash and base64 - let mut m = sha1::Sha1::new(); - m.update(format!("{}{}",kunjika, - crate::SALT.to_owned()).as_bytes()); - let kunjika = base64::encode(m.digest().bytes())[..8].to_owned(); - - let name = match val.get("name") { - Some(val ) => val.as_str().unwrap().to_owned(), - None => { - self.send_err_response("Invalid request"); - return; - } - }; - let kaksh_kunjika = match val.get("kaksh_kunjika") { - Some(val ) => val.as_str().unwrap().to_owned(), - None => { - self.send_err_response("Invalid request"); - return; - } - }; - let length: Option = match val.get("length") { - Some(val) => match val.as_i64(){ - Some(val) => Some(val as usize), - None => None - }, - None => None - }; - - - // Validate - if let Some(val ) = validate(vec![vl::NonEmpty, vl::NoGupt, vl::NoSpace, vl::NoAndOrQuestion], &kaksh_kunjika, "Kaksh Kunjika") { - self.send_err_response(&val); - return; - } else if let Some(val ) = validate(vec![vl::NonEmpty, vl::NoSpace, vl::NoHashtag, vl::NoAndOrQuestion], &kunjika, "Kunjika") { - self.send_err_response(&val); - return; - } else if let Some(val ) = validate(vec![vl::NonEmpty, vl::NoAndOrQuestion], &name, "Name") { - self.send_err_response(&val); - return; - } - - // request - let result: Resp = ChatPinnd::from_registry().send(ms::pind::JoinKaksh { - kaksh_kunjika: kaksh_kunjika.to_owned(), - length, - addr: self.addr.clone().unwrap(), - kunjika: kunjika.to_owned(), - name - }).await.unwrap(); - - - match result { - Resp::Err(err) => self.send_err_response(&err), - Resp::Ok => { - self.isthiti = Isthiti::Kaksh(kaksh_kunjika); - self.addr.clone().unwrap().do_send(ms::sansad::WsKunjikaHash{ kunjika: kunjika.clone() }); - self.kunjika = kunjika; - self.send_ok_response("joined") - } - _ => () - } - } - - /// Request to join to kaksh + /// Request to list vayakti in kaksh pub async fn list(&mut self) { // check if vayakti exist if let Isthiti::None = self.isthiti { @@ -249,7 +255,7 @@ impl WsSansad { _ => None }; - Broker::::issue_async(ms::pind::LeaveUser { + Broker::::issue_async(ms::pind::LeaveVayakti { kaksh_kunjika, kunjika: self.kunjika.to_owned(), addr: self.addr.clone().unwrap() diff --git a/static/js/app.js b/static/js/app.js index dedebef..e39ee38 100644 --- a/static/js/app.js +++ b/static/js/app.js @@ -162,6 +162,7 @@ function connect(frm) { }) data = Object.assign({cmd: frm.attr('cmd')}, data); + console.log(data); socket.send(JSON.stringify(data)); }