gnu-social/plugins/Event/lib/eventsnoticestream.php

64 lines
1.6 KiB
PHP
Raw Normal View History

<?php
class RawEventsNoticeStream extends NoticeStream
{
protected $target;
protected $own;
function __construct(Profile $target)
{
$this->target = $target;
}
function getNoticeIds($offset, $limit, $since_id, $max_id)
{
$notice = new Notice();
$qry = null;
$qry = 'SELECT notice.* FROM notice ';
$qry .= 'INNER JOIN happening ON happening.uri = notice.uri ';
$qry .= 'WHERE happening.profile_id = ' . $this->target->getID() . ' ';
$qry .= 'AND notice.is_local != ' . Notice::GATEWAY . ' ';
if ($since_id != 0) {
$qry .= 'AND notice.id > ' . $since_id . ' ';
}
if ($max_id != 0) {
$qry .= 'AND notice.id <= ' . $max_id . ' ';
}
2016-01-01 02:04:12 +09:00
// NOTE: we sort by event time, not by notice time!
$qry .= 'ORDER BY created DESC ';
if (!is_null($offset)) {
$qry .= "LIMIT $limit OFFSET $offset";
}
$notice->query($qry);
$ids = array();
while ($notice->fetch()) {
$ids[] = $notice->id;
}
$notice->free();
unset($notice);
return $ids;
}
}
class EventsNoticeStream extends ScopingNoticeStream
{
function __construct(Profile $target, Profile $scoped=null)
{
$stream = new RawEventsNoticeStream($target);
if ($target->sameAs($scoped)) {
2016-01-01 02:04:12 +09:00
$key = 'happening:ids_for_user_own:'.$target->getID();
} else {
2016-01-01 02:04:12 +09:00
$key = 'happening:ids_for_user:'.$target->getID();
}
parent::__construct(new CachingNoticeStream($stream, $key), $scoped);
}
}