summaryrefslogtreecommitdiff
path: root/actions
diff options
context:
space:
mode:
authorEvan Prodromou <evan@status.net>2010-10-25 11:08:10 -0400
committerEvan Prodromou <evan@status.net>2010-10-25 11:08:10 -0400
commite6ba379c8bfcf6a057a9cdfc161cae84d031401f (patch)
treed465e51040b544502f83f65f9837b285096b7f3e /actions
parente51ed96b89eb0229f890a3924c653eda51972a76 (diff)
navigation links in user timeline (for AtomPub)
Diffstat (limited to 'actions')
-rw-r--r--actions/apitimelineuser.php58
1 files changed, 53 insertions, 5 deletions
diff --git a/actions/apitimelineuser.php b/actions/apitimelineuser.php
index cb7c847d6..69cd9c2cb 100644
--- a/actions/apitimelineuser.php
+++ b/actions/apitimelineuser.php
@@ -157,6 +157,49 @@ class ApiTimelineUserAction extends ApiBareAuthAction
$atom->setId($self);
$atom->setSelfLink($self);
+
+ // Add navigation links: next, prev, first
+ // Note: we use IDs rather than pages for navigation; page boundaries
+ // change too quickly!
+
+ if (!empty($this->next_id)) {
+ $nextUrl = common_local_url('ApiTimelineUser',
+ array('format' => 'atom',
+ 'id' => $this->user->id),
+ array('max_id' => $this->next_id));
+
+ $atom->addLink($nextUrl,
+ array('rel' => 'next',
+ 'type' => 'application/atom+xml'));
+ }
+
+ 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->user->id),
+ array('since_id' => $lastId));
+
+ $atom->addLink($prevUrl,
+ array('rel' => 'prev',
+ 'type' => 'application/atom+xml'));
+ }
+
+ if ($this->page > 1 || !empty($this->since_id) || !empty($this->max_id)) {
+
+ $firstUrl = common_local_url('ApiTimelineUser',
+ array('format' => 'atom',
+ 'id' => $this->user->id));
+
+ $atom->addLink($firstUrl,
+ array('rel' => 'first',
+ 'type' => 'application/atom+xml'));
+
+ }
+
$atom->addEntryFromNotices($this->notices);
$this->raw($atom->getString());
@@ -181,13 +224,18 @@ class ApiTimelineUserAction extends ApiBareAuthAction
{
$notices = array();
- $notice = $this->user->getNotices(
- ($this->page-1) * $this->count, $this->count,
- $this->since_id, $this->max_id
- );
+ $notice = $this->user->getNotices(($this->page-1) * $this->count,
+ $this->count + 1,
+ $this->since_id,
+ $this->max_id);
while ($notice->fetch()) {
- $notices[] = clone($notice);
+ if (count($notices) < $this->count) {
+ $notices[] = clone($notice);
+ } else {
+ $this->next_id = $notice->id;
+ break;
+ }
}
return $notices;