aboutsummaryrefslogtreecommitdiff
path: root/lib/Matrix/Client/Room.pm6
diff options
context:
space:
mode:
authorMatias Linares <matiaslina@openmailbox.org>2017-04-03 22:23:57 -0300
committerMatias Linares <matiaslina@openmailbox.org>2017-04-03 22:23:57 -0300
commit9c439e653e19472c242fc0bff10e31a57b1ea45f (patch)
tree36f247003cfbe8ec29f26c492d2c794e5d621e16 /lib/Matrix/Client/Room.pm6
downloadperl6-matrix-client-9c439e653e19472c242fc0bff10e31a57b1ea45f.tar.gz
Initial commit
Diffstat (limited to 'lib/Matrix/Client/Room.pm6')
-rw-r--r--lib/Matrix/Client/Room.pm646
1 files changed, 46 insertions, 0 deletions
diff --git a/lib/Matrix/Client/Room.pm6 b/lib/Matrix/Client/Room.pm6
new file mode 100644
index 0000000..5601f33
--- /dev/null
+++ b/lib/Matrix/Client/Room.pm6
@@ -0,0 +1,46 @@
+use JSON::Tiny;
+use Matrix::Client::Common;
+use Matrix::Client::Requester;
+
+unit class Matrix::Client::Room does Matrix::Client::Requester;
+
+has $.name is rw;
+has $.id is rw;
+has $!prev-batch;
+
+submethod BUILD(Str :$id!, :$json, :$home-server!) {
+ $!home-server = $home-server;
+ $!id = $id;
+ $!url-prefix = "/rooms/$!id";
+ $!prev-batch = $json<timeline><prev_batch>;
+
+ if so $json {
+ my @events = $json<state><events>.clone;
+ for @events -> $ev {
+ if $ev<type> eq "m.room.name" {
+ $!name = $ev<content><name>;
+ }
+ }
+ }
+
+ # FIXME: Should be a 1:1 conversation
+ unless $!name {
+ $!name = "Unknown";
+ }
+}
+
+method messages() {
+ my $res = $.get("/messages");
+ my $data = from-json($res.content);
+
+ return $data<chunk>.clone;
+}
+
+method send($room-id, Str $body!, Str :$type? = "m.text") {
+ $Matrix::Client::Common::TXN-ID++;
+ $.put("/send/m.room.message/{$Matrix::Client::Common::TXN-ID}", msgtype => $type, body => $body)
+}
+
+method gist(--> Str) {
+ "Room<name: $.name, id: $.id>"
+}