From 3d103be8d370fc5a51c49b57adf008b4f705699a Mon Sep 17 00:00:00 2001 From: Matias Linares Date: Tue, 8 May 2018 11:02:40 -0300 Subject: Add invites to sync response --- lib/Matrix/Response.pm6 | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) (limited to 'lib') diff --git a/lib/Matrix/Response.pm6 b/lib/Matrix/Response.pm6 index 270cbd0..48fd66a 100644 --- a/lib/Matrix/Response.pm6 +++ b/lib/Matrix/Response.pm6 @@ -43,6 +43,15 @@ class Matrix::Response::RoomInfo { } } +class Matrix::Response::InviteInfo { + has $.room-id is required; + has Matrix::Response::Event @.events; + + method gist(--> Str) { + "" + } +} + sub gather-events($from) { gather for $from.List -> $ev { take Matrix::Response::StateEvent.new(|$ev); @@ -53,6 +62,7 @@ class Matrix::Response::Sync { has Str $.next-batch; has Matrix::Response::Event @.presence; has Matrix::Response::RoomInfo @.joined-rooms; + has Matrix::Response::InviteInfo @.invited-rooms; multi method new(Str $json) { return self.new(from-json($json)); @@ -62,6 +72,7 @@ class Matrix::Response::Sync { my $next-batch = $json; my Matrix::Response::Event @presence; my Matrix::Response::RoomInfo @joined-rooms; + my Matrix::Response::InviteInfo @invited-rooms; for $json.List -> $ev { @presence.push(Matrix::Response::Event.new(|$ev)); @@ -81,6 +92,14 @@ class Matrix::Response::Sync { )); } - return self.bless(:$next-batch, :@presence, :@joined-rooms); + for $json.kv -> $room-id, $data { + my @events = gather-events($data); + @invited-rooms.push(Matrix::Response::InviteInfo.new( + :$room-id, :@events + )); + } + + return self.bless(:$next-batch, :@presence, + :@joined-rooms, :@invited-rooms); } } -- cgit v1.2.3-54-g00ecf