From 10ca028c535d344c57de6a5e54b757e3281436ab Mon Sep 17 00:00:00 2001 From: Daniel Berteaud Date: Wed, 13 Sep 2017 18:42:31 +0200 Subject: [PATCH] Support sending images --- README.md | 1 + TODO | 1 - patrix.spec | 8 ++++++-- scripts/patrix | 11 ++++++++++- 4 files changed, 17 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 7eea137..6951ae1 100644 --- a/README.md +++ b/README.md @@ -15,6 +15,7 @@ It requires the following perl modules * Term::ReadKey * Hash::Merge::Simple * Scalar::Util + * Image::Size Here're the vailable options: diff --git a/TODO b/TODO index 389a0f4..a9ce37c 100644 --- a/TODO +++ b/TODO @@ -1,7 +1,6 @@ * Purge history of a room * Purge history of all empty rooms (with no members) * Modify federation setting of a room -* Send image * Set room avatar * Configure user profile (name, avatar) * Follow discussion of a room (like a tail -f of the room discussion) diff --git a/patrix.spec b/patrix.spec index 78c0baa..f0c363b 100644 --- a/patrix.spec +++ b/patrix.spec @@ -1,6 +1,6 @@ Name: patrix -Version: 0.1.2 -Release: 2%{?dist} +Version: 0.1.3 +Release: 1%{?dist} Summary: Command line client for Matrix Group: Applications/Internet @@ -23,6 +23,7 @@ Requires: perl(URI::Escape) Requires: perl(Term::ReadKey) Requires: perl(Hash::Merge::Simple) Requires: perl(Scalar::Util) +Requires: perl(Image::Size) %description Patrix is a simple (and quite limited) client for the Matrix communication network @@ -52,6 +53,9 @@ room via the command line. %{_bindir}/patrix %changelog +* Wed Sep 13 2017 Daniel Berteaud - 0.1.3-1 +- New release + * Wed Sep 13 2017 Daniel Berteaud - 0.1.2-2 - Fix perl dependency in spec file diff --git a/scripts/patrix b/scripts/patrix index 0604cc6..2d2c9f1 100644 --- a/scripts/patrix +++ b/scripts/patrix @@ -15,6 +15,7 @@ use URI::Escape; use Term::ReadKey; use Hash::Merge::Simple qw(merge); use Scalar::Util qw(looks_like_number); +use Image::Size; our $opt; @@ -262,9 +263,10 @@ sub send_file { # And then we post the uri on the room debug("Uploading file $file to the media store"); my $uri = $opt->{server} . '/_matrix/media/v1/upload?access_token=' . $opt->{access_token} . '&filename=' . basename($file); + my $mime = mimetype($file); my $resp = send_request({ uri => $uri, - content_type => mimetype($file), + content_type => $mime, content => slurp($file) }); debug("File upload response is\n" . to_json(from_json($resp->decoded_content), { pretty => 1 })); @@ -286,6 +288,13 @@ sub send_file { }, url => $file_uri }; + if ($mime =~ m/^image/){ + # The file is an image, change the message type and add the required info so it is + # displayed as an image + my ($w,$h) = imgsize($file); + $json->{msgtype} = 'm.image'; + ($json->{info}->{h}, $json->{info}->{w}) = imgsize($file); + } $resp = send_request({ uri => $uri, content => to_json($json)