diff options
author | Matias Linares <matiaslina@gmail.com> | 2019-03-18 17:12:04 -0300 |
---|---|---|
committer | Matias Linares <matiaslina@gmail.com> | 2019-03-18 17:12:04 -0300 |
commit | 22e9276301e5c9b1a9a38148a5c9ba4194218cea (patch) | |
tree | e6df3ae76fd65afbe8e8b6ee2a2a9ab301c7cd57 | |
parent | 401f3f80dca1cb16e51ab97b91d672ef895d9a0f (diff) | |
download | perl6-matrix-client-22e9276301e5c9b1a9a38148a5c9ba4194218cea.tar.gz |
Separate fallback name from name.
-rw-r--r-- | lib/Matrix/Client/Room.pm6 | 38 |
1 files changed, 17 insertions, 21 deletions
diff --git a/lib/Matrix/Client/Room.pm6 b/lib/Matrix/Client/Room.pm6 index 4c51be6..e0b14a2 100644 --- a/lib/Matrix/Client/Room.pm6 +++ b/lib/Matrix/Client/Room.pm6 @@ -12,26 +12,11 @@ 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/ - ?? self!format-name-from-members + ?? ($!name = '') !! fail } default { fail } @@ -45,16 +30,27 @@ method joined-members { %data<joined> } -method name() { - if $!name { - return $!name; - } - +method name { self!get-name; $!name } +method fallback-name(--> Str) { + 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 messages() { my $res = $.get("/messages"); my $data = from-json($res.content); |