From e2b6b59ff4e451ba0826afaccffd97a888ba1112 Mon Sep 17 00:00:00 2001 From: Ryan Barrett Date: Wed, 21 Aug 2024 11:39:06 -0700 Subject: [PATCH] activitypub.postprocess_as2: for Create/Update, put object's to/cc into activity for possible Pleroma/Akkoma interop: https://git.pleroma.social/pleroma/pleroma/-/issues/3206#note_108296 https://indieweb.social/@diego@lounge.collabfc.com/112977955332152430 --- activitypub.py | 8 ++++++++ tests/test_activitypub.py | 13 +++++++++++++ tests/test_integrations.py | 1 + tests/test_web.py | 6 ++++++ 4 files changed, 28 insertions(+) diff --git a/activitypub.py b/activitypub.py index 7650521..8c27685 100644 --- a/activitypub.py +++ b/activitypub.py @@ -796,6 +796,14 @@ def postprocess_as2(activity, orig_obj=None, wrap=True): for recip in as1.get_objects(orig_obj, field): add(cc, util.get_url(recip) or recip.get('id')) + # for CRUD activities, Pleroma (and Akkoma?) seem to crash if the activity's + # to and cc aren't exactly the same as the object's. (I think?) + # https://indieweb.social/@diego@lounge.collabfc.com/112977955332152430 + # https://git.pleroma.social/pleroma/pleroma/-/issues/3206#note_108296 + if type in ('Create', 'Update'): + activity['to'] = util.get_list(obj, 'to') + activity['cc'] = util.get_list(obj, 'cc') + # WARNING: activity here is AS2, but we're using as1.is_dm. right now the # logic is effectively the same for our purposes, but watch out here if that # ever changes. diff --git a/tests/test_activitypub.py b/tests/test_activitypub.py index a2df3f1..13646f4 100644 --- a/tests/test_activitypub.py +++ b/tests/test_activitypub.py @@ -2459,6 +2459,19 @@ class ActivityPubUtilsTest(TestCase): self.assertEqual(['https://masto.foo/@other'], postprocess_as2(obj)['cc']) + def test_postprocess_as2_object_to_cc_into_activity(self): + got = postprocess_as2({ + '@context': 'https://www.w3.org/ns/activitystreams', + 'type': 'Create', + 'object': { + 'to': ['abc'], + 'cc': ['def', 'xyz'], + }, + }) + self.assertEqual(['abc', 'https://www.w3.org/ns/activitystreams#Public'], + got['to']) + self.assertEqual(['def', 'xyz'], got['cc']) + def test_postprocess_as2_dm_note(self): dm = { 'objectType': 'note', diff --git a/tests/test_integrations.py b/tests/test_integrations.py index e96a588..9276228 100644 --- a/tests/test_integrations.py +++ b/tests/test_integrations.py @@ -158,6 +158,7 @@ class IntegrationTests(TestCase): 'cc': ['http://inst/bob'], }, 'to': ['https://www.w3.org/ns/activitystreams#Public'], + 'cc': ['http://inst/bob'], }) diff --git a/tests/test_web.py b/tests/test_web.py index d60f1be..59ca582 100644 --- a/tests/test_web.py +++ b/tests/test_web.py @@ -277,6 +277,12 @@ AS2_CREATE = { }], }, 'to': [as2.PUBLIC_AUDIENCE], + 'cc': [ + 'https://mas.to/author', + 'https://mas.to/bystander', + 'https://mas.to/recipient', + as2.PUBLIC_AUDIENCE, + ], } AS2_UPDATE = copy.deepcopy(AS2_CREATE) AS2_UPDATE.update({