X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=lib%2Fconversationnoticestream.php;h=c43b5deb24a3bd12d5d26da534a21036bcc17ac3;hb=c751be1c0639dd02432b8f7ddd365a91504e331c;hp=56850fe98248dc03b1ed12704b7adb34ff970c61;hpb=85c4e11f8388a303a07c592d3a1ba0eba6ca698a;p=quix0rs-gnu-social.git diff --git a/lib/conversationnoticestream.php b/lib/conversationnoticestream.php index 56850fe982..c43b5deb24 100644 --- a/lib/conversationnoticestream.php +++ b/lib/conversationnoticestream.php @@ -20,7 +20,7 @@ * You should have received a copy of the GNU Affero General Public License * along with this program. If not, see . * - * @category Cache + * @category NoticeStream * @package StatusNet * @author Evan Prodromou * @copyright 2011 StatusNet, Inc. @@ -46,10 +46,13 @@ if (!defined('STATUSNET')) { */ class ConversationNoticeStream extends ScopingNoticeStream { - function __construct($id, $profile = null) + function __construct($id, $profile = -1) { - parent::__construct(new CachingNoticeStream(new RawConversationNoticeStream($id), - 'notice:conversation_ids:'.$id), + if (is_int($profile) && $profile == -1) { + $profile = Profile::current(); + } + + parent::__construct(new RawConversationNoticeStream($id), $profile); } } @@ -73,32 +76,35 @@ class RawConversationNoticeStream extends NoticeStream $this->id = $id; } - function getNoticeIds($offset, $limit, $since_id, $max_id) + function getNotices($offset, $limit, $sinceId = null, $maxId = null) { - $notice = new Notice(); - - $notice->selectAdd(); // clears it - $notice->selectAdd('id'); - - $notice->conversation = $this->id; - - $notice->orderBy('created DESC, id DESC'); - - if (!is_null($offset)) { - $notice->limit($offset, $limit); - } - - Notice::addWhereSinceId($notice, $since_id); - Notice::addWhereMaxId($notice, $max_id); + $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); + } - $ids = array(); + function getNoticeIds($offset, $limit, $since_id, $max_id) + { + $notice = $this->getNotices($offset, $limit, $since_id, $max_id); + $ids = $notice->fetchAll('id'); + return $ids; + } - if ($notice->find()) { - while ($notice->fetch()) { - $ids[] = $notice->id; - } + 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; } - - return $ids; } -} \ No newline at end of file +}