]> git.mxchange.org Git - quix0rs-gnu-social.git/blobdiff - actions/unsubscribe.php
Make better use of Subscription class
[quix0rs-gnu-social.git] / actions / unsubscribe.php
index 8adfff9cf63ffeb450ec955a8742e28c33b9aa62..8679ea6256bbf6a4b0b16b030398d7f1503b2d27 100644 (file)
@@ -53,11 +53,9 @@ class UnsubscribeAction extends Action
             return;
         }
 
-        $user = common_current_user();
-
         if ($_SERVER['REQUEST_METHOD'] != 'POST') {
             common_redirect(common_local_url('subscriptions',
-                                             array('nickname' => $user->nickname)));
+                                             array('nickname' => $this->scoped->nickname)));
             return;
         }
 
@@ -82,17 +80,16 @@ class UnsubscribeAction extends Action
 
         $other = Profile::getKV('id', $other_id);
 
-        if (!$other) {
+        if (!($other instanceof Profile)) {
             // TRANS: Client error displayed when trying to unsubscribe while providing a non-existing profile ID.
             $this->clientError(_('No profile with that ID.'));
             return;
         }
 
-        $result = subs_unsubscribe_to($user, $other);
-
-        if (is_string($result)) {
-            $this->clientError($result);
-            return;
+        try {
+            Subscription::cancel($this->scoped, $other);
+        } catch (Exception $e) {
+            $this->clientError($e->getMessage());
         }
 
         if ($this->boolean('ajax')) {
@@ -108,7 +105,7 @@ class UnsubscribeAction extends Action
             $this->elementEnd('html');
         } else {
             common_redirect(common_local_url('subscriptions',
-                                             array('nickname' => $user->nickname)),
+                                             array('nickname' => $this->scoped->nickname)),
                             303);
         }
     }