From b1f945d6cc9853b7e0dda302c2c0ba3cd0946ae7 Mon Sep 17 00:00:00 2001 From: Matias Linares Date: Sun, 28 Jan 2018 18:16:25 -0300 Subject: Add joined-rooms and public-rooms methods --- lib/Matrix/Client.pm6 | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) (limited to 'lib') diff --git a/lib/Matrix/Client.pm6 b/lib/Matrix/Client.pm6 index 51141eb..5091319 100644 --- a/lib/Matrix/Client.pm6 +++ b/lib/Matrix/Client.pm6 @@ -188,9 +188,32 @@ method rooms(Bool :$sync = False) { @!rooms } +method joined-rooms() { + my $res = $.get('/joined_rooms'); + + unless $res.is-success { + note "Error getting joined rooms: {$res.status}"; + return (); + } + my $data = from-json($res.content); + return $data.Seq.map(-> $room-id { + Matrix::Client::Room.new( + id => $room-id, + home-server => $!home-server, + access-token => $!access-token + ) + }); +} + +method public-rooms() { + $.get('/publicRooms') +} + method send(Str $room-id, Str $body, :$type? = "m.text") { $Matrix::Client::Common::TXN-ID++; - $.put("/rooms/$room-id/send/m.room.message/{$Matrix::Client::Common::TXN-ID}", msgtype => $type, body => $body) + $.put("/rooms/$room-id/send/m.room.message/{$Matrix::Client::Common::TXN-ID}", + msgtype => $type, body => $body + ) } # Media -- cgit v1.2.3-54-g00ecf