blob: 5601f33e07b71f1d5d3019e51d43214ba2a787ea (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
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>"
}
|