diff options
author | Matias Linares <matiaslina@gmail.com> | 2019-03-18 16:11:30 -0300 |
---|---|---|
committer | Matias Linares <matiaslina@gmail.com> | 2019-03-18 16:11:30 -0300 |
commit | aff2a2eeb6fba35636a863fdf48a3ad08c335877 (patch) | |
tree | 66b44334cb97421fb572b9931beecd365db19056 /lib/Matrix | |
parent | 3d6d5a4828e602837886358918e324f34e37b962 (diff) | |
download | perl6-matrix-client-aff2a2eeb6fba35636a863fdf48a3ad08c335877.tar.gz |
Better room name
Diffstat (limited to 'lib/Matrix')
-rw-r--r-- | lib/Matrix/Client/Room.pm6 | 30 |
1 files changed, 27 insertions, 3 deletions
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') } |