diff --git a/README.md b/README.md index 1d24975..2b07e58 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/TODO b/TODO index 90de152..36c38d5 100644 --- a/TODO +++ b/TODO @@ -1,9 +1,13 @@ 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 diff --git a/src/util.rs b/src/util.rs index 6453110..2cd3c7f 100644 --- a/src/util.rs +++ b/src/util.rs @@ -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() { diff --git a/src/widgets.rs b/src/widgets.rs index 4ac1d3e..7f6b672 100644 --- a/src/widgets.rs +++ b/src/widgets.rs @@ -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) -> gtk::Label { let d = dt.format("%d/%b/%y %H:%M").to_string();