]> git.mxchange.org Git - quix0rs-gnu-social.git/commitdiff
[CORE] Fix subscription-related functions from the Profile class
authortenma <brvnocasteleiro@gmail.com>
Mon, 12 Aug 2019 03:53:43 +0000 (04:53 +0100)
committerDiogo Cordeiro <diogo@fc.up.pt>
Tue, 13 Aug 2019 02:01:24 +0000 (03:01 +0100)
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

index 266883664a021cfb090be996bccc545a89481cc7..4b5badc66301b8bfdcb54129ad563e847bad15d9 100644 (file)
@@ -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) {