Fix #1064 - Add major and minor feed for outbox/feed
authorJessica Tallon <jessica@megworld.co.uk>
Mon, 15 Dec 2014 18:04:50 +0000 (18:04 +0000)
committerJessica Tallon <jessica@megworld.co.uk>
Mon, 15 Dec 2014 18:04:50 +0000 (18:04 +0000)
mediagoblin/federation/routing.py
mediagoblin/federation/views.py

index b585750b2859fc5d5bc95d03b679b21a65ba45b6..6d86c10e115220f6c0cf469a15ef958666769f3e 100644 (file)
@@ -39,6 +39,20 @@ add_route(
     match_slash=False
 )
 
+add_route(
+    "mediagoblin.federation.feed_major",
+    "/api/user/<string:username>/feed/major/",
+    "mediagoblin.federation.views:feed_major_endpoint",
+    match_slash=False
+)
+
+add_route(
+    "mediagoblin.federation.feed_minor",
+    "/api/user/<string:username>/feed/minor/",
+    "mediagoblin.federation.views:feed_minor_endpoint",
+    match_slash=False
+)
+
 add_route(
     "mediagoblin.federation.user.uploads",
     "/api/user/<string:username>/uploads/",
@@ -76,14 +90,14 @@ add_route(
 
 add_route(
     "mediagoblin.federation.inbox_direct_minor",
-    "/api/user/<string:username>/inbox/direct/minor",
+    "/api/user/<string:username>/inbox/direct/minor/",
     "mediagoblin.federation.views:inbox_minor_endpoint",
     match_slash=False
 )
 
 add_route(
     "mediagoblin.federation.inbox_direct_major",
-    "/api/user/<string:username>/inbox/direct/major",
+    "/api/user/<string:username>/inbox/direct/major/",
     "mediagoblin.federation.views:inbox_major_endpoint",
     match_slash=False
 )
index 40873cea31e35b9e2c7e6abb7c0e084076cac48c..69dee7fbd317a60b9ec52313fe1a57cfc7df1799 100644 (file)
@@ -210,7 +210,7 @@ def inbox_major_endpoint(request):
 
 @oauth_required
 @csrf_exempt
-def feed_endpoint(request):
+def feed_endpoint(request, outbox=None):
     """ Handles the user's outbox - /api/user/<username>/feed """
     username = request.matchdict["username"]
     requested_user = User.query.filter_by(username=username).first()
@@ -524,7 +524,10 @@ def feed_endpoint(request):
     }
 
     # Create outbox
-    outbox = Activity.query.filter_by(actor=request.user.id)
+    if outbox is None:
+        outbox = Activity.query.filter_by(actor=request.user.id)
+    else:
+        outbox = outbox.filter_by(actor=request.user.id)
 
     # We want the newest things at the top (issue: #1055)
     outbox = outbox.order_by(Activity.published.desc())
@@ -549,6 +552,28 @@ def feed_endpoint(request):
 
     return json_response(feed)
 
+@oauth_required
+def feed_minor_endpoint(request):
+    """ Outbox for minor activities such as updates """
+    # If it's anything but GET pass it along
+    if request.method != "GET":
+        return feed_endpoint(request)
+
+    outbox = Activity.query.filter(
+        (Activity.verb == "update") | (Activity.verb == "delete")
+    )
+    return feed_endpoint(request, outbox=outbox)
+
+@oauth_required
+def feed_major_endpoint(request):
+    """ Outbox for all major activities """
+    # If it's anything but a GET pass it along
+    if request.method != "GET":
+        return feed_endpoint(request)
+
+    outbox = Activity.query.filter_by(verb="post")
+    return feed_endpoint(request, outbox=outbox)
+
 @oauth_required
 def object_endpoint(request):
     """ Lookup for a object type """