Commit a70e68e0 authored by Brion Vibber's avatar Brion Vibber

Work in progress: can create & cancel sub requests

parent df5def8c
......@@ -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?
......
......@@ -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);
}
}
......@@ -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)
......
......@@ -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();
......
......@@ -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',
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment