Skip to content

Commit

Permalink
Added a method to download attached files
Browse files Browse the repository at this point in the history
  • Loading branch information
danigm committed Oct 4, 2017
1 parent e2fd499 commit ebed582
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 9 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
6 changes: 5 additions & 1 deletion TODO
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
31 changes: 27 additions & 4 deletions src/widgets.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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();

Expand Down

0 comments on commit ebed582

Please sign in to comment.