From: Mikael Nordfeldth <mmn@hethane.se>
Date: Sun, 3 Jan 2016 18:33:26 +0000 (+0100)
Subject: If a user has a private stream, assume a moderated subscription policy
X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=b374e5f08b0a5b0321ddd0ac77baf4675274aba2;p=quix0rs-gnu-social.git

If a user has a private stream, assume a moderated subscription policy
---

diff --git a/classes/Profile.php b/classes/Profile.php
index 1c8dbcc252..f4452391c2 100644
--- a/classes/Profile.php
+++ b/classes/Profile.php
@@ -772,6 +772,25 @@ class Profile extends Managed_DataObject
         return is_null($other) ? false : $other->isSubscribed($this);
     }
 
+    function requiresSubscriptionApproval(Profile $other=null)
+    {
+        if (!$this->isLocal()) {
+            // We don't know for remote users, and we'll always be able to send
+            // the request. Whether it'll work immediately or require moderation
+            // can be determined in another function.
+            return false;
+        }
+
+        // Assume that profiles _we_ subscribe to are permitted. Could be made configurable.
+        if (!is_null($other) && $this->isSubscribed($other)) {
+            return false;
+        }
+
+        // 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;
+    }
+
     /**
      * Check if a pending subscription request is outstanding for this...
      *
diff --git a/classes/Subscription.php b/classes/Subscription.php
index f77472ae70..c532a3c3de 100644
--- a/classes/Subscription.php
+++ b/classes/Subscription.php
@@ -92,8 +92,8 @@ class Subscription extends Managed_DataObject
         }
 
         if (Event::handle('StartSubscribe', array($subscriber, $other))) {
-            $otherUser = User::getKV('id', $other->id);
-            if ($otherUser instanceof User && $otherUser->subscribe_policy == User::SUBSCRIBE_POLICY_MODERATE && !$force) {
+            // unless subscription is forced, the user policy for subscription approvals is tested
+            if (!$force && $other->requiresSubscriptionApproval($subscriber)) {
                 try {
                     $sub = Subscription_queue::saveNew($subscriber, $other);
                     $sub->notify();
@@ -101,6 +101,7 @@ class Subscription extends Managed_DataObject
                     $sub = Subscription_queue::getSubQueue($subscriber, $other);
                 }
             } else {
+                $otherUser = User::getKV('id', $other->id);
                 $sub = self::saveNew($subscriber, $other);
                 $sub->notify();