]> git.mxchange.org Git - quix0rs-gnu-social.git/commitdiff
OStatus: be a little laxer about attempts to start/stop PuSH subscriptions that were...
authorBrion Vibber <brion@pobox.com>
Fri, 19 Mar 2010 22:47:43 +0000 (15:47 -0700)
committerBrion Vibber <brion@pobox.com>
Fri, 19 Mar 2010 22:47:43 +0000 (15:47 -0700)
Instead of aborting, we'll try to reconfirm the sub/unsub, which once confirmed will replace whatever the previous state was on the server side.

plugins/OStatus/classes/FeedSub.php
plugins/OStatus/classes/Ostatus_profile.php

index 80ba37bc111aefaaeaee9059a0472a4c2cb4cb7f..b10509dae6c31806c7f182781a5c4bb75932161d 100644 (file)
@@ -61,7 +61,7 @@ class FeedSub extends Memcached_DataObject
     public $__table = 'feedsub';
 
     public $id;
-    public $feeduri;
+    public $uri;
 
     // PuSH subscription data
     public $huburi;
@@ -238,7 +238,7 @@ class FeedSub extends Memcached_DataObject
     public function subscribe($mode='subscribe')
     {
         if ($this->sub_state && $this->sub_state != 'inactive') {
-            throw new ServerException("Attempting to start PuSH subscription to feed in state $this->sub_state");
+            common_log(LOG_WARNING, "Attempting to (re)start PuSH subscription to $this->uri in unexpected state $this->sub_state");
         }
         if (empty($this->huburi)) {
             if (common_config('feedsub', 'nohub')) {
@@ -261,7 +261,7 @@ class FeedSub extends Memcached_DataObject
      */
     public function unsubscribe() {
         if ($this->sub_state != 'active') {
-            throw new ServerException("Attempting to end PuSH subscription to feed in state $this->sub_state");
+            common_log(LOG_WARNING, "Attempting to (re)end PuSH subscription to $this->uri in unexpected state $this->sub_state");
         }
         if (empty($this->huburi)) {
             if (common_config('feedsub', 'nohub')) {
index e0e0223b8f950cd4382104790b1f489a54cd910a..bff6ff209ba3c04055122a8419f1c7308a2eb17d 100644 (file)
@@ -204,12 +204,13 @@ class Ostatus_profile extends Memcached_DataObject
     public function subscribe()
     {
         $feedsub = FeedSub::ensureFeed($this->feeduri);
-        if ($feedsub->sub_state == 'active' || $feedsub->sub_state == 'subscribe') {
+        if ($feedsub->sub_state == 'active') {
+            // Active subscription, we don't need to do anything.
             return true;
-        } else if ($feedsub->sub_state == '' || $feedsub->sub_state == 'inactive') {
+        } else {
+            // Inactive or we got left in an inconsistent state.
+            // Run a subscription request to make sure we're current!
             return $feedsub->subscribe();
-        } else if ('unsubscribe') {
-            throw new FeedSubException("Unsub is pending, can't subscribe...");
         }
     }
 
@@ -222,15 +223,13 @@ class Ostatus_profile extends Memcached_DataObject
      */
     public function unsubscribe() {
         $feedsub = FeedSub::staticGet('uri', $this->feeduri);
-        if (!$feedsub) {
+        if (!$feedsub || $feedsub->sub_state == '' || $feedsub->sub_state == 'inactive') {
+            // No active PuSH subscription, we can just leave it be.
             return true;
-        }
-        if ($feedsub->sub_state == 'active') {
+        } else {
+            // PuSH subscription is either active or in an indeterminate state.
+            // Send an unsubscribe.
             return $feedsub->unsubscribe();
-        } else if ($feedsub->sub_state == '' || $feedsub->sub_state == 'inactive' || $feedsub->sub_state == 'unsubscribe') {
-            return true;
-        } else if ($feedsub->sub_state == 'subscribe') {
-            throw new FeedSubException("Feed is awaiting subscription, can't unsub...");
         }
     }