Fix #1026 - Add inbox feed with major, minor and direct endpoints
This commit is contained in:
parent
8017abec70
commit
f2698759cd
@ -45,7 +45,37 @@ add_route(
|
|||||||
add_route(
|
add_route(
|
||||||
"mediagoblin.federation.inbox",
|
"mediagoblin.federation.inbox",
|
||||||
"/api/user/<string:username>/inbox",
|
"/api/user/<string:username>/inbox",
|
||||||
"mediagoblin.federation.views:feed_endpoint"
|
"mediagoblin.federation.views:inbox_endpoint"
|
||||||
|
)
|
||||||
|
|
||||||
|
add_route(
|
||||||
|
"mediagoblin.federation.inbox_minor",
|
||||||
|
"/api/user/<string:username>/inbox/minor",
|
||||||
|
"mediagoblin.federation.views:inbox_minor_endpoint"
|
||||||
|
)
|
||||||
|
|
||||||
|
add_route(
|
||||||
|
"mediagoblin.federation.inbox_major",
|
||||||
|
"/api/user/<string:username>/inbox/major",
|
||||||
|
"mediagoblin.federation.views:inbox_major_endpoint"
|
||||||
|
)
|
||||||
|
|
||||||
|
add_route(
|
||||||
|
"mediagoblin.federation.inbox_direct",
|
||||||
|
"/api/user/<string:username>/inbox/direct",
|
||||||
|
"mediagoblin.federation.views:inbox_endpoint"
|
||||||
|
)
|
||||||
|
|
||||||
|
add_route(
|
||||||
|
"mediagoblin.federation.inbox_direct_minor",
|
||||||
|
"/api/user/<string:username>/inbox/direct/minor",
|
||||||
|
"mediagoblin.federation.views:inbox_minor_endpoint"
|
||||||
|
)
|
||||||
|
|
||||||
|
add_route(
|
||||||
|
"mediagoblin.federation.inbox_direct_major",
|
||||||
|
"/api/user/<string:username>/inbox/direct/major",
|
||||||
|
"mediagoblin.federation.views:inbox_major_endpoint"
|
||||||
)
|
)
|
||||||
|
|
||||||
# object endpoints
|
# object endpoints
|
||||||
@ -88,4 +118,4 @@ add_route(
|
|||||||
"mediagoblin.federation.activity_view",
|
"mediagoblin.federation.activity_view",
|
||||||
"/<string:username>/activity/<string:id>",
|
"/<string:username>/activity/<string:id>",
|
||||||
"mediagoblin.federation.views:activity_view"
|
"mediagoblin.federation.views:activity_view"
|
||||||
)
|
)
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
# GN MediaGoblin -- federated, autonomous media hosting
|
# GNU MediaGoblin -- federated, autonomous media hosting
|
||||||
# Copyright (C) 2011, 2012 MediaGoblin contributors. See AUTHORS.
|
# Copyright (C) 2011, 2012 MediaGoblin contributors. See AUTHORS.
|
||||||
#
|
#
|
||||||
# This program is free software: you can redistribute it and/or modify
|
# This program is free software: you can redistribute it and/or modify
|
||||||
@ -130,6 +130,84 @@ def uploads_endpoint(request):
|
|||||||
|
|
||||||
return json_error("Not yet implemented", 501)
|
return json_error("Not yet implemented", 501)
|
||||||
|
|
||||||
|
@oauth_required
|
||||||
|
@csrf_exempt
|
||||||
|
def inbox_endpoint(request, inbox=None):
|
||||||
|
""" This is the user's inbox
|
||||||
|
|
||||||
|
Currently because we don't have the ability to represent the inbox in the
|
||||||
|
database this is not a "real" inbox in the pump.io/Activity streams 1.0
|
||||||
|
sense but instead just gives back all the data on the website
|
||||||
|
|
||||||
|
inbox: allows you to pass a query in to limit inbox scope
|
||||||
|
"""
|
||||||
|
username = request.matchdict["username"]
|
||||||
|
user = User.query.filter_by(username=username).first()
|
||||||
|
|
||||||
|
if user is None:
|
||||||
|
return json_error("No such 'user' with id '{0}'".format(username), 404)
|
||||||
|
|
||||||
|
|
||||||
|
# Only the user who's authorized should be able to read their inbox
|
||||||
|
if user.id != request.user.id:
|
||||||
|
return json_error(
|
||||||
|
"Only '{0}' can read this inbox.".format(user.username),
|
||||||
|
403
|
||||||
|
)
|
||||||
|
|
||||||
|
if inbox is None:
|
||||||
|
inbox = Activity.query.all()
|
||||||
|
|
||||||
|
# We want to make a query for all media on the site and then apply GET
|
||||||
|
# limits where we can.
|
||||||
|
inbox = inbox.order_by(Activity.published.desc())
|
||||||
|
|
||||||
|
# Limit by the "count" (default: 20)
|
||||||
|
inbox = inbox.limit(request.args.get("count", 20))
|
||||||
|
|
||||||
|
# Offset (default: no offset - first <count> results)
|
||||||
|
inbox = inbox.offset(request.args.get("offset", 0))
|
||||||
|
|
||||||
|
# build the inbox feed
|
||||||
|
feed = {
|
||||||
|
"displayName": "Activities for {0}".format(user.username),
|
||||||
|
"author": user.serialize(request),
|
||||||
|
"objectTypes": ["activity"],
|
||||||
|
"url": request.base_url,
|
||||||
|
"links": {"self": {"href": request.url}},
|
||||||
|
"items": [],
|
||||||
|
}
|
||||||
|
|
||||||
|
for activity in inbox:
|
||||||
|
try:
|
||||||
|
feed["items"].append(activity.serialize(request))
|
||||||
|
except AttributeError:
|
||||||
|
# As with the feed endpint this occurs because of how we our
|
||||||
|
# hard-deletion method. Some activites might exist where the
|
||||||
|
# Activity object and/or target no longer exist, for this case we
|
||||||
|
# should just skip them.
|
||||||
|
pass
|
||||||
|
|
||||||
|
feed["totalItems"] = len(feed["items"])
|
||||||
|
return json_response(feed)
|
||||||
|
|
||||||
|
@oauth_required
|
||||||
|
@csrf_exempt
|
||||||
|
def inbox_minor_endpoint(request):
|
||||||
|
""" Inbox subset for less important Activities """
|
||||||
|
inbox = Activity.query.filter(
|
||||||
|
(Activity.verb == "update") | (Activity.verb == "delete")
|
||||||
|
)
|
||||||
|
|
||||||
|
return inbox_endpoint(request=request, inbox=inbox)
|
||||||
|
|
||||||
|
@oauth_required
|
||||||
|
@csrf_exempt
|
||||||
|
def inbox_major_endpoint(request):
|
||||||
|
""" Inbox subset for most important Activities """
|
||||||
|
inbox = Activity.query.filter_by(verb="post")
|
||||||
|
return inbox_endpoint(request=request, inbox=inbox)
|
||||||
|
|
||||||
@oauth_required
|
@oauth_required
|
||||||
@csrf_exempt
|
@csrf_exempt
|
||||||
def feed_endpoint(request):
|
def feed_endpoint(request):
|
||||||
|
Loading…
x
Reference in New Issue
Block a user