]> git.mxchange.org Git - quix0rs-gnu-social.git/commitdiff
Twitter-compatible API - first crack at /statuses/followers.format
authorzach <zach@copley.name>
Fri, 18 Jul 2008 02:55:54 +0000 (22:55 -0400)
committerzach <zach@copley.name>
Fri, 18 Jul 2008 02:55:54 +0000 (22:55 -0400)
darcs-hash:20080718025554-ca946-1e4b5aa5570c15f4e71df58c41d16f6ece1e359b.gz

actions/twitapistatuses.php

index 5e0f29aaff11709d514bcbbd6c846800151552e6..b8ee47eb0e8784df91afdeaac6c8c6dd3e98899b 100644 (file)
@@ -630,9 +630,93 @@ class TwitapistatusesAction extends TwitterapiAction {
        */
        function followers($args, $apidata) {
                parent::handle($args);
-               common_server_error("API method under construction.", $code=501);
+       
+               $user = null;
+               
+               // function was called with an argument /statuses/user_timeline/api_arg.format
+               if (isset($apidata['api_arg'])) {
+               
+                       if (is_numeric($apidata['api_arg'])) {
+                               $user = User::staticGet($apidata['api_arg']);
+                       } else {
+                               $nickname = common_canonical_nickname($apidata['api_arg']);
+                               $user = User::staticGet('nickname', $nickname);
+                       } 
+               } else {
+                       
+                       // if no user was specified, then we'll use the authenticated user
+                       $user = $apidata['user'];
+               }
+
+               if (!$user) {
+                       // Set the user to be the auth user if asked-for can't be found
+                       // honestly! This is what Twitter does, I swear --Zach
+                       $user = $apidata['user'];
+               }
+
+               $profile = $user->getProfile();
+               
+               if (!$profile) {
+                       common_server_error(_('User has no profile.'));
+                       return;
+               }
+                                                               
+               if (!$page) {
+                       $page = 1;
+               }
+                               
+               $sub = new Subscription();
+               $sub->subscribed = $profile->id;
+               $sub->orderBy('created DESC');
+
+               $followers = array();
+
+               if ($sub->find()) {
+                       while ($sub->fetch()) {
+                               
+                               $other = null;
+                               
+                               if ($sub->token) {
+                                       $other = Remote_profile::staticGet('id', $sub->subscriber);
+                               } else {
+                                       $other = User::staticGet('id', $sub->subscriber);
+                               }
+                               if (!$other) {
+                                       common_debug('Got a bad subscription: '.print_r($sub,TRUE));
+                                       continue;
+                               }       
+                                                               
+                               $notice = DB_DataObject::factory('notice');
+                               $notice->whereAdd('profile_id = ' . $other->id);
+                               $notice->orderBy('created DESC, notice.id DESC');
+                               $notice->limit(1);
+                               $notice->find();
+                               
+                               if ($notice->fetch()) {                         
+                                       $follower = array($other, $notice);
+                                       
+                               } else {
+                                       $follower = array($other, "");
+                               }
+
+                               array_push($followers, $follower);
+                               
+                       }
+               } else {
+                       // user has no followers
+               }
+               
+               foreach ($followers as $follower) {
+                       //
+               }       
+       
+               exit();
+       
        }
        
+
+       
+       
        /*
        Returns a list of the users currently featured on the site with their current statuses inline. 
        URL: http://server/api/statuses/featured.format