diff --git a/bookwyrm/models/book.py b/bookwyrm/models/book.py index 5dece504..e4f1f29b 100644 --- a/bookwyrm/models/book.py +++ b/bookwyrm/models/book.py @@ -73,7 +73,10 @@ class Book(ActivitypubMixin, BookWyrmModel): @property def alt_text(self): ''' image alt test ''' - return '%s cover (%s)' % (self.title, self.edition_info) + text = '%s cover' % self.title + if self.edition_info: + text += ' (%s)' % self.edition_info + return text def save(self, *args, **kwargs): ''' can't be abstract for query reasons, but you shouldn't USE it ''' diff --git a/bookwyrm/models/fields.py b/bookwyrm/models/fields.py index b3011e00..408cf1c3 100644 --- a/bookwyrm/models/fields.py +++ b/bookwyrm/models/fields.py @@ -71,6 +71,9 @@ class ActivitypubFieldMixin: return key = self.get_activitypub_field() + # TODO: surely there's a better way + if instance.__class__.__name__ == 'Boost' and key == 'attributedTo': + key = 'actor' if isinstance(activity.get(key), list): activity[key] += formatted else: diff --git a/bookwyrm/models/status.py b/bookwyrm/models/status.py index b358554c..b12173b1 100644 --- a/bookwyrm/models/status.py +++ b/bookwyrm/models/status.py @@ -59,6 +59,11 @@ class Status(OrderedCollectionPageMixin, BookWyrmModel): ''' expose the type of status for the ui using activity type ''' return self.activity_serializer.__name__ + @property + def boostable(self): + ''' you can't boost dms ''' + return self.privacy in ['unlisted', 'public'] + def to_replies(self, **kwargs): ''' helper function for loading AP serialized replies to a status ''' return self.to_ordered_collection( @@ -127,8 +132,8 @@ class Comment(Status): @property def pure_content(self): ''' indicate the book in question for mastodon (or w/e) users ''' - return self.content + '

(comment on "%s")' % \ - (self.book.remote_id, self.book.title) + return '

%s

(comment on "%s")

' % \ + (self.content, self.book.remote_id, self.book.title) activity_serializer = activitypub.Comment pure_type = 'Note' @@ -143,7 +148,7 @@ class Quotation(Status): @property def pure_content(self): ''' indicate the book in question for mastodon (or w/e) users ''' - return '"%s"
-- "%s"

%s' % ( + return '

"%s"
-- "%s"

%s

' % ( self.quote, self.book.remote_id, self.book.title, @@ -184,8 +189,7 @@ class Review(Status): @property def pure_content(self): ''' indicate the book in question for mastodon (or w/e) users ''' - return self.content + '

("%s")' % \ - (self.book.remote_id, self.book.title) + return self.content activity_serializer = activitypub.Review pure_type = 'Article' diff --git a/bookwyrm/models/user.py b/bookwyrm/models/user.py index d5db9949..ce50fc09 100644 --- a/bookwyrm/models/user.py +++ b/bookwyrm/models/user.py @@ -91,6 +91,7 @@ class User(OrderedCollectionPageMixin, AbstractUser): last_active_date = models.DateTimeField(auto_now=True) manually_approves_followers = fields.BooleanField(default=False) + name_field = 'username' @property def alt_text(self): ''' alt text with username ''' diff --git a/bookwyrm/outgoing.py b/bookwyrm/outgoing.py index 65a253e9..209b5858 100644 --- a/bookwyrm/outgoing.py +++ b/bookwyrm/outgoing.py @@ -315,15 +315,19 @@ def handle_unfavorite(user, status): def handle_boost(user, status): ''' a user wishes to boost a status ''' + # is it boostable? + if not status.boostable: + return + if models.Boost.objects.filter( boosted_status=status, user=user).exists(): # you already boosted that. return boost = models.Boost.objects.create( boosted_status=status, + privacy=status.privacy, user=user, ) - boost.save() boost_activity = boost.to_activity() broadcast(user, boost_activity) diff --git a/bookwyrm/templates/snippets/boost_button.html b/bookwyrm/templates/snippets/boost_button.html index bf06cef7..02b55794 100644 --- a/bookwyrm/templates/snippets/boost_button.html +++ b/bookwyrm/templates/snippets/boost_button.html @@ -1,8 +1,9 @@ {% load bookwyrm_tags %} + {% with status.id|uuid as uuid %}
{% csrf_token %} -