diff --git a/actions/subscribe.php b/actions/subscribe.php index 3837915d53..fad153fc6e 100644 --- a/actions/subscribe.php +++ b/actions/subscribe.php @@ -139,8 +139,8 @@ class SubscribeAction extends Action { // Throws exception on error - Subscription::start($this->user->getProfile(), - $this->other); + $sub = Subscription::start($this->user->getProfile(), + $this->other); if ($this->boolean('ajax')) { $this->startHTML('text/xml;charset=utf-8'); @@ -149,8 +149,12 @@ class SubscribeAction extends Action $this->element('title', null, _('Subscribed')); $this->elementEnd('head'); $this->elementStart('body'); - $unsubscribe = new UnsubscribeForm($this, $this->other); - $unsubscribe->show(); + if ($sub instanceof Subscription) { + $form = new UnsubscribeForm($this, $this->other); + } else { + $form = new CancelSubscriptionForm($this, $this->other); + } + $form->show(); $this->elementEnd('body'); $this->elementEnd('html'); } else { diff --git a/classes/Profile.php b/classes/Profile.php index b582451350..9a145a0018 100644 --- a/classes/Profile.php +++ b/classes/Profile.php @@ -363,6 +363,47 @@ class Profile extends Memcached_DataObject } } + /** + * Request a subscription to another local or remote profile. + * This will result in either the subscription going through + * immediately, being queued for approval, or being rejected + * immediately. + * + * @param Profile $profile + * @return mixed: Subscription or Subscription_queue object on success + * @throws Exception of various types on invalid state + */ + function subscribe($profile) + { + // + } + + /** + * Cancel an outstanding subscription request to the other profile. + * + * @param Profile $profile + */ + function cancelSubscribe($profile) + { + $request = Subscribe_join_queue::pkeyGet(array('subscriber' => $this->id, + 'subscribed' => $profile->id)); + if ($request) { + if (Event::handle('StartCancelSubscription', array($this, $profile))) { + $request->delete(); + Event::handle('EndCancelSubscription', array($this, $profile)); + } + } + } + + /** + * + * @param $profile + */ + function completeSubscribe($profile) + { + + } + function getSubscriptions($offset=0, $limit=null) { $subs = Subscription::bySubscriber($this->id,