X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=classes%2FNotice.php;h=13b37993858301e7c3de3f7b9db5df8fd1c1a29a;hb=753019baf27281370e91084d3766e59fa80b66f1;hp=630da81106543d604274893a892c33981896d206;hpb=b3e61ce7d07f73feb8a17d16486d15b72926b4e9;p=quix0rs-gnu-social.git diff --git a/classes/Notice.php b/classes/Notice.php index 630da81106..13b3799385 100644 --- a/classes/Notice.php +++ b/classes/Notice.php @@ -130,11 +130,6 @@ class Notice extends Managed_DataObject return $def; } - - function multiGet($kc, $kvs, $skipNulls=true) - { - return Memcached_DataObject::multiGet('Notice', $kc, $kvs, $skipNulls); - } /* Notice types */ const LOCAL_PUBLIC = 1; @@ -468,7 +463,7 @@ class Notice extends Managed_DataObject // If the original is private to a group, and notice has no group specified, // make it to the same group(s) - if (empty($groups) && ($reply->scope | Notice::GROUP_SCOPE)) { + if (empty($groups) && ($reply->scope & Notice::GROUP_SCOPE)) { $groups = array(); $replyGroups = $reply->getGroups(); foreach ($replyGroups as $group) { @@ -527,14 +522,16 @@ class Notice extends Managed_DataObject // For private streams - $user = $profile->getUser(); + try { + $user = $profile->getUser(); - if (!empty($user)) { if ($user->private_stream && ($notice->scope == Notice::PUBLIC_SCOPE || $notice->scope == Notice::SITE_SCOPE)) { $notice->scope |= Notice::FOLLOWER_SCOPE; } + } catch (NoSuchUserException $e) { + // Cannot handle private streams for remote profiles } // Force the scope for private groups @@ -831,7 +828,7 @@ class Notice extends Managed_DataObject $ids[] = $f2p->file_id; } - $files = Memcached_DataObject::multiGet('File', 'id', $ids); + $files = File::multiGet('id', $ids); $this->_attachments = $files->fetchAll(); @@ -923,23 +920,26 @@ class Notice extends Managed_DataObject if ($root !== false && $root->inScope($profile)) { return $root; - } else { - $last = $this; + } - do { - $parent = $last->getOriginal(); - if (!empty($parent) && $parent->inScope($profile)) { + $last = $this; + while (true) { + try { + $parent = $last->getParent(); + if ($parent->inScope($profile)) { $last = $parent; continue; - } else { - $root = $last; - break; } - } while (!empty($parent)); - - self::cacheSet($keypart, $root); + } catch (Exception $e) { + // Latest notice has no parent + } + // No parent, or parent out of scope + $root = $last; + break; } + self::cacheSet($keypart, $root); + return $root; } @@ -1305,17 +1305,15 @@ class Notice extends Managed_DataObject $replied = array(); // If it's a reply, save for the replied-to author - - if (!empty($this->reply_to)) { - $original = $this->getOriginal(); - if (!empty($original)) { // that'd be weird - $author = $original->getProfile(); - if (!empty($author)) { - $this->saveReply($author->id); - $replied[$author->id] = 1; - self::blow('reply:stream:%d', $author->id); - } + try { + $author = $this->getParent()->getProfile(); + if ($author instanceof Profile) { + $this->saveReply($author->id); + $replied[$author->id] = 1; + self::blow('reply:stream:%d', $author->id); } + } catch (Exception $e) { + // Not a reply, since it has no parent! } // @todo ideally this parser information would only @@ -2425,11 +2423,8 @@ class Notice extends Managed_DataObject // Only for users on this site - if ($scope & Notice::SITE_SCOPE) { - $user = $profile->getUser(); - if (empty($user)) { - return false; - } + if (($scope & Notice::SITE_SCOPE) && !$profile->isLocal()) { + return false; } // Only for users mentioned in the notice @@ -2534,18 +2529,21 @@ class Notice extends Managed_DataObject return $groups; } - protected $_original = -1; + protected $_parent = -1; - function getOriginal() + public function getParent() { - if (is_int($this->_original) && $this->_original == -1) { - if (empty($this->reply_to)) { - $this->_original = null; - } else { - $this->_original = Notice::getKV('id', $this->reply_to); - } + if (empty($this->reply_to)) { + // Should this also be NoResultException? I don't think so. + throw new Exception('Notice has no parent'); + } elseif ($this->_parent === -1) { // local object cache + $this->_parent = Notice::getKV('id', $this->reply_to); + } + + if (!($this->_parent instanceof Notice)) { + throw new NoResultException($this->_parent); } - return $this->_original; + return $this->_parent; } /** @@ -2561,7 +2559,7 @@ class Notice extends Managed_DataObject function __sleep() { $vars = parent::__sleep(); - $skip = array('_original', '_profile', '_groups', '_attachments', '_faves', '_replies', '_repeats'); + $skip = array('_parent', '_profile', '_groups', '_attachments', '_faves', '_replies', '_repeats'); return array_diff($vars, $skip); }