Adds privacy and recipient details to list items

This commit is contained in:
Mouse Reeve
2021-04-08 14:53:45 -07:00
parent 1f930ba821
commit b1491c2ac6
4 changed files with 59 additions and 27 deletions

View File

@ -359,6 +359,20 @@ class CollectionItemMixin(ActivitypubMixin):
activity_serializer = activitypub.CollectionItem
@property
def privacy(self):
""" inherit the privacy of the list, or direct if pending """
collection_field = getattr(self, self.collection_field)
if self.approved:
return collection_field.privacy
return "direct"
@property
def recipients(self):
""" the owner of the list is a direct recipient """
collection_field = getattr(self, self.collection_field)
return [collection_field.user]
def save(self, *args, broadcast=True, **kwargs):
""" broadcast updated """
# first off, we want to save normally no matter what

View File

@ -61,9 +61,7 @@ class ListItem(CollectionItemMixin, BookWyrmModel):
book = fields.ForeignKey(
"Edition", on_delete=models.PROTECT, activitypub_field="book"
)
book_list = models.ForeignKey(
"List", on_delete=models.CASCADE
)
book_list = models.ForeignKey("List", on_delete=models.CASCADE)
user = fields.ForeignKey(
"User", on_delete=models.PROTECT, activitypub_field="actor"
)

View File

@ -68,9 +68,7 @@ class ShelfBook(CollectionItemMixin, BookWyrmModel):
book = fields.ForeignKey(
"Edition", on_delete=models.PROTECT, activitypub_field="book"
)
shelf = models.ForeignKey(
"Shelf", on_delete=models.PROTECT
)
shelf = models.ForeignKey("Shelf", on_delete=models.PROTECT)
user = fields.ForeignKey(
"User", on_delete=models.PROTECT, activitypub_field="actor"
)