Disable boosting private statuses

This commit is contained in:
Mouse Reeve 2020-12-18 09:30:08 -08:00
parent ee8e46ca52
commit 40c4f4f5de
3 changed files with 12 additions and 2 deletions

View file

@ -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(

View file

@ -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)

View file

@ -1,8 +1,9 @@
{% load bookwyrm_tags %}
{% with status.id|uuid as uuid %}
<form name="boost" action="/boost/{{ status.id }}" method="post" onsubmit="return interact(event)" class="boost-{{ status.id }}-{{ uuid }} {% if request.user|boosted:status %}hidden{% endif %}" data-id="boost-{{ status.id }}-{{ uuid }}">
{% csrf_token %}
<button class="button is-small" type="submit">
<button class="button is-small" type="submit" {% if not status.boostable %}disabled{% endif %}>
<span class="icon icon-boost">
<span class="is-sr-only">Boost status</span>
</span>