]> git.mxchange.org Git - quix0rs-gnu-social.git/commitdiff
update conversations to use newer query format
authorEvan Prodromou <evan@controlyourself.ca>
Thu, 25 Jun 2009 16:43:30 +0000 (09:43 -0700)
committerEvan Prodromou <evan@controlyourself.ca>
Thu, 25 Jun 2009 16:43:30 +0000 (09:43 -0700)
actions/conversation.php
classes/Notice.php

index d3fc5b6a9c31d124056619d6a2a0d5c771f8ae10..654a670f54ca6113ddcc31ad34503c29cfdf1791 100644 (file)
@@ -63,6 +63,7 @@ class ConversationAction extends Action
         if (empty($this->id)) {
             return false;
         }
+        $this->id = $this->id+0;
         $this->page = $this->trimmed('page');
         if (empty($this->page)) {
             $this->page = 1;
@@ -106,18 +107,10 @@ class ConversationAction extends Action
 
     function showContent()
     {
-        // FIXME this needs to be a tree, not a list
-
-        $qry = 'SELECT * FROM notice WHERE conversation = %s ';
-
         $offset = ($this->page-1) * NOTICES_PER_PAGE;
         $limit  = NOTICES_PER_PAGE + 1;
 
-        $txt = sprintf($qry, $this->id);
-
-        $notices = Notice::getStream($txt,
-                                     'notice:conversation:'.$this->id,
-                                     $offset, $limit);
+        $notices = Notice::conversationStream($this->id, $offset, $limit);
 
         $ct = new ConversationTree($notices, $this);
 
@@ -126,7 +119,6 @@ class ConversationAction extends Action
         $this->pagination($this->page > 1, $cnt > NOTICES_PER_PAGE,
                           $this->page, 'conversation', array('id' => $this->id));
     }
-
 }
 
 /**
index 59ffef91af0196ef25a4254df6924d6f12ef8939..44179b2543d16f32b35536003810eb0bbac3c20d 100644 (file)
@@ -346,7 +346,7 @@ class Notice extends Memcached_DataObject
     {
         $cache = common_memcache();
         if ($cache) {
-            $ck = 'notice:conversation:'.$this->conversation;
+            $ck = 'notice:conversation_ids:'.$this->conversation;
             $cache->delete($ck);
             if ($blowLast) {
                 $cache->delete($ck.';last');
@@ -762,6 +762,57 @@ class Notice extends Memcached_DataObject
         return $ids;
     }
 
+    function conversationStream($id, $offset=0, $limit=20, $since_id=0, $max_id=0, $since=null)
+    {
+        $ids = Notice::stream(array('Notice', '_conversationStreamDirect'),
+                              array($id),
+                              'notice:conversation_ids:'.$id,
+                              $offset, $limit, $since_id, $max_id, $since);
+
+        return Notice::getStreamByIds($ids);
+    }
+
+    function _conversationStreamDirect($id, $offset=0, $limit=20, $since_id=0, $max_id=0, $since=null)
+    {
+        $notice = new Notice();
+
+        $notice->selectAdd(); // clears it
+        $notice->selectAdd('id');
+
+        $notice->whereAdd('conversation = '.$id);
+
+        $notice->orderBy('id DESC');
+
+        if (!is_null($offset)) {
+            $notice->limit($offset, $limit);
+        }
+
+        if ($since_id != 0) {
+            $notice->whereAdd('id > ' . $since_id);
+        }
+
+        if ($max_id != 0) {
+            $notice->whereAdd('id <= ' . $max_id);
+        }
+
+        if (!is_null($since)) {
+            $notice->whereAdd('created > \'' . date('Y-m-d H:i:s', $since) . '\'');
+        }
+
+        $ids = array();
+
+        if ($notice->find()) {
+            while ($notice->fetch()) {
+                $ids[] = $notice->id;
+            }
+        }
+
+        $notice->free();
+        $notice = NULL;
+
+        return $ids;
+    }
+
     function addToInboxes()
     {
         $enabled = common_config('inboxes', 'enabled');