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(-) (limited to 'lib') 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