Type-aware comparison is necessary for Notice is_local/scope

This commit is contained in:
Mikael Nordfeldth 2015-10-14 00:27:51 +02:00
parent b6aeff89c4
commit 79c40bc73b
8 changed files with 22 additions and 35 deletions

View File

@ -997,15 +997,13 @@ class Notice extends Managed_DataObject
} }
static public function figureOutScope(Profile $actor, array $groups, $scope=null) { static public function figureOutScope(Profile $actor, array $groups, $scope=null) {
if (is_null($scope)) { $scope = is_null($scope) ? self::defaultScope() : intval($scope);
$scope = self::defaultScope();
}
// For private streams // For private streams
try { try {
$user = $actor->getUser(); $user = $actor->getUser();
// FIXME: We can't do bit comparison with == (Legacy StatusNet thing. Let's keep it for now.) // FIXME: We can't do bit comparison with == (Legacy StatusNet thing. Let's keep it for now.)
if ($user->private_stream && ($scope == Notice::PUBLIC_SCOPE || $scope == Notice::SITE_SCOPE)) { if ($user->private_stream && ($scope === Notice::PUBLIC_SCOPE || $scope === Notice::SITE_SCOPE)) {
$scope |= Notice::FOLLOWER_SCOPE; $scope |= Notice::FOLLOWER_SCOPE;
} }
} catch (NoSuchUserException $e) { } catch (NoSuchUserException $e) {
@ -2489,8 +2487,13 @@ class Notice extends Managed_DataObject
public function isLocal() public function isLocal()
{ {
return ($this->is_local == Notice::LOCAL_PUBLIC || $is_local = intval($this->is_local);
$this->is_local == Notice::LOCAL_NONPUBLIC); return ($is_local === self::LOCAL_PUBLIC || $is_local === self::LOCAL_NONPUBLIC);
}
public function getScope()
{
return intval($this->scope);
} }
public function isRepeat() public function isRepeat()
@ -2683,13 +2686,9 @@ class Notice extends Managed_DataObject
protected function _inScope($profile) protected function _inScope($profile)
{ {
if (!is_null($this->scope)) { $scope = is_null($this->scope) ? self::defaultScope() : $this->getScope();
$scope = $this->scope;
} else {
$scope = self::defaultScope();
}
if ($scope == 0 && !$this->getProfile()->isPrivateStream()) { // Not scoping, so it is public. if ($scope === 0 && !$this->getProfile()->isPrivateStream()) { // Not scoping, so it is public.
return !$this->isHiddenSpam($profile); return !$this->isHiddenSpam($profile);
} }

View File

@ -818,7 +818,7 @@ class User_group extends Managed_DataObject
function isPrivate() function isPrivate()
{ {
return ($this->join_policy == self::JOIN_POLICY_MODERATE && return ($this->join_policy == self::JOIN_POLICY_MODERATE &&
$this->force_scope == 1); intval($this->force_scope) === 1);
} }
public function isLocal() public function isLocal()

View File

@ -38,8 +38,7 @@ class ImQueueHandler extends QueueHandler
function handle($notice) function handle($notice)
{ {
$this->plugin->broadcastNotice($notice); $this->plugin->broadcastNotice($notice);
if ($notice->is_local == Notice::LOCAL_PUBLIC || if ($notice->isLocal()) {
$notice->is_local == Notice::LOCAL_NONPUBLIC) {
$this->plugin->publicNotice($notice); $this->plugin->publicNotice($notice);
} }
return true; return true;

View File

@ -40,22 +40,9 @@ class FacebookQueueHandler extends QueueHandler
function handle($notice) function handle($notice)
{ {
if ($this->_isLocal($notice)) { if ($notice->isLocal()) {
return Facebookclient::facebookBroadcastNotice($notice); return Facebookclient::facebookBroadcastNotice($notice);
} }
return true; return true;
} }
/**
* Determine whether the notice was locally created
*
* @param Notice $notice the notice
*
* @return boolean locality
*/
function _isLocal($notice)
{
return ($notice->is_local == Notice::LOCAL_PUBLIC ||
$notice->is_local == Notice::LOCAL_NONPUBLIC);
}
} }

View File

@ -96,7 +96,7 @@ class GeoURLPlugin extends Plugin
*/ */
function onHandleQueuedNotice(&$notice) function onHandleQueuedNotice(&$notice)
{ {
if ($notice->is_local == 1) { if (intval($notice->is_local) === Notice::LOCAL_PUBLIC) {
$request = HTTPClient::start(); $request = HTTPClient::start();

View File

@ -60,7 +60,7 @@ class LinkbackPlugin extends Plugin
function onHandleQueuedNotice($notice) function onHandleQueuedNotice($notice)
{ {
if ($notice->is_local == 1) { if (intval($notice->is_local) === Notice::LOCAL_PUBLIC) {
// Try to avoid actually mucking with the // Try to avoid actually mucking with the
// notice content // notice content
$c = $notice->content; $c = $notice->content;

View File

@ -173,8 +173,9 @@ class RealtimePlugin extends Plugin
// Add to the public timeline // Add to the public timeline
if ($notice->is_local == Notice::LOCAL_PUBLIC || $is_local = intval($notice->is_local);
($notice->is_local == Notice::REMOTE && !common_config('public', 'localonly'))) { if ($is_local === Notice::LOCAL_PUBLIC ||
($is_local === Notice::REMOTE && !common_config('public', 'localonly'))) {
$paths[] = array('public', null, null); $paths[] = array('public', null, null);
} }

View File

@ -231,8 +231,9 @@ class SharePlugin extends ActivityVerbHandlerPlugin
public function onEndShowNoticeOptionItems($nli) public function onEndShowNoticeOptionItems($nli)
{ {
// FIXME: Use bitmasks (but be aware that PUBLIC_SCOPE is 0!) // FIXME: Use bitmasks (but be aware that PUBLIC_SCOPE is 0!)
if ($nli->notice->scope == Notice::PUBLIC_SCOPE || // Also: AHHH, $scope and $scoped are scarily similar looking.
$nli->notice->scope == Notice::SITE_SCOPE) { $scope = $nli->notice->getScope();
if ($scope === Notice::PUBLIC_SCOPE || $scope === Notice::SITE_SCOPE) {
$scoped = Profile::current(); $scoped = Profile::current();
if ($scoped instanceof Profile && if ($scoped instanceof Profile &&
$scoped->getID() !== $nli->notice->getProfile()->getID()) { $scoped->getID() !== $nli->notice->getProfile()->getID()) {