From a70e68e09c4d936a88847d7623b43264050c7312 Mon Sep 17 00:00:00 2001 From: Brion Vibber Date: Mon, 28 Mar 2011 16:12:51 -0700 Subject: [PATCH] Work in progress: can create & cancel sub requests --- classes/Profile.php | 11 +++++++++++ classes/Subscription_queue.php | 21 ++++++++++++++------- classes/User.php | 6 ++++++ lib/accountprofileblock.php | 3 +++ lib/router.php | 3 ++- 5 files changed, 36 insertions(+), 8 deletions(-) diff --git a/classes/Profile.php b/classes/Profile.php index 98fe9ede2f..94e709b508 100644 --- a/classes/Profile.php +++ b/classes/Profile.php @@ -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? diff --git a/classes/Subscription_queue.php b/classes/Subscription_queue.php index e7572ae725..3e254dfce1 100644 --- a/classes/Subscription_queue.php +++ b/classes/Subscription_queue.php @@ -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); } } diff --git a/classes/User.php b/classes/User.php index 5945456b18..f395dc1e49 100644 --- a/classes/User.php +++ b/classes/User.php @@ -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) diff --git a/lib/accountprofileblock.php b/lib/accountprofileblock.php index a8bdb4715b..6a4021bf04 100644 --- a/lib/accountprofileblock.php +++ b/lib/accountprofileblock.php @@ -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(); diff --git a/lib/router.php b/lib/router.php index fa9fe9aee1..2cbb1ad649 100644 --- a/lib/router.php +++ b/lib/router.php @@ -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',