moviewyrm/bookwyrm/activitypub/note.py

70 lines
1.7 KiB
Python
Raw Normal View History

''' note serializer and children thereof '''
from dataclasses import dataclass, field
from typing import Dict, List
2021-02-16 17:35:00 +00:00
from django.apps import apps
2020-11-28 01:58:21 +00:00
from .base_activity import ActivityObject, Link
from .image import Image
2020-10-08 19:32:45 +00:00
@dataclass(init=False)
class Tombstone(ActivityObject):
2020-10-17 02:13:18 +00:00
''' the placeholder for a deleted status '''
2020-10-08 19:32:45 +00:00
type: str = 'Tombstone'
2021-02-16 17:35:00 +00:00
def to_model(self, *args, **kwargs):
''' this should never really get serialized, just searched for '''
model = apps.get_model('bookwyrm.Status')
return model.find_existing_by_remote_id(self.id)
2020-10-08 19:32:45 +00:00
@dataclass(init=False)
class Note(ActivityObject):
''' Note activity '''
published: str
attributedTo: str
2021-02-08 17:38:28 +00:00
content: str = ''
2020-11-30 22:24:31 +00:00
to: List[str] = field(default_factory=lambda: [])
cc: List[str] = field(default_factory=lambda: [])
replies: Dict = field(default_factory=lambda: {})
inReplyTo: str = ''
2020-12-13 02:00:39 +00:00
summary: str = ''
tag: List[Link] = field(default_factory=lambda: [])
attachment: List[Image] = field(default_factory=lambda: [])
sensitive: bool = False
type: str = 'Note'
@dataclass(init=False)
class Article(Note):
''' what's an article except a note with more fields '''
name: str
type: str = 'Article'
@dataclass(init=False)
class GeneratedNote(Note):
''' just a re-typed note '''
type: str = 'GeneratedNote'
@dataclass(init=False)
class Comment(Note):
''' like a note but with a book '''
inReplyToBook: str
type: str = 'Comment'
@dataclass(init=False)
class Review(Comment):
''' a full book review '''
2020-12-17 21:21:21 +00:00
name: str = None
rating: int = None
type: str = 'Review'
@dataclass(init=False)
class Quotation(Comment):
''' a quote and commentary on a book '''
quote: str
type: str = 'Quotation'