Consistent behaviour for ScopingNoticeStream $scoped

We don't guess the current profile anymore if the value of the profile === -1

Also sets $this->scoped for all ScopingNoticeStream inheritors, which just
like in an Action can be null if we're not scoped in any way (logged in).
This commit is contained in:
Mikael Nordfeldth 2016-03-01 14:51:47 +01:00
parent 7862b853bf
commit 63c087a255
38 changed files with 151 additions and 239 deletions

View File

@ -46,7 +46,7 @@ class AllrssAction extends TargetedRss10Action
{ {
protected function getNotices() protected function getNotices()
{ {
$stream = new InboxNoticeStream($this->target); $stream = new InboxNoticeStream($this->target, $this->scoped);
return $stream->getNotices(0, $this->limit)->fetchAll(); return $stream->getNotices(0, $this->limit)->fetchAll();
} }

View File

@ -65,8 +65,7 @@ class NoticesearchAction extends SearchAction
if (!empty($this->q)) { if (!empty($this->q)) {
$profile = Profile::current(); $stream = new SearchNoticeStream($this->q, $this->scoped);
$stream = new SearchNoticeStream($this->q, $profile);
$page = $this->trimmed('page'); $page = $this->trimmed('page');
if (empty($page)) { if (empty($page)) {

View File

@ -28,12 +28,7 @@
* @link http://status.net/ * @link http://status.net/
*/ */
if (!defined('STATUSNET') && !defined('LACONICA')) { if (!defined('GNUSOCIAL')) { exit(1); }
exit(1);
}
require_once INSTALLDIR.'/lib/noticelist.php';
require_once INSTALLDIR.'/lib/feedlist.php';
/** /**
* Group main page * Group main page
@ -48,7 +43,6 @@ class ShowgroupAction extends GroupAction
{ {
/** page we're viewing. */ /** page we're viewing. */
var $page = null; var $page = null;
var $userProfile = null;
var $notice = null; var $notice = null;
/** /**
@ -97,14 +91,10 @@ class ShowgroupAction extends GroupAction
$this->page = ($this->arg('page')) ? ($this->arg('page')+0) : 1; $this->page = ($this->arg('page')) ? ($this->arg('page')+0) : 1;
$this->userProfile = Profile::current(); if ($this->scoped instanceof Profile && $this->scoped->isLocal() && $this->scoped->getUser()->streamModeOnly()) {
$stream = new GroupNoticeStream($this->group, $this->scoped);
$user = common_current_user();
if (!empty($user) && $user->streamModeOnly()) {
$stream = new GroupNoticeStream($this->group, $this->userProfile);
} else { } else {
$stream = new ThreadingGroupNoticeStream($this->group, $this->userProfile); $stream = new ThreadingGroupNoticeStream($this->group, $this->scoped);
} }
$this->notice = $stream->getNotices(($this->page-1)*NOTICES_PER_PAGE, $this->notice = $stream->getNotices(($this->page-1)*NOTICES_PER_PAGE,
@ -146,12 +136,10 @@ class ShowgroupAction extends GroupAction
*/ */
function showGroupNotices() function showGroupNotices()
{ {
$user = common_current_user(); if ($this->scoped instanceof Profile && $this->scoped->isLocal() && $this->scoped->getUser()->streamModeOnly()) {
if (!empty($user) && $user->streamModeOnly()) {
$nl = new PrimaryNoticeList($this->notice, $this, array('show_n'=>NOTICES_PER_PAGE)); $nl = new PrimaryNoticeList($this->notice, $this, array('show_n'=>NOTICES_PER_PAGE));
} else { } else {
$nl = new ThreadedNoticeList($this->notice, $this, $this->userProfile); $nl = new ThreadedNoticeList($this->notice, $this, $this->scoped);
} }
$cnt = $nl->show(); $cnt = $nl->show();

View File

@ -579,7 +579,9 @@ class File extends Managed_DataObject
function stream($offset=0, $limit=NOTICES_PER_PAGE, $since_id=0, $max_id=0) function stream($offset=0, $limit=NOTICES_PER_PAGE, $since_id=0, $max_id=0)
{ {
$stream = new FileNoticeStream($this); // FIXME: Try to get the Profile::current() here in some other way to avoid mixing
// the current session user with possibly background/queue processing.
$stream = new FileNoticeStream($this, Profile::current());
return $stream->getNotices($offset, $limit, $since_id, $max_id); return $stream->getNotices($offset, $limit, $since_id, $max_id);
} }

View File

@ -1280,9 +1280,9 @@ class Notice extends Managed_DataObject
return $stream->getNotices($offset, $limit, $since_id, $max_id); return $stream->getNotices($offset, $limit, $since_id, $max_id);
} }
static function conversationStream($id, $offset=0, $limit=20, $since_id=null, $max_id=null) static function conversationStream($id, $offset=0, $limit=20, $since_id=null, $max_id=null, Profile $scoped=null)
{ {
$stream = new ConversationNoticeStream($id); $stream = new ConversationNoticeStream($id, $scoped);
return $stream->getNotices($offset, $limit, $since_id, $max_id); return $stream->getNotices($offset, $limit, $since_id, $max_id);
} }
@ -1300,8 +1300,9 @@ class Notice extends Managed_DataObject
return false; return false;
} }
$stream = new ConversationNoticeStream($this->conversation); //FIXME: Get the Profile::current() stuff some other way
$notice = $stream->getNotices(/*offset*/ 1, /*limit*/ 1); // to avoid confusion between queue processing and session.
$notice = self::conversationStream($this->conversation, 1, 1, null, null, Profile::current());
// if our "offset 1, limit 1" query got a result, return true else false // if our "offset 1, limit 1" query got a result, return true else false
return $notice->N > 0; return $notice->N > 0;

View File

@ -55,7 +55,9 @@ class Notice_tag extends Managed_DataObject
static function getStream($tag, $offset=0, $limit=20, $sinceId=0, $maxId=0) static function getStream($tag, $offset=0, $limit=20, $sinceId=0, $maxId=0)
{ {
$stream = new TagNoticeStream($tag); // FIXME: Get the Profile::current value some other way
// to avoid confusino between queue processing and session.
$stream = new TagNoticeStream($tag, Profile::current());
return $stream; return $stream;
} }

View File

@ -266,7 +266,9 @@ class Profile extends Managed_DataObject
function getTaggedNotices($tag, $offset=0, $limit=NOTICES_PER_PAGE, $since_id=0, $max_id=0) function getTaggedNotices($tag, $offset=0, $limit=NOTICES_PER_PAGE, $since_id=0, $max_id=0)
{ {
$stream = new TaggedProfileNoticeStream($this, $tag); //FIXME: Get Profile::current() some other way to avoid possible
// confusion between current session profile and background processing.
$stream = new TaggedProfileNoticeStream($this, $tag, Profile::current());
return $stream->getNotices($offset, $limit, $since_id, $max_id); return $stream->getNotices($offset, $limit, $since_id, $max_id);
} }

View File

@ -171,7 +171,9 @@ class Profile_list extends Managed_DataObject
function getNotices($offset, $limit, $since_id=null, $max_id=null) function getNotices($offset, $limit, $since_id=null, $max_id=null)
{ {
$stream = new PeopletagNoticeStream($this); // FIXME: Use something else than Profile::current() to avoid
// possible confusion between session user and queue processing.
$stream = new PeopletagNoticeStream($this, Profile::current());
return $stream->getNotices($offset, $limit, $since_id, $max_id); return $stream->getNotices($offset, $limit, $since_id, $max_id);
} }

View File

@ -57,7 +57,9 @@ class Reply extends Managed_DataObject
static function stream($user_id, $offset=0, $limit=NOTICES_PER_PAGE, $since_id=0, $max_id=0) static function stream($user_id, $offset=0, $limit=NOTICES_PER_PAGE, $since_id=0, $max_id=0)
{ {
$stream = new ReplyNoticeStream($user_id); // FIXME: Use some other method to get Profile::current() in order
// to avoid confusion between background processing and session user.
$stream = new ReplyNoticeStream($user_id, Profile::current());
return $stream->getNotices($offset, $limit, $since_id, $max_id); return $stream->getNotices($offset, $limit, $since_id, $max_id);
} }
} }

View File

@ -701,15 +701,18 @@ class User extends Managed_DataObject
function repeatedByMe($offset=0, $limit=20, $since_id=null, $max_id=null) function repeatedByMe($offset=0, $limit=20, $since_id=null, $max_id=null)
{ {
$stream = new RepeatedByMeNoticeStream($this); // FIXME: Use another way to get Profile::current() since we
// want to avoid confusion between session user and queue processing.
$stream = new RepeatedByMeNoticeStream($this->getProfile(), Profile::current());
return $stream->getNotices($offset, $limit, $since_id, $max_id); return $stream->getNotices($offset, $limit, $since_id, $max_id);
} }
function repeatsOfMe($offset=0, $limit=20, $since_id=null, $max_id=null) function repeatsOfMe($offset=0, $limit=20, $since_id=null, $max_id=null)
{ {
$stream = new RepeatsOfMeNoticeStream($this); // FIXME: Use another way to get Profile::current() since we
// want to avoid confusion between session user and queue processing.
$stream = new RepeatsOfMeNoticeStream($this->getProfile(), Profile::current());
return $stream->getNotices($offset, $limit, $since_id, $max_id); return $stream->getNotices($offset, $limit, $since_id, $max_id);
} }

View File

@ -153,7 +153,9 @@ class User_group extends Managed_DataObject
function getNotices($offset, $limit, $since_id=null, $max_id=null) function getNotices($offset, $limit, $since_id=null, $max_id=null)
{ {
$stream = new GroupNoticeStream($this); // FIXME: Get the Profile::current() some other way, to avoid
// possible confusion between current session and queue process.
$stream = new GroupNoticeStream($this, Profile::current());
return $stream->getNotices($offset, $limit, $since_id, $max_id); return $stream->getNotices($offset, $limit, $since_id, $max_id);
} }

View File

@ -42,14 +42,10 @@ if (!defined('GNUSOCIAL')) { exit(1); }
*/ */
class ConversationNoticeStream extends ScopingNoticeStream class ConversationNoticeStream extends ScopingNoticeStream
{ {
function __construct($id, $profile = -1) function __construct($id, Profile $scoped=null)
{ {
if (is_int($profile) && $profile == -1) {
$profile = Profile::current();
}
parent::__construct(new RawConversationNoticeStream($id), parent::__construct(new RawConversationNoticeStream($id),
$profile); $scoped);
} }
} }

View File

@ -28,22 +28,15 @@
* @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 FileNoticeStream extends ScopingNoticeStream class FileNoticeStream extends ScopingNoticeStream
{ {
function __construct($file, $profile = -1) function __construct($file, Profile $scoped=null)
{ {
if (is_int($profile) && $profile == -1) {
$profile = Profile::current();
}
parent::__construct(new CachingNoticeStream(new RawFileNoticeStream($file), parent::__construct(new CachingNoticeStream(new RawFileNoticeStream($file),
'file:notice-ids:'.$file->id), 'file:notice-ids:'.$file->id),
$profile); $scoped);
} }
} }

View File

@ -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 for a group * Stream of notices for a group
@ -47,19 +43,14 @@ if (!defined('STATUSNET')) {
class GroupNoticeStream extends ScopingNoticeStream class GroupNoticeStream extends ScopingNoticeStream
{ {
var $group; var $group;
var $userProfile;
function __construct($group, $profile = -1) function __construct($group, Profile $scoped=null)
{ {
if (is_int($profile) && $profile == -1) {
$profile = Profile::current();
}
$this->group = $group; $this->group = $group;
$this->userProfile = $profile;
parent::__construct(new CachingNoticeStream(new RawGroupNoticeStream($group), parent::__construct(new CachingNoticeStream(new RawGroupNoticeStream($group),
'user_group:notice_ids:' . $group->id), 'user_group:notice_ids:' . $group->id),
$profile); $scoped);
} }
function getNoticeIds($offset, $limit, $since_id, $max_id) function getNoticeIds($offset, $limit, $since_id, $max_id)
@ -83,7 +74,7 @@ class GroupNoticeStream extends ScopingNoticeStream
function impossibleStream() function impossibleStream()
{ {
if ($this->group->force_scope && if ($this->group->force_scope &&
(empty($this->userProfile) || !$this->userProfile->isMember($this->group))) { (!$this->scoped instanceof Profile || $this->scoped->isMember($this->group))) {
return true; return true;
} }

View File

@ -54,9 +54,6 @@ class InboxNoticeStream extends ScopingNoticeStream
*/ */
function __construct(Profile $target, Profile $scoped=null) function __construct(Profile $target, Profile $scoped=null)
{ {
if ($scoped === null) {
$scoped = Profile::current();
}
// FIXME: we don't use CachingNoticeStream - but maybe we should? // FIXME: we don't use CachingNoticeStream - but maybe we should?
parent::__construct(new CachingNoticeStream(new RawInboxNoticeStream($target), 'profileall'), $scoped); parent::__construct(new CachingNoticeStream(new RawInboxNoticeStream($target), 'profileall'), $scoped);
} }

View File

@ -27,9 +27,7 @@
* @link http://status.net/ * @link http://status.net/
*/ */
if (!defined('STATUSNET') && !defined('LACONICA')) { if (!defined('GNUSOCIAL')) { exit(1); }
exit(1);
}
/** /**
* Personal tag cloud section * Personal tag cloud section
@ -60,9 +58,9 @@ class InboxTagCloudSection extends TagCloudSection
function getTags() function getTags()
{ {
$profile = Profile::current(); // FIXME: Get the Profile::current() value some other way
// to avoid confusion between background stuff and session.
$stream = new InboxNoticeStream($this->target, $profile); $stream = new InboxNoticeStream($this->target, Profile::current());
$ids = $stream->getNoticeIds(0, self::MAX_NOTICES, null, null); $ids = $stream->getNoticeIds(0, self::MAX_NOTICES, null, null);

View File

@ -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 for a list * Stream of notices for a list
@ -47,14 +43,11 @@ if (!defined('STATUSNET')) {
*/ */
class PeopletagNoticeStream extends ScopingNoticeStream class PeopletagNoticeStream extends ScopingNoticeStream
{ {
function __construct($plist, $profile = -1) function __construct($plist, Profile $scoped=null)
{ {
if (is_int($profile) && $profile == -1) {
$profile = Profile::current();
}
parent::__construct(new CachingNoticeStream(new RawPeopletagNoticeStream($plist), parent::__construct(new CachingNoticeStream(new RawPeopletagNoticeStream($plist),
'profile_list:notice_ids:' . $plist->id), 'profile_list:notice_ids:' . $plist->id),
$profile); $scoped);
} }
} }

View File

@ -43,19 +43,14 @@ if (!defined('GNUSOCIAL')) { exit(1); }
class ProfileNoticeStream extends ScopingNoticeStream class ProfileNoticeStream extends ScopingNoticeStream
{ {
var $streamProfile; protected $target;
var $userProfile;
function __construct($profile, $userProfile = -1) function __construct(Profile $target, Profile $scoped=null)
{ {
if (is_int($userProfile) && $userProfile == -1) { $this->target = $target;
$userProfile = Profile::current(); parent::__construct(new CachingNoticeStream(new RawProfileNoticeStream($target),
} 'profile:notice_ids:' . $target->getID()),
$this->streamProfile = $profile; $scoped);
$this->userProfile = $userProfile;
parent::__construct(new CachingNoticeStream(new RawProfileNoticeStream($profile),
'profile:notice_ids:' . $profile->id),
$userProfile);
} }
function getNoticeIds($offset, $limit, $since_id=null, $max_id=null) function getNoticeIds($offset, $limit, $since_id=null, $max_id=null)
@ -70,7 +65,7 @@ class ProfileNoticeStream extends ScopingNoticeStream
function getNotices($offset, $limit, $since_id=null, $max_id=null) function getNotices($offset, $limit, $since_id=null, $max_id=null)
{ {
if ($this->impossibleStream()) { if ($this->impossibleStream()) {
throw new PrivateStreamException($this->streamProfile, $this->userProfile); throw new PrivateStreamException($this->target, $this->scoped);
} else { } else {
return parent::getNotices($offset, $limit, $since_id, $max_id); return parent::getNotices($offset, $limit, $since_id, $max_id);
} }
@ -78,7 +73,7 @@ class ProfileNoticeStream extends ScopingNoticeStream
function impossibleStream() function impossibleStream()
{ {
if (!$this->streamProfile->readableBy($this->userProfile)) { if (!$this->target->readableBy($this->scoped)) {
// cannot read because it's a private stream and either noone's logged in or they are not subscribers // cannot read because it's a private stream and either noone's logged in or they are not subscribers
return true; return true;
} }
@ -86,8 +81,13 @@ class ProfileNoticeStream extends ScopingNoticeStream
// If it's a spammy stream, and no user or not a moderator // If it's a spammy stream, and no user or not a moderator
if (common_config('notice', 'hidespam')) { if (common_config('notice', 'hidespam')) {
if ($this->streamProfile->hasRole(Profile_role::SILENCED) && // if this is a silenced user
(empty($this->userProfile) || (($this->userProfile->id !== $this->streamProfile->id) && !$this->userProfile->hasRight(Right::REVIEWSPAM)))) { if ($this->target->hasRole(Profile_role::SILENCED)
// and we are either not logged in
&& (!$this->scoped instanceof Profile
// or if we are, we are not logged in as the target, and we don't have right to review spam
|| (!$this->scoped->sameAs($this->target) && !$this->scoped->hasRight(Right::REVIEWSPAM))
)) {
return true; return true;
} }
} }
@ -109,20 +109,20 @@ class ProfileNoticeStream extends ScopingNoticeStream
class RawProfileNoticeStream extends NoticeStream class RawProfileNoticeStream extends NoticeStream
{ {
protected $profile; protected $target;
protected $selectVerbs = array(); // select all verbs protected $selectVerbs = array(); // select all verbs
function __construct($profile) function __construct(Profile $target)
{ {
parent::__construct(); parent::__construct();
$this->profile = $profile; $this->target = $target;
} }
function getNoticeIds($offset, $limit, $since_id, $max_id) function getNoticeIds($offset, $limit, $since_id, $max_id)
{ {
$notice = new Notice(); $notice = new Notice();
$notice->profile_id = $this->profile->id; $notice->profile_id = $this->target->getID();
$notice->selectAdd(); $notice->selectAdd();
$notice->selectAdd('id'); $notice->selectAdd('id');

View File

@ -43,11 +43,11 @@ if (!defined('GNUSOCIAL')) { exit(1); }
class PublicNoticeStream extends ScopingNoticeStream class PublicNoticeStream extends ScopingNoticeStream
{ {
function __construct($profile=null) function __construct(Profile $scoped=null)
{ {
parent::__construct(new CachingNoticeStream(new RawPublicNoticeStream(), parent::__construct(new CachingNoticeStream(new RawPublicNoticeStream(),
'public'), 'public'),
$profile); $scoped);
} }
} }

View File

@ -43,14 +43,11 @@ if (!defined('GNUSOCIAL')) { exit(1); }
class ReplyNoticeStream extends ScopingNoticeStream class ReplyNoticeStream extends ScopingNoticeStream
{ {
function __construct($userId, $profile=-1) function __construct($userId, Profile $scoped=null)
{ {
if (is_int($profile) && $profile == -1) {
$profile = Profile::current();
}
parent::__construct(new CachingNoticeStream(new RawReplyNoticeStream($userId), parent::__construct(new CachingNoticeStream(new RawReplyNoticeStream($userId),
'reply:stream:' . $userId), 'reply:stream:' . $userId),
$profile); $scoped);
} }
} }

View File

@ -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 comment * Class comment
@ -49,16 +45,12 @@ class ScopingNoticeStream extends FilteringNoticeStream
{ {
protected $profile; protected $profile;
function __construct($upstream, $profile = -1) function __construct(NoticeStream $upstream, Profile $scoped=null)
{ {
parent::__construct($upstream); parent::__construct($upstream);
// Invalid but not null $this->profile = $scoped; // legacy
if (is_int($profile) && $profile == -1) { $this->scoped = $scoped;
$profile = Profile::current();
}
$this->profile = $profile;
} }
/** /**
@ -71,7 +63,7 @@ class ScopingNoticeStream extends FilteringNoticeStream
function filter($notice) function filter($notice)
{ {
return $notice->inScope($this->profile); return $notice->inScope($this->scoped);
} }
function prefill($notices) function prefill($notices)

View File

@ -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 notice search results * Stream of notice search results
@ -47,13 +43,9 @@ if (!defined('STATUSNET')) {
class SearchNoticeStream extends ScopingNoticeStream class SearchNoticeStream extends ScopingNoticeStream
{ {
function __construct($q, $profile = -1) function __construct($q, Profile $scoped=null)
{ {
if (is_int($profile) && $profile == -1) { parent::__construct(new RawSearchNoticeStream($q), $scoped);
$profile = Profile::current();
}
parent::__construct(new RawSearchNoticeStream($q), $profile);
} }
} }

View File

@ -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 profile and tag * Stream of notices with a given profile and tag
@ -47,14 +43,11 @@ if (!defined('STATUSNET')) {
class TaggedProfileNoticeStream extends ScopingNoticeStream class TaggedProfileNoticeStream extends ScopingNoticeStream
{ {
function __construct($profile, $tag, $userProfile=-1) function __construct($profile, $tag, Profile $scoped=null)
{ {
if (is_int($userProfile) && $userProfile == -1) {
$userProfile = Profile::current();
}
parent::__construct(new CachingNoticeStream(new RawTaggedProfileNoticeStream($profile, $tag), parent::__construct(new CachingNoticeStream(new RawTaggedProfileNoticeStream($profile, $tag),
'profile:notice_ids_tagged:'.$profile->id.':'.Cache::keyize($tag)), 'profile:notice_ids_tagged:'.$profile->id.':'.Cache::keyize($tag)),
$userProfile); $scoped);
} }
} }

View File

@ -43,13 +43,11 @@ if (!defined('GNUSOCIAL')) { exit(1); }
class TagNoticeStream extends ScopingNoticeStream class TagNoticeStream extends ScopingNoticeStream
{ {
function __construct($tag, $profile = -1) function __construct($tag, Profile $scoped=null)
{ {
if (is_int($profile) && $profile == -1) {
$profile = Profile::current();
}
parent::__construct(new CachingNoticeStream(new RawTagNoticeStream($tag), parent::__construct(new CachingNoticeStream(new RawTagNoticeStream($tag),
'notice_tag:notice_ids:' . Cache::keyize($tag))); 'notice_tag:notice_ids:' . Cache::keyize($tag)),
$scoped);
} }
} }

View File

@ -4,8 +4,8 @@ if (!defined('GNUSOCIAL')) { exit(1); }
class ThreadingGroupNoticeStream extends ThreadingNoticeStream class ThreadingGroupNoticeStream extends ThreadingNoticeStream
{ {
function __construct($group, $profile) function __construct($group, Profile $scoped=null)
{ {
parent::__construct(new GroupNoticeStream($group, $profile)); parent::__construct(new GroupNoticeStream($group, $scoped));
} }
} }

View File

@ -74,19 +74,17 @@ class SpamAction extends Action
// User must be logged in. // User must be logged in.
$user = common_current_user(); if (!$this->scoped instanceof Profile) {
if (empty($user)) {
throw new ClientException(_("You must be logged in to review."), 403); throw new ClientException(_("You must be logged in to review."), 403);
} }
// User must have the right to review spam // User must have the right to review spam
if (!$user->hasRight(ActivitySpamPlugin::REVIEWSPAM)) { if (!$this->scoped->hasRight(ActivitySpamPlugin::REVIEWSPAM)) {
throw new ClientException(_('You cannot review spam on this site.'), 403); throw new ClientException(_('You cannot review spam on this site.'), 403);
} }
$stream = new SpamNoticeStream($user->getProfile()); $stream = new SpamNoticeStream($this->scoped);
$this->notices = $stream->getNotices(($this->page-1)*NOTICES_PER_PAGE, $this->notices = $stream->getNotices(($this->page-1)*NOTICES_PER_PAGE,
NOTICES_PER_PAGE + 1); NOTICES_PER_PAGE + 1);

View File

@ -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);
}
/** /**
* Spam notice stream * Spam notice stream
@ -47,13 +43,10 @@ if (!defined('STATUSNET')) {
class SpamNoticeStream extends ScopingNoticeStream class SpamNoticeStream extends ScopingNoticeStream
{ {
function __construct($tag, $profile = -1) function __construct(Profile $scoped=null)
{ {
if (is_int($profile) && $profile == -1) { parent::__construct(new CachingNoticeStream(new RawSpamNoticeStream(), 'spam_score:notice_ids'),
$profile = Profile::current(); $scoped);
}
parent::__construct(new CachingNoticeStream(new RawSpamNoticeStream(),
'spam_score:notice_ids'));
} }
} }

View File

@ -1,5 +1,7 @@
<?php <?php
if (!defined('GNUSOCIAL')) { exit(1); }
class RawBookmarksNoticeStream extends NoticeStream class RawBookmarksNoticeStream extends NoticeStream
{ {
protected $user_id; protected $user_id;
@ -60,7 +62,7 @@ class RawBookmarksNoticeStream extends NoticeStream
class BookmarksNoticeStream extends ScopingNoticeStream class BookmarksNoticeStream extends ScopingNoticeStream
{ {
function __construct($user_id, $own, $profile = -1) function __construct($user_id, $own, Profile $scoped=null)
{ {
$stream = new RawBookmarksNoticeStream($user_id, $own); $stream = new RawBookmarksNoticeStream($user_id, $own);
@ -70,11 +72,6 @@ class BookmarksNoticeStream extends ScopingNoticeStream
$key = 'bookmark:ids_by_user:'.$user_id; $key = 'bookmark:ids_by_user:'.$user_id;
} }
if (is_int($profile) && $profile == -1) { parent::__construct(new CachingNoticeStream($stream, $key), $scoped);
$profile = Profile::current();
}
parent::__construct(new CachingNoticeStream($stream, $key),
$profile);
} }
} }

View File

@ -26,9 +26,7 @@
* @link http://status.net/ * @link http://status.net/
*/ */
if (!defined('STATUSNET')) { if (!defined('GNUSOCIAL')) { exit(1); }
exit(1);
}
/** /**
* Handler for queue items of type 'usersum', sends an email summaries * Handler for queue items of type 'usersum', sends an email summaries
@ -95,15 +93,15 @@ class UserEmailSummaryHandler extends QueueHandler
return true; return true;
} }
$profile = $user->getProfile(); try {
$profile = $user->getProfile();
if (empty($profile)) { } catch (UserNoProfileException $e) {
common_log(LOG_WARNING, sprintf('Not sending email summary for user %s; no profile.', $user_id)); common_log(LOG_WARNING, sprintf('Not sending email summary for user %s; no profile.', $user_id));
return true; return true;
} }
// An InboxNoticeStream for a certain user, scoped to its own view // An InboxNoticeStream for a certain user, scoped to its own view
$stream = new InboxNoticeStream($profile); $stream = new InboxNoticeStream($profile, $profile);
$notice = $stream->getNotices(0, self::MAX_NOTICES, $since_id); $notice = $stream->getNotices(0, self::MAX_NOTICES, $since_id);

View File

@ -1,5 +1,7 @@
<?php <?php
if (!defined('GNUSOCIAL')) { exit(1); }
class RawEventsNoticeStream extends NoticeStream class RawEventsNoticeStream extends NoticeStream
{ {
function getNoticeIds($offset, $limit, $since_id, $max_id) function getNoticeIds($offset, $limit, $since_id, $max_id)

View File

@ -167,7 +167,7 @@ class FavoritedAction extends Action
*/ */
function showContent() function showContent()
{ {
$stream = new PopularNoticeStream(Profile::current()); $stream = new PopularNoticeStream($this->scoped);
$notice = $stream->getNotices(($this->page-1)*NOTICES_PER_PAGE, NOTICES_PER_PAGE+1); $notice = $stream->getNotices(($this->page-1)*NOTICES_PER_PAGE, NOTICES_PER_PAGE+1);
$nl = new NoticeList($notice, $this); $nl = new NoticeList($notice, $this);

View File

@ -57,8 +57,7 @@ class ShowfavoritesAction extends ShowstreamAction
public function getStream() public function getStream()
{ {
$own = $this->scoped instanceof Profile ? $this->scoped->sameAs($this->getTarget()) : false; return new FaveNoticeStream($this->getTarget(), $this->scoped);
return new FaveNoticeStream($this->getTarget()->getID(), $own);
} }
function getFeeds() function getFeeds()

View File

@ -152,16 +152,22 @@ class Fave extends Managed_DataObject
return $result; return $result;
} }
// FIXME: Instead of $own, send the scoped Profile so we can pass it along directly to FaveNoticeStream
// and preferrably we should get a Profile instead of $user_id
static function stream($user_id, $offset=0, $limit=NOTICES_PER_PAGE, $own=false, $since_id=0, $max_id=0) static function stream($user_id, $offset=0, $limit=NOTICES_PER_PAGE, $own=false, $since_id=0, $max_id=0)
{ {
$stream = new FaveNoticeStream($user_id, $own); $target = Profile::getByID($user_id);
$stream = new FaveNoticeStream($target, ($own ? $target : null));
return $stream->getNotices($offset, $limit, $since_id, $max_id); return $stream->getNotices($offset, $limit, $since_id, $max_id);
} }
// FIXME: Instead of $own, send the scoped Profile so we can pass it along directly to FaveNoticeStream
// and preferrably we should get a Profile instead of $user_id
function idStream($user_id, $offset=0, $limit=NOTICES_PER_PAGE, $own=false, $since_id=0, $max_id=0) function idStream($user_id, $offset=0, $limit=NOTICES_PER_PAGE, $own=false, $since_id=0, $max_id=0)
{ {
$stream = new FaveNoticeStream($user_id, $own); $target = Profile::getByID($user_id);
$stream = new FaveNoticeStream($target, ($own ? $target : null));
return $stream->getNoticeIds($offset, $limit, $since_id, $max_id); return $stream->getNoticeIds($offset, $limit, $since_id, $max_id);
} }

View File

@ -42,19 +42,15 @@ if (!defined('GNUSOCIAL')) { exit(1); }
*/ */
class FaveNoticeStream extends ScopingNoticeStream class FaveNoticeStream extends ScopingNoticeStream
{ {
function __construct($user_id, $own, $profile = -1) function __construct(Profile $target, Profile $scoped=null)
{ {
$stream = new RawFaveNoticeStream($user_id, $own); $stream = new RawFaveNoticeStream($target, $scoped);
if ($own) { if ($target->sameAs($scoped)) {
$key = 'fave:ids_by_user_own:'.$user_id; $key = 'fave:ids_by_user_own:'.$user_id;
} else { } else {
$key = 'fave:ids_by_user:'.$user_id; $key = 'fave:ids_by_user:'.$user_id;
} }
if (is_int($profile) && $profile == -1) { parent::__construct(new CachingNoticeStream($stream, $key), $scoped);
$profile = Profile::current();
}
parent::__construct(new CachingNoticeStream($stream, $key),
$profile);
} }
} }
@ -75,12 +71,12 @@ class RawFaveNoticeStream extends NoticeStream
protected $selectVerbs = array(); protected $selectVerbs = array();
function __construct($user_id, $own) function __construct(Profile $target, Profile $scoped=null)
{ {
parent::__construct(); parent::__construct();
$this->user_id = $user_id; $this->user_id = $target->getID();
$this->own = $own; $this->own = $target->sameAs($scoped);
} }
/** /**

View File

@ -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 sorted by popularity * Stream of notices sorted by popularity
@ -47,12 +43,12 @@ if (!defined('STATUSNET')) {
class PopularNoticeStream extends ScopingNoticeStream class PopularNoticeStream extends ScopingNoticeStream
{ {
function __construct($profile=null) function __construct(Profile $scoped=null)
{ {
parent::__construct(new CachingNoticeStream(new RawPopularNoticeStream(), parent::__construct(new CachingNoticeStream(new RawPopularNoticeStream(),
'popular', 'popular',
false), false),
$profile); $scoped);
} }
} }

View File

@ -27,9 +27,7 @@
* @link http://status.net/ * @link http://status.net/
*/ */
if (!defined('STATUSNET')) { if (!defined('GNUSOCIAL')) { exit(1); }
exit(1);
}
/** /**
* Show a map of user's notices * Show a map of user's notices

View File

@ -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 repeated by me * Stream of notices repeated by me
@ -47,14 +43,11 @@ if (!defined('STATUSNET')) {
class RepeatedByMeNoticeStream extends ScopingNoticeStream class RepeatedByMeNoticeStream extends ScopingNoticeStream
{ {
function __construct($user, $profile = -1) function __construct(Profile $target, Profile $scoped=null)
{ {
if (is_int($profile) && $profile == -1) { parent::__construct(new CachingNoticeStream(new RawRepeatedByMeNoticeStream($target),
$profile = Profile::current(); 'user:repeated_by_me:'.$target->getID()),
} $scoped);
parent::__construct(new CachingNoticeStream(new RawRepeatedByMeNoticeStream($user),
'user:repeated_by_me:'.$user->id),
$profile);
} }
} }
@ -71,11 +64,11 @@ class RepeatedByMeNoticeStream extends ScopingNoticeStream
class RawRepeatedByMeNoticeStream extends NoticeStream class RawRepeatedByMeNoticeStream extends NoticeStream
{ {
protected $user; protected $target;
function __construct($user) function __construct(Profile $target)
{ {
$this->user = $user; $this->target = $target;
} }
function getNoticeIds($offset, $limit, $since_id, $max_id) function getNoticeIds($offset, $limit, $since_id, $max_id)
@ -85,7 +78,7 @@ class RawRepeatedByMeNoticeStream extends NoticeStream
$notice->selectAdd(); // clears it $notice->selectAdd(); // clears it
$notice->selectAdd('id'); $notice->selectAdd('id');
$notice->profile_id = $this->user->id; $notice->profile_id = $this->target->getID();
$notice->whereAdd('repeat_of IS NOT NULL'); $notice->whereAdd('repeat_of IS NOT NULL');
$notice->orderBy('created DESC, id DESC'); $notice->orderBy('created DESC, id DESC');

View File

@ -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 that are repeats of mine * Stream of notices that are repeats of mine
@ -47,14 +43,11 @@ if (!defined('STATUSNET')) {
class RepeatsOfMeNoticeStream extends ScopingNoticeStream class RepeatsOfMeNoticeStream extends ScopingNoticeStream
{ {
function __construct($user, $profile=-1) function __construct(Profile $target, Profile $scoped=null)
{ {
if (is_int($profile) && $profile == -1) { parent::__construct(new CachingNoticeStream(new RawRepeatsOfMeNoticeStream($target),
$profile = Profile::current(); 'user:repeats_of_me:'.$target->getID()),
} $scoped);
parent::__construct(new CachingNoticeStream(new RawRepeatsOfMeNoticeStream($user),
'user:repeats_of_me:'.$user->id),
$profile);
} }
} }
@ -70,11 +63,11 @@ class RepeatsOfMeNoticeStream extends ScopingNoticeStream
*/ */
class RawRepeatsOfMeNoticeStream extends NoticeStream class RawRepeatsOfMeNoticeStream extends NoticeStream
{ {
protected $user; protected $target;
function __construct($user) function __construct(Profile $target)
{ {
$this->user = $user; $this->target = $target;
} }
function getNoticeIds($offset, $limit, $since_id, $max_id) function getNoticeIds($offset, $limit, $since_id, $max_id)
@ -82,7 +75,7 @@ class RawRepeatsOfMeNoticeStream extends NoticeStream
$qry = $qry =
'SELECT DISTINCT original.id AS id ' . 'SELECT DISTINCT original.id AS id ' .
'FROM notice original JOIN notice rept ON original.id = rept.repeat_of ' . 'FROM notice original JOIN notice rept ON original.id = rept.repeat_of ' .
'WHERE original.profile_id = ' . $this->user->id . ' '; 'WHERE original.profile_id = ' . $this->target->getID() . ' ';
$since = Notice::whereSinceId($since_id, 'original.id', 'original.created'); $since = Notice::whereSinceId($since_id, 'original.id', 'original.created');
if ($since) { if ($since) {