conversationnoticestream.php 1.07 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52
<?php

class ConversationNoticeStream extends CachingNoticeStream
{
    function __construct($id)
    {
        parent::__construct(new RawConversationNoticeStream($id),
                            'notice:conversation_ids:'.$id);
    }
}

class RawConversationNoticeStream extends NoticeStream
{
    protected $id;

    function __construct($id)
    {
        $this->id = $id;
    }

    function getNoticeIds($offset=0, $limit=20, $since_id=0, $max_id=0)
    {
        $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);

        $ids = array();

        if ($notice->find()) {
            while ($notice->fetch()) {
                $ids[] = $notice->id;
            }
        }

        $notice->free();
        $notice = NULL;

        return $ids;
    }
}