Commit ebed582c authored by Daniel García Moreno's avatar Daniel García Moreno

Added a method to download attached files

parent e2fd4991
......@@ -18,9 +18,9 @@ m.text | Done | Done
m.emote | |
m.notice | |
m.image | Done | Done
m.file | | Done
m.file | Done | Done
m.location | |
m.video | | Done
m.audio | | Done
m.video | Done | Done
m.audio | Done | Done
Full reference in: https://matrix.org/docs/spec/client\_server/r0.2.0.html#m-room-message-msgtypes
Fixs:
* Make it work to download a file with only one click, I don't know why
with text files I need to click several times to open it... Maybe we
should show a "save as" dialog to save the file instead of trying to
open with xdg-open.
* Ignore launched threads when changing room...
* Sort rooms by last message or fav?
Functionality:
* Show media messages (images / videos)
* Show event messages in message list
* Register
* Room creation
......
......@@ -532,7 +532,7 @@ pub fn parse_room_message(baseu: &Url, roomid: String, msg: &JsonValue) -> Messa
let mut thumb = String::new();
match mtype {
"m.image" => {
"m.image" | "m.file" | "m.video" | "m.audio" => {
url = String::from(c["url"].as_str().unwrap_or(""));
let mut t = String::from(c["info"]["thumbnail_url"].as_str().unwrap_or(""));
if t.is_empty() && !url.is_empty() {
......
......@@ -74,10 +74,16 @@ impl<'a> MessageBox<'a> {
let body: gtk::Box;
if msg.mtype == "m.image" {
body = self.build_room_msg_image();
} else {
body = self.build_room_msg_body(&msg.body);
match msg.mtype.as_ref() {
"m.image" => {
body = self.build_room_msg_image();
}
"m.video" | "m.audio" | "m.file" => {
body = self.build_room_msg_file();
}
_ => {
body = self.build_room_msg_body(&msg.body);
}
}
content.pack_start(&body, true, true, 0);
......@@ -175,6 +181,23 @@ impl<'a> MessageBox<'a> {
bx
}
fn build_room_msg_file(&self) -> gtk::Box {
let msg = self.msg;
let bx = gtk::Box::new(gtk::Orientation::Horizontal, 0);
let viewbtn = gtk::Button::new();
let url = msg.url.clone();
let backend = self.op.backend.clone();
viewbtn.connect_clicked(move |_| {
backend.send(BKCommand::GetMedia(url.clone())).unwrap();
});
viewbtn.set_label(&msg.body);
bx.add(&viewbtn);
bx
}
fn build_room_msg_date(&self, dt: &DateTime<Local>) -> gtk::Label {
let d = dt.format("%d/%b/%y %H:%M").to_string();
......
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