Removing whitespace and creating an early-return in inScope

This commit is contained in:
Mikael Nordfeldth 2015-02-24 22:44:43 +01:00
parent 325e784ccd
commit 060dbe1b56

View File

@ -1067,13 +1067,9 @@ class Notice extends Managed_DataObject
} }
$args = func_get_args(); $args = func_get_args();
$format = array_shift($args); $format = array_shift($args);
$keyPart = vsprintf($format, $args); $keyPart = vsprintf($format, $args);
$cacheKey = Cache::key($keyPart); $cacheKey = Cache::key($keyPart);
$c->delete($cacheKey); $c->delete($cacheKey);
// delete the "last" stream, too, if this notice is // delete the "last" stream, too, if this notice is
@ -1194,17 +1190,13 @@ class Notice extends Managed_DataObject
} }
$f2ps = File_to_post::listGet('post_id', array($this->id)); $f2ps = File_to_post::listGet('post_id', array($this->id));
$ids = array(); $ids = array();
foreach ($f2ps[$this->id] as $f2p) { foreach ($f2ps[$this->id] as $f2p) {
$ids[] = $f2p->file_id; $ids[] = $f2p->file_id;
} }
$files = File::multiGet('id', $ids); $files = File::multiGet('id', $ids);
$this->_attachments[$this->id] = $files->fetchAll(); $this->_attachments[$this->id] = $files->fetchAll();
return $this->_attachments[$this->id]; return $this->_attachments[$this->id];
} }
@ -1766,15 +1758,12 @@ class Notice extends Managed_DataObject
$ids = array(); $ids = array();
foreach ($gis[$this->id] as $gi) foreach ($gis[$this->id] as $gi) {
{
$ids[] = $gi->group_id; $ids[] = $gi->group_id;
} }
$groups = User_group::multiGet('id', $ids); $groups = User_group::multiGet('id', $ids);
$this->_groups[$this->id] = $groups->fetchAll(); $this->_groups[$this->id] = $groups->fetchAll();
return $this->_groups[$this->id]; return $this->_groups[$this->id];
} }
@ -2687,34 +2676,26 @@ class Notice extends Managed_DataObject
$scope = self::defaultScope(); $scope = self::defaultScope();
} }
// If there's no scope, anyone (even anon) is in scope. if ($scope == 0) { // Not scoping, so it is public.
if ($scope == 0) { // Not private
return !$this->isHiddenSpam($profile); return !$this->isHiddenSpam($profile);
}
} else { // Private, somehow
// If there's scope, anon cannot be in scope // If there's scope, anon cannot be in scope
if (empty($profile)) { if (empty($profile)) {
return false; return false;
} }
// Author is always in scope // Author is always in scope
if ($this->profile_id == $profile->id) { if ($this->profile_id == $profile->id) {
return true; return true;
} }
// Only for users on this site // Only for users on this site
if (($scope & Notice::SITE_SCOPE) && !$profile->isLocal()) { if (($scope & Notice::SITE_SCOPE) && !$profile->isLocal()) {
return false; return false;
} }
// Only for users mentioned in the notice // Only for users mentioned in the notice
if ($scope & Notice::ADDRESSEE_SCOPE) { if ($scope & Notice::ADDRESSEE_SCOPE) {
$reply = Reply::pkeyGet(array('notice_id' => $this->id, $reply = Reply::pkeyGet(array('notice_id' => $this->id,
@ -2726,7 +2707,6 @@ class Notice extends Managed_DataObject
} }
// Only for members of the given group // Only for members of the given group
if ($scope & Notice::GROUP_SCOPE) { if ($scope & Notice::GROUP_SCOPE) {
// XXX: just query for the single membership // XXX: just query for the single membership
@ -2748,7 +2728,6 @@ class Notice extends Managed_DataObject
} }
// Only for followers of the author // Only for followers of the author
$author = null; $author = null;
if ($scope & Notice::FOLLOWER_SCOPE) { if ($scope & Notice::FOLLOWER_SCOPE) {
@ -2766,7 +2745,6 @@ class Notice extends Managed_DataObject
return !$this->isHiddenSpam($profile); return !$this->isHiddenSpam($profile);
} }
}
function isHiddenSpam($profile) { function isHiddenSpam($profile) {
@ -2836,7 +2814,6 @@ class Notice extends Managed_DataObject
static function fillProfiles($notices) static function fillProfiles($notices)
{ {
$map = self::getProfiles($notices); $map = self::getProfiles($notices);
foreach ($notices as $entry=>$notice) { foreach ($notices as $entry=>$notice) {
try { try {
if (array_key_exists($notice->profile_id, $map)) { if (array_key_exists($notice->profile_id, $map)) {
@ -2857,22 +2834,17 @@ class Notice extends Managed_DataObject
foreach ($notices as $notice) { foreach ($notices as $notice) {
$ids[] = $notice->profile_id; $ids[] = $notice->profile_id;
} }
$ids = array_unique($ids); $ids = array_unique($ids);
return Profile::pivotGet('id', $ids); return Profile::pivotGet('id', $ids);
} }
static function fillGroups(&$notices) static function fillGroups(&$notices)
{ {
$ids = self::_idsOf($notices); $ids = self::_idsOf($notices);
$gis = Group_inbox::listGet('notice_id', $ids); $gis = Group_inbox::listGet('notice_id', $ids);
$gids = array(); $gids = array();
foreach ($gis as $id => $gi) foreach ($gis as $id => $gi) {
{
foreach ($gi as $g) foreach ($gi as $g)
{ {
$gids[] = $g->group_id; $gids[] = $g->group_id;
@ -2880,9 +2852,7 @@ class Notice extends Managed_DataObject
} }
$gids = array_unique($gids); $gids = array_unique($gids);
$group = User_group::pivotGet('id', $gids); $group = User_group::pivotGet('id', $gids);
foreach ($notices as $notice) foreach ($notices as $notice)
{ {
$grps = array(); $grps = array();
@ -2906,11 +2876,8 @@ class Notice extends Managed_DataObject
static function fillAttachments(&$notices) static function fillAttachments(&$notices)
{ {
$ids = self::_idsOf($notices); $ids = self::_idsOf($notices);
$f2pMap = File_to_post::listGet('post_id', $ids); $f2pMap = File_to_post::listGet('post_id', $ids);
$fileIds = array(); $fileIds = array();
foreach ($f2pMap as $noticeId => $f2ps) { foreach ($f2pMap as $noticeId => $f2ps) {
foreach ($f2ps as $f2p) { foreach ($f2ps as $f2p) {
$fileIds[] = $f2p->file_id; $fileIds[] = $f2p->file_id;
@ -2918,9 +2885,7 @@ class Notice extends Managed_DataObject
} }
$fileIds = array_unique($fileIds); $fileIds = array_unique($fileIds);
$fileMap = File::pivotGet('id', $fileIds); $fileMap = File::pivotGet('id', $fileIds);
foreach ($notices as $notice) foreach ($notices as $notice)
{ {
$files = array(); $files = array();