]> git.mxchange.org Git - quix0rs-gnu-social.git/commitdiff
- Fix bugs with block and friendship API methods
authorZach Copley <zach@status.net>
Mon, 28 Jun 2010 23:53:05 +0000 (16:53 -0700)
committerZach Copley <zach@status.net>
Mon, 28 Jun 2010 23:54:39 +0000 (16:54 -0700)
- Friendship API methods now use a Profile instead of User for target

actions/apiblockcreate.php
actions/apiblockdestroy.php
actions/apifriendshipscreate.php
actions/apifriendshipsdestroy.php
actions/apifriendshipsexists.php
lib/apiaction.php

index c26485f591b23196917eb07f3fcc8b65e6ab72d3..b355cd1c7e7e3ed0b6b9dc44abe6d65f6400820a 100644 (file)
@@ -23,7 +23,7 @@
  * @package   StatusNet
  * @author    Evan Prodromou <evan@status.net>
  * @author    Zach Copley <zach@status.net>
- * @copyright 2009 StatusNet, Inc.
+ * @copyright 2009-2010 StatusNet, Inc.
  * @license   http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
  * @link      http://status.net/
  */
@@ -65,7 +65,7 @@ class ApiBlockCreateAction extends ApiAuthAction
         parent::prepare($args);
 
         $this->user   = $this->auth_user;
-        $this->other  = $this->getTargetUser($this->arg('id'));
+        $this->other  = $this->getTargetProfile($this->arg('id'));
 
         return true;
     }
index 666f308f4c5a3819ce1c83ff35e9fb9620c4b5d2..7ea201677e677fe2c2e0373153bc9a752db3ef7c 100644 (file)
@@ -23,7 +23,7 @@
  * @package   StatusNet
  * @author    Evan Prodromou <evan@status.net>
  * @author    Zach Copley <zach@status.net>
- * @copyright 2009 StatusNet, Inc.
+ * @copyright 2009-2010 StatusNet, Inc.
  * @license   http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
  * @link      http://status.net/
  */
@@ -64,7 +64,7 @@ class ApiBlockDestroyAction extends ApiAuthAction
         parent::prepare($args);
 
         $this->user   = $this->auth_user;
-        $this->other  = $this->getTargetUser($this->arg('id'));
+        $this->other  = $this->getTargetProfile($this->arg('id'));
 
         return true;
     }
index 1de2cc32e0ba906362e8f5832fa9497910649d5d..a7ec5b28a44452996e666d60c36ce72075fc400b 100644 (file)
@@ -24,7 +24,7 @@
  * @author    Dan Moore <dan@moore.cx>
  * @author    Evan Prodromou <evan@status.net>
  * @author    Zach Copley <zach@status.net>
- * @copyright 2009 StatusNet, Inc.
+ * @copyright 2009-2010 StatusNet, Inc.
  * @license   http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
  * @link      http://status.net/
  */
@@ -67,7 +67,7 @@ class ApiFriendshipsCreateAction extends ApiAuthAction
         parent::prepare($args);
 
         $this->user   = $this->auth_user;
-        $this->other  = $this->getTargetUser($id);
+        $this->other  = $this->getTargetProfile($this->arg('id'));
 
         return true;
     }
@@ -106,7 +106,7 @@ class ApiFriendshipsCreateAction extends ApiAuthAction
 
         if (empty($this->other)) {
             $this->clientError(
-                _('Could not follow user: User not found.'),
+                _('Could not follow user: profile not found.'),
                 403,
                 $this->format
             );
index d48a577562af968e259899c56e5a32edb8a79933..551d016823ba143a1057cbac84ca6cbda0f1962e 100644 (file)
@@ -24,7 +24,7 @@
  * @author    Dan Moore <dan@moore.cx>
  * @author    Evan Prodromou <evan@status.net>
  * @author    Zach Copley <zach@status.net>
- * @copyright 2009 StatusNet, Inc.
+ * @copyright 2009-2010 StatusNet, Inc.
  * @license   http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
  * @link      http://status.net/
  */
@@ -67,7 +67,7 @@ class ApiFriendshipsDestroyAction extends ApiAuthAction
         parent::prepare($args);
 
         $this->user   = $this->auth_user;
-        $this->other  = $this->getTargetUser($id);
+        $this->other  = $this->getTargetProfile($this->arg('id'));
 
         return true;
     }
@@ -125,8 +125,7 @@ class ApiFriendshipsDestroyAction extends ApiAuthAction
         }
 
         // throws an exception on error
-        Subscription::cancel($this->user->getProfile(),
-                             $this->other->getProfile());
+        Subscription::cancel($this->user->getProfile(), $this->other);
 
         $this->initDocument($this->format);
         $this->showProfile($this->other, $this->format);
index ca62b5f51420b81009d766bdebb30e6fd17d359d..725178fd427bf52d0265909871cdfda465b900eb 100644 (file)
@@ -24,7 +24,7 @@
  * @author    Dan Moore <dan@moore.cx>
  * @author    Evan Prodromou <evan@status.net>
  * @author    Zach Copley <zach@status.net>
- * @copyright 2009 StatusNet, Inc.
+ * @copyright 2009-2010 StatusNet, Inc.
  * @license   http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
  * @link      http://status.net/
  */
@@ -50,8 +50,8 @@ require_once INSTALLDIR . '/lib/apiprivateauth.php';
 
 class ApiFriendshipsExistsAction extends ApiPrivateAuthAction
 {
-    var $user_a = null;
-    var $user_b = null;
+    var $profile_a = null;
+    var $profile_b = null;
 
     /**
      * Take arguments for running
@@ -66,11 +66,8 @@ class ApiFriendshipsExistsAction extends ApiPrivateAuthAction
     {
         parent::prepare($args);
 
-        $user_a_id = $this->trimmed('user_a');
-        $user_b_id = $this->trimmed('user_b');
-
-        $this->user_a = $this->getTargetUser($user_a_id);
-        $this->user_b = $this->getTargetUser($user_b_id);
+        $this->profile_a = $this->getTargetProfile($this->trimmed('user_a'));
+        $this->profile_b = $this->getTargetProfile($this->trimmed('user_b'));
 
         return true;
     }
@@ -89,16 +86,16 @@ class ApiFriendshipsExistsAction extends ApiPrivateAuthAction
     {
         parent::handle($args);
 
-        if (empty($this->user_a) || empty($this->user_b)) {
+        if (empty($this->profile_a) || empty($this->profile_b)) {
             $this->clientError(
-                _('Two user ids or screen_names must be supplied.'),
+                _('Two valid IDs or screen_names must be supplied.'),
                 400,
                 $this->format
             );
             return;
         }
 
-        $result = $this->user_a->isSubscribed($this->user_b);
+        $result = Subscription::exists($this->profile_a, $this->profile_b);
 
         switch ($this->format) {
         case 'xml':
index 89a4871029d3efc208cd3fc512c777bb8f0840cc..8de13a62da127b7348380befbddec372ddaa23dc 100644 (file)
@@ -1374,6 +1374,34 @@ class ApiAction extends Action
         }
     }
 
+    function getTargetProfile($id)
+    {
+        if (empty($id)) {
+
+            // Twitter supports these other ways of passing the user ID
+            if (is_numeric($this->arg('id'))) {
+                return Profile::staticGet($this->arg('id'));
+            } else if ($this->arg('id')) {
+                $nickname = common_canonical_nickname($this->arg('id'));
+                return Profile::staticGet('nickname', $nickname);
+            } else if ($this->arg('user_id')) {
+                // This is to ensure that a non-numeric user_id still
+                // overrides screen_name even if it doesn't get used
+                if (is_numeric($this->arg('user_id'))) {
+                    return Profile::staticGet('id', $this->arg('user_id'));
+                }
+            } else if ($this->arg('screen_name')) {
+                $nickname = common_canonical_nickname($this->arg('screen_name'));
+                return Profile::staticGet('nickname', $nickname);
+            }
+        } else if (is_numeric($id)) {
+            return Profile::staticGet($id);
+        } else {
+            $nickname = common_canonical_nickname($id);
+            return Profile::staticGet('nickname', $nickname);
+        }
+    }
+
     function getTargetGroup($id)
     {
         if (empty($id)) {