2015-11-23 13:40:59 +00:00
|
|
|
<?php
|
2020-06-08 16:31:22 +01:00
|
|
|
// This file is part of GNU social - https://www.gnu.org/software/social
|
|
|
|
//
|
|
|
|
// GNU social is free software: you can redistribute it and/or modify
|
|
|
|
// it under the terms of the GNU Affero General Public License as published by
|
|
|
|
// the Free Software Foundation, either version 3 of the License, or
|
|
|
|
// (at your option) any later version.
|
|
|
|
//
|
|
|
|
// GNU social is distributed in the hope that it will be useful,
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
// GNU Affero General Public License for more details.
|
|
|
|
//
|
|
|
|
// You should have received a copy of the GNU Affero General Public License
|
|
|
|
// along with GNU social. If not, see <http://www.gnu.org/licenses/>.
|
2015-11-23 13:40:59 +00:00
|
|
|
|
2020-06-08 16:31:22 +01:00
|
|
|
defined('GNUSOCIAL') || die();
|
2016-03-01 13:51:47 +00:00
|
|
|
|
2015-11-23 13:40:59 +00:00
|
|
|
class RawEventsNoticeStream extends NoticeStream
|
|
|
|
{
|
2020-06-08 16:31:22 +01:00
|
|
|
public function getNoticeIds($offset, $limit, $since_id, $max_id)
|
2015-11-23 13:40:59 +00:00
|
|
|
{
|
|
|
|
$notice = new Notice();
|
|
|
|
|
2020-09-15 14:59:27 +01:00
|
|
|
$notice->selectAdd();
|
|
|
|
$notice->selectAdd('notice.*');
|
2015-11-23 13:40:59 +00:00
|
|
|
|
2020-09-15 14:59:27 +01:00
|
|
|
$notice->joinAdd(['uri', 'happening:uri']);
|
2015-11-23 13:40:59 +00:00
|
|
|
|
2020-09-15 14:59:27 +01:00
|
|
|
$notice->whereAdd('notice.is_local <> ' . Notice::GATEWAY);
|
|
|
|
|
|
|
|
Notice::addWhereSinceId($notice, $since_id, 'notice.id', 'happening.created');
|
|
|
|
Notice::addWhereMaxId($notice, $max_id, 'notice.id', 'happening.created');
|
2015-11-23 13:40:59 +00:00
|
|
|
|
2015-12-31 17:04:12 +00:00
|
|
|
// NOTE: we sort by event time, not by notice time!
|
2020-09-15 14:59:27 +01:00
|
|
|
$notice->orderBy('happening.created DESC');
|
2015-11-23 13:40:59 +00:00
|
|
|
if (!is_null($offset)) {
|
2020-09-15 14:59:27 +01:00
|
|
|
$notice->limit($offset, $limit);
|
2015-11-23 13:40:59 +00:00
|
|
|
}
|
|
|
|
|
2020-09-15 14:59:27 +01:00
|
|
|
$ids = [];
|
|
|
|
if ($notice->find()) {
|
|
|
|
while ($notice->fetch()) {
|
|
|
|
$ids[] = $notice->id;
|
|
|
|
}
|
2015-11-23 13:40:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
$notice->free();
|
|
|
|
unset($notice);
|
|
|
|
return $ids;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
class EventsNoticeStream extends ScopingNoticeStream
|
|
|
|
{
|
2015-12-31 18:23:05 +00:00
|
|
|
// possible values of RSVP in our database
|
|
|
|
protected $rsvp = ['Y', 'N', '?'];
|
|
|
|
protected $target = null;
|
|
|
|
|
2020-06-08 16:31:22 +01:00
|
|
|
public function __construct(Profile $target, Profile $scoped = null, array $rsvp = [])
|
2015-11-23 13:40:59 +00:00
|
|
|
{
|
2015-12-31 18:23:05 +00:00
|
|
|
$stream = new RawEventsNoticeStream();
|
2015-11-23 13:40:59 +00:00
|
|
|
|
|
|
|
if ($target->sameAs($scoped)) {
|
2015-12-31 17:04:12 +00:00
|
|
|
$key = 'happening:ids_for_user_own:'.$target->getID();
|
2015-11-23 13:40:59 +00:00
|
|
|
} else {
|
2015-12-31 17:04:12 +00:00
|
|
|
$key = 'happening:ids_for_user:'.$target->getID();
|
2015-11-23 13:40:59 +00:00
|
|
|
}
|
|
|
|
|
2015-12-31 18:23:05 +00:00
|
|
|
// Match RSVP against our possible values, given in the class variable
|
|
|
|
// and if no RSVPs are given is empty, assume we want all events, even
|
|
|
|
// without RSVPs from this profile.
|
|
|
|
$this->rsvp = array_intersect($this->rsvp, $rsvp);
|
|
|
|
$this->target = $target;
|
|
|
|
|
2015-11-23 13:40:59 +00:00
|
|
|
parent::__construct(new CachingNoticeStream($stream, $key), $scoped);
|
|
|
|
}
|
2015-12-31 18:23:05 +00:00
|
|
|
|
2016-03-02 10:40:43 +00:00
|
|
|
protected function filter(Notice $notice)
|
2015-12-31 18:23:05 +00:00
|
|
|
{
|
|
|
|
if (!parent::filter($notice)) {
|
|
|
|
// if not in our scope, return false
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (empty($this->rsvp)) {
|
|
|
|
// Don't filter on RSVP (for only events with RSVP if no responses
|
|
|
|
// are given (give ['Y', 'N', '?'] for only RSVP'd events!).
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
$rsvp = new RSVP();
|
|
|
|
$rsvp->profile_id = $this->target->getID();
|
|
|
|
$rsvp->event_uri = $notice->getUri();
|
|
|
|
$rsvp->whereAddIn('response', $this->rsvp, $rsvp->columnType('response'));
|
|
|
|
|
|
|
|
// filter out if no RSVP match was found
|
|
|
|
return $rsvp->N > 0;
|
|
|
|
}
|
2015-11-23 13:40:59 +00:00
|
|
|
}
|