forked from GNUsocial/gnu-social
Use NoticeStream::filterVerbs for filtering in noticestreams
This commit is contained in:
parent
c23c3a4f53
commit
e2a090c9cc
@ -28,11 +28,7 @@
|
|||||||
* @link http://status.net/
|
* @link http://status.net/
|
||||||
*/
|
*/
|
||||||
|
|
||||||
if (!defined('STATUSNET')) {
|
if (!defined('GNUSOCIAL')) { exit(1); }
|
||||||
// This check helps protect against security problems;
|
|
||||||
// your code file can't be executed directly from the web.
|
|
||||||
exit(1);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Notice stream for a conversation
|
* Notice stream for a conversation
|
||||||
@ -96,9 +92,7 @@ class RawConversationNoticeStream extends NoticeStream
|
|||||||
$notice->limit($offset, $limit);
|
$notice->limit($offset, $limit);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!empty($this->selectVerbs)) {
|
self::filterVerbs($notice, $this->selectVerbs);
|
||||||
$notice->whereAddIn('verb', $this->selectVerbs, $notice->columnType('verb'));
|
|
||||||
}
|
|
||||||
|
|
||||||
// ORDER BY
|
// ORDER BY
|
||||||
// currently imitates the previously used "_reverseChron" sorting
|
// currently imitates the previously used "_reverseChron" sorting
|
||||||
|
@ -30,7 +30,7 @@
|
|||||||
* @link http://status.net/
|
* @link http://status.net/
|
||||||
*/
|
*/
|
||||||
|
|
||||||
if (!defined('GNUSOCIAL') && !defined('STATUSNET')) { exit(1); }
|
if (!defined('GNUSOCIAL')) { exit(1); }
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Stream of notices for a profile's "all" feed
|
* Stream of notices for a profile's "all" feed
|
||||||
@ -77,6 +77,8 @@ class RawInboxNoticeStream extends NoticeStream
|
|||||||
protected $target = null;
|
protected $target = null;
|
||||||
protected $inbox = null;
|
protected $inbox = null;
|
||||||
|
|
||||||
|
protected $selectVerbs = array();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructor
|
* Constructor
|
||||||
*
|
*
|
||||||
@ -84,8 +86,8 @@ class RawInboxNoticeStream extends NoticeStream
|
|||||||
*/
|
*/
|
||||||
function __construct(Profile $target)
|
function __construct(Profile $target)
|
||||||
{
|
{
|
||||||
|
parent::__construct();
|
||||||
$this->target = $target;
|
$this->target = $target;
|
||||||
$this->unselectVerbs = array(ActivityVerb::DELETE);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -119,12 +121,9 @@ class RawInboxNoticeStream extends NoticeStream
|
|||||||
if (!empty($max_id)) {
|
if (!empty($max_id)) {
|
||||||
$notice->whereAdd(sprintf('notice.id <= %d', $max_id));
|
$notice->whereAdd(sprintf('notice.id <= %d', $max_id));
|
||||||
}
|
}
|
||||||
if (!empty($this->selectVerbs)) {
|
|
||||||
$notice->whereAddIn('verb', $this->selectVerbs, $notice->columnType('verb'));
|
self::filterVerbs($notice, $this->selectVerbs);
|
||||||
}
|
|
||||||
if (!empty($this->unselectVerbs)) {
|
|
||||||
$notice->whereAddIn('!verb', $this->unselectVerbs, $notice->columnType('verb'));
|
|
||||||
}
|
|
||||||
$notice->limit($offset, $limit);
|
$notice->limit($offset, $limit);
|
||||||
// notice.id will give us even really old posts, which were
|
// notice.id will give us even really old posts, which were
|
||||||
// recently imported. For example if a remote instance had
|
// recently imported. For example if a remote instance had
|
||||||
|
@ -46,9 +46,7 @@ class RawNetworkPublicNoticeStream extends NoticeStream
|
|||||||
Notice::addWhereSinceId($notice, $since_id);
|
Notice::addWhereSinceId($notice, $since_id);
|
||||||
Notice::addWhereMaxId($notice, $max_id);
|
Notice::addWhereMaxId($notice, $max_id);
|
||||||
|
|
||||||
if (!empty($this->selectVerbs)) {
|
self::filterVerbs($notice, $this->selectVerbs);
|
||||||
$notice->whereAddIn('verb', $this->selectVerbs, $notice->columnType('verb'));
|
|
||||||
}
|
|
||||||
|
|
||||||
$ids = array();
|
$ids = array();
|
||||||
|
|
||||||
|
@ -28,11 +28,7 @@
|
|||||||
* @link http://status.net/
|
* @link http://status.net/
|
||||||
*/
|
*/
|
||||||
|
|
||||||
if (!defined('STATUSNET')) {
|
if (!defined('GNUSOCIAL')) { exit(1); }
|
||||||
// This check helps protect against security problems;
|
|
||||||
// your code file can't be executed directly from the web.
|
|
||||||
exit(1);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class for notice streams
|
* Class for notice streams
|
||||||
@ -46,16 +42,15 @@ if (!defined('STATUSNET')) {
|
|||||||
*/
|
*/
|
||||||
abstract class NoticeStream
|
abstract class NoticeStream
|
||||||
{
|
{
|
||||||
protected $selectVerbs = null; // must be set to array
|
protected $selectVerbs = array(ActivityVerb::POST => true,
|
||||||
protected $unselectVerbs = null; // must be set to array
|
ActivityVerb::DELETE => false);
|
||||||
|
|
||||||
public function __construct()
|
public function __construct()
|
||||||
{
|
{
|
||||||
if ($this->selectVerbs === null) {
|
foreach ($this->selectVerbs as $key=>$val) {
|
||||||
$this->selectVerbs = array(ActivityVerb::POST, ActivityUtils::resolveUri(ActivityVerb::POST, true));
|
// to avoid database inconsistency issues we select both relative and absolute verbs
|
||||||
}
|
$this->selectVerbs[ActivityUtils::resolveUri($key)] = $val;
|
||||||
if ($this->unselectVerbs === null) {
|
$this->selectVerbs[ActivityUtils::resolveUri($key, true)] = $val;
|
||||||
$this->unselectVerbs = array(ActivityVerb::DELETE);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -74,4 +69,21 @@ abstract class NoticeStream
|
|||||||
{
|
{
|
||||||
return Notice::multiGet('id', $ids);
|
return Notice::multiGet('id', $ids);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static function filterVerbs(Notice $notice, array $selectVerbs)
|
||||||
|
{
|
||||||
|
$filter = array_keys(array_filter($selectVerbs));
|
||||||
|
if (!empty($filter)) {
|
||||||
|
// include verbs in selectVerbs with values that equate to true
|
||||||
|
$notice->whereAddIn('verb', $filter, $notice->columnType('verb'));
|
||||||
|
}
|
||||||
|
|
||||||
|
$filter = array_keys(array_filter($selectVerbs, function ($v) { return !$v; }));
|
||||||
|
if (!empty($filter)) {
|
||||||
|
// exclude verbs in selectVerbs with values that equate to false
|
||||||
|
$notice->whereAddIn('!verb', $filter, $notice->columnType('verb'));
|
||||||
|
}
|
||||||
|
|
||||||
|
unset($filter);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -28,11 +28,7 @@
|
|||||||
* @link http://status.net/
|
* @link http://status.net/
|
||||||
*/
|
*/
|
||||||
|
|
||||||
if (!defined('STATUSNET')) {
|
if (!defined('GNUSOCIAL')) { exit(1); }
|
||||||
// This check helps protect against security problems;
|
|
||||||
// your code file can't be executed directly from the web.
|
|
||||||
exit(1);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Stream of notices by a profile
|
* Stream of notices by a profile
|
||||||
@ -134,12 +130,7 @@ class RawProfileNoticeStream extends NoticeStream
|
|||||||
Notice::addWhereSinceId($notice, $since_id);
|
Notice::addWhereSinceId($notice, $since_id);
|
||||||
Notice::addWhereMaxId($notice, $max_id);
|
Notice::addWhereMaxId($notice, $max_id);
|
||||||
|
|
||||||
if (!empty($this->selectVerbs)) {
|
self::filterVerbs($notice, $this->selectVerbs);
|
||||||
$notice->whereAddIn('verb', $this->selectVerbs, $notice->columnType('verb'));
|
|
||||||
}
|
|
||||||
if (!empty($this->unselectVerbs)) {
|
|
||||||
$notice->whereAddIn('!verb', $this->unselectVerbs, $notice->columnType('verb'));
|
|
||||||
}
|
|
||||||
|
|
||||||
$notice->orderBy('created DESC, id DESC');
|
$notice->orderBy('created DESC, id DESC');
|
||||||
|
|
||||||
|
@ -28,11 +28,7 @@
|
|||||||
* @link http://status.net/
|
* @link http://status.net/
|
||||||
*/
|
*/
|
||||||
|
|
||||||
if (!defined('STATUSNET')) {
|
if (!defined('GNUSOCIAL')) { exit(1); }
|
||||||
// This check helps protect against security problems;
|
|
||||||
// your code file can't be executed directly from the web.
|
|
||||||
exit(1);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Public stream
|
* Public stream
|
||||||
@ -87,9 +83,7 @@ class RawPublicNoticeStream extends NoticeStream
|
|||||||
Notice::addWhereSinceId($notice, $since_id);
|
Notice::addWhereSinceId($notice, $since_id);
|
||||||
Notice::addWhereMaxId($notice, $max_id);
|
Notice::addWhereMaxId($notice, $max_id);
|
||||||
|
|
||||||
if (!empty($this->selectVerbs)) {
|
self::filterVerbs($notice, $this->selectVerbs);
|
||||||
$notice->whereAddIn('verb', $this->selectVerbs, $notice->columnType('verb'));
|
|
||||||
}
|
|
||||||
|
|
||||||
$ids = array();
|
$ids = array();
|
||||||
|
|
||||||
|
@ -28,11 +28,7 @@
|
|||||||
* @link http://status.net/
|
* @link http://status.net/
|
||||||
*/
|
*/
|
||||||
|
|
||||||
if (!defined('STATUSNET')) {
|
if (!defined('GNUSOCIAL')) { exit(1); }
|
||||||
// This check helps protect against security problems;
|
|
||||||
// your code file can't be executed directly from the web.
|
|
||||||
exit(1);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Stream of mentions of me
|
* Stream of mentions of me
|
||||||
@ -92,8 +88,20 @@ class RawReplyNoticeStream extends NoticeStream
|
|||||||
Notice::addWhereMaxId($reply, $max_id, 'notice_id', 'reply.modified');
|
Notice::addWhereMaxId($reply, $max_id, 'notice_id', 'reply.modified');
|
||||||
|
|
||||||
if (!empty($this->selectVerbs)) {
|
if (!empty($this->selectVerbs)) {
|
||||||
|
// this is a little special since we have to join in Notice
|
||||||
$reply->joinAdd(array('notice_id', 'notice:id'));
|
$reply->joinAdd(array('notice_id', 'notice:id'));
|
||||||
$reply->whereAddIn('notice.verb', $this->selectVerbs, 'string');
|
|
||||||
|
$filter = array_keys(array_filter($this->selectVerbs));
|
||||||
|
if (!empty($filter)) {
|
||||||
|
// include verbs in selectVerbs with values that equate to true
|
||||||
|
$reply->whereAddIn('notice.verb', $filter, 'string');
|
||||||
|
}
|
||||||
|
|
||||||
|
$filter = array_keys(array_filter($this->selectVerbs, function ($v) { return !$v; }));
|
||||||
|
if (!empty($filter)) {
|
||||||
|
// exclude verbs in selectVerbs with values that equate to false
|
||||||
|
$reply->whereAddIn('!notice.verb', $filter, 'string');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$reply->orderBy('reply.modified DESC, reply.notice_id DESC');
|
$reply->orderBy('reply.modified DESC, reply.notice_id DESC');
|
||||||
|
@ -28,11 +28,7 @@
|
|||||||
* @link http://status.net/
|
* @link http://status.net/
|
||||||
*/
|
*/
|
||||||
|
|
||||||
if (!defined('STATUSNET')) {
|
if (!defined('GNUSOCIAL')) { exit(1); }
|
||||||
// This check helps protect against security problems;
|
|
||||||
// your code file can't be executed directly from the web.
|
|
||||||
exit(1);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Stream of notices with a given tag
|
* Stream of notices with a given tag
|
||||||
@ -90,10 +86,19 @@ class RawTagNoticeStream extends NoticeStream
|
|||||||
Notice::addWhereMaxId($nt, $max_id, 'notice_id');
|
Notice::addWhereMaxId($nt, $max_id, 'notice_id');
|
||||||
|
|
||||||
if (!empty($this->selectVerbs)) {
|
if (!empty($this->selectVerbs)) {
|
||||||
$notice->whereAddIn('verb', $this->selectVerbs, $notice->columnType('verb'));
|
$nt->joinAdd(array('notice_id', 'notice:id'));
|
||||||
}
|
|
||||||
if (!empty($this->unselectVerbs)) {
|
$filter = array_keys(array_filter($this->selectVerbs));
|
||||||
$notice->whereAddIn('!verb', $this->unselectVerbs, $notice->columnType('verb'));
|
if (!empty($filter)) {
|
||||||
|
// include verbs in selectVerbs with values that equate to true
|
||||||
|
$nt->whereAddIn('notice.verb', $filter, 'string');
|
||||||
|
}
|
||||||
|
|
||||||
|
$filter = array_keys(array_filter($this->selectVerbs, function ($v) { return !$v; }));
|
||||||
|
if (!empty($filter)) {
|
||||||
|
// exclude verbs in selectVerbs with values that equate to false
|
||||||
|
$nt->whereAddIn('!notice.verb', $filter, 'string');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$nt->orderBy('created DESC, notice_id DESC');
|
$nt->orderBy('created DESC, notice_id DESC');
|
||||||
|
@ -28,11 +28,7 @@
|
|||||||
* @link http://status.net/
|
* @link http://status.net/
|
||||||
*/
|
*/
|
||||||
|
|
||||||
if (!defined('STATUSNET')) {
|
if (!defined('GNUSOCIAL')) { exit(1); }
|
||||||
// This check helps protect against security problems;
|
|
||||||
// your code file can't be executed directly from the web.
|
|
||||||
exit(1);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Notice stream for favorites
|
* Notice stream for favorites
|
||||||
@ -77,14 +73,14 @@ class RawFaveNoticeStream extends NoticeStream
|
|||||||
protected $user_id;
|
protected $user_id;
|
||||||
protected $own;
|
protected $own;
|
||||||
|
|
||||||
|
protected $selectVerbs = array();
|
||||||
|
|
||||||
function __construct($user_id, $own)
|
function __construct($user_id, $own)
|
||||||
{
|
{
|
||||||
parent::__construct();
|
parent::__construct();
|
||||||
|
|
||||||
$this->user_id = $user_id;
|
$this->user_id = $user_id;
|
||||||
$this->own = $own;
|
$this->own = $own;
|
||||||
|
|
||||||
$this->selectVerbs = array();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Loading…
Reference in New Issue
Block a user