Commit 0e55e01e authored by Daniel Garcia Moreno's avatar Daniel Garcia Moreno Committed by Daniel Garcia Moreno

Send typing notifications

parent 3fd6a475
......@@ -55,6 +55,12 @@ impl App {
_ => Inhibit(false),
});
op = self.op.clone();
msg_entry.connect_key_release_event(move |_, _| {
op.lock().unwrap().send_typing();
Inhibit(false)
});
op = self.op.clone();
msg_entry.connect_paste_clipboard(move |_| {
attach::paste(op.clone());
......
......@@ -594,4 +594,12 @@ impl AppOp {
}
}
}
pub fn send_typing(&self) {
if let Some(ref active_room) = self.active_room {
self.backend
.send(BKCommand::SendTyping(active_room.clone()))
.unwrap();
}
}
}
......@@ -207,6 +207,10 @@ impl Backend {
let r = room::redact_msg(self, &msg);
bkerror!(r, tx, BKResponse::SendMsgRedactionError);
}
Ok(BKCommand::SendTyping(room)) => {
let r = room::send_typing(self, room);
bkerror!(r, tx, BKResponse::SendTypingError);
}
Ok(BKCommand::SetRoom(id)) => {
let r = room::set_room(self, id);
bkerror!(r, tx, BKResponse::SetRoomError);
......
......@@ -280,6 +280,23 @@ pub fn send_msg(bk: &Backend, msg: Message) -> Result<(), Error> {
Ok(())
}
pub fn send_typing(bk: &Backend, roomid: String) -> Result<(), Error> {
let userid = bk.data.lock().unwrap().user_id.clone();
let url = bk.url(&format!("rooms/{}/typing/{}", roomid, userid), vec![])?;
let attrs = json!({
"timeout": 1000,
"typing": true
});
let tx = bk.tx.clone();
query!("put", &url, &attrs, move |_| {}, |err| {
tx.send(BKResponse::SendTypingError(err)).unwrap();
});
Ok(())
}
pub fn redact_msg(bk: &Backend, msg: &Message) -> Result<(), Error> {
let roomid = msg.room.clone();
let txnid = msg.id.clone();
......
......@@ -61,6 +61,7 @@ pub enum BKCommand {
GetUserNameAsync(String, Sender<String>),
SendMsg(Message),
SendMsgRedaction(Message),
SendTyping(String),
SetRoom(String),
ShutDown,
DirectoryProtocols,
......@@ -158,6 +159,7 @@ pub enum BKResponse {
RoomMembersError(Error),
SendMsgError(Error),
SendMsgRedactionError(Error),
SendTypingError(Error),
SetRoomError(Error),
CommandError(Error),
DirectoryError(Error),
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment