2012-09-14 16:37:42 +01: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/>.
|
2012-09-14 16:37:42 +01:00
|
|
|
|
2020-06-08 16:31:22 +01:00
|
|
|
defined('GNUSOCIAL') || die();
|
2016-03-01 13:51:47 +00:00
|
|
|
|
2012-09-14 16:37:42 +01:00
|
|
|
class RawBookmarksNoticeStream extends NoticeStream
|
|
|
|
{
|
|
|
|
protected $user_id;
|
|
|
|
protected $own;
|
|
|
|
|
2020-06-08 16:31:22 +01:00
|
|
|
public function __construct($user_id, $own)
|
2012-09-14 16:37:42 +01:00
|
|
|
{
|
|
|
|
$this->user_id = $user_id;
|
|
|
|
$this->own = $own;
|
|
|
|
}
|
|
|
|
|
2020-06-08 16:31:22 +01:00
|
|
|
public function getNoticeIds($offset, $limit, $since_id, $max_id)
|
2012-09-14 16:37:42 +01:00
|
|
|
{
|
|
|
|
$notice = new Notice();
|
|
|
|
|
2020-09-15 14:59:27 +01:00
|
|
|
$notice->selectAdd();
|
|
|
|
$notice->selectAdd('notice.*');
|
2012-09-14 16:37:42 +01:00
|
|
|
|
2020-09-15 14:59:27 +01:00
|
|
|
$notice->joinAdd(['uri', 'bookmark:uri']);
|
2012-09-14 16:37:42 +01:00
|
|
|
|
2020-09-15 14:59:27 +01:00
|
|
|
$notice->whereAdd(sprintf('bookmark.profile_id = %d', $this->user_id));
|
|
|
|
$notice->whereAdd('notice.is_local <> ' . Notice::GATEWAY);
|
|
|
|
|
|
|
|
Notice::addWhereSinceId($notice, $since_id, 'notice.id', 'bookmark.created');
|
|
|
|
Notice::addWhereMaxId($notice, $max_id, 'notice.id', 'bookmark.created');
|
2012-09-14 16:37:42 +01:00
|
|
|
|
|
|
|
// NOTE: we sort by bookmark time, not by notice time!
|
2020-09-15 14:59:27 +01:00
|
|
|
$notice->orderBy('bookmark.created DESC');
|
2012-09-14 16:37:42 +01:00
|
|
|
if (!is_null($offset)) {
|
2020-09-15 14:59:27 +01:00
|
|
|
$notice->limit($offset, $limit);
|
2012-09-14 16:37:42 +01:00
|
|
|
}
|
|
|
|
|
2020-09-15 14:59:27 +01:00
|
|
|
$ids = [];
|
|
|
|
if ($notice->find()) {
|
|
|
|
while ($notice->fetch()) {
|
|
|
|
$ids[] = $notice->id;
|
|
|
|
}
|
2012-09-14 16:37:42 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
$notice->free();
|
|
|
|
unset($notice);
|
|
|
|
return $ids;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Notice stream for bookmarks
|
|
|
|
*
|
|
|
|
* @category Stream
|
|
|
|
* @package StatusNet
|
|
|
|
* @author Stephane Berube <chimo@chromic.org>
|
|
|
|
* @copyright 2011 StatusNet, Inc.
|
|
|
|
* @license http://www.fsf.org/licensing/licenses/agpl-3.0.html AGPL 3.0
|
|
|
|
* @link http://status.net/
|
|
|
|
*/
|
|
|
|
|
|
|
|
class BookmarksNoticeStream extends ScopingNoticeStream
|
|
|
|
{
|
2020-06-08 16:31:22 +01:00
|
|
|
public function __construct($user_id, $own, Profile $scoped = null)
|
2012-09-14 16:37:42 +01:00
|
|
|
{
|
|
|
|
$stream = new RawBookmarksNoticeStream($user_id, $own);
|
|
|
|
|
|
|
|
if ($own) {
|
|
|
|
$key = 'bookmark:ids_by_user_own:'.$user_id;
|
|
|
|
} else {
|
|
|
|
$key = 'bookmark:ids_by_user:'.$user_id;
|
|
|
|
}
|
|
|
|
|
2016-03-01 13:51:47 +00:00
|
|
|
parent::__construct(new CachingNoticeStream($stream, $key), $scoped);
|
2012-09-14 16:37:42 +01:00
|
|
|
}
|
|
|
|
}
|