From ba413134ddcc6177b3673ba18d0035d78714e3fe Mon Sep 17 00:00:00 2001 From: Matias Linares Date: Thu, 7 May 2020 20:08:28 -0300 Subject: Bump version 0.5.2 --- .gitignore | 3 ++- META6.json | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/.gitignore b/.gitignore index 5bf717a..206dd0d 100644 --- a/.gitignore +++ b/.gitignore @@ -3,4 +3,5 @@ file.json .precomp **/*/.precomp todo.org -*~ \ No newline at end of file +*~ +*.tar.gz \ No newline at end of file diff --git a/META6.json b/META6.json index bfac3e3..84bd589 100644 --- a/META6.json +++ b/META6.json @@ -34,5 +34,5 @@ "Test", "Test::META" ], - "version" : "0.5.1" + "version" : "0.5.2" } -- cgit v1.2.3-70-g09d2 From 4823babb29e8d2c2f65b775e72210aac7a2175c5 Mon Sep 17 00:00:00 2001 From: Matias Linares Date: Sun, 17 May 2020 20:09:38 -0300 Subject: Add Matrix::Client::MediaStore class This is to wrap all the endpoints pointing to the media store. --- lib/Matrix/Client.pm6 | 20 +++++------ lib/Matrix/Client/Exception.pm6 | 6 ++++ lib/Matrix/Client/MediaStore.rakumod | 70 ++++++++++++++++++++++++++++++++++++ lib/Matrix/Client/Requester.pm6 | 2 +- t/10-use.t | 2 ++ 5 files changed, 89 insertions(+), 11 deletions(-) create mode 100644 lib/Matrix/Client/MediaStore.rakumod diff --git a/lib/Matrix/Client.pm6 b/lib/Matrix/Client.pm6 index 9022c65..2e26ee7 100644 --- a/lib/Matrix/Client.pm6 +++ b/lib/Matrix/Client.pm6 @@ -5,6 +5,7 @@ use Matrix::Response; use Matrix::Client::Common; use Matrix::Client::Room; use Matrix::Client::Requester; +use Matrix::Client::MediaStore; unit class Matrix::Client does Matrix::Client::Requester; @@ -331,16 +332,15 @@ method remove-room-alias($room-alias) { # Media -#| POST - /_matrix/media/r0/upload -method upload(IO::Path $path, Str $filename?) { - my $buf = slurp $path, :bin; - my $fn = $filename ?? $filename !! $path.basename; - my $res = $.post-bin("/upload", $buf, - content-type => "image/png", - filename => $fn, - ); - my $data = from-json($res.content); - $data // ""; +method media(--> Matrix::Client::MediaStore) { + return Matrix::Client::MediaStore.new( + home-server => $!home-server, + access-token => $!access-token + ) +} + +method upload(IO::Path $path, Str $filename?) is DEPRECATED('media.upload') { + self.media.upload($path, $filename) } # Misc diff --git a/lib/Matrix/Client/Exception.pm6 b/lib/Matrix/Client/Exception.pm6 index 924eece..e02f572 100644 --- a/lib/Matrix/Client/Exception.pm6 +++ b/lib/Matrix/Client/Exception.pm6 @@ -7,4 +7,10 @@ package X::Matrix { "$!code: $!error" } } + + class MXCParse is Exception { + has $.uri; + + method message { "Cannot parse '$!uri'" } + } } diff --git a/lib/Matrix/Client/MediaStore.rakumod b/lib/Matrix/Client/MediaStore.rakumod new file mode 100644 index 0000000..34fbda3 --- /dev/null +++ b/lib/Matrix/Client/MediaStore.rakumod @@ -0,0 +1,70 @@ +use JSON::Fast; +use Matrix::Client::Requester; +use Matrix::Client::Exception; +use URI::Escape; + +unit class Matrix::Client::MediaStore does Matrix::Client::Requester; + +class Matrix::Client::MediaStore::File { + has Str $.content-type; + has Str $.content-disposition; + has Buf $.content; +} + +submethod TWEAK { + # Different client endpoint for media + $!client-endpoint = "/_matrix/media/r0"; +} + +# https://matrix.deprecated.org/_matrix/media/r0/thumbnail/matrix.org/TKTUVTAazFocrTjezhiXZiIe?width=25&height=25&method=crop +method parse-mxc(Str $uri) { + if $uri ~~ m/"mxc://" $ = [.*] "/" $ = [ .* ]/ { + return { + server-name => $, + media-id => $ + } + } + + X::Matrix::MXCParse.new(:$uri).throw; +} + +#| POST - /_matrix/media/r0/upload +method upload(IO::Path $path, Str $filename?, Str :$content-type is copy = "image/png" --> Str) { + my $buf = slurp $path, :bin; + my $fn = $filename ?? $filename !! $path.basename; + + # The filename is passed on a query param. + my $endpoint = "/upload?filename=" ~ uri-escape($fn); + + + my $res = $.post-bin( + $endpoint, $buf, + :$content-type, + ); + + my $data = from-json($res.content); + $data // ""; +} + +# GET - /_matrix/media/r0/download/{serverName}/{mediaId} +multi method download(Str $mxc-uri, :$allow-remote = True) { + my $mxc = self.parse-mxc($mxc-uri); + + samewith($mxc, $mxc, :$allow-remote) +} + +# GET - /_matrix/media/r0/download/{serverName}/{mediaId} +multi method download(Str $server-name, Str $media-id, Bool :$allow-remote = True) { + my $response = $.get( + "/download/{$server-name}/{$media-id}", + allow_remote => $allow-remote.Str.lc + ); + + my %headers = $response.header.hash(); + + Matrix::Client::MediaStore::File.new( + content-type => %headers.head, + content-disposition => %headers.head, + content => $response.content + ) +} diff --git a/lib/Matrix/Client/Requester.pm6 b/lib/Matrix/Client/Requester.pm6 index ff543c9..36a9f69 100644 --- a/lib/Matrix/Client/Requester.pm6 +++ b/lib/Matrix/Client/Requester.pm6 @@ -73,7 +73,7 @@ multi method post(Str $path, :$media = False, *%params) { method post-bin(Str $path, Buf $buf, :$content-type) { my $encoded-path = $path.subst('#', '%23'); my $req = POST( - $.base-url(:media) ~ $encoded-path, + $.base-url() ~ $encoded-path, content => $buf, Content-Type => $content-type ); diff --git a/t/10-use.t b/t/10-use.t index df4130b..1c6f97e 100644 --- a/t/10-use.t +++ b/t/10-use.t @@ -6,4 +6,6 @@ use-ok 'Matrix::Client::Room'; use-ok 'Matrix::Client::Requester'; use-ok 'Matrix::Response'; use-ok 'Matrix::Client::Exception'; +use-ok 'Matrix::Client::MediaStore'; + done-testing; -- cgit v1.2.3-70-g09d2 From 4b01ebdcaa8d7df0ec34c758ae9f3b8ec32fdcd0 Mon Sep 17 00:00:00 2001 From: Matias Linares Date: Sun, 17 May 2020 20:25:25 -0300 Subject: Fix missing multi methods on the endpoints TODO generator --- endpoints.md | 16 +++++++++------- lib/Matrix/Client/MediaStore.rakumod | 4 ++-- scripts/load-docs.p6 | 5 +++-- 3 files changed, 14 insertions(+), 11 deletions(-) diff --git a/endpoints.md b/endpoints.md index 2ddf2c3..c77b6c4 100644 --- a/endpoints.md +++ b/endpoints.md @@ -30,7 +30,7 @@ from matrix.org. This will give you an overview about what's implemented in the ## Media - [ ] GET - /_matrix/media/r0/config -- [ ] GET - /_matrix/media/r0/download/{serverName}/{mediaId} +- [X] GET - /_matrix/media/r0/download/{serverName}/{mediaId} - [ ] GET - /_matrix/media/r0/download/{serverName}/{mediaId}/{fileName} - [ ] GET - /_matrix/media/r0/preview_url - [ ] GET - /_matrix/media/r0/thumbnail/{serverName}/{mediaId} @@ -104,9 +104,9 @@ from matrix.org. This will give you an overview about what's implemented in the - [X] GET - /_matrix/client/r0/rooms/{roomId}/joined_members - [ ] GET - /_matrix/client/r0/rooms/{roomId}/members - [X] GET - /_matrix/client/r0/rooms/{roomId}/messages -- [ ] GET - /_matrix/client/r0/rooms/{roomId}/state +- [X] GET - /_matrix/client/r0/rooms/{roomId}/state - [ ] GET - /_matrix/client/r0/rooms/{roomId}/state/{eventType}/{stateKey} -- [ ] GET - /_matrix/client/r0/sync +- [X] GET - /_matrix/client/r0/sync - [ ] GET - /_matrix/client/r0/user/{userId}/filter/{filterId} - [ ] POST - /_matrix/client/r0/rooms/{roomId}/receipt/{receiptType}/{eventId} - [ ] POST - /_matrix/client/r0/user/{userId}/filter @@ -136,7 +136,7 @@ from matrix.org. This will give you an overview about what's implemented in the ## Session management - [ ] GET - /_matrix/client/r0/login -- [ ] POST - /_matrix/client/r0/login +- [X] POST - /_matrix/client/r0/login - [X] POST - /_matrix/client/r0/logout - [ ] POST - /_matrix/client/r0/logout/all @@ -151,18 +151,20 @@ from matrix.org. This will give you an overview about what's implemented in the - [ ] GET - /_matrix/client/r0/register/available - [ ] GET - /_matrix/client/r0/user/{userId}/account_data/{type} - [ ] GET - /_matrix/client/r0/user/{userId}/rooms/{roomId}/account_data/{type} -- [ ] GET - /_matrix/client/r0/user/{userId}/rooms/{roomId}/tags +- [X] GET - /_matrix/client/r0/user/{userId}/rooms/{roomId}/tags - [ ] POST - /_matrix/client/r0/account/3pid +- [ ] POST - /_matrix/client/r0/account/3pid/bind - [ ] POST - /_matrix/client/r0/account/3pid/delete +- [ ] POST - /_matrix/client/r0/account/3pid/unbind - [ ] POST - /_matrix/client/r0/account/deactivate - [ ] POST - /_matrix/client/r0/account/password - [X] POST - /_matrix/client/r0/register - [ ] POST - /_matrix/client/r0/user_directory/search -- [ ] PUT - /_matrix/client/r0/profile/{userId}/avatar_url +- [X] PUT - /_matrix/client/r0/profile/{userId}/avatar_url - [X] PUT - /_matrix/client/r0/profile/{userId}/displayname - [ ] PUT - /_matrix/client/r0/user/{userId}/account_data/{type} - [ ] PUT - /_matrix/client/r0/user/{userId}/rooms/{roomId}/account_data/{type} -- [ ] PUT - /_matrix/client/r0/user/{userId}/rooms/{roomId}/tags/{tag} +- [X] PUT - /_matrix/client/r0/user/{userId}/rooms/{roomId}/tags/{tag} ## VOIP diff --git a/lib/Matrix/Client/MediaStore.rakumod b/lib/Matrix/Client/MediaStore.rakumod index 34fbda3..7086083 100644 --- a/lib/Matrix/Client/MediaStore.rakumod +++ b/lib/Matrix/Client/MediaStore.rakumod @@ -46,14 +46,14 @@ method upload(IO::Path $path, Str $filename?, Str :$content-type is copy = "imag $data // ""; } -# GET - /_matrix/media/r0/download/{serverName}/{mediaId} +#| GET - /_matrix/media/r0/download/{serverName}/{mediaId} multi method download(Str $mxc-uri, :$allow-remote = True) { my $mxc = self.parse-mxc($mxc-uri); samewith($mxc, $mxc, :$allow-remote) } -# GET - /_matrix/media/r0/download/{serverName}/{mediaId} +#| GET - /_matrix/media/r0/download/{serverName}/{mediaId} multi method download(Str $server-name, Str $media-id, Bool :$allow-remote = True) { my $response = $.get( "/download/{$server-name}/{$media-id}", diff --git a/scripts/load-docs.p6 b/scripts/load-docs.p6 index b20dd86..87ef0d4 100755 --- a/scripts/load-docs.p6 +++ b/scripts/load-docs.p6 @@ -34,8 +34,9 @@ sub get-api-docs { sub MAIN(:$spec?) { my %tags = get-api-docs; - my $implemented-methods = (Matrix::Client, Matrix::Client::Room).map(*.^methods) - .flat.map( + my $implemented-methods = ( + Matrix::Client, Matrix::Client::Room, Matrix::Client::MediaStore + ).map(*.^methods».candidates).flat.map( { quietly try { .WHY.Str } or "" }).grep(/_matrix/).SetHash; -- cgit v1.2.3-70-g09d2 From c1851c5a391f3c72cc8de3cfb166fbdb8fee3ae5 Mon Sep 17 00:00:00 2001 From: Matias Linares Date: Sun, 17 May 2020 20:26:17 -0300 Subject: Add MediaStore tests --- t/60-media.t | 49 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100644 t/60-media.t diff --git a/t/60-media.t b/t/60-media.t new file mode 100644 index 0000000..602b0fc --- /dev/null +++ b/t/60-media.t @@ -0,0 +1,49 @@ +use lib 'lib'; +use Test; +use Matrix::Client::MediaStore; +use Matrix::Client::Exception; + +plan 6; + +my $path = $*TMPDIR.add('matrix-client-test'); +LEAVE { unlink $path; } +$path.spurt("") unless $path.f; + +# Mock the post-bin method of Matrix::Client::Requester. +my $media = Matrix::Client::MediaStore.new(:home-server("1234")) but role { + has %.called-with; + method post-bin(Str $path, Buf $buf, :$content-type) { + %.called-with = $path; + %.called-with = $buf; + %.called-with = $content-type; + + class { method content { '{"content_uri": "bla" }' } } + } +} + + +$media.upload($path, "something"); +is $media.called-with, '/upload?filename=something', "Send filename pass by parameter"; + +$media.upload($path, "something with spaces"); +is $media.called-with, '/upload?filename=something%20with%20spaces', "Escaped filename"; + +$media.upload($path); +is $media.called-with, "/upload?filename={$path.basename}", "Send file basename if not set"; +is $media.called-with, 'image/png', "By default use `image/png` MIME"; + +$media.upload($path, content-type => 'application/pdf'); +is $media.called-with, 'application/pdf', "Can change the content type"; + +subtest { + plan 2; + my $media = Matrix::Client::MediaStore.new(:home-server("1234")); + is $media.parse-mxc("mxc://matrix.org/123456.pdf"), { + server-name => "matrix.org", media-id => "123456.pdf" + }, 'Simple parsing'; + + throws-like { + $media.parse-mxc("http://matrix.org/123456.pdf") + }, X::Matrix::MXCParse, 'Dies with HTTP URI'; + +}, 'mxc parsing'; -- cgit v1.2.3-70-g09d2 From 17b787aeeab455bbe432414948c01544891631a4 Mon Sep 17 00:00:00 2001 From: Matias Linares Date: Sun, 17 May 2020 21:13:34 -0300 Subject: Create main.yml --- .github/workflows/main.yml | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 .github/workflows/main.yml diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml new file mode 100644 index 0000000..88a2991 --- /dev/null +++ b/.github/workflows/main.yml @@ -0,0 +1,27 @@ +# This is a basic workflow to help you get started with Actions + +name: Tests + +# Controls when the action will run. Triggers the workflow on push or pull request +# events but only for the master branch +on: + push: + branches: [ master ] + pull_request: + branches: [ master ] + +# A workflow run is made up of one or more jobs that can run sequentially or in parallel +jobs: + # This workflow contains a single job called "build" + test: + # The type of runner that the job will run on + runs-on: ubuntu-latest + + # Steps represent a sequence of tasks that will be executed as part of the job + steps: + # Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it + - uses: actions/checkout@v2 + + - name: Run tests + id: tests + uses: JJ/raku-container-action@master -- cgit v1.2.3-70-g09d2 From ecf6d6583d343dd3a14c0b4629fa399d79c71d32 Mon Sep 17 00:00:00 2001 From: Matias Linares Date: Sun, 17 May 2020 21:20:40 -0300 Subject: Remove travis.yml --- .travis.yml | 9 --------- 1 file changed, 9 deletions(-) delete mode 100644 .travis.yml diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index 22775c4..0000000 --- a/.travis.yml +++ /dev/null @@ -1,9 +0,0 @@ -language: perl6 -perl6: - - latest -install: - - rakudobrew build zef - - zef --debug --depsonly install . -script: - - prove -v -e 'perl6 -Ilib' t/ -sudo: false -- cgit v1.2.3-70-g09d2 From ae506f4258324f77b8644459c1cb0c18359d793b Mon Sep 17 00:00:00 2001 From: Matias Linares Date: Sun, 6 Sep 2020 18:54:36 -0300 Subject: Provide MediaStore --- META6.json | 1 + 1 file changed, 1 insertion(+) diff --git a/META6.json b/META6.json index 84bd589..6f3a5fb 100644 --- a/META6.json +++ b/META6.json @@ -18,6 +18,7 @@ "Matrix::Client::Common" : "lib/Matrix/Client/Common.pm6", "Matrix::Client::Exception" : "lib/Matrix/Client/Exception.pm6", "Matrix::Client::Requester" : "lib/Matrix/Client/Requester.pm6", + "Matrix::Client::MediaStore": "lib/Matrix/Client/MediaStore.rakumod", "Matrix::Client::Room" : "lib/Matrix/Client/Room.pm6", "Matrix::Response" : "lib/Matrix/Response.pm6" }, -- cgit v1.2.3-70-g09d2 From 80d50c14866f6e58ee57792a383920a7e8a1274a Mon Sep 17 00:00:00 2001 From: Matias Linares Date: Sun, 6 Sep 2020 19:38:12 -0300 Subject: Add media store config method --- lib/Matrix/Client/MediaStore.rakumod | 10 ++++-- lib/Matrix/Response.pm6 | 9 ++++- t/40-response.t | 44 +++++++++++++++-------- t/60-media.t | 69 ++++++++++++++++++++++++------------ 4 files changed, 92 insertions(+), 40 deletions(-) diff --git a/lib/Matrix/Client/MediaStore.rakumod b/lib/Matrix/Client/MediaStore.rakumod index 7086083..7afa9e3 100644 --- a/lib/Matrix/Client/MediaStore.rakumod +++ b/lib/Matrix/Client/MediaStore.rakumod @@ -1,7 +1,9 @@ use JSON::Fast; +use URI::Escape; + use Matrix::Client::Requester; use Matrix::Client::Exception; -use URI::Escape; +use Matrix::Response; unit class Matrix::Client::MediaStore does Matrix::Client::Requester; @@ -16,7 +18,6 @@ submethod TWEAK { $!client-endpoint = "/_matrix/media/r0"; } -# https://matrix.deprecated.org/_matrix/media/r0/thumbnail/matrix.org/TKTUVTAazFocrTjezhiXZiIe?width=25&height=25&method=crop method parse-mxc(Str $uri) { if $uri ~~ m/"mxc://" $ = [.*] "/" $ = [ .* ]/ { return { @@ -68,3 +69,8 @@ multi method download(Str $server-name, Str $media-id, Bool :$allow-remote = Tru content => $response.content ) } + +method config(--> Matrix::Response::MediaStore::Config) { + my $response = $.get("/config"); + Matrix::Response::MediaStore::Config.new(from-json($response.content)) +} diff --git a/lib/Matrix/Response.pm6 b/lib/Matrix/Response.pm6 index 268be84..ec93cf3 100644 --- a/lib/Matrix/Response.pm6 +++ b/lib/Matrix/Response.pm6 @@ -123,7 +123,6 @@ class Tag { } } - class Matrix::Response::Device { has Str $.device-id; has $.display-name; @@ -137,3 +136,11 @@ class Matrix::Response::Device { :last_seen_ts(:$!last-seen-ts)? ) { } } + +class Matrix::Response::MediaStore::Config { + has Int $.upload-size; + + method new(%config) { + self.bless(:upload-size(%config // Int)); + } +} diff --git a/t/40-response.t b/t/40-response.t index cc219b2..8bc3569 100644 --- a/t/40-response.t +++ b/t/40-response.t @@ -2,24 +2,38 @@ use lib 'lib'; use Test; use JSON::Fast; use Matrix::Response; -plan 7; +plan 2; -my $test-file = 'sync.json'; +subtest 'Sync', { + plan 7; + my $test-file = 'sync.json'; + my $data; -unless $test-file.IO.f { - skip-rest 'Missing sync.json to test'; - exit; -} + if $test-file.IO.f { + $data = from-json($test-file.IO.slurp); + lives-ok { Matrix::Response::Sync.new($test-file.IO.slurp) }, 'Sync.new accepts Str'; + lives-ok { Matrix::Response::Sync.new($data) }, 'Sync.new accepts Associative'; -my $data = from-json($test-file.IO.slurp); + my $res = Matrix::Response::Sync.new($data); + can-ok $res, 'joined-rooms', 'can .joined-rooms'; + can-ok $res, 'presence', 'can .presence'; -ok $data; -lives-ok { Matrix::Response::Sync.new($test-file.IO.slurp) }; -lives-ok { Matrix::Response::Sync.new($data) }; + isa-ok $res.joined-rooms, List, '.joined-rooms returns a List'; + isa-ok $res.presence, List, '.presence returns a List'; -my $res = Matrix::Response::Sync.new($data); -can-ok $res, 'joined-rooms'; -can-ok $res, 'presence'; + } else { + skip 'Missing sync.json to test', 7; + } -isa-ok $res.joined-rooms, List; -isa-ok $res.presence, List; +}; + +subtest 'MediaStore', { + plan 4; + my %config = 'm.upload.size' => 5000; + my $config-response = Matrix::Response::MediaStore::Config.new(|%config); + + isa-ok $config-response, Matrix::Response::MediaStore::Config; + can-ok $config-response, 'upload-size'; + isa-ok $config-response.upload-size, Int; + is $config-response.upload-size, %config, 'correct upload size'; +}; diff --git a/t/60-media.t b/t/60-media.t index 602b0fc..5601d8a 100644 --- a/t/60-media.t +++ b/t/60-media.t @@ -3,39 +3,40 @@ use Test; use Matrix::Client::MediaStore; use Matrix::Client::Exception; -plan 6; - my $path = $*TMPDIR.add('matrix-client-test'); LEAVE { unlink $path; } $path.spurt("") unless $path.f; -# Mock the post-bin method of Matrix::Client::Requester. -my $media = Matrix::Client::MediaStore.new(:home-server("1234")) but role { - has %.called-with; - method post-bin(Str $path, Buf $buf, :$content-type) { - %.called-with = $path; - %.called-with = $buf; - %.called-with = $content-type; +subtest 'Upload', { + plan 5; + # Mock the post-bin method of Matrix::Client::Requester. + my $media = Matrix::Client::MediaStore.new(:home-server("1234")) but role { + has %.called-with; + method post-bin(Str $path, Buf $buf, :$content-type) { + %.called-with = $path; + %.called-with = $buf; + %.called-with = $content-type; - class { method content { '{"content_uri": "bla" }' } } + class { method content { '{"content_uri": "bla" }' } } + } } -} -$media.upload($path, "something"); -is $media.called-with, '/upload?filename=something', "Send filename pass by parameter"; + $media.upload($path, "something"); + is $media.called-with, '/upload?filename=something', "Send filename pass by parameter"; -$media.upload($path, "something with spaces"); -is $media.called-with, '/upload?filename=something%20with%20spaces', "Escaped filename"; + $media.upload($path, "something with spaces"); + is $media.called-with, '/upload?filename=something%20with%20spaces', "Escaped filename"; -$media.upload($path); -is $media.called-with, "/upload?filename={$path.basename}", "Send file basename if not set"; -is $media.called-with, 'image/png', "By default use `image/png` MIME"; + $media.upload($path); + is $media.called-with, "/upload?filename={$path.basename}", "Send file basename if not set"; + is $media.called-with, 'image/png', "By default use `image/png` MIME"; -$media.upload($path, content-type => 'application/pdf'); -is $media.called-with, 'application/pdf', "Can change the content type"; + $media.upload($path, content-type => 'application/pdf'); + is $media.called-with, 'application/pdf', "Can change the content type"; +} -subtest { +subtest 'mxc parsing', { plan 2; my $media = Matrix::Client::MediaStore.new(:home-server("1234")); is $media.parse-mxc("mxc://matrix.org/123456.pdf"), { @@ -46,4 +47,28 @@ subtest { $media.parse-mxc("http://matrix.org/123456.pdf") }, X::Matrix::MXCParse, 'Dies with HTTP URI'; -}, 'mxc parsing'; +}; + +subtest 'config', { + # Mock the post-bin method of Matrix::Client::Requester. + plan 5; + my $media = Matrix::Client::MediaStore.new(:home-server("1234")) but role { + method get(Str $path) { + class { method content { '{"m.upload.size": 5000 }' } } + } + } + + isa-ok $media.config, Matrix::Response::MediaStore::Config, 'Can load Associative'; + is $media.config.upload-size, 5000, 'correct upload size'; + + my $empty-media = Matrix::Client::MediaStore.new(:home-server("1234")) but role { + method get(Str $path) { + class { method content { '{}' } } + } + } + + isa-ok $empty-media.config, Matrix::Response::MediaStore::Config, 'Can load empty configuration'; + is $empty-media.config.upload-size, Int, 'Unknown upload-size'; + nok $empty-media.config.upload-size.defined, 'upload-size not defined'; + +} -- cgit v1.2.3-70-g09d2 From e32ac2fe81a3ab4e5532f1a67a5df3c6904aad2b Mon Sep 17 00:00:00 2001 From: Matias Linares Date: Sun, 6 Sep 2020 19:41:46 -0300 Subject: [Github workflow] Change actions/checkout from v2 to v1 --- .github/workflows/main.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 88a2991..c0d8c82 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -20,8 +20,8 @@ jobs: # Steps represent a sequence of tasks that will be executed as part of the job steps: # Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it - - uses: actions/checkout@v2 - + - uses: actions/checkout@v1 + - name: Run tests id: tests uses: JJ/raku-container-action@master -- cgit v1.2.3-70-g09d2 From ab2a237e5cff43f9b8cd806b7e9e271ffb01b461 Mon Sep 17 00:00:00 2001 From: Matias Linares Date: Sun, 6 Sep 2020 19:51:23 -0300 Subject: Update endpoints script. Show the total of endpoints implemented at the end --- endpoints.md | 12 ++++++++++-- lib/Matrix/Client/MediaStore.rakumod | 1 + scripts/load-docs.p6 | 12 ++++++++++++ 3 files changed, 23 insertions(+), 2 deletions(-) diff --git a/endpoints.md b/endpoints.md index c77b6c4..f47105b 100644 --- a/endpoints.md +++ b/endpoints.md @@ -29,7 +29,7 @@ from matrix.org. This will give you an overview about what's implemented in the ## Media -- [ ] GET - /_matrix/media/r0/config +- [X] GET - /_matrix/media/r0/config - [X] GET - /_matrix/media/r0/download/{serverName}/{mediaId} - [ ] GET - /_matrix/media/r0/download/{serverName}/{mediaId}/{fileName} - [ ] GET - /_matrix/media/r0/preview_url @@ -52,6 +52,8 @@ from matrix.org. This will give you an overview about what's implemented in the - [ ] GET - /_matrix/client/r0/pushers - [ ] GET - /_matrix/client/r0/pushrules/ - [ ] GET - /_matrix/client/r0/pushrules/{scope}/{kind}/{ruleId} +- [ ] GET - /_matrix/client/r0/pushrules/{scope}/{kind}/{ruleId}/actions +- [ ] GET - /_matrix/client/r0/pushrules/{scope}/{kind}/{ruleId}/enabled - [ ] POST - /_matrix/client/r0/pushers/set - [ ] PUT - /_matrix/client/r0/pushrules/{scope}/{kind}/{ruleId} - [ ] PUT - /_matrix/client/r0/pushrules/{scope}/{kind}/{ruleId}/actions @@ -73,6 +75,7 @@ from matrix.org. This will give you an overview about what's implemented in the - [X] DELETE - /_matrix/client/r0/directory/room/{roomAlias} - [X] GET - /_matrix/client/r0/directory/room/{roomAlias} +- [ ] GET - /_matrix/client/r0/rooms/{roomId}/aliases - [X] PUT - /_matrix/client/r0/directory/room/{roomAlias} ## Room discovery @@ -115,7 +118,7 @@ from matrix.org. This will give you an overview about what's implemented in the - [X] PUT - /_matrix/client/r0/rooms/{roomId}/state/{eventType}/{stateKey} - [ ] PUT - /_matrix/client/r0/rooms/{roomId}/typing/{userId} -## Room ugprades +## Room upgrades - [ ] POST - /_matrix/client/r0/rooms/{roomId}/upgrade @@ -170,3 +173,8 @@ from matrix.org. This will give you an overview about what's implemented in the - [ ] GET - /_matrix/client/r0/voip/turnServer + +# Endpoint completion + +0.378641% - (39/103) + diff --git a/lib/Matrix/Client/MediaStore.rakumod b/lib/Matrix/Client/MediaStore.rakumod index 7afa9e3..cb59626 100644 --- a/lib/Matrix/Client/MediaStore.rakumod +++ b/lib/Matrix/Client/MediaStore.rakumod @@ -70,6 +70,7 @@ multi method download(Str $server-name, Str $media-id, Bool :$allow-remote = Tru ) } +#| GET - /_matrix/media/r0/config method config(--> Matrix::Response::MediaStore::Config) { my $response = $.get("/config"); Matrix::Response::MediaStore::Config.new(from-json($response.content)) diff --git a/scripts/load-docs.p6 b/scripts/load-docs.p6 index 87ef0d4..2392a3a 100755 --- a/scripts/load-docs.p6 +++ b/scripts/load-docs.p6 @@ -34,6 +34,8 @@ sub get-api-docs { sub MAIN(:$spec?) { my %tags = get-api-docs; + my $total = 0; + my $completed = 0; my $implemented-methods = ( Matrix::Client, Matrix::Client::Room, Matrix::Client::MediaStore ).map(*.^methods».candidates).flat.map( @@ -58,6 +60,9 @@ sub MAIN(:$spec?) { for $methods.Seq.sort -> $m { my Str $method = $m.trim; my $checked = $implemented-methods{$m} ?? "X" !! " "; + $completed++ if $implemented-methods{$m}; + $total++; + if $spec { $method = $m.subst(/unstable/, $spec) } @@ -65,4 +70,11 @@ sub MAIN(:$spec?) { } say ""; } + + say qq:to/EOF/; + + # Endpoint completion + + {$completed/$total}% - ($completed/$total) + EOF } -- cgit v1.2.3-70-g09d2 From d8f623d8093ff8e47d386f86e61deebdac66fc29 Mon Sep 17 00:00:00 2001 From: Matias Linares Date: Sun, 6 Sep 2020 20:16:15 -0300 Subject: Add thumbnail endpoint --- endpoints.md | 6 ++--- lib/Matrix/Client/MediaStore.rakumod | 49 ++++++++++++++++++++++++++++++++---- 2 files changed, 47 insertions(+), 8 deletions(-) diff --git a/endpoints.md b/endpoints.md index f47105b..ad26ad9 100644 --- a/endpoints.md +++ b/endpoints.md @@ -31,9 +31,9 @@ from matrix.org. This will give you an overview about what's implemented in the - [X] GET - /_matrix/media/r0/config - [X] GET - /_matrix/media/r0/download/{serverName}/{mediaId} -- [ ] GET - /_matrix/media/r0/download/{serverName}/{mediaId}/{fileName} +- [X] GET - /_matrix/media/r0/download/{serverName}/{mediaId}/{fileName} - [ ] GET - /_matrix/media/r0/preview_url -- [ ] GET - /_matrix/media/r0/thumbnail/{serverName}/{mediaId} +- [X] GET - /_matrix/media/r0/thumbnail/{serverName}/{mediaId} - [X] POST - /_matrix/media/r0/upload ## OpenID @@ -176,5 +176,5 @@ from matrix.org. This will give you an overview about what's implemented in the # Endpoint completion -0.378641% - (39/103) +0.398058% - (41/103) diff --git a/lib/Matrix/Client/MediaStore.rakumod b/lib/Matrix/Client/MediaStore.rakumod index cb59626..9779db2 100644 --- a/lib/Matrix/Client/MediaStore.rakumod +++ b/lib/Matrix/Client/MediaStore.rakumod @@ -48,16 +48,20 @@ method upload(IO::Path $path, Str $filename?, Str :$content-type is copy = "imag } #| GET - /_matrix/media/r0/download/{serverName}/{mediaId} -multi method download(Str $mxc-uri, :$allow-remote = True) { +multi method download(Str $mxc-uri, :$allow-remote = True, Str :$filename?) { my $mxc = self.parse-mxc($mxc-uri); - samewith($mxc, $mxc, :$allow-remote) + samewith($mxc, $mxc, :$allow-remote, :$filename) } -#| GET - /_matrix/media/r0/download/{serverName}/{mediaId} -multi method download(Str $server-name, Str $media-id, Bool :$allow-remote = True) { +#| GET - /_matrix/media/r0/download/{serverName}/{mediaId}/{fileName} +multi method download(Str $server-name, Str $media-id, + Bool :$allow-remote = True, Str :$filename?) { + my $endpoint = "/download/{$server-name}/{$media-id}"; + + $endpoint ~= "/{$filename}" if $filename.defined; my $response = $.get( - "/download/{$server-name}/{$media-id}", + $endpoint, allow_remote => $allow-remote.Str.lc ); @@ -70,6 +74,41 @@ multi method download(Str $server-name, Str $media-id, Bool :$allow-remote = Tru ) } +#| GET - /_matrix/media/r0/thumbnail/{serverName}/{mediaId} +multi method thumbnail(Str $mxc-uri, Int $width, Int $height, + Str :$method where * eq 'crop'|'scale', + Bool :$allow-remote = True) { + my $mxc = self.parse-mxc($mxc-uri); + samewith( + $mxc, $mxc, + $width, $height, + :$method, :$allow-remote + ) +} + +#| GET - /_matrix/media/r0/thumbnail/{serverName}/{mediaId} +multi method thumbnail(Str $server-name, Str $media-id, + Int $width, Int $height, + Str :$method where * eq 'crop'|'scale', + Bool :$allow-remote = True) { + my $endpoint = "/thumbnail/{$server-name}/{$media-id}"; + + my $response = $.get( + $endpoint, + :$height, + :$width, + :$method, + allow_remote => $allow-remote.Str.lc + ); + + my %headers = $response.header.hash(); + + Matrix::Client::MediaStore::File.new( + content-type => %headers.head, + content => $response.content + ) +} + #| GET - /_matrix/media/r0/config method config(--> Matrix::Response::MediaStore::Config) { my $response = $.get("/config"); -- cgit v1.2.3-70-g09d2 From 4cd5b4da65ee1d94ea8b6ce54e990e0bdda99053 Mon Sep 17 00:00:00 2001 From: Matias Linares Date: Sun, 6 Sep 2020 20:33:42 -0300 Subject: Bump version on META --- META6.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/META6.json b/META6.json index 6f3a5fb..bff3fc7 100644 --- a/META6.json +++ b/META6.json @@ -35,5 +35,5 @@ "Test", "Test::META" ], - "version" : "0.5.2" + "version" : "0.6.0" } -- cgit v1.2.3-70-g09d2 From 6c44b6f1d932a993b88c3faa7fde3ef2f3dd527d Mon Sep 17 00:00:00 2001 From: Matias Linares Date: Mon, 23 Nov 2020 19:24:45 -0300 Subject: Update main.yml --- .github/workflows/main.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index c0d8c82..f059876 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -20,8 +20,8 @@ jobs: # Steps represent a sequence of tasks that will be executed as part of the job steps: # Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it - - uses: actions/checkout@v1 - + - name: Checkout + uses: actions/checkout@v1 - name: Run tests id: tests uses: JJ/raku-container-action@master -- cgit v1.2.3-70-g09d2 From 346f058b08e3c0b911243f59996cd0ef635ae211 Mon Sep 17 00:00:00 2001 From: Matias Linares Date: Mon, 23 Nov 2020 19:52:11 -0300 Subject: Fix tests --- t/40-response.t | 2 +- t/60-media.t | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/t/40-response.t b/t/40-response.t index 8bc3569..c401378 100644 --- a/t/40-response.t +++ b/t/40-response.t @@ -30,7 +30,7 @@ subtest 'Sync', { subtest 'MediaStore', { plan 4; my %config = 'm.upload.size' => 5000; - my $config-response = Matrix::Response::MediaStore::Config.new(|%config); + my $config-response = Matrix::Response::MediaStore::Config.new(%config); isa-ok $config-response, Matrix::Response::MediaStore::Config; can-ok $config-response, 'upload-size'; diff --git a/t/60-media.t b/t/60-media.t index 5601d8a..2417cb1 100644 --- a/t/60-media.t +++ b/t/60-media.t @@ -7,6 +7,8 @@ my $path = $*TMPDIR.add('matrix-client-test'); LEAVE { unlink $path; } $path.spurt("") unless $path.f; +plan 3; + subtest 'Upload', { plan 5; # Mock the post-bin method of Matrix::Client::Requester. -- cgit v1.2.3-70-g09d2 From 8f423e22081a8579bb37a61b16ade04617e50ddc Mon Sep 17 00:00:00 2001 From: Matias Linares Date: Mon, 23 Nov 2020 19:57:47 -0300 Subject: Update META for release v0.6.1 --- META6.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/META6.json b/META6.json index bff3fc7..1ce78d4 100644 --- a/META6.json +++ b/META6.json @@ -35,5 +35,5 @@ "Test", "Test::META" ], - "version" : "0.6.0" + "version" : "0.6.1" } -- cgit v1.2.3-70-g09d2 From d5b3361c9ceeac3ed3a90dab35b12b0bd4ab7612 Mon Sep 17 00:00:00 2001 From: Matias Linares Date: Sat, 26 Dec 2020 22:33:31 -0300 Subject: Implement membership endpoints for Matrix::Client::Room This implements for room endpoints: * Join a room * Get a single event * Get states * Get room aliases * Get room members --- endpoints.md | 13 +++-- lib/Matrix/Client/Room.pm6 | 116 ++++++++++++++++++++++++++++++++++++--------- lib/Matrix/Response.pm6 | 4 ++ 3 files changed, 103 insertions(+), 30 deletions(-) diff --git a/endpoints.md b/endpoints.md index ad26ad9..e8bc9f8 100644 --- a/endpoints.md +++ b/endpoints.md @@ -75,7 +75,7 @@ from matrix.org. This will give you an overview about what's implemented in the - [X] DELETE - /_matrix/client/r0/directory/room/{roomAlias} - [X] GET - /_matrix/client/r0/directory/room/{roomAlias} -- [ ] GET - /_matrix/client/r0/rooms/{roomId}/aliases +- [X] GET - /_matrix/client/r0/rooms/{roomId}/aliases - [X] PUT - /_matrix/client/r0/directory/room/{roomAlias} ## Room discovery @@ -91,7 +91,7 @@ from matrix.org. This will give you an overview about what's implemented in the - [X] POST - /_matrix/client/r0/rooms/{roomId}/forget - [X] POST - /_matrix/client/r0/rooms/{roomId}/invite - [ ] POST - /_matrix/client/r0/rooms/{roomId}/invite -- [ ] POST - /_matrix/client/r0/rooms/{roomId}/join +- [X] POST - /_matrix/client/r0/rooms/{roomId}/join - [X] POST - /_matrix/client/r0/rooms/{roomId}/kick - [X] POST - /_matrix/client/r0/rooms/{roomId}/leave - [X] POST - /_matrix/client/r0/rooms/{roomId}/unban @@ -102,13 +102,13 @@ from matrix.org. This will give you an overview about what's implemented in the - [ ] GET - /_matrix/client/r0/events/{eventId} - [ ] GET - /_matrix/client/r0/initialSync - [ ] GET - /_matrix/client/r0/rooms/{roomId}/context/{eventId} -- [ ] GET - /_matrix/client/r0/rooms/{roomId}/event/{eventId} +- [X] GET - /_matrix/client/r0/rooms/{roomId}/event/{eventId} - [ ] GET - /_matrix/client/r0/rooms/{roomId}/initialSync - [X] GET - /_matrix/client/r0/rooms/{roomId}/joined_members -- [ ] GET - /_matrix/client/r0/rooms/{roomId}/members +- [X] GET - /_matrix/client/r0/rooms/{roomId}/members - [X] GET - /_matrix/client/r0/rooms/{roomId}/messages - [X] GET - /_matrix/client/r0/rooms/{roomId}/state -- [ ] GET - /_matrix/client/r0/rooms/{roomId}/state/{eventType}/{stateKey} +- [X] GET - /_matrix/client/r0/rooms/{roomId}/state/{eventType}/{stateKey} - [X] GET - /_matrix/client/r0/sync - [ ] GET - /_matrix/client/r0/user/{userId}/filter/{filterId} - [ ] POST - /_matrix/client/r0/rooms/{roomId}/receipt/{receiptType}/{eventId} @@ -176,5 +176,4 @@ from matrix.org. This will give you an overview about what's implemented in the # Endpoint completion -0.398058% - (41/103) - +0.446602% - (46/103) diff --git a/lib/Matrix/Client/Room.pm6 b/lib/Matrix/Client/Room.pm6 index ca97d2f..72dfb62 100644 --- a/lib/Matrix/Client/Room.pm6 +++ b/lib/Matrix/Client/Room.pm6 @@ -25,15 +25,8 @@ method !get-name() { $!name = $data; } -#| GET - /_matrix/client/r0/rooms/{roomId}/joined_members -method joined-members { - my %data = from-json($.get("/joined_members").content); - %data -} - -method name { +method name(--> Str) { self!get-name; - $!name } @@ -52,6 +45,42 @@ method fallback-name(--> Str) { }; } +#| GET - /_matrix/client/r0/rooms/{roomId}/aliases +method aliases(--> List) { + my %data = from-json($.get('/aliases').content); + %data.List +} + +# Events + +## Getting events for a room + +#| GET - /_matrix/client/r0/rooms/{roomId}/event/{eventId} +method event(Str $event-id --> Matrix::Response::RoomEvent) { + my %data = from-json($.get("/event/$event-id").content); + Matrix::Response::RoomEvent.new(|%data) +} + +#| GET - /_matrix/client/r0/rooms/{roomId}/state +multi method state(--> Seq) { + my $data = from-json($.get('/state').content); + + gather for $data.List -> $event { + take Matrix::Response::StateEvent.new(:room-id($.id), |$event) + } +} + +#| GET - /_matrix/client/r0/rooms/{roomId}/state/{eventType}/{stateKey} +multi method state(Str $event-type, Str $state-key = "") { + from-json($.get("/state/$event-type/$state-key").content) +} + +#| GET - /_matrix/client/r0/rooms/{roomId}/joined_members +method joined-members { + my %data = from-json($.get("/joined_members").content); + %data +} + #| GET - /_matrix/client/r0/rooms/{roomId}/messages method messages() { my $res = $.get("/messages"); @@ -60,6 +89,23 @@ method messages() { return $data.clone; } +#| GET - /_matrix/client/r0/rooms/{roomId}/members +method members(:$at, Str :$membership, Str :$not-membership) { + my %query; + + %query = $at with $at; + %query = $membership with $membership; + %query = $not-membership with $not-membership; + + my %data = from-json($.get('/members', |%query).content); + + gather for %data.List -> $ev { + take Matrix::Response::MemberEvent.new(|$ev) + } +} + +## Sending events to a room + #| PUT - /_matrix/client/r0/rooms/{roomId}/send/{eventType}/{txnId} method send(Str $body!, Str :$type? = "m.text") { $Matrix::Client::Common::TXN-ID++; @@ -71,20 +117,6 @@ method send(Str $body!, Str :$type? = "m.text") { from-json($res.content) } -#| GET - /_matrix/client/r0/rooms/{roomId}/state -multi method state(--> Seq) { - my $data = from-json($.get('/state').content); - - gather for $data.List -> $event { - take Matrix::Response::StateEvent.new(:room-id($.id), |$event) - } -} - -#| GET - /_matrix/client/r0/rooms/{roomId}/state/{eventType} -multi method state(Str $event-type) { - from-json($.get("/state/$event-type").content) -} - #| PUT - /_matrix/client/r0/rooms/{roomId}/state/{eventType}/{stateKey} method send-state(Str:D $event-type, :$state-key = "", *%args --> Str) { my $res = $.put( @@ -94,11 +126,49 @@ method send-state(Str:D $event-type, :$state-key = "", *%args --> Str) { from-json($res.content) } +# Room membership! + +## Joining rooms + +#| POST - /_matrix/client/r0/rooms/{roomId}/invite +method invite(Str $user-id) { + $.post('/invite', :$user-id) +} + +#| POST - /_matrix/client/r0/rooms/{roomId}/join +method join { + $.post('/join') +} + +## Leaving rooms + #| POST - /_matrix/client/r0/rooms/{roomId}/leave -method leave() { +method leave { $.post('/leave') } +#| POST - /_matrix/client/r0/rooms/{roomId}/forget +method forget { + $.post('/forget') +} + +#| POST - /_matrix/client/r0/rooms/{roomId}/kick +method kick(Str $user-id, Str $reason = "") { + $.post('/kick', :$user-id, :$reason) +} + +## Banning users + +#| POST - /_matrix/client/r0/rooms/{roomId}/ban +method ban(Str $user-id, $reason = "") { + $.post('/ban', :$user-id, :$reason) +} + +#| POST - /_matrix/client/r0/rooms/{roomId}/unban +method unban(Str $user-id) { + $.post('/unban', :$user-id) +} + method Str(--> Str) { "Room" } diff --git a/lib/Matrix/Response.pm6 b/lib/Matrix/Response.pm6 index ec93cf3..cc9e7a8 100644 --- a/lib/Matrix/Response.pm6 +++ b/lib/Matrix/Response.pm6 @@ -23,6 +23,10 @@ class Matrix::Response::StateEvent is Matrix::Response::RoomEvent { has $.state_key; } +class Matrix::Response::MemberEvent is Matrix::Response::StateEvent { + has $.type is required where 'm.room.member'; +} + class Matrix::Response::Timeline { has Matrix::Response::Event @.events; has Bool $limited; -- cgit v1.2.3-70-g09d2 From 2983d424bad511d5c50c52caf5daedff27eb2ada Mon Sep 17 00:00:00 2001 From: Matias Linares Date: Sun, 27 Dec 2020 11:53:50 -0300 Subject: Complete messages method for Matrix::Client::Room --- lib/Matrix/Client/Room.pm6 | 24 ++++++++++++++++++++---- lib/Matrix/Response.pm6 | 6 ++++++ 2 files changed, 26 insertions(+), 4 deletions(-) diff --git a/lib/Matrix/Client/Room.pm6 b/lib/Matrix/Client/Room.pm6 index 72dfb62..3d6ecaa 100644 --- a/lib/Matrix/Client/Room.pm6 +++ b/lib/Matrix/Client/Room.pm6 @@ -82,15 +82,31 @@ method joined-members { } #| GET - /_matrix/client/r0/rooms/{roomId}/messages -method messages() { - my $res = $.get("/messages"); +method messages( + Str:D :$from!, Str :$to, + Str :$dir where * eq 'f'|'b' = 'f', + Int :$limit = 10, :%filter, + --> Matrix::Response::Messages +) { + my $res = $.get( + "/messages", :$from, :$to, :$dir, :$limit, :%filter + ); my $data = from-json($res.content); - return $data.clone; + + my @messages = $data.map(-> $ev { + Matrix::Response::RoomEvent.new(|$ev) + }); + + Matrix::Response::Messages.new( + start => $data, + end => $data, + messages => @messages + ) } #| GET - /_matrix/client/r0/rooms/{roomId}/members -method members(:$at, Str :$membership, Str :$not-membership) { +method members(:$at, Str :$membership, Str :$not-membership --> Seq) { my %query; %query = $at with $at; diff --git a/lib/Matrix/Response.pm6 b/lib/Matrix/Response.pm6 index cc9e7a8..a0b2896 100644 --- a/lib/Matrix/Response.pm6 +++ b/lib/Matrix/Response.pm6 @@ -58,6 +58,12 @@ sub gather-events($room-id, $from) { } } +class Matrix::Response::Messages { + has $.start; + has $.end; + has Matrix::Response::RoomEvent @.messages; +} + class Matrix::Response::Sync { has Str $.next-batch; has Matrix::Response::Event @.presence; -- cgit v1.2.3-70-g09d2 From 9e21432cb90b3d1ae4867871a05841f4687ecc01 Mon Sep 17 00:00:00 2001 From: Matias Linares Date: Sun, 27 Dec 2020 11:54:20 -0300 Subject: Update room documentation --- docs/basics.pod6 | 3 +- docs/room.pod6 | 113 +++++++++++++++++++++++++++++++++++++++++++++++++++++-- 2 files changed, 110 insertions(+), 6 deletions(-) diff --git a/docs/basics.pod6 b/docs/basics.pod6 index 694983f..5770f4f 100644 --- a/docs/basics.pod6 +++ b/docs/basics.pod6 @@ -50,8 +50,7 @@ repeated data. my $new-response = $client.sync(:$since); There's a C argument that you could use to filter the response. To -see available parameters to the filter you can go -L. +see available parameters to the filter you can go L. # limit the messages per room to 1 diff --git a/docs/room.pod6 b/docs/room.pod6 index 9724793..f186583 100644 --- a/docs/room.pod6 +++ b/docs/room.pod6 @@ -34,16 +34,37 @@ without the need for a L. Returns the name of the room. If no C was emmited (i.e.: no name was set for this room), then an empty string is returned. -=head2 send +=head2 fallback-name - method send(Str $body!, Str :$type? = "m.text") + method fallback-name(--> Str) -Sends a message to the room. It will return the C for this message. +Return a name for the room with the members of the room. Use this if +the room doesn't have a name set or in 1-1 chats. + +Example: + + my $room = Matrix::Client::Room $room .= new( + :$access-token, :$home-server, :id('#34df12:matrix.org') + ); + say 'Room name: ' ~ $room.name # OUTPUT: «Room name: » + say 'Room name: ' ~ $room.fallback-name # OUTPUT: «Room name: Alice and Bob» + +=head2 aliases + + method aliases(--> List) + +Get a list of aliases maintained by the local server for the given room. + +=head2 event + + method event(Str $event-id --> Matrix::Response::RoomEvent) + +Get a single event based on the C<$event-id>. Returns a L. =head2 state multi method state(--> Seq) - multi method state(Str $event-type) + multi method state(Str $event-type, Str $state-key = "") Get the state events for the current state of a room. it will return a C for every event on that room. @@ -51,6 +72,52 @@ for every event on that room. If an C<$event-type> is passed, the return value will be the value of that single event. +C<$state-key> is the key of the state to look up. + +=head2 joined-members + + method joined-members() + +Returns the data for the members of the room. + +Example: + + my $room = Matrix::Client::Room $room .= new( + :$access-token, :$home-server, :id('#34df12:matrix.org') + ); + my $member = $room.joined-members.head; + # the key is the matrix id + say $member.key # OUTPUT: «@meeple:matrix.deprecated.org» + say $member.values # OUTPUT: «mxc://matrix.deprecated.org/NdSvF..» + say $member.values # OUTPUT: «meeple» + +=head2 messages + + method messages( + Str:D :$from!, Str :$to, + Str :$dir where * eq 'f'|'b' = 'f', + Int :$limit = 10, :%filter + --> Matrix::Response::Messages + ) + +Return a L with the messages from +C<$from>. This token can be obtained from a C token +returned for each room by the sync API, or from a C or C +attributes from L. + +=head2 members + + method members(:$at, Str :$membership, Str :$not-membership --> Seq) + +Get the list of members for this room. This returns a C of +L. + +=head2 send + + method send(Str $body!, Str :$type? = "m.text") + +Sends a message to the room. It will return the C for this message. + =head2 send-state method send-state(Str:D $event-type, :$state-key = "", *%args --> Str) @@ -61,10 +128,48 @@ server. It will return the C for this state change. +=head2 invite + + method invite(Str $user-id) + +Invite a user to the room. + +=head2 join + + method join() + +Join the room. As the creation of the C expects +a room id (C<#032mf90f:matrix.org> for example), you need to use the +L method of C to join by an alias. + =head2 leave method leave() Leaves the room. +=head2 forget + + method forget() + +Stop a user of remembering this particular room. + +=head2 kick + + method kick(Str $user-id, Str $reason = "") + +Kick an user of this room. + +=head2 ban + + method ban(Str $user-id, $reason = "") + +Ban an user of this room. + +=head2 unban + + method unban(Str $user-id) + +Unban a user of this room. + =end pod -- cgit v1.2.3-70-g09d2 From 84dad3c022ed222f9c63fe50af18125c1009df7d Mon Sep 17 00:00:00 2001 From: Matias Linares Date: Sun, 27 Dec 2020 11:58:38 -0300 Subject: Update github action --- .github/workflows/main.yml | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index f059876..38432cc 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -21,7 +21,15 @@ jobs: steps: # Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it - name: Checkout - uses: actions/checkout@v1 + uses: actions/checkout@v2 - name: Run tests id: tests - uses: JJ/raku-container-action@master + uses: Raku/setup-raku@v1 + with: + raku-version: 'latest' + - name: Install Dependencies + run: zef install --deps-only --/test --test-depends . + - name: Install App::Prove6 + run: zef install --/test App::Prove6 + - name: Run Tests + run: prove6 -l t xt -- cgit v1.2.3-70-g09d2 From f1d1a526cc4950578e8769fe3c94147777466531 Mon Sep 17 00:00:00 2001 From: Matias Linares Date: Sun, 27 Dec 2020 12:03:26 -0300 Subject: Remove unused xt/ directory from github actions --- .github/workflows/main.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 38432cc..b568bda 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -32,4 +32,4 @@ jobs: - name: Install App::Prove6 run: zef install --/test App::Prove6 - name: Run Tests - run: prove6 -l t xt + run: prove6 -l t -- cgit v1.2.3-70-g09d2