forked from mirrors/bookwyrm
Merge pull request #882 from mouse-reeve/boost-status-bug
Fixes boosted remote statuses coming in as Statuses instead of Review/Comment/etc
This commit is contained in:
commit
d85808a0d2
2 changed files with 52 additions and 1 deletions
|
@ -265,7 +265,8 @@ def resolve_remote_id(
|
||||||
"Could not connect to host for remote_id in: %s" % (remote_id)
|
"Could not connect to host for remote_id in: %s" % (remote_id)
|
||||||
)
|
)
|
||||||
# determine the model implicitly, if not provided
|
# determine the model implicitly, if not provided
|
||||||
if not model:
|
# or if it's a model with subclasses like Status, check again
|
||||||
|
if not model or hasattr(model.objects, "select_subclasses"):
|
||||||
model = get_model_from_type(data.get("type"))
|
model = get_model_from_type(data.get("type"))
|
||||||
|
|
||||||
# check for existing items with shared unique identifiers
|
# check for existing items with shared unique identifiers
|
||||||
|
|
|
@ -572,6 +572,56 @@ class Inbox(TestCase):
|
||||||
self.assertEqual(notification.user, self.local_user)
|
self.assertEqual(notification.user, self.local_user)
|
||||||
self.assertEqual(notification.related_status, self.status)
|
self.assertEqual(notification.related_status, self.status)
|
||||||
|
|
||||||
|
@responses.activate
|
||||||
|
@patch("bookwyrm.activitystreams.ActivityStream.add_status")
|
||||||
|
def test_handle_boost_remote_status(self, redis_mock):
|
||||||
|
""" boost a status """
|
||||||
|
work = models.Work.objects.create(title="work title")
|
||||||
|
book = models.Edition.objects.create(
|
||||||
|
title="Test",
|
||||||
|
remote_id="https://bookwyrm.social/book/37292",
|
||||||
|
parent_work=work,
|
||||||
|
)
|
||||||
|
self.assertEqual(models.Notification.objects.count(), 0)
|
||||||
|
activity = {
|
||||||
|
"type": "Announce",
|
||||||
|
"id": "%s/boost" % self.status.remote_id,
|
||||||
|
"actor": self.remote_user.remote_id,
|
||||||
|
"object": "https://remote.com/status/1",
|
||||||
|
"to": ["https://www.w3.org/ns/activitystreams#public"],
|
||||||
|
"cc": ["https://example.com/user/mouse/followers"],
|
||||||
|
"published": "Mon, 25 May 2020 19:31:20 GMT",
|
||||||
|
}
|
||||||
|
responses.add(
|
||||||
|
responses.GET,
|
||||||
|
"https://remote.com/status/1",
|
||||||
|
json={
|
||||||
|
"id": "https://remote.com/status/1",
|
||||||
|
"type": "Comment",
|
||||||
|
"published": "2021-04-05T18:04:59.735190+00:00",
|
||||||
|
"attributedTo": self.remote_user.remote_id,
|
||||||
|
"content": "<p>a comment</p>",
|
||||||
|
"to": ["https://www.w3.org/ns/activitystreams#Public"],
|
||||||
|
"cc": ["https://b875df3d118b.ngrok.io/user/mouse/followers"],
|
||||||
|
"inReplyTo": "",
|
||||||
|
"inReplyToBook": book.remote_id,
|
||||||
|
"summary": "",
|
||||||
|
"tag": [],
|
||||||
|
"sensitive": False,
|
||||||
|
"@context": "https://www.w3.org/ns/activitystreams",
|
||||||
|
},
|
||||||
|
)
|
||||||
|
|
||||||
|
with patch("bookwyrm.models.status.Status.ignore_activity") as discarder:
|
||||||
|
discarder.return_value = False
|
||||||
|
views.inbox.activity_task(activity)
|
||||||
|
self.assertTrue(redis_mock.called)
|
||||||
|
|
||||||
|
boost = models.Boost.objects.get()
|
||||||
|
self.assertEqual(boost.boosted_status.remote_id, "https://remote.com/status/1")
|
||||||
|
self.assertEqual(boost.boosted_status.comment.status_type, "Comment")
|
||||||
|
self.assertEqual(boost.boosted_status.comment.book, book)
|
||||||
|
|
||||||
@responses.activate
|
@responses.activate
|
||||||
def test_handle_discarded_boost(self):
|
def test_handle_discarded_boost(self):
|
||||||
""" test a boost of a mastodon status that will be discarded """
|
""" test a boost of a mastodon status that will be discarded """
|
||||||
|
|
Loading…
Reference in a new issue