old browser fix

This commit is contained in:
Piyush मिश्रः 2021-05-11 10:39:58 +05:30
parent 6f461ab4e2
commit 6623fda897
8 changed files with 111 additions and 11 deletions

View File

@ -52,7 +52,7 @@ pub struct SendImage {
pub src: String
}
// Request to send text t
// Request to send status
#[derive(Clone, Message)]
#[rtype(result = "()")]
pub struct SendStatus {
@ -61,7 +61,16 @@ pub struct SendStatus {
pub status: String
}
// Request to send text t
// Request to delete messages
#[derive(Clone, Message)]
#[rtype(result = "()")]
pub struct DeleteMsg {
pub kaksh_kunjika: String,
pub kunjika: String,
pub msg_id: Vec<u128>
}
// Request to send list of users
#[derive(Clone, Message)]
#[rtype(result = "String")]
pub struct List {

View File

@ -19,7 +19,7 @@ pub struct WsText {
pub msg_id: u128
}
// Request to send transfer text
// Request to send transfer Image
#[derive(Clone, Message)]
#[rtype(result = "()")]
pub struct WsImage {
@ -28,7 +28,7 @@ pub struct WsImage {
pub msg_id: u128
}
// Request to send transfer text
// Request to send transfer status
#[derive(Clone, Message)]
#[rtype(result = "()")]
pub struct WsStatus {
@ -36,6 +36,14 @@ pub struct WsStatus {
pub sender_kunjika: String
}
// Request to delete messages
#[derive(Clone, Message)]
#[rtype(result = "()")]
pub struct WsDeleteMsg {
pub msg_id: Vec<u128>,
pub sender_kunjika: String
}
// Request to send transfer text
#[derive(Clone, Message)]
#[rtype(result = "()")]

View File

@ -58,3 +58,20 @@ impl Handler<ms::pind::SendStatus> for ChatPinnd {
}
}
}
/// send delete messages for everyone
impl Handler<ms::pind::DeleteMsg> for ChatPinnd {
type Result = ();
fn handle(&mut self, msg: ms::pind::DeleteMsg, _: &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::WsDeleteMsg {
sender_kunjika: msg.kunjika.to_owned(),
msg_id: msg.msg_id.clone()
});
});
}
}
}

View File

@ -16,7 +16,7 @@ impl Handler<ms::sansad::WsText> for WsSansad {
}
}
/// send text message
/// 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 {
@ -30,7 +30,6 @@ impl Handler<ms::sansad::WsImage> for WsSansad {
}
}
/// send text status
impl Handler<ms::sansad::WsStatus> for WsSansad {
type Result = ();
@ -44,6 +43,19 @@ impl Handler<ms::sansad::WsStatus> for WsSansad {
}
}
/// 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());
}
}
/// List Vayakti
impl Handler<ms::sansad::WsList> for WsSansad {
type Result = ();

View File

@ -87,7 +87,7 @@ impl WsSansad {
});
}
/// send text to vayakti in kaksh
/// send image to vayakti in kaksh
pub async fn send_image(&mut self, val: Value) {
// check if vayakti exist
if let Isthiti::None = self.isthiti {
@ -126,4 +126,51 @@ impl WsSansad {
src
});
}
/// delete text to vayakti in kaksh
pub async fn delete_msg(&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;
}
}
// image src
let mut msg_id = vec![];
let ids = match val.get("msg_id") {
Some(val) => val,
None => {
self.send_err_response("Invalid request");
return;
}
}.as_array().unwrap();
for id in ids {
msg_id.push(id.as_str().unwrap().parse::<u128>().unwrap());
}
drop(ids);
let kaksh_kunjika = match &self.isthiti {
Isthiti::Kaksh(kaksh_kunjika) => {
kaksh_kunjika.to_owned()
}, _ => {
return;
}
};
Broker::<SystemBroker>::issue_async(ms::pind::DeleteMsg {
kaksh_kunjika,
kunjika: self.kunjika.to_owned(),
msg_id
});
}
}

View File

@ -108,6 +108,7 @@ impl WsSansad {
"text" => { self.send_text(val).await },
"img" => { self.send_image(val).await },
"status" => { self.send_status(val).await },
"del" => { self.delete_msg(val).await },
"list" => { self.list().await },
"leave" => { self.leave_kaksh().await },
_ => ()

View File

@ -1,6 +1,8 @@
class Actions {
actions = []; // [[id, func]]
constructor() {
this.actions = []; // [[id, func]]
}
execute() {
if(this.actions.length <= 0) return;

View File

@ -124,7 +124,7 @@ let Messages = class {
}
static prepareReply() {
var text = this.selectedMessageToText();
var text = Messages.selectedMessageToText();
var el = $('#reply_clip');
el.removeClass('is-hidden');
el.attr('msg', text);
@ -135,7 +135,7 @@ let Messages = class {
static copyMessagesToClipboard() {
var $temp = $("<textarea>");
$("body").append($temp);
$temp.val(this.selectedMessageToText()).select();
$temp.val(Messages.selectedMessageToText()).select();
document.execCommand("copy");
$temp.remove();
Messages.unselectAll();
@ -157,7 +157,11 @@ let Messages = class {
dialog(prop, function() {
if($('#dialog_check').prop('checked')) {
var msg_id = [];
$('.message.active').each(function() {
msg_id.push($(this).attr('msgid'));
});
console.log(msg_id)
} else $('.message.active').remove();
});