Fixes broadcasting on generated notes

This commit is contained in:
Mouse Reeve 2021-02-10 13:09:04 -08:00
parent 222dc118af
commit 88b2504402

View file

@ -1,4 +1,5 @@
''' Handle user activity '''
from django.db import transaction
from django.utils import timezone
from bookwyrm import models
@ -19,16 +20,20 @@ def create_generated_note(user, content, mention_books=None, privacy='public'):
parser.feed(content)
content = parser.get_output()
status = models.GeneratedNote.objects.create(
with transaction.atomic():
# create but don't save
status = models.GeneratedNote(
user=user,
content=content,
privacy=privacy
)
# we have to save it to set the related fields, but hold off on telling
# folks about it because it is not ready
status.save(broadcast=False)
if mention_books:
for book in mention_books:
status.mention_books.add(book)
status.mention_books.set(mention_books)
status.save(created=True)
return status