]> git.mxchange.org Git - quix0rs-gnu-social.git/commitdiff
Work in progress: can create & cancel sub requests
authorBrion Vibber <brion@pobox.com>
Mon, 28 Mar 2011 23:12:51 +0000 (16:12 -0700)
committerBrion Vibber <brion@pobox.com>
Mon, 28 Mar 2011 23:12:51 +0000 (16:12 -0700)
classes/Profile.php
classes/Subscription_queue.php
classes/User.php
lib/accountprofileblock.php
lib/router.php

index 98fe9ede2facf0bcf7fc700291ed1e534f7cf84c..94e709b5084c83979e141d33286d00b235858262 100644 (file)
@@ -413,6 +413,17 @@ class Profile extends Memcached_DataObject
     {
         return Subscription::exists($this, $other);
     }
+    
+    /**
+     * Check if a pending subscription request is outstanding for this...
+     *
+     * @param Profile $other
+     * @return boolean
+     */
+    function hasPendingSubscription($other)
+    {
+        return Subscription_queue::exists($this, $other);
+    }
 
     /**
      * Are these two profiles subscribed to each other?
index e7572ae7258654ad6681e448cf01ad31f38d559f..3e254dfce1dcb732b97a5cbb490b1390c45d566e 100644 (file)
@@ -36,19 +36,19 @@ class Subscription_queue extends Managed_DataObject
             ),
             'primary key' => array('subscriber', 'subscribed'),
             'indexes' => array(
-                'group_join_queue_profile_id_created_idx' => array('subscriber', 'created'),
-                'group_join_queue_group_id_created_idx' => array('subscribed', 'created'),
+                'subscription_queue_subscriber_created_idx' => array('subscriber', 'created'),
+                'subscription_queue_subscribed_created_idx' => array('subscribed', 'created'),
             ),
             'foreign keys' => array(
-                'group_join_queue_subscriber_fkey' => array('profile', array('subscriber' => 'id')),
-                'group_join_queue_subscribed_fkey' => array('profile', array('subscribed' => 'id')),
+                'subscription_queue_subscriber_fkey' => array('profile', array('subscriber' => 'id')),
+                'subscription_queue_subscribed_fkey' => array('profile', array('subscribed' => 'id')),
             )
         );
     }
 
-    public static function saveNew(Profile $subscriber, Profile $other)
+    public static function saveNew(Profile $subscriber, Profile $subscribed)
     {
-        $rq = new Group_join_queue();
+        $rq = new Subscription_queue();
         $rq->subscriber = $subscriber->id;
         $rq->subscribed = $subscribed->id;
         $rq->created = common_sql_now();
@@ -56,6 +56,13 @@ class Subscription_queue extends Managed_DataObject
         return $rq;
     }
 
+    function exists($subscriber, $other)
+    {
+        $sub = Subscription_queue::pkeyGet(array('subscriber' => $subscriber->id,
+                                                 'subscribed' => $other->id));
+        return (empty($sub)) ? false : true;
+    }
+
     /**
      * Complete a pending subscription, as we've got approval of some sort.
      *
@@ -93,6 +100,6 @@ class Subscription_queue extends Managed_DataObject
     {
         $subscriber = Profile::staticGet('id', $this->subscriber);
         $subscribed = Profile::staticGet('id', $this->subscribed);
-        mail_notify_subscription_pending($subscribed, $subscriber);
+        //mail_notify_subscription_pending($subscribed, $subscriber);
     }
 }
index 5945456b1814b4002466049e5179526c526f6340..f395dc1e49eab43cffe50ea2bfef13ae0b07dd6d 100644 (file)
@@ -90,6 +90,12 @@ class User extends Memcached_DataObject
         return $profile->isSubscribed($other);
     }
 
+    function hasPendingSubscription($other)
+    {
+        $profile = $this->getProfile();
+        return $profile->hasPendingSubscription($other);
+    }
+
     // 'update' won't write key columns, so we have to do it ourselves.
 
     function updateKeys(&$orig)
index a8bdb4715bf5794e8025ac0c699d3b1434dab15e..6a4021bf04577b024eeac23d7ee6cd3d892b10a4 100644 (file)
@@ -144,6 +144,9 @@ class AccountProfileBlock extends ProfileBlock
                         if ($cur->isSubscribed($this->profile)) {
                             $usf = new UnsubscribeForm($this->out, $this->profile);
                             $usf->show();
+                        } else if ($cur->hasPendingSubscription($this->profile)) {
+                            $sf = new CancelSubscriptionForm($this->out, $this->profile);
+                            $sf->show();
                         } else {
                             $sf = new SubscribeForm($this->out, $this->profile);
                             $sf->show();
index fa9fe9aee16e3b0a978d6133251a807f6faa0398..2cbb1ad649702844fa59582b8610f106b36a4213 100644 (file)
@@ -199,7 +199,8 @@ class Router
             // main stuff is repetitive
 
             $main = array('login', 'logout', 'register', 'subscribe',
-                          'unsubscribe', 'confirmaddress', 'recoverpassword',
+                          'unsubscribe', 'cancelsubscription',
+                          'confirmaddress', 'recoverpassword',
                           'invite', 'favor', 'disfavor', 'sup',
                           'block', 'unblock', 'subedit',
                           'groupblock', 'groupunblock',