]> git.mxchange.org Git - quix0rs-gnu-social.git/blobdiff - lib/repeatedbymenoticestream.php
Break up stream code to use separate notice stream classes
[quix0rs-gnu-social.git] / lib / repeatedbymenoticestream.php
diff --git a/lib/repeatedbymenoticestream.php b/lib/repeatedbymenoticestream.php
new file mode 100644 (file)
index 0000000..2c4c00e
--- /dev/null
@@ -0,0 +1,53 @@
+<?php
+
+class RepeatedByMeNoticeStream extends CachingNoticeStream
+{
+    function __construct($user)
+    {
+        parent::__construct(new RawRepeatedByMeNoticeStream($user),
+                            'user:repeated_by_me:'.$user->id);
+    }
+}
+
+class RawRepeatedByMeNoticeStream extends NoticeStream
+{
+    protected $user;
+
+    function __construct($user)
+    {
+        $this->user = $user;
+    }
+
+    function getNoticeIds($offset, $limit, $since_id, $max_id)
+    {
+        $notice = new Notice();
+
+        $notice->selectAdd(); // clears it
+        $notice->selectAdd('id');
+
+        $notice->profile_id = $this->user->id;
+        $notice->whereAdd('repeat_of IS NOT NULL');
+
+        $notice->orderBy('created DESC, id DESC');
+
+        if (!is_null($offset)) {
+            $notice->limit($offset, $limit);
+        }
+
+        Notice::addWhereSinceId($notice, $since_id);
+        Notice::addWhereMaxId($notice, $max_id);
+
+        $ids = array();
+
+        if ($notice->find()) {
+            while ($notice->fetch()) {
+                $ids[] = $notice->id;
+            }
+        }
+
+        $notice->free();
+        $notice = NULL;
+
+        return $ids;
+    }
+}
\ No newline at end of file