use JSON::Tiny; use Matrix::Client::Common; use Matrix::Client::Requester; use Matrix::Response; unit class Matrix::Client::Room does Matrix::Client::Requester; has $!name; has $.id; submethod TWEAK { $!url-prefix = "/rooms/$!id"; } method !get-name() { my $data = $.state('m.room.name'); $!name = $data; } method name() { unless $!name.so { self!get-name() } $!name } method messages() { my $res = $.get("/messages"); my $data = from-json($res.content); return $data.clone; } method send(Str $body!, Str :$type? = "m.text") { $Matrix::Client::Common::TXN-ID++; my $res = $.put( "/send/m.room.message/{$Matrix::Client::Common::TXN-ID}", msgtype => $type, body => $body ); from-json($res.content) } 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) } } multi method state(Str $event-type) { from-json($.get("/state/$event-type").content) } method send-state(Str:D $event-type, :$state-key = "", *%args --> Str) { my $res = $.put( "/state/$event-type/$state-key", |%args ); from-json($res.content) } method leave() { $.post('/leave') } method Str(--> Str) { "Room" }