]> git.mxchange.org Git - quix0rs-gnu-social.git/commitdiff
User timeline ActivityStreams output now has paging data
authorMikael Nordfeldth <mmn@hethane.se>
Thu, 7 Aug 2014 20:40:36 +0000 (22:40 +0200)
committerMikael Nordfeldth <mmn@hethane.se>
Thu, 7 Aug 2014 20:40:55 +0000 (22:40 +0200)
actions/apitimelineuser.php

index c0894c5dbaa69491eae1725def746626f66bd477..ac33beada40f21a0bf78984e745f0148f214c251 100644 (file)
@@ -124,6 +124,22 @@ class ApiTimelineUserAction extends ApiBareAuthAction
         $suplink = common_local_url('sup', null, null, $this->target->id);
         header('X-SUP-ID: ' . $suplink);
 
+
+        // paging links
+        $nextUrl = common_local_url('ApiTimelineUser',
+                                    array('format' => $this->format,
+                                          'id' => $this->target->id),
+                                    array('max_id' => $this->next_id));
+        $lastNotice = $this->notices[0];
+        $lastId     = $lastNotice->id;
+        $prevUrl = common_local_url('ApiTimelineUser',
+                                    array('format' => $this->format,
+                                          'id' => $this->target->id),
+                                    array('since_id' => $lastId));
+        $firstUrl = common_local_url('ApiTimelineUser',
+                                    array('format' => $this->format,
+                                          'id' => $this->target->id));
+
         switch($this->format) {
         case 'xml':
             $this->showXmlTimeline($this->notices);
@@ -150,10 +166,6 @@ class ApiTimelineUserAction extends ApiBareAuthAction
             // change too quickly!
 
             if (!empty($this->next_id)) {
-                $nextUrl = common_local_url('ApiTimelineUser',
-                                            array('format' => 'atom',
-                                                  'id' => $this->target->id),
-                                            array('max_id' => $this->next_id));
 
                 $atom->addLink($nextUrl,
                                array('rel' => 'next',
@@ -162,13 +174,6 @@ class ApiTimelineUserAction extends ApiBareAuthAction
 
             if (($this->page > 1 || !empty($this->max_id)) && !empty($this->notices)) {
 
-                $lastNotice = $this->notices[0];
-                $lastId     = $lastNotice->id;
-
-                $prevUrl = common_local_url('ApiTimelineUser',
-                                            array('format' => 'atom',
-                                                  'id' => $this->target->id),
-                                            array('since_id' => $lastId));
 
                 $atom->addLink($prevUrl,
                                array('rel' => 'prev',
@@ -177,10 +182,6 @@ class ApiTimelineUserAction extends ApiBareAuthAction
 
             if ($this->page > 1 || !empty($this->since_id) || !empty($this->max_id)) {
 
-                $firstUrl = common_local_url('ApiTimelineUser',
-                                            array('format' => 'atom',
-                                                  'id' => $this->target->id));
-
                 $atom->addLink($firstUrl,
                                array('rel' => 'first',
                                      'type' => 'application/atom+xml'));
@@ -201,7 +202,23 @@ class ApiTimelineUserAction extends ApiBareAuthAction
             $doc->addLink($link, 'alternate', 'text/html');
             $doc->addItemsFromNotices($this->notices);
 
-            // XXX: Add paging extension?
+            if (!empty($this->next_id)) {
+                $doc->addLink($nextUrl,
+                               array('rel' => 'next',
+                                     'type' => ActivityStreamJSONDocument::CONTENT_TYPE));
+            }
+
+            if (($this->page > 1 || !empty($this->max_id)) && !empty($this->notices)) {
+                $doc->addLink($prevUrl,
+                               array('rel' => 'prev',
+                                     'type' => ActivityStreamJSONDocument::CONTENT_TYPE));
+            }
+
+            if ($this->page > 1 || !empty($this->since_id) || !empty($this->max_id)) {
+                $doc->addLink($firstUrl,
+                               array('rel' => 'first',
+                                     'type' => ActivityStreamJSONDocument::CONTENT_TYPE));
+            }
 
             $this->raw($doc->asString());
             break;