We are no longer offering accounts on this server. Consider https://gitlab.freedesktop.org/ as a place to host projects.

Commit 79c40bc7 authored by mattl's avatar mattl

Type-aware comparison is necessary for Notice is_local/scope

parent b6aeff89
......@@ -997,15 +997,13 @@ class Notice extends Managed_DataObject
}
static public function figureOutScope(Profile $actor, array $groups, $scope=null) {
if (is_null($scope)) {
$scope = self::defaultScope();
}
$scope = is_null($scope) ? self::defaultScope() : intval($scope);
// For private streams
try {
$user = $actor->getUser();
// 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;
}
} catch (NoSuchUserException $e) {
......@@ -2489,8 +2487,13 @@ class Notice extends Managed_DataObject
public function isLocal()
{
return ($this->is_local == Notice::LOCAL_PUBLIC ||
$this->is_local == Notice::LOCAL_NONPUBLIC);
$is_local = intval($this->is_local);
return ($is_local === self::LOCAL_PUBLIC || $is_local === self::LOCAL_NONPUBLIC);
}
public function getScope()
{
return intval($this->scope);
}
public function isRepeat()
......@@ -2683,13 +2686,9 @@ class Notice extends Managed_DataObject
protected function _inScope($profile)
{
if (!is_null($this->scope)) {
$scope = $this->scope;
} else {
$scope = self::defaultScope();
}
$scope = is_null($this->scope) ? self::defaultScope() : $this->getScope();
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);
}
......
......@@ -818,7 +818,7 @@ class User_group extends Managed_DataObject
function isPrivate()
{
return ($this->join_policy == self::JOIN_POLICY_MODERATE &&
$this->force_scope == 1);
intval($this->force_scope) === 1);
}
public function isLocal()
......
......@@ -38,8 +38,7 @@ class ImQueueHandler extends QueueHandler
function handle($notice)
{
$this->plugin->broadcastNotice($notice);
if ($notice->is_local == Notice::LOCAL_PUBLIC ||
$notice->is_local == Notice::LOCAL_NONPUBLIC) {
if ($notice->isLocal()) {
$this->plugin->publicNotice($notice);
}
return true;
......
......@@ -40,22 +40,9 @@ class FacebookQueueHandler extends QueueHandler
function handle($notice)
{
if ($this->_isLocal($notice)) {
if ($notice->isLocal()) {
return Facebookclient::facebookBroadcastNotice($notice);
}
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);
}
}
......@@ -96,7 +96,7 @@ class GeoURLPlugin extends Plugin
*/
function onHandleQueuedNotice(&$notice)
{
if ($notice->is_local == 1) {
if (intval($notice->is_local) === Notice::LOCAL_PUBLIC) {
$request = HTTPClient::start();
......
......@@ -60,7 +60,7 @@ class LinkbackPlugin extends Plugin
function onHandleQueuedNotice($notice)
{
if ($notice->is_local == 1) {
if (intval($notice->is_local) === Notice::LOCAL_PUBLIC) {
// Try to avoid actually mucking with the
// notice content
$c = $notice->content;
......
......@@ -173,8 +173,9 @@ class RealtimePlugin extends Plugin
// Add to the public timeline
if ($notice->is_local == Notice::LOCAL_PUBLIC ||
($notice->is_local == Notice::REMOTE && !common_config('public', 'localonly'))) {
$is_local = intval($notice->is_local);
if ($is_local === Notice::LOCAL_PUBLIC ||
($is_local === Notice::REMOTE && !common_config('public', 'localonly'))) {
$paths[] = array('public', null, null);
}
......
......@@ -231,8 +231,9 @@ class SharePlugin extends ActivityVerbHandlerPlugin
public function onEndShowNoticeOptionItems($nli)
{
// FIXME: Use bitmasks (but be aware that PUBLIC_SCOPE is 0!)
if ($nli->notice->scope == Notice::PUBLIC_SCOPE ||
$nli->notice->scope == Notice::SITE_SCOPE) {
// Also: AHHH, $scope and $scoped are scarily similar looking.
$scope = $nli->notice->getScope();
if ($scope === Notice::PUBLIC_SCOPE || $scope === Notice::SITE_SCOPE) {
$scoped = Profile::current();
if ($scoped instanceof Profile &&
$scoped->getID() !== $nli->notice->getProfile()->getID()) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment