mirror of
https://github.com/bookwyrm-social/bookwyrm.git
synced 2024-11-27 03:51:08 +00:00
Serialize and broadcast ratings
This commit is contained in:
parent
54ccd6ce47
commit
030233fb1a
3 changed files with 36 additions and 11 deletions
|
@ -7,6 +7,7 @@ from .follow import get_follow_request, get_unfollow, get_accept, get_reject
|
||||||
from .outbox import get_outbox, get_outbox_page
|
from .outbox import get_outbox, get_outbox_page
|
||||||
from .shelve import get_add, get_remove
|
from .shelve import get_add, get_remove
|
||||||
from .status import get_review, get_review_article
|
from .status import get_review, get_review_article
|
||||||
|
from .status import get_rating, get_rating_note
|
||||||
from .status import get_comment, get_comment_article
|
from .status import get_comment, get_comment_article
|
||||||
from .status import get_status, get_replies, get_replies_page
|
from .status import get_status, get_replies, get_replies_page
|
||||||
from .status import get_favorite, get_unfavorite
|
from .status import get_favorite, get_unfavorite
|
||||||
|
|
|
@ -4,6 +4,16 @@ from uuid import uuid4
|
||||||
from fedireads.settings import DOMAIN
|
from fedireads.settings import DOMAIN
|
||||||
|
|
||||||
|
|
||||||
|
def get_rating(review):
|
||||||
|
''' activitypub serialize rating activity '''
|
||||||
|
status = get_status(review)
|
||||||
|
status['inReplyToBook'] = review.book.absolute_id
|
||||||
|
status['fedireadsType'] = review.status_type
|
||||||
|
status['rating'] = review.rating
|
||||||
|
status['content'] = '%d star rating of "%s"' % (
|
||||||
|
review.rating, review.book.title)
|
||||||
|
return status
|
||||||
|
|
||||||
def get_review(review):
|
def get_review(review):
|
||||||
''' fedireads json for book reviews '''
|
''' fedireads json for book reviews '''
|
||||||
status = get_status(review)
|
status = get_status(review)
|
||||||
|
@ -22,27 +32,31 @@ def get_comment(comment):
|
||||||
return status
|
return status
|
||||||
|
|
||||||
|
|
||||||
|
def get_rating_note(review):
|
||||||
|
''' simple rating, send it as a note not an artciel '''
|
||||||
|
status = get_status(review)
|
||||||
|
status['content'] = 'Rated "%s": %d stars' % (
|
||||||
|
review.book.title,
|
||||||
|
review.rating,
|
||||||
|
)
|
||||||
|
status['type'] = 'Note'
|
||||||
|
return status
|
||||||
|
|
||||||
def get_review_article(review):
|
def get_review_article(review):
|
||||||
''' a book review formatted for a non-fedireads isntance (mastodon) '''
|
''' a book review formatted for a non-fedireads isntance (mastodon) '''
|
||||||
status = get_status(review)
|
status = get_status(review)
|
||||||
if review.rating and review.name:
|
if review.rating:
|
||||||
name = 'Review of "%s" (%d stars): %s' % (
|
status['name'] = 'Review of "%s" (%d stars): %s' % (
|
||||||
review.book.title,
|
review.book.title,
|
||||||
review.rating,
|
review.rating,
|
||||||
review.name
|
review.name
|
||||||
)
|
)
|
||||||
elif review.rating:
|
|
||||||
name = 'Rated "%s" (%d stars)' % (
|
|
||||||
review.book.title,
|
|
||||||
review.rating,
|
|
||||||
)
|
|
||||||
else:
|
else:
|
||||||
name = 'Review of "%s": %s' % (
|
status['name'] = 'Review of "%s": %s' % (
|
||||||
review.book.title,
|
review.book.title,
|
||||||
review.name
|
review.name
|
||||||
)
|
)
|
||||||
|
|
||||||
status['name'] = name
|
|
||||||
return status
|
return status
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -190,8 +190,18 @@ def handle_import_books(user, items):
|
||||||
|
|
||||||
def handle_rate(user, book, rating):
|
def handle_rate(user, book, rating):
|
||||||
''' a review that's just a rating '''
|
''' a review that's just a rating '''
|
||||||
review = create_rating(user, book, rating)
|
rating = create_rating(user, book, rating)
|
||||||
# TODO: serialize and broadcast
|
rating_activity = activitypub.get_rating(rating)
|
||||||
|
rating_create_activity = activitypub.get_create(user, rating_activity)
|
||||||
|
fr_recipients = get_recipients(user, 'public', limit='fedireads')
|
||||||
|
broadcast(user, rating_create_activity, fr_recipients)
|
||||||
|
|
||||||
|
# re-format the activity for non-fedireads servers
|
||||||
|
note_activity = activitypub.get_rating_note(rating)
|
||||||
|
note_create_activity = activitypub.get_create(user, note_activity)
|
||||||
|
|
||||||
|
other_recipients = get_recipients(user, 'public', limit='other')
|
||||||
|
broadcast(user, note_create_activity, other_recipients)
|
||||||
|
|
||||||
|
|
||||||
def handle_review(user, book, name, content, rating):
|
def handle_review(user, book, name, content, rating):
|
||||||
|
|
Loading…
Reference in a new issue