summaryrefslogtreecommitdiff
path: root/lib/Matrix
diff options
context:
space:
mode:
authorMatias Linares <matiaslina@openmailbox.org>2018-06-03 12:39:43 -0300
committerMatias Linares <matiaslina@openmailbox.org>2018-06-03 12:39:43 -0300
commit64a52325639053bf8db926eb3b9495e201623d42 (patch)
treeaa1c3c1f4af4dec63aadf69995b82e3c216fddb8 /lib/Matrix
parent17a3ee676f0db46ad3d4c596832e2aeec2cb2411 (diff)
downloadperl6-matrix-client-64a52325639053bf8db926eb3b9495e201623d42.tar.gz
Add new run method.
Diffstat (limited to 'lib/Matrix')
-rw-r--r--lib/Matrix/Client.pm628
1 files changed, 28 insertions, 0 deletions
diff --git a/lib/Matrix/Client.pm6 b/lib/Matrix/Client.pm6
index 5e4914a..fe3e259 100644
--- a/lib/Matrix/Client.pm6
+++ b/lib/Matrix/Client.pm6
@@ -198,3 +198,31 @@ method upload(IO::Path $path, Str $filename?) {
my $data = from-json($res.content);
$data<content_uri> // "";
}
+
+# Misc
+
+method run(Int :$sleep = 10, :$sync-filter? --> Supply) {
+ my $s = Supplier.new;
+ my $supply = $s.Supply;
+ my $since = "";
+
+ start {
+ loop {
+ my $sync = $.sync(:$since, :$sync-filter);
+ $since = $sync.next-batch;
+ say $since;
+
+ for $sync.invited-rooms -> $info {
+ $s.emit($info);
+ }
+
+ for $sync.joined-rooms -> $room {
+ for $room.timeline.events -> $event {
+ $s.emit($event)
+ }
+ }
+ sleep $sleep;
+ }
+ }
+ $supply
+}