Fixes boost, recursive to_model calls
This commit is contained in:
@ -8,7 +8,6 @@ from .base_activity import ActivitySerializerError, resolve_remote_id
|
||||
from .image import Image
|
||||
from .note import Note, GeneratedNote, Article, Comment, Review, Quotation
|
||||
from .note import Tombstone
|
||||
from .interaction import Boost, Like
|
||||
from .ordered_collection import OrderedCollection, OrderedCollectionPage
|
||||
from .ordered_collection import BookList, Shelf
|
||||
from .person import Person, PublicKey
|
||||
@ -17,6 +16,7 @@ from .book import Edition, Work, Author
|
||||
from .verbs import Create, Delete, Undo, Update
|
||||
from .verbs import Follow, Accept, Reject, Block
|
||||
from .verbs import Add, AddBook, AddListItem, Remove
|
||||
from .verbs import Announce, Like
|
||||
|
||||
# this creates a list of all the Activity types that we can serialize,
|
||||
# so when an Activity comes in from outside, we can check if it's known
|
||||
|
@ -95,9 +95,10 @@ class ActivityObject:
|
||||
if hasattr(model, 'ignore_activity') and model.ignore_activity(self):
|
||||
return instance
|
||||
|
||||
# check for an existing instance, if we're not updating a known obj
|
||||
# check for an existing instance
|
||||
instance = instance or model.find_existing(self.serialize())
|
||||
if not instance and not allow_create:
|
||||
# so that we don't create when we want to delete or update
|
||||
return None
|
||||
instance = instance or model()
|
||||
|
||||
@ -197,7 +198,7 @@ def set_related_field(
|
||||
getattr(model_field, 'activitypub_field'),
|
||||
instance.remote_id
|
||||
)
|
||||
item = activity.to_model(model)
|
||||
item = activity.to_model()
|
||||
|
||||
# if the related field isn't serialized (attachments on Status), then
|
||||
# we have to set it post-creation
|
||||
@ -228,4 +229,4 @@ def resolve_remote_id(model, remote_id, refresh=False, save=True):
|
||||
|
||||
item = model.activity_serializer(**data)
|
||||
# if we're refreshing, "result" will be set and we'll update it
|
||||
return item.to_model(model, instance=result, save=save)
|
||||
return item.to_model(instance=result, save=save)
|
||||
|
@ -68,6 +68,10 @@ class Follow(Verb):
|
||||
object: str
|
||||
type: str = 'Follow'
|
||||
|
||||
def action(self):
|
||||
''' relationship save '''
|
||||
self.to_model()
|
||||
|
||||
|
||||
@dataclass(init=False)
|
||||
class Block(Verb):
|
||||
@ -75,6 +79,10 @@ class Block(Verb):
|
||||
object: str
|
||||
type: str = 'Block'
|
||||
|
||||
def action(self):
|
||||
''' relationship save '''
|
||||
self.to_model()
|
||||
|
||||
|
||||
@dataclass(init=False)
|
||||
class Accept(Verb):
|
||||
@ -107,6 +115,10 @@ class Add(Verb):
|
||||
object: ActivityObject
|
||||
type: str = 'Add'
|
||||
|
||||
def action(self):
|
||||
''' add obj to collection '''
|
||||
self.to_model()
|
||||
|
||||
|
||||
@dataclass(init=False)
|
||||
class AddBook(Add):
|
||||
@ -133,3 +145,25 @@ class Remove(Verb):
|
||||
''' find and remove the activity object '''
|
||||
obj = self.object.to_model(save=False, allow_create=False)
|
||||
obj.delete()
|
||||
|
||||
|
||||
@dataclass(init=False)
|
||||
class Like(Verb):
|
||||
''' a user faving an object '''
|
||||
object: str
|
||||
type: str = 'Like'
|
||||
|
||||
def action(self):
|
||||
''' like '''
|
||||
self.to_model()
|
||||
|
||||
|
||||
@dataclass(init=False)
|
||||
class Announce(Verb):
|
||||
''' boosting a status '''
|
||||
object: str
|
||||
type: str = 'Announce'
|
||||
|
||||
def action(self):
|
||||
''' boost '''
|
||||
self.to_model()
|
||||
|
Reference in New Issue
Block a user