Fix #1055 - API feed should be sorted in order of newest first
authorJessica Tallon <jessica@megworld.co.uk>
Thu, 11 Dec 2014 16:35:10 +0000 (16:35 +0000)
committerJessica Tallon <jessica@megworld.co.uk>
Thu, 11 Dec 2014 16:35:10 +0000 (16:35 +0000)
mediagoblin/federation/views.py

index fadf3294688d5dd82eb2447e2dda529cdc2023e6..ad7baacf9853278c36b45114ce98839859df8ce2 100644 (file)
@@ -436,38 +436,32 @@ def feed_endpoint(request):
             status=501
         )
 
-    feed_url = request.urlgen(
-        "mediagoblin.federation.feed",
-        username=request.user.username,
-        qualified=True
-    )
-
     feed = {
         "displayName": "Activities by {user}@{host}".format(
             user=request.user.username,
             host=request.host
         ),
         "objectTypes": ["activity"],
-        "url": feed_url,
-        "links": {
-            "first": {
-                "href": feed_url,
-            },
-            "self": {
-                "href": request.url,
-            },
-            "prev": {
-                "href": feed_url,
-            },
-            "next": {
-                "href": feed_url,
-            }
-        },
+        "url": request.base_url,
+        "links": {"self": {"href": request.url}},
         "author": request.user.serialize(request),
         "items": [],
     }
 
-    for activity in Activity.query.filter_by(actor=request.user.id):
+    # Create outbox
+    outbox = Activity.query.filter_by(actor=request.user.id)
+
+    # We want the newest things at the top (issue: #1055)
+    outbox = outbox.order_by(Activity.published.desc())
+
+    # Limit by the "count" (default: 20)
+    outbox = outbox.limit(request.args.get("count", 20))
+
+    # Offset (default: no offset - first <count>  result)
+    outbox = outbox.offset(request.args.get("offset", 0))
+
+    # Build feed.
+    for activity in outbox:
         try:
             feed["items"].append(activity.serialize(request))
         except AttributeError: