mirror of
https://github.com/bookwyrm-social/bookwyrm.git
synced 2025-02-01 03:42:22 +00:00
Incoming shelve activities
This commit is contained in:
parent
4cfded3d19
commit
5501318f95
3 changed files with 24 additions and 3 deletions
|
@ -62,6 +62,8 @@ def shared_inbox(request):
|
|||
'Announce': handle_boost,
|
||||
'Add': {
|
||||
'Tag': handle_tag,
|
||||
'Edition': handle_shelve,
|
||||
'Work': handle_shelve,
|
||||
},
|
||||
'Undo': {
|
||||
'Follow': handle_unfollow,
|
||||
|
@ -318,6 +320,22 @@ def handle_tag(activity):
|
|||
status_builder.create_tag(user, book, activity['object']['name'])
|
||||
|
||||
|
||||
@app.task
|
||||
def handle_shelve(activity):
|
||||
''' putting a book on a shelf '''
|
||||
user = get_or_create_remote_user(activity['actor'])
|
||||
book = books_manager.get_or_create_book(activity['object'])
|
||||
try:
|
||||
shelf = models.Shelf.objects.get(remote_id=activity['target'])
|
||||
except models.Shelf.DoesNotExist:
|
||||
return
|
||||
if shelf.user != user:
|
||||
# this doesn't add up.
|
||||
return
|
||||
shelf.books.add(book)
|
||||
shelf.save()
|
||||
|
||||
|
||||
@app.task
|
||||
def handle_update_user(activity):
|
||||
''' receive an updated user Person activity object '''
|
||||
|
|
|
@ -68,7 +68,10 @@ class ActivitypubMixin:
|
|||
if not hasattr(self, mapping.model_key) or not mapping.activity_key:
|
||||
continue
|
||||
value = getattr(self, mapping.model_key)
|
||||
if hasattr(value, 'remote_id'):
|
||||
print(value)
|
||||
if hasattr(value, 'local_id'):
|
||||
value = value.local_id
|
||||
elif hasattr(value, 'remote_id'):
|
||||
value = value.remote_id
|
||||
if isinstance(value, datetime):
|
||||
value = value.isoformat()
|
||||
|
|
|
@ -49,8 +49,8 @@ class ShelfBook(BookWyrmModel):
|
|||
return activitypub.Add(
|
||||
id='%s#add' % self.remote_id,
|
||||
actor=user.remote_id,
|
||||
object=self.book.to_activity(),
|
||||
target=self.shelf.to_activity()
|
||||
object=self.book.local_id,
|
||||
target=self.shelf.remote_id,
|
||||
).serialize()
|
||||
|
||||
def to_remove_activity(self, user):
|
||||
|
|
Loading…
Reference in a new issue