From 25d272470010548cd5b62c1f451c100e501f02ce Mon Sep 17 00:00:00 2001 From: Ryan Barrett Date: Tue, 16 Oct 2018 08:26:55 -0700 Subject: [PATCH] add Mention tag for Mastodon replies fixes #34. thanks @swentel! --- common.py | 15 +++++++++++++++ tests/test_webmention.py | 5 ++++- 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/common.py b/common.py index 0059271..067ae96 100644 --- a/common.py +++ b/common.py @@ -254,6 +254,21 @@ def postprocess_as2(activity, target=None, key=None): 'Only using the first: %s' % in_reply_tos[0]) activity['inReplyTo'] = in_reply_to[0] + # Mastodon evidently requires a Mention tag for replies to generate a + # notification to the original post's author. not required for likes, + # reposts, etc. details: + # https://github.com/snarfed/bridgy-fed/issues/34 + to = target.get('actor') or target.get('attributedTo') + if to: + if isinstance(to, dict): + to = to.get('url') or to.get('id') + if to: + activity.setdefault('tag', []).append({ + 'type': 'Mention', + 'href': to, + }) + + # activity objects (for Like, Announce, etc): prefer id over url obj = activity.get('object', {}) if obj: diff --git a/tests/test_webmention.py b/tests/test_webmention.py index 6667978..9b43080 100644 --- a/tests/test_webmention.py +++ b/tests/test_webmention.py @@ -175,6 +175,10 @@ class WebmentionTest(testutil.TestCase): 'preferredUsername': 'orig', 'name': 'Ms. ☕ Baz', }], + 'tag': [{ + 'type': 'Mention', + 'href': 'http://orig/author', + }], }, } self.as2_update = copy.deepcopy(self.as2_create) @@ -503,4 +507,3 @@ class WebmentionTest(testutil.TestCase): self.assertIn('Target post http://orig/url has no Atom link', got.body) self.assertIsNone(Response.get_by_id('http://a/reply http://orig/post')) -