diff --git a/test/test_webmention.py b/test/test_webmention.py index 9dd567c7..d8ba1bd5 100644 --- a/test/test_webmention.py +++ b/test/test_webmention.py @@ -99,6 +99,7 @@ class WebmentionTest(testutil.TestCase): '@type': 'Create', 'type': 'Create', 'object': { + '@context': 'https://www.w3.org/ns/activitystreams', '@type': 'Note', 'type': 'Note', 'url': 'http://a/reply', diff --git a/webmention.py b/webmention.py index e61da139..f9a76777 100644 --- a/webmention.py +++ b/webmention.py @@ -31,8 +31,8 @@ import models def prepare_as2(activity): """Prepare an AS2 object to be sent via ActivityPub.""" activity.update({ - 'type': activity['@type'], # for Mastodon - 'id': activity['@id'], # " + 'type': activity.get('@type'), # for Mastodon + 'id': activity.get('@id'), # " 'cc': (activity.get('cc', []) + [activitypub.PUBLIC_AUDIENCE] + util.get_list(activity, 'inReplyTo')), @@ -50,16 +50,16 @@ def prepare_as2(activity): 'Only using the first: %s' % in_reply_tos[0]) activity['inReplyTo'] = in_reply_tos[0] - if activity.get('@type') in as2.TYPE_TO_VERB: - return activity - else: - return { + if activity.get('@type') not in as2.TYPE_TO_VERB: + activity = { '@context': as2.CONTEXT, '@type': 'Create', 'type': 'Create', 'object': activity, } + return util.trim_nulls(activity) + class WebmentionHandler(webapp2.RequestHandler): """Handles inbound webmention, converts to ActivityPub or Salmon."""