aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--endpoints.md4
-rw-r--r--lib/Matrix/Client/Room.pm630
2 files changed, 29 insertions, 5 deletions
diff --git a/endpoints.md b/endpoints.md
index a9ee8e6..2d7cb4e 100644
--- a/endpoints.md
+++ b/endpoints.md
@@ -80,10 +80,10 @@ from matrix.org. This will give you an overview about what's implemented in the
## Room membership
-- [ ] POST - /_matrix/client/r0/rooms/{roomId}/join
+- [x] POST - /_matrix/client/r0/rooms/{roomId}/join
- [ ] POST - /_matrix/client/r0/join/{roomIdOrAlias}
- [ ] POST - /_matrix/client/r0/rooms/{roomId}/kick
-- [ ] POST - /_matrix/client/r0/rooms/{roomId}/leave
+- [x] POST - /_matrix/client/r0/rooms/{roomId}/leave
- [x] GET - /_matrix/client/r0/joined_rooms
- [ ] POST - /_matrix/client/r0/rooms/{roomId}/invite
- [ ] POST - /_matrix/client/r0/rooms/{roomId}/unban
diff --git a/lib/Matrix/Client/Room.pm6 b/lib/Matrix/Client/Room.pm6
index fa4501a..4c51be6 100644
--- a/lib/Matrix/Client/Room.pm6
+++ b/lib/Matrix/Client/Room.pm6
@@ -12,11 +12,26 @@ submethod TWEAK {
$!url-prefix = "/rooms/$!id";
}
+method !format-name-from-members {
+ my @members = $.joined-members.kv.map(
+ -> $k, %v {
+ %v<display_name> // $k
+ }
+ );
+
+ $!name = do given @members.elems {
+ when 1 { @members.first }
+ when 2 { @members[0] ~ " and " ~ @members[1] }
+ when * > 2 { @members.first ~ " and {@members.elems - 1} others" }
+ default { "Empty room" }
+ };
+}
+
method !get-name() {
CATCH {
when X::Matrix::Response {
.code ~~ /M_NOT_FOUND/
- ?? ($!name = '')
+ ?? self!format-name-from-members
!! fail
}
default { fail }
@@ -25,8 +40,18 @@ method !get-name() {
$!name = $data<name>;
}
+method joined-members {
+ my %data = from-json($.get("/joined_members").content);
+ %data<joined>
+}
+
method name() {
- unless $!name.so { self!get-name() }
+ if $!name {
+ return $!name;
+ }
+
+ self!get-name;
+
$!name
}
@@ -67,7 +92,6 @@ method send-state(Str:D $event-type, :$state-key = "", *%args --> Str) {
from-json($res.content)<event_id>
}
-
method leave() {
$.post('/leave')
}