mirror of
https://github.com/bookwyrm-social/bookwyrm.git
synced 2024-11-25 19:11:09 +00:00
Endpoint for status
This commit is contained in:
parent
8aba8e80e4
commit
8bd566bccb
6 changed files with 53 additions and 16 deletions
|
@ -138,6 +138,26 @@ def get_actor(request, username):
|
|||
})
|
||||
|
||||
|
||||
@csrf_exempt
|
||||
def get_status(request, username, status_id):
|
||||
''' return activity json for a specific status '''
|
||||
if request.method != 'GET':
|
||||
return HttpResponseBadRequest()
|
||||
|
||||
try:
|
||||
user = models.User.objects.get(localname=username)
|
||||
status = models.Status.objects.get(id=status_id)
|
||||
except ValueError:
|
||||
return HttpResponseNotFound()
|
||||
|
||||
if user != status.user:
|
||||
return HttpResponseNotFound()
|
||||
|
||||
return JsonResponse(status.activity)
|
||||
|
||||
|
||||
|
||||
|
||||
@csrf_exempt
|
||||
def get_followers(request, username):
|
||||
''' return a list of followers for an actor '''
|
||||
|
@ -267,32 +287,36 @@ def handle_incoming_create(activity):
|
|||
return HttpResponseBadRequest()
|
||||
|
||||
response = HttpResponse()
|
||||
# if it's an article and in reply to a book, we have a review
|
||||
if activity['object']['fedireadsType'] == 'Review' and \
|
||||
if activity['object'].get('fedireadsType') == 'Review' and \
|
||||
'inReplyTo' in activity['object']:
|
||||
book = activity['object']['inReplyTo']
|
||||
book = book.split('/')[-1]
|
||||
name = activity['object'].get('name')
|
||||
content = activity['object'].get('content')
|
||||
rating = activity['object'].get('rating')
|
||||
if user.local:
|
||||
review_id = activity['object']['id'].split('/')[-1]
|
||||
review = models.Review.objects.get(id=review_id)
|
||||
else:
|
||||
try:
|
||||
create_review(user, book, name, content, rating)
|
||||
review = create_review(user, book, name, content, rating)
|
||||
except ValueError:
|
||||
return HttpResponseBadRequest()
|
||||
models.ReviewActivity(
|
||||
models.ReviewActivity.objects.create(
|
||||
uuid=activity['id'],
|
||||
user=user,
|
||||
content=activity,
|
||||
content=activity['object'],
|
||||
activity_type=activity['object']['type'],
|
||||
book=book,
|
||||
).save()
|
||||
book=review.book,
|
||||
)
|
||||
|
||||
else:
|
||||
models.Activity(
|
||||
models.Activity.objects.create(
|
||||
uuid=activity['id'],
|
||||
user=user,
|
||||
content=activity,
|
||||
activity_type=activity['object']['type']
|
||||
).save()
|
||||
)
|
||||
return response
|
||||
|
||||
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
# Generated by Django 3.0.2 on 2020-02-15 18:25
|
||||
# Generated by Django 3.0.2 on 2020-02-15 20:11
|
||||
|
||||
from django.conf import settings
|
||||
import django.contrib.auth.models
|
||||
|
@ -122,6 +122,7 @@ class Migration(migrations.Migration):
|
|||
fields=[
|
||||
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
|
||||
('status_type', models.CharField(default='Note', max_length=255)),
|
||||
('activity', django.contrib.postgres.fields.jsonb.JSONField(max_length=5000, null=True)),
|
||||
('content', models.TextField(blank=True, null=True)),
|
||||
('created_date', models.DateTimeField(auto_now_add=True)),
|
||||
('updated_date', models.DateTimeField(auto_now=True)),
|
||||
|
|
|
@ -56,6 +56,7 @@ class Status(models.Model):
|
|||
''' reply to a review, etc '''
|
||||
user = models.ForeignKey('User', on_delete=models.PROTECT)
|
||||
status_type = models.CharField(max_length=255, default='Note')
|
||||
activity = JSONField(max_length=5000, null=True)
|
||||
reply_parent = models.ForeignKey(
|
||||
'self',
|
||||
null=True,
|
||||
|
|
|
@ -252,8 +252,10 @@ def handle_review(user, book, name, content, rating):
|
|||
}
|
||||
}
|
||||
}
|
||||
review.activity = review_activity
|
||||
review.save()
|
||||
|
||||
activity = {
|
||||
create_activity = {
|
||||
'@context': 'https://www.w3.org/ns/activitystreams',
|
||||
|
||||
'id': '%s/activity' % review_path,
|
||||
|
@ -269,5 +271,5 @@ def handle_review(user, book, name, content, rating):
|
|||
}
|
||||
|
||||
recipients = get_recipients(user, 'public')
|
||||
broadcast(user, activity, recipients)
|
||||
broadcast(user, create_activity, recipients)
|
||||
|
||||
|
|
|
@ -16,6 +16,15 @@ urlpatterns = [
|
|||
re_path(r'^user/(?P<username>\w+)/outbox/?$', outgoing.outbox),
|
||||
re_path(r'^user/(?P<username>\w+)/followers/?$', incoming.get_followers),
|
||||
re_path(r'^user/(?P<username>\w+)/following/?$', incoming.get_following),
|
||||
re_path(
|
||||
r'^user/(?P<username>\w+)/status/(?P<status_id>\d+)/?$',
|
||||
incoming.get_status
|
||||
),
|
||||
re_path(
|
||||
r'^user/(?P<username>\w+)/status/(?P<status_id>\d+)/activity/?$',
|
||||
incoming.get_status
|
||||
),
|
||||
re_path(r'^user/(?P<username>\w+)/status/?$', incoming.get_following),
|
||||
# TODO: shelves need pages in the UI and for their activitypub Collection
|
||||
|
||||
# .well-known endpoints
|
||||
|
|
|
@ -55,7 +55,7 @@ def nodeinfo(request):
|
|||
"version": "2.0",
|
||||
"software": {
|
||||
"name": "mastodon",
|
||||
"version": "3.0.1"
|
||||
"version": "0.0.1"
|
||||
},
|
||||
"protocols": [
|
||||
"activitypub"
|
||||
|
|
Loading…
Reference in a new issue