mirror of https://github.com/PiyushXCoder/lupt.git
bug fix and arranged
This commit is contained in:
parent
87ecf0faf3
commit
0b0b164c01
|
|
@ -42,7 +42,7 @@ pub struct JoinRandom {
|
||||||
pub name: String,
|
pub name: String,
|
||||||
pub tags: Vec<String>,
|
pub tags: Vec<String>,
|
||||||
}
|
}
|
||||||
/// Request to connect Random vayakti
|
/// Request to connect Random Next vayakti
|
||||||
#[derive(Clone, Message)]
|
#[derive(Clone, Message)]
|
||||||
#[rtype(result = "Resp")]
|
#[rtype(result = "Resp")]
|
||||||
pub struct JoinRandomNext {
|
pub struct JoinRandomNext {
|
||||||
|
|
@ -50,6 +50,22 @@ pub struct JoinRandomNext {
|
||||||
pub kunjika: String
|
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<String>,
|
||||||
|
pub kunjika: String,
|
||||||
|
pub addr: Addr<WsSansad>
|
||||||
|
}
|
||||||
|
|
||||||
/// Request to send text
|
/// Request to send text
|
||||||
#[derive(Clone, Message)]
|
#[derive(Clone, Message)]
|
||||||
#[rtype(result = "()")]
|
#[rtype(result = "()")]
|
||||||
|
|
@ -96,7 +112,7 @@ pub struct DeleteMsg {
|
||||||
pub msg_id: Vec<String>
|
pub msg_id: Vec<String>
|
||||||
}
|
}
|
||||||
|
|
||||||
// Request to delete messages
|
// Request to edit messages
|
||||||
#[derive(Clone, Message)]
|
#[derive(Clone, Message)]
|
||||||
#[rtype(result = "()")]
|
#[rtype(result = "()")]
|
||||||
pub struct EditMsg {
|
pub struct EditMsg {
|
||||||
|
|
@ -105,19 +121,3 @@ pub struct EditMsg {
|
||||||
pub text: String,
|
pub text: String,
|
||||||
pub msg_id: 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<String>,
|
|
||||||
pub kunjika: String,
|
|
||||||
pub addr: Addr<WsSansad>
|
|
||||||
}
|
|
||||||
|
|
@ -19,12 +19,48 @@ use super::*;
|
||||||
|
|
||||||
//################################################## For WsSansad ##################################################
|
//################################################## For WsSansad ##################################################
|
||||||
// Request to send own kunjika hash
|
// 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)]
|
#[derive(Clone, Message)]
|
||||||
#[rtype(result = "()")]
|
#[rtype(result = "()")]
|
||||||
pub struct WsKunjikaHash {
|
pub struct WsKunjikaHash {
|
||||||
pub kunjika: String
|
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)]
|
#[derive(Clone, Message)]
|
||||||
#[rtype(result = "()")]
|
#[rtype(result = "()")]
|
||||||
pub struct WsText {
|
pub struct WsText {
|
||||||
|
|
@ -34,7 +70,7 @@ pub struct WsText {
|
||||||
pub msg_id: u128
|
pub msg_id: u128
|
||||||
}
|
}
|
||||||
|
|
||||||
// Request to send transfer Image
|
// Request to send Image
|
||||||
#[derive(Clone, Message)]
|
#[derive(Clone, Message)]
|
||||||
#[rtype(result = "()")]
|
#[rtype(result = "()")]
|
||||||
pub struct WsImage {
|
pub struct WsImage {
|
||||||
|
|
@ -42,7 +78,7 @@ pub struct WsImage {
|
||||||
pub sender_kunjika: String,
|
pub sender_kunjika: String,
|
||||||
pub msg_id: u128
|
pub msg_id: u128
|
||||||
}
|
}
|
||||||
// Request to send REaction
|
// Request to send Reaction
|
||||||
#[derive(Clone, Message)]
|
#[derive(Clone, Message)]
|
||||||
#[rtype(result = "()")]
|
#[rtype(result = "()")]
|
||||||
pub struct WsReaction {
|
pub struct WsReaction {
|
||||||
|
|
@ -52,7 +88,7 @@ pub struct WsReaction {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// Request to send transfer status
|
// Request to send Status
|
||||||
#[derive(Clone, Message)]
|
#[derive(Clone, Message)]
|
||||||
#[rtype(result = "()")]
|
#[rtype(result = "()")]
|
||||||
pub struct WsStatus {
|
pub struct WsStatus {
|
||||||
|
|
@ -68,7 +104,7 @@ pub struct WsDeleteMsg {
|
||||||
pub sender_kunjika: String
|
pub sender_kunjika: String
|
||||||
}
|
}
|
||||||
|
|
||||||
// Request to delete messages
|
// Request to edit messages
|
||||||
#[derive(Clone, Message)]
|
#[derive(Clone, Message)]
|
||||||
#[rtype(result = "()")]
|
#[rtype(result = "()")]
|
||||||
pub struct WsEditMsg {
|
pub struct WsEditMsg {
|
||||||
|
|
@ -77,29 +113,6 @@ pub struct WsEditMsg {
|
||||||
pub msg_id: String
|
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
|
// Give response message
|
||||||
#[derive(Clone, Message)]
|
#[derive(Clone, Message)]
|
||||||
#[rtype(result = "()")]
|
#[rtype(result = "()")]
|
||||||
|
|
@ -107,12 +120,3 @@ pub struct WsResponse {
|
||||||
pub result: String,
|
pub result: String,
|
||||||
pub message: 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
|
|
||||||
}
|
|
||||||
|
|
|
||||||
|
|
@ -109,7 +109,7 @@ impl Handler<ms::pind::DeleteMsg> for ChatPinnd {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/// send delete messages for everyone
|
/// send edit messages for everyone
|
||||||
impl Handler<ms::pind::EditMsg> for ChatPinnd {
|
impl Handler<ms::pind::EditMsg> for ChatPinnd {
|
||||||
type Result = ();
|
type Result = ();
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -69,7 +69,7 @@ impl Actor for ChatPinnd {
|
||||||
self.subscribe_system_async::<ms::pind::DeleteMsg>(ctx);
|
self.subscribe_system_async::<ms::pind::DeleteMsg>(ctx);
|
||||||
self.subscribe_system_async::<ms::pind::EditMsg>(ctx);
|
self.subscribe_system_async::<ms::pind::EditMsg>(ctx);
|
||||||
self.subscribe_system_async::<ms::pind::SendStatus>(ctx);
|
self.subscribe_system_async::<ms::pind::SendStatus>(ctx);
|
||||||
self.subscribe_system_async::<ms::pind::LeaveUser>(ctx);
|
self.subscribe_system_async::<ms::pind::LeaveVayakti>(ctx);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -152,7 +152,7 @@ impl Handler<ms::pind::JoinRandom> for ChatPinnd {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Next Random user
|
/// Next Random next vayakti
|
||||||
impl Handler<ms::pind::JoinRandomNext> for ChatPinnd {
|
impl Handler<ms::pind::JoinRandomNext> for ChatPinnd {
|
||||||
type Result = Resp;
|
type Result = Resp;
|
||||||
fn handle(&mut self, msg: ms::pind::JoinRandomNext, _: &mut Self::Context) -> Self::Result {
|
fn handle(&mut self, msg: ms::pind::JoinRandomNext, _: &mut Self::Context) -> Self::Result {
|
||||||
|
|
@ -258,7 +258,7 @@ impl Handler<ms::pind::JoinRandomNext> for ChatPinnd {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// send list of users
|
/// send list of vayakti
|
||||||
impl Handler<ms::pind::List> for ChatPinnd {
|
impl Handler<ms::pind::List> for ChatPinnd {
|
||||||
type Result = String;
|
type Result = String;
|
||||||
|
|
||||||
|
|
@ -275,11 +275,11 @@ impl Handler<ms::pind::List> for ChatPinnd {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Notifiy a user disconnected and trim kaksh
|
/// Notifiy a vayakti disconnected and trim kaksh
|
||||||
impl Handler<ms::pind::LeaveUser> for ChatPinnd {
|
impl Handler<ms::pind::LeaveVayakti> for ChatPinnd {
|
||||||
type Result = ();
|
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_kunjika) = &msg.kaksh_kunjika {
|
||||||
if let Some(kaksh) = self.kaksh.get_mut(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) {
|
let name = if let Some(i) = kaksh.loog.iter().position(|x| x.addr == msg.addr) {
|
||||||
|
|
|
||||||
|
|
@ -40,7 +40,7 @@ pub fn validate(val: Vec<Validation>, dat: &str, entry_name: &str) -> Option<Str
|
||||||
}
|
}
|
||||||
|
|
||||||
fn non_empty(dat: &str, entry_name: &str) -> Option<String> {
|
fn non_empty(dat: &str, entry_name: &str) -> Option<String> {
|
||||||
if dat.len() > 0 {
|
if dat.len() > 0 || dat != "" {
|
||||||
None
|
None
|
||||||
} else {
|
} else {
|
||||||
Some(format!("{} is Required", entry_name))
|
Some(format!("{} is Required", entry_name))
|
||||||
|
|
|
||||||
|
|
@ -17,96 +17,29 @@
|
||||||
|
|
||||||
use super::*;
|
use super::*;
|
||||||
|
|
||||||
/// send text message
|
|
||||||
impl Handler<ms::sansad::WsText> for WsSansad {
|
/// notify someone got connected
|
||||||
|
impl Handler<ms::sansad::WsConnected> for WsSansad {
|
||||||
type Result = ();
|
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!({
|
let json = json!({
|
||||||
"cmd": "text",
|
"cmd": "connected",
|
||||||
"text": msg.text,
|
"name": msg.name,
|
||||||
"reply": msg.reply,
|
"kunjika": msg.kunjika
|
||||||
"kunjika": msg.sender_kunjika, // Sender's kunjuka
|
|
||||||
"msg_id": msg.msg_id.to_string()
|
|
||||||
});
|
});
|
||||||
ctx.text(json.to_string());
|
ctx.text(json.to_string());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// send image message
|
/// notify got connected as random person
|
||||||
impl Handler<ms::sansad::WsImage> for WsSansad {
|
impl Handler<ms::sansad::WsConnectedRandom> for WsSansad {
|
||||||
type Result = ();
|
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!({
|
let json = json!({
|
||||||
"cmd": "img",
|
"cmd": "random",
|
||||||
"src": msg.src,
|
"name": msg.name,
|
||||||
"kunjika": msg.sender_kunjika, // Sender's kunjuka
|
"kunjika": msg.kunjika
|
||||||
"msg_id": msg.msg_id.to_string()
|
|
||||||
});
|
|
||||||
ctx.text(json.to_string());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// send image message
|
|
||||||
impl Handler<ms::sansad::WsReaction> 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<ms::sansad::WsStatus> 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<ms::sansad::WsDeleteMsg> 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<ms::sansad::WsEditMsg> 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<ms::sansad::WsList> 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
|
|
||||||
});
|
});
|
||||||
ctx.text(json.to_string());
|
ctx.text(json.to_string());
|
||||||
}
|
}
|
||||||
|
|
@ -124,33 +57,19 @@ impl Handler<ms::sansad::WsKunjikaHash> for WsSansad {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// send response ok, error
|
/// List Vayakti
|
||||||
impl Handler<ms::sansad::WsResponse> for WsSansad {
|
impl Handler<ms::sansad::WsList> for WsSansad {
|
||||||
type Result = ();
|
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!({
|
let json = json!({
|
||||||
"cmd": "resp",
|
"cmd": "list",
|
||||||
"result": msg.result,
|
"vayakti": msg.json
|
||||||
"message": msg.message
|
|
||||||
});
|
});
|
||||||
ctx.text(json.to_string());
|
ctx.text(json.to_string());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// notify someone got connected
|
/// Notify someone got disconnected
|
||||||
impl Handler<ms::sansad::WsConnected> 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
|
|
||||||
impl Handler<ms::sansad::WsDisconnected> for WsSansad {
|
impl Handler<ms::sansad::WsDisconnected> for WsSansad {
|
||||||
type Result = ();
|
type Result = ();
|
||||||
fn handle(&mut self, msg: ms::sansad::WsDisconnected, ctx: &mut Self::Context) -> Self::Result {
|
fn handle(&mut self, msg: ms::sansad::WsDisconnected, ctx: &mut Self::Context) -> Self::Result {
|
||||||
|
|
@ -163,16 +82,99 @@ impl Handler<ms::sansad::WsDisconnected> for WsSansad {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// notify got connected to random person
|
/// Send text message
|
||||||
impl Handler<ms::sansad::WsConnectedRandom> for WsSansad {
|
impl Handler<ms::sansad::WsText> for WsSansad {
|
||||||
type Result = ();
|
type Result = ();
|
||||||
fn handle(&mut self, msg: ms::sansad::WsConnectedRandom, ctx: &mut Self::Context) -> Self::Result {
|
fn handle(&mut self, msg: ms::sansad::WsText, ctx: &mut Self::Context) -> Self::Result {
|
||||||
self.isthiti = Isthiti::Kaksh(msg.kaksh_kunjika);
|
|
||||||
let json = json!({
|
let json = json!({
|
||||||
"cmd": "random",
|
"cmd": "text",
|
||||||
"name": msg.name,
|
"text": msg.text,
|
||||||
"kunjika": msg.kunjika
|
"reply": msg.reply,
|
||||||
|
"kunjika": msg.sender_kunjika, // Sender's kunjuka
|
||||||
|
"msg_id": msg.msg_id.to_string()
|
||||||
});
|
});
|
||||||
ctx.text(json.to_string());
|
ctx.text(json.to_string());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Send image message
|
||||||
|
impl Handler<ms::sansad::WsImage> 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<ms::sansad::WsReaction> 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<ms::sansad::WsStatus> 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<ms::sansad::WsDeleteMsg> 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<ms::sansad::WsEditMsg> 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<ms::sansad::WsResponse> 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());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -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::<SystemBroker>::issue_async(ms::pind::SendStatus {
|
|
||||||
kaksh_kunjika,
|
|
||||||
kunjika: self.kunjika.to_owned(),
|
|
||||||
status
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
/// send image to vayakti in kaksh
|
/// send image to vayakti in kaksh
|
||||||
pub async fn send_image(&mut self, val: Value) {
|
pub async fn send_image(&mut self, val: Value) {
|
||||||
|
|
@ -144,6 +106,7 @@ impl WsSansad {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/// send reaction to vayakti in kaksh
|
/// send reaction to vayakti in kaksh
|
||||||
pub async fn send_reaction(&mut self, val: Value) {
|
pub async fn send_reaction(&mut self, val: Value) {
|
||||||
// check if vayakti exist
|
// 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::<SystemBroker>::issue_async(ms::pind::SendStatus {
|
||||||
|
kaksh_kunjika,
|
||||||
|
kunjika: self.kunjika.to_owned(),
|
||||||
|
status
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
/// delete text to vayakti in kaksh
|
/// delete text to vayakti in kaksh
|
||||||
pub async fn delete_msg(&mut self, val: Value) {
|
pub async fn delete_msg(&mut self, val: Value) {
|
||||||
// check if vayakti exist
|
// 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) {
|
pub async fn edit_msg(&mut self, val: Value) {
|
||||||
// check if vayakti exist
|
// check if vayakti exist
|
||||||
if let Isthiti::None = self.isthiti {
|
if let Isthiti::None = self.isthiti {
|
||||||
|
|
|
||||||
|
|
@ -18,6 +18,94 @@
|
||||||
use super::*;
|
use super::*;
|
||||||
|
|
||||||
impl WsSansad {
|
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<usize> = 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
|
/// Request for joining to random person
|
||||||
pub async fn join_random(&mut self, val: Value) {
|
pub async fn join_random(&mut self, val: Value) {
|
||||||
// Check is already joined
|
// Check is already joined
|
||||||
|
|
@ -29,6 +117,7 @@ impl WsSansad {
|
||||||
}, Isthiti::Kaksh(_) => return
|
}, Isthiti::Kaksh(_) => return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Kunjika
|
||||||
let kunjika = match val.get("kunjika") {
|
let kunjika = match val.get("kunjika") {
|
||||||
Some(val ) => val.as_str().unwrap().to_owned(),
|
Some(val ) => val.as_str().unwrap().to_owned(),
|
||||||
None => {
|
None => {
|
||||||
|
|
@ -36,12 +125,16 @@ impl WsSansad {
|
||||||
return;
|
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();
|
let mut m = sha1::Sha1::new();
|
||||||
m.update(format!("{}{}",kunjika,
|
m.update(format!("{}{}",kunjika,
|
||||||
crate::SALT.to_owned()).as_bytes());
|
crate::SALT.to_owned()).as_bytes());
|
||||||
let kunjika = base64::encode(m.digest().bytes())[..8].to_owned();
|
let kunjika = base64::encode(m.digest().bytes())[..8].to_owned();
|
||||||
|
|
||||||
|
// Name
|
||||||
let name = match val.get("name") {
|
let name = match val.get("name") {
|
||||||
Some(val ) => val.as_str().unwrap().to_owned(),
|
Some(val ) => val.as_str().unwrap().to_owned(),
|
||||||
None => {
|
None => {
|
||||||
|
|
@ -49,6 +142,12 @@ impl WsSansad {
|
||||||
return;
|
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") {
|
let tags = match val.get("tags") {
|
||||||
Some(val ) => {
|
Some(val ) => {
|
||||||
let mut v = Vec::new();
|
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
|
// request
|
||||||
let result: Resp = ChatPinnd::from_registry().send(ms::pind::JoinRandom{
|
let result: Resp = ChatPinnd::from_registry().send(ms::pind::JoinRandom{
|
||||||
addr: self.addr.clone().unwrap(),
|
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) {
|
pub async fn join_random_next(&mut self) {
|
||||||
// Check is already joined
|
// Check is already joined
|
||||||
let kaksh_kunjika = match &self.isthiti {
|
let kaksh_kunjika = match &self.isthiti {
|
||||||
|
|
@ -132,91 +222,7 @@ impl WsSansad {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Request to join to kaksh
|
/// Request to list vayakti in 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<usize> = 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
|
|
||||||
pub async fn list(&mut self) {
|
pub async fn list(&mut self) {
|
||||||
// check if vayakti exist
|
// check if vayakti exist
|
||||||
if let Isthiti::None = self.isthiti {
|
if let Isthiti::None = self.isthiti {
|
||||||
|
|
@ -249,7 +255,7 @@ impl WsSansad {
|
||||||
_ => None
|
_ => None
|
||||||
};
|
};
|
||||||
|
|
||||||
Broker::<SystemBroker>::issue_async(ms::pind::LeaveUser {
|
Broker::<SystemBroker>::issue_async(ms::pind::LeaveVayakti {
|
||||||
kaksh_kunjika,
|
kaksh_kunjika,
|
||||||
kunjika: self.kunjika.to_owned(),
|
kunjika: self.kunjika.to_owned(),
|
||||||
addr: self.addr.clone().unwrap()
|
addr: self.addr.clone().unwrap()
|
||||||
|
|
|
||||||
|
|
@ -162,6 +162,7 @@ function connect(frm) {
|
||||||
})
|
})
|
||||||
|
|
||||||
data = Object.assign({cmd: frm.attr('cmd')}, data);
|
data = Object.assign({cmd: frm.attr('cmd')}, data);
|
||||||
|
console.log(data);
|
||||||
socket.send(JSON.stringify(data));
|
socket.send(JSON.stringify(data));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue