]> git.mxchange.org Git - quix0rs-gnu-social.git/blobdiff - lib/conversationnoticestream.php
Merge branch 'fixes/private_scope_on_tags' into social-master
[quix0rs-gnu-social.git] / lib / conversationnoticestream.php
index c43b5deb24a3bd12d5d26da534a21036bcc17ac3..9c32159d42aabe90de6fa2284e3c0ac281671fca 100644 (file)
@@ -73,38 +73,37 @@ class RawConversationNoticeStream extends NoticeStream
 
     function __construct($id)
     {
+        parent::__construct();
         $this->id = $id;
     }
 
-    function getNotices($offset, $limit, $sinceId = null, $maxId = null)
+    function getNoticeIds($offset, $limit, $since_id=null, $max_id=null)
     {
-        $all = Memcached_DataObject::listGet('Notice', 'conversation', array($this->id));
-        $notices = $all[$this->id];
-        // Re-order in reverse-chron
-        usort($notices, array('RawConversationNoticeStream', '_reverseChron'));
-        // FIXME: handle since and max
-        $wanted = array_slice($notices, $offset, $limit);
-        return new ArrayWrapper($wanted);
-    }
+        $notice = new Notice();
+        // SELECT
+        $notice->selectAdd();
+        $notice->selectAdd('id');
 
-    function getNoticeIds($offset, $limit, $since_id, $max_id)
-    {
-        $notice = $this->getNotices($offset, $limit, $since_id, $max_id);
-        $ids = $notice->fetchAll('id');
-        return $ids;
-    }
+        // WHERE
+        $notice->conversation = $this->id;
+        if (!empty($since_id)) {
+            $notice->whereAdd(sprintf('notice.id > %d', $since_id));
+        }
+        if (!empty($max_id)) {
+            $notice->whereAdd(sprintf('notice.id <= %d', $max_id));
+        }
+        if (!is_null($offset)) {
+            $notice->limit($offset, $limit);
+        }
 
-    function _reverseChron($a, $b)
-    {
-        $at = strtotime($a->created);
-        $bt = strtotime($b->created);
-        
-        if ($at == $bt) {
-            return 0;
-        } else if ($at > $bt) {
-            return -1;
-        } else {
-            return 1;
+        if (!empty($this->selectVerbs)) {
+            $notice->whereAddIn('verb', $this->selectVerbs, $notice->columnType('verb'));
         }
+
+        // ORDER BY
+        // currently imitates the previously used "_reverseChron" sorting
+        $notice->orderBy('notice.created DESC');
+        $notice->find();
+        return $notice->fetchAll('id');
     }
 }