aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatias Linares <matiaslina@openmailbox.org>2018-01-28 18:14:07 -0300
committerMatias Linares <matiaslina@openmailbox.org>2018-01-28 18:14:07 -0300
commitc44f123719632f295467ae1c89bb43e1d86d6221 (patch)
tree4f3069b0ab6dad82cef807e5cac999f9884a1f5b
parente4eba6be757fee76c3985419c0b7fd8ae16b5269 (diff)
downloadperl6-matrix-client-c44f123719632f295467ae1c89bb43e1d86d6221.tar.gz
Refactor change-avatar and upload methods
-rw-r--r--lib/Matrix/Client.pm620
1 files changed, 11 insertions, 9 deletions
diff --git a/lib/Matrix/Client.pm6 b/lib/Matrix/Client.pm6
index 7dfcd27..36e0bb7 100644
--- a/lib/Matrix/Client.pm6
+++ b/lib/Matrix/Client.pm6
@@ -122,14 +122,12 @@ method avatar-url(Str :$user-id?) {
$data<avatar_url> // ""
}
-method change-avatar(Str:D $avatar!, Bool :$upload) {
- my $mxc-url;
- if so $upload {
- $mxc-url = $.upload($avatar);
- } else {
- $mxc-url = $avatar;
- }
+multi method change-avatar(IO::Path $avatar) {
+ my $mxc-url = $.upload($avatar.IO);
+ samewith($mxc-url);
+}
+multi method change-avatar(Str:D $mxc-url!) {
my $res = $.put("/profile/" ~ $.user-id ~ "/avatar_url",
avatar_url => $mxc-url);
return $.check-res($res);
@@ -193,9 +191,13 @@ method send(Str $room-id, Str $body, :$type? = "m.text") {
# Media
-method upload(Str $path where *.IO.f) {
+method upload(IO::Path $path, Str $filename?) {
my $buf = slurp $path, :bin;
- my $res = $.post-bin("/upload", $buf, content-type => "image/png");
+ my $fn = $filename ?? $filename !! $path.basename;
+ my $res = $.post-bin("/upload", $buf,
+ content-type => "image/png",
+ filename => $fn,
+ );
$.check-res($res);
my $data = from-json($res.content);
$data<content_uri> // "";