diff --git a/bookwyrm/models/favorite.py b/bookwyrm/models/favorite.py index 66befd80..de500e51 100644 --- a/bookwyrm/models/favorite.py +++ b/bookwyrm/models/favorite.py @@ -20,7 +20,7 @@ class Favorite(ActivityMixin, BookWyrmModel): @classmethod def ignore_activity(cls, activity): ''' don't bother with incoming favs of unknown statuses ''' - return cls.objects.filter(remote_id=activity.object).exists() + return not cls.objects.filter(remote_id=activity.object).exists() def save(self, *args, **kwargs): ''' update user active time ''' diff --git a/bookwyrm/tests/views/test_inbox.py b/bookwyrm/tests/views/test_inbox.py index ff55ad04..b0bd3e42 100644 --- a/bookwyrm/tests/views/test_inbox.py +++ b/bookwyrm/tests/views/test_inbox.py @@ -74,7 +74,7 @@ class Inbox(TestCase): mock_valid.return_value = False result = self.client.post( '/user/mouse/inbox', - '{"type": "Test", "object": "exists"}', + '{"type": "Announce", "object": "exists"}', content_type="application/json" ) self.assertEqual(result.status_code, 401) @@ -494,6 +494,21 @@ class Inbox(TestCase): self.assertEqual(fav.remote_id, 'https://example.com/fav/1') self.assertEqual(fav.user, self.remote_user) + def test_ignore_favorite(self): + ''' don't try to save an unknown status ''' + activity = { + '@context': 'https://www.w3.org/ns/activitystreams', + 'id': 'https://example.com/fav/1', + 'actor': 'https://example.com/users/rat', + 'type': 'Like', + 'published': 'Mon, 25 May 2020 19:31:20 GMT', + 'object': 'https://unknown.status/not-found', + } + + views.inbox.activity_task(activity) + + self.assertFalse(models.Favorite.objects.exists()) + def test_handle_unfavorite(self): ''' fav a status ''' activity = {