forked from mirrors/bookwyrm
remove boost notification on delete
This commit is contained in:
parent
ee96c01cc1
commit
62fd118016
3 changed files with 39 additions and 22 deletions
|
@ -358,10 +358,12 @@ def handle_unfavorite(user, status):
|
|||
|
||||
# check for notification
|
||||
if status.user.local:
|
||||
models.Notification.objects.filter(
|
||||
notification = models.Notification.objects.filter(
|
||||
user=status.user, related_user=user,
|
||||
related_status=status, notification_type='FAVORITE'
|
||||
).first().delete()
|
||||
).first()
|
||||
if notification:
|
||||
notification.delete()
|
||||
|
||||
|
||||
def handle_boost(user, status):
|
||||
|
@ -383,6 +385,7 @@ def handle_boost(user, status):
|
|||
boost_activity = boost.to_activity()
|
||||
broadcast(user, boost_activity)
|
||||
|
||||
if status.user.local:
|
||||
create_notification(
|
||||
status.user,
|
||||
'BOOST',
|
||||
|
@ -401,12 +404,11 @@ def handle_unboost(user, status):
|
|||
boost.delete()
|
||||
broadcast(user, activity)
|
||||
|
||||
|
||||
def handle_update_book_data(user, item):
|
||||
''' broadcast the news about our book '''
|
||||
broadcast(user, item.to_update_activity(user))
|
||||
|
||||
|
||||
def handle_update_user(user):
|
||||
''' broadcast editing a user's profile '''
|
||||
broadcast(user, user.to_update_activity(user))
|
||||
# delete related notification
|
||||
if status.user.local:
|
||||
notification = models.Notification.objects.filter(
|
||||
user=status.user, related_user=user,
|
||||
related_status=status, notification_type='BOOST'
|
||||
).first()
|
||||
if notification:
|
||||
notification.delete()
|
||||
|
|
|
@ -688,3 +688,18 @@ class Outgoing(TestCase):
|
|||
outgoing.handle_boost(self.remote_user, status)
|
||||
outgoing.handle_boost(self.remote_user, status)
|
||||
self.assertEqual(models.Boost.objects.count(), 1)
|
||||
|
||||
|
||||
def test_handle_unboost(self):
|
||||
''' undo a boost '''
|
||||
status = models.Status.objects.create(
|
||||
user=self.local_user, content='hi')
|
||||
with patch('bookwyrm.broadcast.broadcast_task.delay'):
|
||||
outgoing.handle_boost(self.remote_user, status)
|
||||
|
||||
self.assertEqual(models.Boost.objects.count(), 1)
|
||||
self.assertEqual(models.Notification.objects.count(), 1)
|
||||
with patch('bookwyrm.broadcast.broadcast_task.delay'):
|
||||
outgoing.handle_unboost(self.remote_user, status)
|
||||
self.assertEqual(models.Boost.objects.count(), 0)
|
||||
self.assertEqual(models.Notification.objects.count(), 0)
|
||||
|
|
|
@ -210,7 +210,7 @@ def edit_profile(request):
|
|||
user.avatar.save(filename, ContentFile(output.getvalue()))
|
||||
user.save()
|
||||
|
||||
outgoing.handle_update_user(user)
|
||||
broadcast(user, user.to_update_activity(user))
|
||||
return redirect('/user/%s' % request.user.localname)
|
||||
|
||||
|
||||
|
@ -241,7 +241,7 @@ def edit_book(request, book_id):
|
|||
return TemplateResponse(request, 'edit_book.html', data)
|
||||
book = form.save()
|
||||
|
||||
outgoing.handle_update_book_data(request.user, book)
|
||||
broadcast(request.user, book.to_update_activity(request.user))
|
||||
return redirect('/book/%s' % book.id)
|
||||
|
||||
|
||||
|
@ -288,7 +288,7 @@ def upload_cover(request, book_id):
|
|||
book.cover = form.files['cover']
|
||||
book.save()
|
||||
|
||||
outgoing.handle_update_book_data(request.user, book)
|
||||
broadcast(request.user, book.to_update_activity(request.user))
|
||||
return redirect('/book/%s' % book.id)
|
||||
|
||||
|
||||
|
@ -307,7 +307,7 @@ def add_description(request, book_id):
|
|||
book.description = description
|
||||
book.save()
|
||||
|
||||
outgoing.handle_update_book_data(request.user, book)
|
||||
broadcast(request.user, book.to_update_activity(request.user))
|
||||
return redirect('/book/%s' % book.id)
|
||||
|
||||
|
||||
|
@ -328,7 +328,7 @@ def edit_author(request, author_id):
|
|||
return TemplateResponse(request, 'edit_author.html', data)
|
||||
author = form.save()
|
||||
|
||||
outgoing.handle_update_book_data(request.user, author)
|
||||
broadcast(request.user, author.to_update_activity(request.user))
|
||||
return redirect('/author/%s' % author.id)
|
||||
|
||||
|
||||
|
|
Loading…
Reference in a new issue