]> git.mxchange.org Git - quix0rs-gnu-social.git/commitdiff
Consistent behaviour for ScopingNoticeStream $scoped
authorMikael Nordfeldth <mmn@hethane.se>
Tue, 1 Mar 2016 13:51:47 +0000 (14:51 +0100)
committerMikael Nordfeldth <mmn@hethane.se>
Tue, 1 Mar 2016 13:51:47 +0000 (14:51 +0100)
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).

38 files changed:
actions/allrss.php
actions/noticesearch.php
actions/showgroup.php
classes/File.php
classes/Notice.php
classes/Notice_tag.php
classes/Profile.php
classes/Profile_list.php
classes/Reply.php
classes/User.php
classes/User_group.php
lib/conversationnoticestream.php
lib/filenoticestream.php
lib/groupnoticestream.php
lib/inboxnoticestream.php
lib/inboxtagcloudsection.php
lib/peopletagnoticestream.php
lib/profilenoticestream.php
lib/publicnoticestream.php
lib/replynoticestream.php
lib/scopingnoticestream.php
lib/searchnoticestream.php
lib/taggedprofilenoticestream.php
lib/tagnoticestream.php
lib/threadinggroupnoticestream.php
plugins/ActivitySpam/actions/spam.php
plugins/ActivitySpam/lib/spamnoticestream.php
plugins/Bookmark/lib/bookmarksnoticestream.php
plugins/EmailSummary/lib/useremailsummaryhandler.php
plugins/Event/lib/eventsnoticestream.php
plugins/Favorite/actions/favorited.php
plugins/Favorite/actions/showfavorites.php
plugins/Favorite/classes/Fave.php
plugins/Favorite/lib/favenoticestream.php
plugins/Favorite/lib/popularnoticestream.php
plugins/Mapstraction/actions/allmap.php
plugins/Share/lib/repeatedbymenoticestream.php
plugins/Share/lib/repeatsofmenoticestream.php

index 4b6df25048645286e97f6c12cb319d9f3e317dfe..d7f11bb1eb36130fe76dded7a7402acc464c58e4 100644 (file)
@@ -46,7 +46,7 @@ class AllrssAction extends TargetedRss10Action
 {
     protected function getNotices()
     {
-        $stream = new InboxNoticeStream($this->target);
+        $stream = new InboxNoticeStream($this->target, $this->scoped);
         return $stream->getNotices(0, $this->limit)->fetchAll();
     }
 
index fd8fdf68e52f38139956ab5350aca4e1cee44a97..d7cdeaacc6a1cc4e7054ea450861a6b7d214c087 100644 (file)
@@ -65,8 +65,7 @@ class NoticesearchAction extends SearchAction
 
         if (!empty($this->q)) {
 
-            $profile = Profile::current();
-            $stream  = new SearchNoticeStream($this->q, $profile);
+            $stream  = new SearchNoticeStream($this->q, $this->scoped);
             $page    = $this->trimmed('page');
 
             if (empty($page)) {
index 46d0a227f536ecc4253212e6b55cb5fe2ba71d1b..8770e6cc8b5061735295ad7787c4f47eab035a39 100644 (file)
  * @link      http://status.net/
  */
 
-if (!defined('STATUSNET') && !defined('LACONICA')) {
-    exit(1);
-}
-
-require_once INSTALLDIR.'/lib/noticelist.php';
-require_once INSTALLDIR.'/lib/feedlist.php';
+if (!defined('GNUSOCIAL')) { exit(1); }
 
 /**
  * Group main page
@@ -48,7 +43,6 @@ class ShowgroupAction extends GroupAction
 {
     /** page we're viewing. */
     var $page = null;
-    var $userProfile = null;
     var $notice = null;
 
     /**
@@ -97,14 +91,10 @@ class ShowgroupAction extends GroupAction
 
         $this->page = ($this->arg('page')) ? ($this->arg('page')+0) : 1;
 
-        $this->userProfile = Profile::current();
-
-        $user = common_current_user();
-
-        if (!empty($user) && $user->streamModeOnly()) {
-            $stream = new GroupNoticeStream($this->group, $this->userProfile);
+        if ($this->scoped instanceof Profile && $this->scoped->isLocal() && $this->scoped->getUser()->streamModeOnly()) {
+            $stream = new GroupNoticeStream($this->group, $this->scoped);
         } 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,
@@ -146,12 +136,10 @@ class ShowgroupAction extends GroupAction
      */
     function showGroupNotices()
     {
-        $user = common_current_user();
-
-        if (!empty($user) && $user->streamModeOnly()) {
+        if ($this->scoped instanceof Profile && $this->scoped->isLocal() && $this->scoped->getUser()->streamModeOnly()) {
             $nl = new PrimaryNoticeList($this->notice, $this, array('show_n'=>NOTICES_PER_PAGE));
         } else {
-            $nl = new ThreadedNoticeList($this->notice, $this, $this->userProfile);
+            $nl = new ThreadedNoticeList($this->notice, $this, $this->scoped);
         } 
 
         $cnt = $nl->show();
index ef4b2cfb3c75d9667cf7c3742279cdf7b0d6723c..d6dd78cbef0afde8437245af1b11e88d0d0eb2a8 100644 (file)
@@ -579,7 +579,9 @@ class File extends Managed_DataObject
 
     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);
     }
 
index 2bae300115d3eece1bf24f8123276bb1a6ecbf55..6f406472c74378edfbf5f506d6f75e73bf9ab974 100644 (file)
@@ -1280,9 +1280,9 @@ class Notice extends Managed_DataObject
         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);
     }
 
@@ -1300,8 +1300,9 @@ class Notice extends Managed_DataObject
             return false;
         }
 
-        $stream = new ConversationNoticeStream($this->conversation);
-        $notice = $stream->getNotices(/*offset*/ 1, /*limit*/ 1);
+        //FIXME: Get the Profile::current() stuff some other way
+        // 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
         return $notice->N > 0;
index b864de80092b31001b03a8048519b0ab97b6e5ee..9d6bec6d2f401b2ae4ec7f8cdd971198815c84f9 100644 (file)
@@ -55,7 +55,9 @@ class Notice_tag extends Managed_DataObject
     
     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;
     }
 
index a5e0d092dc473e56d671c0734ffc1efc1db3e135..36e91c3ad0b990ef2ddb9eeeff2234bd046d912b 100644 (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)
     {
-        $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);
     }
index 000e10b41f5fb7cc598c7c7a2d7ffa37378e98ed..b60f4afffdc6d008886015a7ecc3154f7195e20a 100644 (file)
@@ -171,7 +171,9 @@ class Profile_list extends Managed_DataObject
 
     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);
     }
index d3405e6581c26213a9d658e5e8408ef9c2912a71..018937ba6c70c1a6199c91eb2768880aa1e16029 100644 (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)
     {
-        $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);
     }
 }
index 40e1a1b6443a2503371e1e81c680ea73d26cce58..12cc170f861a0a6c88cfb53d8f39c92c6c478a70 100644 (file)
@@ -701,15 +701,18 @@ class User extends Managed_DataObject
 
     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);
     }
 
 
     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);
     }
 
index ecec1ee663d5d1de785c1c72916b85bf0cfeda86..8f736de6d09a5728b194f37487405ee5f2905fee 100644 (file)
@@ -153,7 +153,9 @@ class User_group extends Managed_DataObject
 
     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);
     }
index 21b2d7f0be59a0561e6ecf1994cfcc7e89a451dd..bcb16c2d4b5a87a05773dcac134afe2b652d39a0 100644 (file)
@@ -42,14 +42,10 @@ if (!defined('GNUSOCIAL')) { exit(1); }
  */
 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),
-                            $profile);
+                            $scoped);
     }
 }
 
index f7bca1ed68e52ec1e7092e62c2267a65002cffad..49b93732fbc091e253299df0fb47050ec24be820 100644 (file)
  * @link      http://status.net/
  */
 
-if (!defined('STATUSNET')) {
-    // This check helps protect against security problems;
-    // your code file can't be executed directly from the web.
-    exit(1);
-}
+if (!defined('GNUSOCIAL')) { exit(1); }
 
 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),
                                                     'file:notice-ids:'.$file->id),
-                            $profile);
+                            $scoped);
     }
 }
 
index 723f064cb3523dab13b8de075fbd66b0e140ff1a..2d6e7b37cb4b6328b928e8d69ead7c631c4df739 100644 (file)
  * @link      http://status.net/
  */
 
-if (!defined('STATUSNET')) {
-    // This check helps protect against security problems;
-    // your code file can't be executed directly from the web.
-    exit(1);
-}
+if (!defined('GNUSOCIAL')) { exit(1); }
 
 /**
  * Stream of notices for a group
@@ -47,19 +43,14 @@ if (!defined('STATUSNET')) {
 class GroupNoticeStream extends ScopingNoticeStream
 {
     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->userProfile = $profile;
 
         parent::__construct(new CachingNoticeStream(new RawGroupNoticeStream($group),
                                                     'user_group:notice_ids:' . $group->id),
-                            $profile);
+                            $scoped);
     }
 
     function getNoticeIds($offset, $limit, $since_id, $max_id)
@@ -83,7 +74,7 @@ class GroupNoticeStream extends ScopingNoticeStream
     function impossibleStream() 
     {
         if ($this->group->force_scope &&
-            (empty($this->userProfile) || !$this->userProfile->isMember($this->group))) {
+            (!$this->scoped instanceof Profile || $this->scoped->isMember($this->group))) {
             return true;
         }
 
index ccf0f460c971adfde9f5cfd2f71712a633cfff30..2b19461c5763d7bc542cac96ce956fbf9fcdda4b 100644 (file)
@@ -54,9 +54,6 @@ class InboxNoticeStream extends ScopingNoticeStream
      */
     function __construct(Profile $target, Profile $scoped=null)
     {
-        if ($scoped === null) {
-            $scoped = Profile::current();
-        }
         // FIXME: we don't use CachingNoticeStream - but maybe we should?
         parent::__construct(new CachingNoticeStream(new RawInboxNoticeStream($target), 'profileall'), $scoped);
     }
index d19f76366d6f09d072f8f04218d83d0c4f465d54..4268ee48548722093c6f67a2a799b9e891b97cdd 100644 (file)
@@ -27,9 +27,7 @@
  * @link      http://status.net/
  */
 
-if (!defined('STATUSNET') && !defined('LACONICA')) {
-    exit(1);
-}
+if (!defined('GNUSOCIAL')) { exit(1); }
 
 /**
  * Personal tag cloud section
@@ -60,9 +58,9 @@ class InboxTagCloudSection extends TagCloudSection
 
     function getTags()
     {
-        $profile = Profile::current();
-
-        $stream = new InboxNoticeStream($this->target, $profile);
+        // FIXME: Get the Profile::current() value some other way
+        // to avoid confusion between background stuff and session.
+        $stream = new InboxNoticeStream($this->target, Profile::current());
 
         $ids = $stream->getNoticeIds(0, self::MAX_NOTICES, null, null);
 
index 4422261ae9a6950881d7823ea1c1190b1123a894..cc453bf1f81aeed2fe5d3bc0f48066988fb8f1af 100644 (file)
  * @link      http://status.net/
  */
 
-if (!defined('STATUSNET')) {
-    // This check helps protect against security problems;
-    // your code file can't be executed directly from the web.
-    exit(1);
-}
+if (!defined('GNUSOCIAL')) { exit(1); }
 
 /**
  * Stream of notices for a list
@@ -47,14 +43,11 @@ if (!defined('STATUSNET')) {
  */
 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),
                                                     'profile_list:notice_ids:' . $plist->id),
-                            $profile);
+                            $scoped);
     }
 }
 
index 7ff4163fcbc96dbdde5b583219872ef46a886591..bfe49efea579b64644bffff44c4fce19399d5357 100644 (file)
@@ -43,19 +43,14 @@ if (!defined('GNUSOCIAL')) { exit(1); }
 
 class ProfileNoticeStream extends ScopingNoticeStream
 {
-    var $streamProfile;
-    var $userProfile;
+    protected $target;
 
-    function __construct($profile, $userProfile = -1)
+    function __construct(Profile $target, Profile $scoped=null)
     {
-        if (is_int($userProfile) && $userProfile == -1) {
-            $userProfile = Profile::current();
-        }
-        $this->streamProfile = $profile;
-        $this->userProfile   = $userProfile;
-        parent::__construct(new CachingNoticeStream(new RawProfileNoticeStream($profile),
-                                                    'profile:notice_ids:' . $profile->id),
-                            $userProfile);
+        $this->target = $target;
+        parent::__construct(new CachingNoticeStream(new RawProfileNoticeStream($target),
+                                                    'profile:notice_ids:' . $target->getID()),
+                            $scoped);
     }
 
     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)
     {
         if ($this->impossibleStream()) {
-            throw new PrivateStreamException($this->streamProfile, $this->userProfile);
+            throw new PrivateStreamException($this->target, $this->scoped);
         } else {
             return parent::getNotices($offset, $limit, $since_id, $max_id);
         }
@@ -78,7 +73,7 @@ class ProfileNoticeStream extends ScopingNoticeStream
 
     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
             return true;
         }
@@ -86,8 +81,13 @@ class ProfileNoticeStream extends ScopingNoticeStream
         // If it's a spammy stream, and no user or not a moderator
 
         if (common_config('notice', 'hidespam')) {
-            if ($this->streamProfile->hasRole(Profile_role::SILENCED) &&
-                (empty($this->userProfile) || (($this->userProfile->id !== $this->streamProfile->id) && !$this->userProfile->hasRight(Right::REVIEWSPAM)))) {
+            // if this is a silenced user
+            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;
             }
         }
@@ -109,20 +109,20 @@ class ProfileNoticeStream extends ScopingNoticeStream
 
 class RawProfileNoticeStream extends NoticeStream
 {
-    protected $profile;
+    protected $target;
     protected $selectVerbs = array();   // select all verbs
 
-    function __construct($profile)
+    function __construct(Profile $target)
     {
         parent::__construct();
-        $this->profile = $profile;
+        $this->target = $target;
     }
 
     function getNoticeIds($offset, $limit, $since_id, $max_id)
     {
         $notice = new Notice();
 
-        $notice->profile_id = $this->profile->id;
+        $notice->profile_id = $this->target->getID();
 
         $notice->selectAdd();
         $notice->selectAdd('id');
index 4a16cbd235b789a6465b23ced61ee4feef9b1c1d..1dd59059fd7e357f8ce2c2d1676ec6ea391c44ff 100644 (file)
@@ -43,11 +43,11 @@ if (!defined('GNUSOCIAL')) { exit(1); }
 
 class PublicNoticeStream extends ScopingNoticeStream
 {
-    function __construct($profile=null)
+    function __construct(Profile $scoped=null)
     {
         parent::__construct(new CachingNoticeStream(new RawPublicNoticeStream(),
                                                     'public'),
-                            $profile);
+                            $scoped);
     }
 }
 
index 9eb188d54db2d43d0105a4ea48d2b395b911f64d..d6b2882193c9266a0bc5477d0b6d9a0a0da669e5 100644 (file)
@@ -43,14 +43,11 @@ if (!defined('GNUSOCIAL')) { exit(1); }
 
 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),
                                                     'reply:stream:' . $userId),
-                            $profile);
+                            $scoped);
     }
 }
 
index c1651d5a30b1c347c33803091ddf441d5b65f1b3..84af75948df626488191fb8757c15d9a0dc8c42a 100644 (file)
  * @link      http://status.net/
  */
 
-if (!defined('STATUSNET')) {
-    // This check helps protect against security problems;
-    // your code file can't be executed directly from the web.
-    exit(1);
-}
+if (!defined('GNUSOCIAL')) { exit(1); }
 
 /**
  * Class comment
@@ -49,16 +45,12 @@ class ScopingNoticeStream extends FilteringNoticeStream
 {
     protected $profile;
 
-    function __construct($upstream, $profile = -1)
+    function __construct(NoticeStream $upstream, Profile $scoped=null)
     {
         parent::__construct($upstream);
 
-        // Invalid but not null
-        if (is_int($profile) && $profile == -1) {
-            $profile = Profile::current();
-        }
-
-        $this->profile = $profile;
+        $this->profile = $scoped;   // legacy
+        $this->scoped = $scoped;
     }
 
     /**
@@ -71,7 +63,7 @@ class ScopingNoticeStream extends FilteringNoticeStream
 
     function filter($notice)
     {
-        return $notice->inScope($this->profile);
+        return $notice->inScope($this->scoped);
     }
 
     function prefill($notices)
index 6593a4c86087ebfaddba661281f10acadba57239..9c31a709c64366bc2b41dc57199cf4e5326f4567 100644 (file)
  * @link      http://status.net/
  */
 
-if (!defined('STATUSNET')) {
-    // This check helps protect against security problems;
-    // your code file can't be executed directly from the web.
-    exit(1);
-}
+if (!defined('GNUSOCIAL')) { exit(1); }
 
 /**
  * Stream of notice search results
@@ -47,13 +43,9 @@ if (!defined('STATUSNET')) {
 
 class SearchNoticeStream extends ScopingNoticeStream
 {
-    function __construct($q, $profile = -1)
+    function __construct($q, Profile $scoped=null)
     {
-        if (is_int($profile) && $profile == -1) {
-            $profile = Profile::current();
-        }
-
-        parent::__construct(new RawSearchNoticeStream($q), $profile);
+        parent::__construct(new RawSearchNoticeStream($q), $scoped);
     }
 }
 
@@ -89,4 +81,4 @@ class RawSearchNoticeStream extends NoticeStream
 
         return $ids;
     }
-}
\ No newline at end of file
+}
index eec20cd8c660153f209ba1c518adc05d7da0fe95..f6fb476ff1767e3ca85d065fad2f6f69b20fd972 100644 (file)
  * @link      http://status.net/
  */
 
-if (!defined('STATUSNET')) {
-    // This check helps protect against security problems;
-    // your code file can't be executed directly from the web.
-    exit(1);
-}
+if (!defined('GNUSOCIAL')) { exit(1); }
 
 /**
  * Stream of notices with a given profile and tag
@@ -47,14 +43,11 @@ if (!defined('STATUSNET')) {
 
 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),
                                                     'profile:notice_ids_tagged:'.$profile->id.':'.Cache::keyize($tag)),
-                            $userProfile);
+                            $scoped);
     }
 }
 
index 28f5d0e82483ab4536b4427c07002f0c80e00e12..5a99a1aa68a0b30faf7cc6b2ae0f0f371941ce40 100644 (file)
@@ -43,13 +43,11 @@ if (!defined('GNUSOCIAL')) { exit(1); }
 
 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),
-                                                    'notice_tag:notice_ids:' . Cache::keyize($tag)));
+                                                    'notice_tag:notice_ids:' . Cache::keyize($tag)),
+                            $scoped);
     }
 }
 
index b026ee47141d64fd2e72e726ccc7d38cd617e7ad..bc42a6247ad7349675f761b1053f86b980f96858 100644 (file)
@@ -4,8 +4,8 @@ if (!defined('GNUSOCIAL')) { exit(1); }
 
 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));
     }
 }
index a66b73a8294db0a1495d1560d56c6d3d08520af8..00a1e0b8a1b7bfe10a443a8363d07af2841e8acc 100644 (file)
@@ -74,19 +74,17 @@ class SpamAction extends Action
 
         // User must be logged in.
 
-        $user = common_current_user();
-
-        if (empty($user)) {
+        if (!$this->scoped instanceof Profile) {
             throw new ClientException(_("You must be logged in to review."), 403);
         }
 
         // 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);
         }
 
-        $stream = new SpamNoticeStream($user->getProfile());
+        $stream = new SpamNoticeStream($this->scoped);
 
         $this->notices = $stream->getNotices(($this->page-1)*NOTICES_PER_PAGE,
                                              NOTICES_PER_PAGE + 1);
index ffb8d080251d5e22e7949c328fbf09de5da816d3..d19814509c134be3706555391eaf92a0c0e8b8dc 100644 (file)
  * @link      http://status.net/
  */
 
-if (!defined('STATUSNET')) {
-    // This check helps protect against security problems;
-    // your code file can't be executed directly from the web.
-    exit(1);
-}
+if (!defined('GNUSOCIAL')) { exit(1); }
 
 /**
  * Spam notice stream
@@ -47,13 +43,10 @@ if (!defined('STATUSNET')) {
 
 class SpamNoticeStream extends ScopingNoticeStream
 {
-    function __construct($tag, $profile = -1)
+    function __construct(Profile $scoped=null)
     {
-        if (is_int($profile) && $profile == -1) {
-            $profile = Profile::current();
-        }
-        parent::__construct(new CachingNoticeStream(new RawSpamNoticeStream(),
-                                                    'spam_score:notice_ids'));
+        parent::__construct(new CachingNoticeStream(new RawSpamNoticeStream(), 'spam_score:notice_ids'),
+                            $scoped);
     }
 }
 
index a3ac0359d7b180b8bbba9a0cd327e4a0578c25c1..f5d384c2e57bac62a963c106d14f4db12fde1b30 100644 (file)
@@ -1,5 +1,7 @@
 <?php
 
+if (!defined('GNUSOCIAL')) { exit(1); }
+
 class RawBookmarksNoticeStream extends NoticeStream
 {
     protected $user_id;
@@ -60,7 +62,7 @@ class RawBookmarksNoticeStream extends NoticeStream
 
 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);
 
@@ -70,11 +72,6 @@ class BookmarksNoticeStream extends ScopingNoticeStream
             $key = 'bookmark:ids_by_user:'.$user_id;
         }
 
-        if (is_int($profile) && $profile == -1) {
-            $profile = Profile::current();
-        }
-
-        parent::__construct(new CachingNoticeStream($stream, $key),
-                            $profile);
+        parent::__construct(new CachingNoticeStream($stream, $key), $scoped);
     }
 }
index 621d14122cff67137ba23460cce509520482169c..143d6c1bd222382e12b1160e4b8111cf97eaba5e 100644 (file)
@@ -26,9 +26,7 @@
  * @link      http://status.net/
  */
 
-if (!defined('STATUSNET')) {
-    exit(1);
-}
+if (!defined('GNUSOCIAL')) { exit(1); }
 
 /**
  * Handler for queue items of type 'usersum', sends an email summaries
@@ -95,15 +93,15 @@ class UserEmailSummaryHandler extends QueueHandler
             return true;
         }
 
-        $profile = $user->getProfile();
-
-        if (empty($profile)) {
+        try {
+            $profile = $user->getProfile();
+        } catch (UserNoProfileException $e) {
             common_log(LOG_WARNING, sprintf('Not sending email summary for user %s; no profile.', $user_id));
             return true;
         }
 
         // 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);
 
index c0d91060be36bbcfd77707c7d1216168cf34ae97..3dd1a81bd1243b7be1fd37050255239479e9efb3 100644 (file)
@@ -1,5 +1,7 @@
 <?php
 
+if (!defined('GNUSOCIAL')) { exit(1); }
+
 class RawEventsNoticeStream extends NoticeStream
 {
     function getNoticeIds($offset, $limit, $since_id, $max_id)
index 849a1c8b07a5662799b33b84f2c7fa1ed25d6d14..8c2871dc3c8c8ded54c041087f1718ded379fb04 100644 (file)
@@ -167,7 +167,7 @@ class FavoritedAction extends Action
      */
     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);
 
         $nl = new NoticeList($notice, $this);
index cba29063c28b2de8787890db5c0920ac98ac5c8b..ea1169957c0a761d2628a38598e7a2aaee18a052 100644 (file)
@@ -57,8 +57,7 @@ class ShowfavoritesAction extends ShowstreamAction
 
     public function getStream()
     {
-        $own = $this->scoped instanceof Profile ? $this->scoped->sameAs($this->getTarget()) : false;
-        return new FaveNoticeStream($this->getTarget()->getID(), $own);
+        return new FaveNoticeStream($this->getTarget(), $this->scoped);
     }
 
     function getFeeds()
index 826d34a36c7ee1964c04ac25f400bf47f9a386ca..864a0fc37b4a9280f09cd1ab4e6d8b83d5e495c6 100644 (file)
@@ -152,16 +152,22 @@ class Fave extends Managed_DataObject
         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)
     {
-        $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);
     }
 
+    // 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)
     {
-        $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);
     }
index d10272ac91578478d58aa589bbcfa16791d53912..10a3ec83bd82796de59174eedba4d75de755518e 100644 (file)
@@ -42,19 +42,15 @@ if (!defined('GNUSOCIAL')) { exit(1); }
  */
 class FaveNoticeStream extends ScopingNoticeStream
 {
-    function __construct($user_id, $own, $profile = -1)
+    function __construct(Profile $target, Profile $scoped=null)
     {
-        $stream = new RawFaveNoticeStream($user_id, $own);
-        if ($own) {
+        $stream = new RawFaveNoticeStream($target, $scoped);
+        if ($target->sameAs($scoped)) {
             $key = 'fave:ids_by_user_own:'.$user_id;
         } else {
             $key = 'fave:ids_by_user:'.$user_id;
         }
-        if (is_int($profile) && $profile == -1) {
-            $profile = Profile::current();
-        }
-        parent::__construct(new CachingNoticeStream($stream, $key),
-                            $profile);
+        parent::__construct(new CachingNoticeStream($stream, $key), $scoped);
     }
 }
 
@@ -75,12 +71,12 @@ class RawFaveNoticeStream extends NoticeStream
 
     protected $selectVerbs = array();
 
-    function __construct($user_id, $own)
+    function __construct(Profile $target, Profile $scoped=null)
     {
         parent::__construct();
 
-        $this->user_id = $user_id;
-        $this->own     = $own;
+        $this->user_id = $target->getID();
+        $this->own     = $target->sameAs($scoped);
     }
 
     /**
index eeba5412388324d1863c536e03b19c39d445079f..6ef564d32f4dd32f152ef5fdf194dadf7660f383 100644 (file)
  * @link      http://status.net/
  */
 
-if (!defined('STATUSNET')) {
-    // This check helps protect against security problems;
-    // your code file can't be executed directly from the web.
-    exit(1);
-}
+if (!defined('GNUSOCIAL')) { exit(1); }
 
 /**
  * Stream of notices sorted by popularity
@@ -47,12 +43,12 @@ if (!defined('STATUSNET')) {
 
 class PopularNoticeStream extends ScopingNoticeStream
 {
-    function __construct($profile=null)
+    function __construct(Profile $scoped=null)
     {
         parent::__construct(new CachingNoticeStream(new RawPopularNoticeStream(),
                                                     'popular',
                                                     false),
-                            $profile);
+                            $scoped);
     }
 }
 
index 21bdf62eaa94594a5c7615e3dcaa46ddcc61f09c..77e722e3efdd24c7d6c8ed452dd9555dcb4fbcb9 100644 (file)
@@ -27,9 +27,7 @@
  * @link      http://status.net/
  */
 
-if (!defined('STATUSNET')) {
-    exit(1);
-}
+if (!defined('GNUSOCIAL')) { exit(1); }
 
 /**
  * Show a map of user's notices
index 4e3e34162b15acb33feee43a98937ea6683aae98..ecbbefb1cce9b9891737d01e16afeefa80360ee7 100644 (file)
  * @link      http://status.net/
  */
 
-if (!defined('STATUSNET')) {
-    // This check helps protect against security problems;
-    // your code file can't be executed directly from the web.
-    exit(1);
-}
+if (!defined('GNUSOCIAL')) { exit(1); }
 
 /**
  * Stream of notices repeated by me
@@ -47,14 +43,11 @@ if (!defined('STATUSNET')) {
 
 class RepeatedByMeNoticeStream extends ScopingNoticeStream
 {
-    function __construct($user, $profile = -1)
+    function __construct(Profile $target, Profile $scoped=null)
     {
-        if (is_int($profile) && $profile == -1) {
-            $profile = Profile::current();
-        }
-        parent::__construct(new CachingNoticeStream(new RawRepeatedByMeNoticeStream($user),
-                                                    'user:repeated_by_me:'.$user->id),
-                            $profile);
+        parent::__construct(new CachingNoticeStream(new RawRepeatedByMeNoticeStream($target),
+                                                    'user:repeated_by_me:'.$target->getID()),
+                            $scoped);
     }
 }
 
@@ -71,11 +64,11 @@ class RepeatedByMeNoticeStream extends ScopingNoticeStream
 
 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)
@@ -85,7 +78,7 @@ class RawRepeatedByMeNoticeStream extends NoticeStream
         $notice->selectAdd(); // clears it
         $notice->selectAdd('id');
 
-        $notice->profile_id = $this->user->id;
+        $notice->profile_id = $this->target->getID();
         $notice->whereAdd('repeat_of IS NOT NULL');
 
         $notice->orderBy('created DESC, id DESC');
@@ -110,4 +103,4 @@ class RawRepeatedByMeNoticeStream extends NoticeStream
 
         return $ids;
     }
-}
\ No newline at end of file
+}
index ec80d8431447c10fadb929728ecc4f04055fa908..672e3dd973cb541d1078318b9ad53e02ac352bb9 100644 (file)
  * @link      http://status.net/
  */
 
-if (!defined('STATUSNET')) {
-    // This check helps protect against security problems;
-    // your code file can't be executed directly from the web.
-    exit(1);
-}
+if (!defined('GNUSOCIAL')) { exit(1); }
 
 /**
  * Stream of notices that are repeats of mine
@@ -47,14 +43,11 @@ if (!defined('STATUSNET')) {
 
 class RepeatsOfMeNoticeStream extends ScopingNoticeStream
 {
-    function __construct($user, $profile=-1)
+    function __construct(Profile $target, Profile $scoped=null)
     {
-        if (is_int($profile) && $profile == -1) {
-            $profile = Profile::current();
-        }
-        parent::__construct(new CachingNoticeStream(new RawRepeatsOfMeNoticeStream($user),
-                                                    'user:repeats_of_me:'.$user->id),
-                            $profile);
+        parent::__construct(new CachingNoticeStream(new RawRepeatsOfMeNoticeStream($target),
+                                                    'user:repeats_of_me:'.$target->getID()),
+                            $scoped);
     }
 }
 
@@ -70,11 +63,11 @@ class RepeatsOfMeNoticeStream extends ScopingNoticeStream
  */
 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)
@@ -82,7 +75,7 @@ class RawRepeatsOfMeNoticeStream extends NoticeStream
         $qry =
           'SELECT DISTINCT original.id AS id ' .
           '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');
         if ($since) {