forked from mirrors/bookwyrm
Adds status type for app-generated statuses
This commit is contained in:
parent
10d18cc633
commit
39931e2e69
6 changed files with 47 additions and 11 deletions
|
@ -3,7 +3,7 @@ import inspect
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
from .base_activity import ActivityEncoder, Image, PublicKey, Signature
|
from .base_activity import ActivityEncoder, Image, PublicKey, Signature
|
||||||
from .note import Note, Article, Comment, Review, Quotation
|
from .note import Note, GeneratedNote, Article, Comment, Review, Quotation
|
||||||
from .interaction import Boost, Like
|
from .interaction import Boost, Like
|
||||||
from .ordered_collection import OrderedCollection, OrderedCollectionPage
|
from .ordered_collection import OrderedCollection, OrderedCollectionPage
|
||||||
from .person import Person
|
from .person import Person
|
||||||
|
|
|
@ -28,6 +28,12 @@ class Article(Note):
|
||||||
type: str = 'Article'
|
type: str = 'Article'
|
||||||
|
|
||||||
|
|
||||||
|
@dataclass(init=False)
|
||||||
|
class GeneratedNote(Note):
|
||||||
|
''' just a re-typed note '''
|
||||||
|
type: str = 'NoteUpdate'
|
||||||
|
|
||||||
|
|
||||||
@dataclass(init=False)
|
@dataclass(init=False)
|
||||||
class Comment(Note):
|
class Comment(Note):
|
||||||
''' like a note but with a book '''
|
''' like a note but with a book '''
|
||||||
|
|
|
@ -6,7 +6,7 @@ from .book import Book, Work, Edition, Author
|
||||||
from .connector import Connector
|
from .connector import Connector
|
||||||
from .relationship import UserFollows, UserFollowRequest, UserBlocks
|
from .relationship import UserFollows, UserFollowRequest, UserBlocks
|
||||||
from .shelf import Shelf, ShelfBook
|
from .shelf import Shelf, ShelfBook
|
||||||
from .status import Status, Review, Comment, Quotation
|
from .status import Status, GeneratedStatus, Review, Comment, Quotation
|
||||||
from .status import Favorite, Boost, Notification, ReadThrough
|
from .status import Favorite, Boost, Notification, ReadThrough
|
||||||
from .tag import Tag
|
from .tag import Tag
|
||||||
from .user import User
|
from .user import User
|
||||||
|
|
|
@ -99,6 +99,21 @@ class Status(OrderedCollectionPageMixin, BookWyrmModel):
|
||||||
**kwargs
|
**kwargs
|
||||||
)
|
)
|
||||||
|
|
||||||
|
class GeneratedStatus(Status):
|
||||||
|
''' these are app-generated messages about user activity '''
|
||||||
|
@property
|
||||||
|
def ap_pure_content(self):
|
||||||
|
''' indicate the book in question for mastodon (or w/e) users '''
|
||||||
|
message = self.content
|
||||||
|
books = ', '.join(
|
||||||
|
'<a href="%s">"%s"</a>' % (self.book.local_id, self.book.title) \
|
||||||
|
for book in self.mention_books
|
||||||
|
)
|
||||||
|
return '%s %s' % (message, books)
|
||||||
|
|
||||||
|
activity_serializer = activitypub.GeneratedNote
|
||||||
|
pure_activity_serializer = activitypub.Note
|
||||||
|
|
||||||
|
|
||||||
class Comment(Status):
|
class Comment(Status):
|
||||||
''' like a review but without a rating and transient '''
|
''' like a review but without a rating and transient '''
|
||||||
|
|
|
@ -12,6 +12,7 @@ from bookwyrm.broadcast import broadcast
|
||||||
from bookwyrm.status import create_review, create_status
|
from bookwyrm.status import create_review, create_status
|
||||||
from bookwyrm.status import create_quotation, create_comment
|
from bookwyrm.status import create_quotation, create_comment
|
||||||
from bookwyrm.status import create_tag, create_notification, create_rating
|
from bookwyrm.status import create_tag, create_notification, create_rating
|
||||||
|
from bookwyrm.status import create_generated_note
|
||||||
from bookwyrm.remote_user import get_or_create_remote_user
|
from bookwyrm.remote_user import get_or_create_remote_user
|
||||||
|
|
||||||
|
|
||||||
|
@ -107,14 +108,12 @@ def handle_shelve(user, book, shelf):
|
||||||
broadcast(user, shelve.to_add_activity(user))
|
broadcast(user, shelve.to_add_activity(user))
|
||||||
|
|
||||||
# tell the world about this cool thing that happened
|
# tell the world about this cool thing that happened
|
||||||
verb = {
|
message = {
|
||||||
'to-read': 'wants to read',
|
'to-read': 'wants to read',
|
||||||
'reading': 'started reading',
|
'reading': 'started reading',
|
||||||
'read': 'finished reading'
|
'read': 'finished reading'
|
||||||
}[shelf.identifier]
|
}[shelf.identifier]
|
||||||
message = '%s "%s"' % (verb, book.title)
|
status = create_generated_note(user, message, mention_books=[book])
|
||||||
status = create_status(user, message, mention_books=[book])
|
|
||||||
status.status_type = 'Update'
|
|
||||||
status.save()
|
status.save()
|
||||||
|
|
||||||
if shelf.identifier == 'reading':
|
if shelf.identifier == 'reading':
|
||||||
|
@ -187,8 +186,7 @@ def handle_import_books(user, items):
|
||||||
|
|
||||||
if new_books:
|
if new_books:
|
||||||
message = 'imported {} books'.format(len(new_books))
|
message = 'imported {} books'.format(len(new_books))
|
||||||
status = create_status(user, message, mention_books=new_books)
|
status = create_generated_note(user, message, mention_books=new_books)
|
||||||
status.status_type = 'Update'
|
|
||||||
status.save()
|
status.save()
|
||||||
|
|
||||||
broadcast(user, status.to_create_activity(user))
|
broadcast(user, status.to_create_activity(user))
|
||||||
|
|
|
@ -101,8 +101,26 @@ def get_status(remote_id):
|
||||||
).first()
|
).first()
|
||||||
|
|
||||||
|
|
||||||
def create_status(user, content, reply_parent=None, mention_books=None,
|
def create_generated_note(user, content, mention_books=None):
|
||||||
remote_id=None):
|
''' a note created by the app about user activity '''
|
||||||
|
# sanitize input html
|
||||||
|
parser = InputHtmlParser()
|
||||||
|
parser.feed(content)
|
||||||
|
content = parser.get_output()
|
||||||
|
|
||||||
|
status = models.GeneratedStatus.objects.create(
|
||||||
|
user=user,
|
||||||
|
content=content,
|
||||||
|
)
|
||||||
|
|
||||||
|
if mention_books:
|
||||||
|
for book in mention_books:
|
||||||
|
status.mention_books.add(book)
|
||||||
|
|
||||||
|
return status
|
||||||
|
|
||||||
|
|
||||||
|
def create_status(user, content, reply_parent=None, mention_books=None):
|
||||||
''' a status update '''
|
''' a status update '''
|
||||||
# TODO: handle @'ing users
|
# TODO: handle @'ing users
|
||||||
|
|
||||||
|
@ -115,7 +133,6 @@ def create_status(user, content, reply_parent=None, mention_books=None,
|
||||||
user=user,
|
user=user,
|
||||||
content=content,
|
content=content,
|
||||||
reply_parent=reply_parent,
|
reply_parent=reply_parent,
|
||||||
remote_id=remote_id,
|
|
||||||
)
|
)
|
||||||
|
|
||||||
if mention_books:
|
if mention_books:
|
||||||
|
|
Loading…
Reference in a new issue