aboutsummaryrefslogtreecommitdiff
path: root/lib/Matrix/Client/Room.pm6
diff options
context:
space:
mode:
authorMatias Linares <matiaslina@gmail.com>2020-12-27 12:19:17 -0300
committerMatias Linares <matiaslina@gmail.com>2020-12-27 12:19:17 -0300
commit6883348dafc0e6c58a5478074221f8cca7859716 (patch)
tree8dd8db05b0f31f2bf3aef81426758b2b658e9f7f /lib/Matrix/Client/Room.pm6
parente1abad7a57fd34ffb55c1d57d0b89ee91e55296b (diff)
parentf1d1a526cc4950578e8769fe3c94147777466531 (diff)
downloadperl6-matrix-client-6883348dafc0e6c58a5478074221f8cca7859716.tar.gz
Merge branch 'master' into documentation
Diffstat (limited to 'lib/Matrix/Client/Room.pm6')
-rw-r--r--lib/Matrix/Client/Room.pm6138
1 files changed, 112 insertions, 26 deletions
diff --git a/lib/Matrix/Client/Room.pm6 b/lib/Matrix/Client/Room.pm6
index ca97d2f..3d6ecaa 100644
--- a/lib/Matrix/Client/Room.pm6
+++ b/lib/Matrix/Client/Room.pm6
@@ -25,15 +25,8 @@ method !get-name() {
$!name = $data<name>;
}
-#| GET - /_matrix/client/r0/rooms/{roomId}/joined_members
-method joined-members {
- my %data = from-json($.get("/joined_members").content);
- %data<joined>
-}
-
-method name {
+method name(--> Str) {
self!get-name;
-
$!name
}
@@ -52,23 +45,20 @@ method fallback-name(--> Str) {
};
}
-#| GET - /_matrix/client/r0/rooms/{roomId}/messages
-method messages() {
- my $res = $.get("/messages");
- my $data = from-json($res.content);
-
- return $data<chunk>.clone;
+#| GET - /_matrix/client/r0/rooms/{roomId}/aliases
+method aliases(--> List) {
+ my %data = from-json($.get('/aliases').content);
+ %data<aliases>.List
}
-#| PUT - /_matrix/client/r0/rooms/{roomId}/send/{eventType}/{txnId}
-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
- );
+# Events
- from-json($res.content)<event_id>
+## Getting events for a room
+
+#| GET - /_matrix/client/r0/rooms/{roomId}/event/{eventId}
+method event(Str $event-id --> Matrix::Response::RoomEvent) {
+ my %data = from-json($.get("/event/$event-id").content);
+ Matrix::Response::RoomEvent.new(|%data)
}
#| GET - /_matrix/client/r0/rooms/{roomId}/state
@@ -80,9 +70,67 @@ multi method state(--> Seq) {
}
}
-#| GET - /_matrix/client/r0/rooms/{roomId}/state/{eventType}
-multi method state(Str $event-type) {
- from-json($.get("/state/$event-type").content)
+#| GET - /_matrix/client/r0/rooms/{roomId}/state/{eventType}/{stateKey}
+multi method state(Str $event-type, Str $state-key = "") {
+ from-json($.get("/state/$event-type/$state-key").content)
+}
+
+#| GET - /_matrix/client/r0/rooms/{roomId}/joined_members
+method joined-members {
+ my %data = from-json($.get("/joined_members").content);
+ %data<joined>
+}
+
+#| GET - /_matrix/client/r0/rooms/{roomId}/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);
+
+
+ my @messages = $data<chunk>.map(-> $ev {
+ Matrix::Response::RoomEvent.new(|$ev)
+ });
+
+ Matrix::Response::Messages.new(
+ start => $data<start>,
+ end => $data<end>,
+ messages => @messages
+ )
+}
+
+#| GET - /_matrix/client/r0/rooms/{roomId}/members
+method members(:$at, Str :$membership, Str :$not-membership --> Seq) {
+ my %query;
+
+ %query<at> = $at with $at;
+ %query<membership> = $membership with $membership;
+ %query<not_membership> = $not-membership with $not-membership;
+
+ my %data = from-json($.get('/members', |%query).content);
+
+ gather for %data<chunk>.List -> $ev {
+ take Matrix::Response::MemberEvent.new(|$ev)
+ }
+}
+
+## Sending events to a room
+
+#| PUT - /_matrix/client/r0/rooms/{roomId}/send/{eventType}/{txnId}
+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)<event_id>
}
#| PUT - /_matrix/client/r0/rooms/{roomId}/state/{eventType}/{stateKey}
@@ -94,11 +142,49 @@ method send-state(Str:D $event-type, :$state-key = "", *%args --> Str) {
from-json($res.content)<event_id>
}
+# Room membership!
+
+## Joining rooms
+
+#| POST - /_matrix/client/r0/rooms/{roomId}/invite
+method invite(Str $user-id) {
+ $.post('/invite', :$user-id)
+}
+
+#| POST - /_matrix/client/r0/rooms/{roomId}/join
+method join {
+ $.post('/join')
+}
+
+## Leaving rooms
+
#| POST - /_matrix/client/r0/rooms/{roomId}/leave
-method leave() {
+method leave {
$.post('/leave')
}
+#| POST - /_matrix/client/r0/rooms/{roomId}/forget
+method forget {
+ $.post('/forget')
+}
+
+#| POST - /_matrix/client/r0/rooms/{roomId}/kick
+method kick(Str $user-id, Str $reason = "") {
+ $.post('/kick', :$user-id, :$reason)
+}
+
+## Banning users
+
+#| POST - /_matrix/client/r0/rooms/{roomId}/ban
+method ban(Str $user-id, $reason = "") {
+ $.post('/ban', :$user-id, :$reason)
+}
+
+#| POST - /_matrix/client/r0/rooms/{roomId}/unban
+method unban(Str $user-id) {
+ $.post('/unban', :$user-id)
+}
+
method Str(--> Str) {
"Room<id: {self.id}>"
}