From 357296baebfe63e1b41efac448951c029609cfb0 Mon Sep 17 00:00:00 2001 From: tenma Date: Mon, 12 Aug 2019 04:53:43 +0100 Subject: [PATCH] [CORE] Fix subscription-related functions from the Profile class The undifined variable $private_stream, from the User class, was causing undifined behavior from calling requiresSubscriptionApproval. The is_null test was added to fix this problem. --- classes/Profile.php | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/classes/Profile.php b/classes/Profile.php index 266883664a..4b5badc663 100644 --- a/classes/Profile.php +++ b/classes/Profile.php @@ -793,7 +793,7 @@ class Profile extends Managed_DataObject return is_null($other) ? false : $other->isSubscribed($this); } - function requiresSubscriptionApproval(Profile $other=null) + function requiresSubscriptionApproval(Profile $other=null): bool { if (!$this->isLocal()) { // We don't know for remote users, and we'll always be able to send @@ -809,7 +809,7 @@ class Profile extends Managed_DataObject // If the local user either has a private stream (implies the following) // or user has a moderation policy for new subscriptions, return true. - return $this->getUser()->private_stream || $this->getUser()->subscribe_policy === User::SUBSCRIBE_POLICY_MODERATE; + return $this->isPrivateStream() || $this->getUser()->subscribe_policy === User::SUBSCRIBE_POLICY_MODERATE; } /** @@ -1792,13 +1792,14 @@ class Profile extends Managed_DataObject return $this->getUser()->shortenLinks($text, $always); } - public function isPrivateStream() + public function isPrivateStream(): bool { // We only know of public remote users as of yet... if (!$this->isLocal()) { return false; } - return $this->getUser()->private_stream ? true : false; + $private_stream = $this->getUser()->private_stream; + return !is_null($private_stream) && $private_stream; } public function delPref($namespace, $topic) {