From 99a2d73c6a49749d07a713f8d4f495096bfec95c Mon Sep 17 00:00:00 2001 From: Piyush Mishra Date: Tue, 11 May 2021 20:54:24 +0530 Subject: [PATCH] emoji and bug fixes --- src/broker_messages/pind.rs | 9 +++ src/broker_messages/sansad.rs | 9 +++ src/chat_pinnd/message.rs | 17 ++++++ src/chat_pinnd/mod.rs | 1 + src/ws_sansad/handlers.rs | 14 +++++ src/ws_sansad/messages.rs | 50 +++++++++++++++++ src/ws_sansad/mod.rs | 1 + static/img/heart.svg | 38 +++++++++++++ static/img/laugh.svg | 66 ++++++++++++++++++++++ static/img/like.svg | 47 ++++++++++++++++ static/img/sad.svg | 61 ++++++++++++++++++++ static/index.html | 3 + static/js/app.js | 22 +++++++- static/js/message.js | 101 +++++++++++++++++++++------------- static/js/taphold.js | 82 +++++++++++++++++++++++++++ 15 files changed, 481 insertions(+), 40 deletions(-) create mode 100644 static/img/heart.svg create mode 100644 static/img/laugh.svg create mode 100644 static/img/like.svg create mode 100644 static/img/sad.svg create mode 100644 static/js/taphold.js diff --git a/src/broker_messages/pind.rs b/src/broker_messages/pind.rs index aede602..c913e18 100644 --- a/src/broker_messages/pind.rs +++ b/src/broker_messages/pind.rs @@ -51,6 +51,15 @@ pub struct SendImage { pub kunjika: String, pub src: String } +/// Request to reaction +#[derive(Clone, Message)] +#[rtype(result = "()")] +pub struct SendReaction { + pub kaksh_kunjika: String, + pub kunjika: String, + pub emoji: String, + pub msg_id: String +} // Request to send status #[derive(Clone, Message)] diff --git a/src/broker_messages/sansad.rs b/src/broker_messages/sansad.rs index 2deaf60..11b6e86 100644 --- a/src/broker_messages/sansad.rs +++ b/src/broker_messages/sansad.rs @@ -27,6 +27,15 @@ pub struct WsImage { pub sender_kunjika: String, pub msg_id: u128 } +// Request to send REaction +#[derive(Clone, Message)] +#[rtype(result = "()")] +pub struct WsReaction { + pub emoji: String, + pub sender_kunjika: String, + pub msg_id: String +} + // Request to send transfer status #[derive(Clone, Message)] diff --git a/src/chat_pinnd/message.rs b/src/chat_pinnd/message.rs index 3d3beac..807a17f 100644 --- a/src/chat_pinnd/message.rs +++ b/src/chat_pinnd/message.rs @@ -40,6 +40,23 @@ impl Handler for ChatPinnd { } } +/// send Reaction to everyone +impl Handler for ChatPinnd { + type Result = (); + + fn handle(&mut self, msg: ms::pind::SendReaction, _: &mut Self::Context) -> Self::Result { + if let Some(kaksh) = self.kaksh.get_mut(&msg.kaksh_kunjika) { + kaksh.loog.iter().for_each(|c| { + c.addr.do_send(ms::sansad::WsReaction { + sender_kunjika: msg.kunjika.to_owned(), + emoji: msg.emoji.to_owned(), + msg_id: msg.msg_id.to_owned() + }); + }); + } + } +} + /// send status to everyone impl Handler for ChatPinnd { type Result = (); diff --git a/src/chat_pinnd/mod.rs b/src/chat_pinnd/mod.rs index 0aad304..b90b693 100644 --- a/src/chat_pinnd/mod.rs +++ b/src/chat_pinnd/mod.rs @@ -48,6 +48,7 @@ impl Actor for ChatPinnd { // for actix broker 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); self.subscribe_system_async::(ctx); diff --git a/src/ws_sansad/handlers.rs b/src/ws_sansad/handlers.rs index 19f33fa..e7ccd7c 100644 --- a/src/ws_sansad/handlers.rs +++ b/src/ws_sansad/handlers.rs @@ -30,6 +30,20 @@ impl Handler for WsSansad { } } +/// 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 = (); diff --git a/src/ws_sansad/messages.rs b/src/ws_sansad/messages.rs index 0684d28..88dce44 100644 --- a/src/ws_sansad/messages.rs +++ b/src/ws_sansad/messages.rs @@ -127,6 +127,56 @@ impl WsSansad { }); } + /// send reaction to vayakti in kaksh + pub async fn send_reaction(&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 emoji + let emoji = match val.get("emoji") { + Some(val) => val, + None => { + self.send_err_response("Invalid request"); + return; + } + }.as_str().unwrap().to_owned(); + + // sent emoji + let msg_id = match val.get("msg_id") { + 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::SendReaction { + kaksh_kunjika, + kunjika: self.kunjika.to_owned(), + emoji, + msg_id + }); + } + /// delete text to vayakti in kaksh pub async fn delete_msg(&mut self, val: Value) { // check if vayakti exist diff --git a/src/ws_sansad/mod.rs b/src/ws_sansad/mod.rs index 3727593..eed77bb 100644 --- a/src/ws_sansad/mod.rs +++ b/src/ws_sansad/mod.rs @@ -107,6 +107,7 @@ impl WsSansad { "randnext" => { self.join_random_next().await }, "text" => { self.send_text(val).await }, "img" => { self.send_image(val).await }, + "react" => { self.send_reaction(val).await }, "status" => { self.send_status(val).await }, "del" => { self.delete_msg(val).await }, "edit" => { self.edit_msg(val).await }, diff --git a/static/img/heart.svg b/static/img/heart.svg new file mode 100644 index 0000000..9813e89 --- /dev/null +++ b/static/img/heart.svg @@ -0,0 +1,38 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/static/img/laugh.svg b/static/img/laugh.svg new file mode 100644 index 0000000..4cfbe23 --- /dev/null +++ b/static/img/laugh.svg @@ -0,0 +1,66 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/static/img/like.svg b/static/img/like.svg new file mode 100644 index 0000000..e3fb635 --- /dev/null +++ b/static/img/like.svg @@ -0,0 +1,47 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/static/img/sad.svg b/static/img/sad.svg new file mode 100644 index 0000000..bb7f45f --- /dev/null +++ b/static/img/sad.svg @@ -0,0 +1,61 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/static/index.html b/static/index.html index 003be8b..552c06f 100644 --- a/static/index.html +++ b/static/index.html @@ -143,6 +143,8 @@ + +