mirror of
https://github.com/bookwyrm-social/bookwyrm.git
synced 2024-12-23 00:26:33 +00:00
Adds outbox pages
This commit is contained in:
parent
96ebb43235
commit
d6d16f4096
1 changed files with 54 additions and 15 deletions
|
@ -1,8 +1,9 @@
|
||||||
''' handles all the activity coming out of the server '''
|
''' handles all the activity coming out of the server '''
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
from django.http import HttpResponse, JsonResponse
|
from django.http import HttpResponseNotFound, JsonResponse
|
||||||
from django.views.decorators.csrf import csrf_exempt
|
from django.views.decorators.csrf import csrf_exempt
|
||||||
import requests
|
import requests
|
||||||
|
from urllib.parse import urlencode
|
||||||
from uuid import uuid4
|
from uuid import uuid4
|
||||||
|
|
||||||
from fedireads import models
|
from fedireads import models
|
||||||
|
@ -15,21 +16,59 @@ from fedireads.settings import DOMAIN
|
||||||
def outbox(request, username):
|
def outbox(request, username):
|
||||||
''' outbox for the requested user '''
|
''' outbox for the requested user '''
|
||||||
user = models.User.objects.get(localname=username)
|
user = models.User.objects.get(localname=username)
|
||||||
size = models.Review.objects.filter(user=user).count()
|
if request.method != 'GET':
|
||||||
if request.method == 'GET':
|
return HttpResponseNotFound()
|
||||||
# list of activities
|
|
||||||
return JsonResponse({
|
|
||||||
'@context': 'https://www.w3.org/ns/activitystreams',
|
|
||||||
'id': '%s/outbox' % user.actor,
|
|
||||||
'type': 'OrderedCollection',
|
|
||||||
'totalItems': size,
|
|
||||||
'first': '%s/outbox?page=true' % user.actor,
|
|
||||||
'last': '%s/outbox?min_id=0&page=true' % user.actor
|
|
||||||
})
|
|
||||||
# TODO: paginated list of messages
|
|
||||||
|
|
||||||
#data = request.body.decode('utf-8')
|
# paginated list of messages
|
||||||
return HttpResponse()
|
if request.GET.get('page'):
|
||||||
|
limit = 20
|
||||||
|
min_id = request.GET.get('min_id')
|
||||||
|
max_id = request.GET.get('max_id')
|
||||||
|
|
||||||
|
path = 'https://%s%s?' % (DOMAIN, request.path)
|
||||||
|
# filters for use in the django queryset min/max
|
||||||
|
filters = {}
|
||||||
|
# params for the outbox page id
|
||||||
|
params = {'page': 'true'}
|
||||||
|
if min_id != None:
|
||||||
|
params['min_id'] = min_id
|
||||||
|
filters['id__gt'] = min_id
|
||||||
|
if max_id != None:
|
||||||
|
params['max_id'] = max_id
|
||||||
|
filters['id__lte'] = max_id
|
||||||
|
collection_id = path + urlencode(params)
|
||||||
|
|
||||||
|
messages = models.Activity.objects.filter(
|
||||||
|
user=user,
|
||||||
|
activity_type__in=['Article', 'Note'],
|
||||||
|
**filters
|
||||||
|
).all()[:limit]
|
||||||
|
|
||||||
|
outbox_page = {
|
||||||
|
'@context': 'https://www.w3.org/ns/activitystreams',
|
||||||
|
'id': collection_id,
|
||||||
|
'type': 'OrderedCollectionPage',
|
||||||
|
'partOf': 'https://oulipo.social/users/mus/outbox',
|
||||||
|
'orderedItems': [m.content for m in messages],
|
||||||
|
}
|
||||||
|
if max_id:
|
||||||
|
outbox_page['next'] = path + \
|
||||||
|
urlencode({'min_id': max_id, 'page': 'true'})
|
||||||
|
if min_id:
|
||||||
|
outbox_page['prev'] = path + \
|
||||||
|
urlencode({'max_id': min_id, 'page': 'true'})
|
||||||
|
return JsonResponse(outbox_page)
|
||||||
|
|
||||||
|
# collection overview
|
||||||
|
size = models.Review.objects.filter(user=user).count()
|
||||||
|
return JsonResponse({
|
||||||
|
'@context': 'https://www.w3.org/ns/activitystreams',
|
||||||
|
'id': '%s/outbox' % user.actor,
|
||||||
|
'type': 'OrderedCollection',
|
||||||
|
'totalItems': size,
|
||||||
|
'first': '%s/outbox?page=true' % user.actor,
|
||||||
|
'last': '%s/outbox?min_id=0&page=true' % user.actor
|
||||||
|
})
|
||||||
|
|
||||||
|
|
||||||
def handle_account_search(query):
|
def handle_account_search(query):
|
||||||
|
|
Loading…
Reference in a new issue