kopia lustrzana https://github.com/snarfed/bridgy-fed
AP: put Public in to instead of cc to make Mastodon posts public, not unlisted
fixes #277pull/280/head
rodzic
4cc43f4c56
commit
7966650178
22
common.py
22
common.py
|
@ -167,6 +167,9 @@ def send_webmentions(activity_wrapped, proxy=None, **activity_props):
|
|||
source = obj_url or obj.get('id')
|
||||
targets.extend(util.get_list(obj, 'inReplyTo'))
|
||||
|
||||
if not source:
|
||||
error("Couldn't find original post URL")
|
||||
|
||||
tags = util.get_list(activity_wrapped, 'tags')
|
||||
obj_wrapped = activity_wrapped.get('object')
|
||||
if isinstance(obj_wrapped, dict):
|
||||
|
@ -181,8 +184,6 @@ def send_webmentions(activity_wrapped, proxy=None, **activity_props):
|
|||
targets.append(obj_url)
|
||||
|
||||
targets = util.dedupe_urls(util.get_url(t) for t in targets)
|
||||
if not source:
|
||||
error("Couldn't find original post URL")
|
||||
if not targets:
|
||||
error("Couldn't find any target URLs in inReplyTo, object, or mention tags")
|
||||
|
||||
|
@ -195,7 +196,7 @@ def send_webmentions(activity_wrapped, proxy=None, **activity_props):
|
|||
continue
|
||||
|
||||
activity = Activity(source=source, target=target, direction='in',
|
||||
domain=domain, **activity_props)
|
||||
domain=domain, **activity_props)
|
||||
activity.put()
|
||||
wm_source = (activity.proxy_url()
|
||||
if verb in ('follow', 'like', 'share') or proxy
|
||||
|
@ -310,17 +311,20 @@ def postprocess_as2(activity, target=None, key=None):
|
|||
if img:
|
||||
obj_or_activity.setdefault('attachment', []).append(img)
|
||||
|
||||
# cc public and target's author(s) and recipients
|
||||
# cc target's author(s) and recipients
|
||||
# https://www.w3.org/TR/activitystreams-vocabulary/#audienceTargeting
|
||||
# https://w3c.github.io/activitypub/#delivery
|
||||
if type in as2.TYPE_TO_VERB or type in ('Article', 'Note'):
|
||||
recips = [AS2_PUBLIC_AUDIENCE]
|
||||
if target:
|
||||
recips += itertools.chain(*(util.get_list(target, field) for field in
|
||||
('actor', 'attributedTo', 'to', 'cc')))
|
||||
if target and (type in as2.TYPE_TO_VERB or type in ('Article', 'Note')):
|
||||
recips = itertools.chain(*(util.get_list(target, field) for field in
|
||||
('actor', 'attributedTo', 'to', 'cc')))
|
||||
activity['cc'] = util.dedupe_urls(util.get_url(recip) or recip.get('id')
|
||||
for recip in recips)
|
||||
|
||||
# to public, since Mastodon interprets to public as public, cc public as unlisted:
|
||||
# https://socialhub.activitypub.rocks/t/visibility-to-cc-mapping/284
|
||||
# https://wordsmith.social/falkreon/securing-activitypub
|
||||
activity.setdefault('to', []).append(AS2_PUBLIC_AUDIENCE)
|
||||
|
||||
# wrap articles and notes in a Create activity
|
||||
if type in ('Article', 'Note'):
|
||||
activity = {
|
||||
|
|
|
@ -24,7 +24,7 @@ REPLY_OBJECT = {
|
|||
'id': 'http://this/reply/id',
|
||||
'url': 'http://this/reply',
|
||||
'inReplyTo': 'http://orig/post',
|
||||
'cc': ['https://www.w3.org/ns/activitystreams#Public'],
|
||||
'to': ['https://www.w3.org/ns/activitystreams#Public'],
|
||||
}
|
||||
REPLY_OBJECT_WRAPPED = copy.deepcopy(REPLY_OBJECT)
|
||||
REPLY_OBJECT_WRAPPED['inReplyTo'] = 'http://localhost/r/orig/post'
|
||||
|
@ -34,10 +34,10 @@ REPLY = {
|
|||
'id': 'http://this/reply/as2',
|
||||
'object': REPLY_OBJECT,
|
||||
}
|
||||
MENTION_OBJECT = {
|
||||
NOTE_OBJECT = {
|
||||
'@context': 'https://www.w3.org/ns/activitystreams',
|
||||
'type': 'Note',
|
||||
'content': '☕ mentions of @other @target@target',
|
||||
'content': '☕ just a normal post',
|
||||
'id': 'http://this/mention/id',
|
||||
'url': 'http://this/mention',
|
||||
'to': ['https://www.w3.org/ns/activitystreams#Public'],
|
||||
|
@ -46,16 +46,23 @@ MENTION_OBJECT = {
|
|||
'https://masto.foo/@other',
|
||||
'http://localhost/target', # redirect-wrapped
|
||||
],
|
||||
'tag': [{
|
||||
'type': 'Mention',
|
||||
'href': 'https://masto.foo/@other',
|
||||
'name': '@other@masto.foo',
|
||||
}, {
|
||||
'type': 'Mention',
|
||||
'href': 'http://localhost/target', # redirect-wrapped
|
||||
'name': '@target@target',
|
||||
}],
|
||||
}
|
||||
NOTE = {
|
||||
'@context': 'https://www.w3.org/ns/activitystreams',
|
||||
'type': 'Create',
|
||||
'id': 'http://this/note/as2',
|
||||
'object': NOTE_OBJECT,
|
||||
}
|
||||
MENTION_OBJECT = copy.deepcopy(NOTE_OBJECT)
|
||||
MENTION_OBJECT['tag'] = [{
|
||||
'type': 'Mention',
|
||||
'href': 'https://masto.foo/@other',
|
||||
'name': '@other@masto.foo',
|
||||
}, {
|
||||
'type': 'Mention',
|
||||
'href': 'http://localhost/target', # redirect-wrapped
|
||||
'name': '@target@target',
|
||||
}]
|
||||
MENTION = {
|
||||
'@context': 'https://www.w3.org/ns/activitystreams',
|
||||
'type': 'Create',
|
||||
|
|
|
@ -70,6 +70,7 @@ class CommonTest(testutil.TestCase):
|
|||
self.assertEqual({
|
||||
'id': 'http://localhost/r/xyz',
|
||||
'inReplyTo': 'foo',
|
||||
'to': [common.AS2_PUBLIC_AUDIENCE],
|
||||
}, common.postprocess_as2({
|
||||
'id': 'xyz',
|
||||
'inReplyTo': ['foo', 'bar'],
|
||||
|
|
|
@ -56,8 +56,9 @@ class RedirectTest(testutil.TestCase):
|
|||
https://github.com/snarfed/bridgy-fed/issues/39
|
||||
"""
|
||||
as2 = copy.deepcopy(REPOST_AS2)
|
||||
del as2['cc']
|
||||
as2.update({
|
||||
'cc': [common.AS2_PUBLIC_AUDIENCE],
|
||||
'to': [common.AS2_PUBLIC_AUDIENCE],
|
||||
'object': 'http://orig/post',
|
||||
})
|
||||
|
||||
|
|
|
@ -47,10 +47,11 @@ REPOST_AS2 = {
|
|||
'url': 'http://localhost/r/http://a/repost',
|
||||
'name': 'reposted!',
|
||||
'object': 'tag:orig,2017:as2',
|
||||
'to': [AS2_PUBLIC_AUDIENCE],
|
||||
'cc': [
|
||||
AS2_PUBLIC_AUDIENCE,
|
||||
'http://orig/author',
|
||||
'http://orig/recipient',
|
||||
AS2_PUBLIC_AUDIENCE,
|
||||
'http://orig/bystander',
|
||||
],
|
||||
'actor': {
|
||||
|
@ -99,7 +100,7 @@ class WebmentionTest(testutil.TestCase):
|
|||
'id': 'tag:orig,2017:as2',
|
||||
'content': 'Lots of ☕ words...',
|
||||
'actor': {'url': 'http://orig/author'},
|
||||
'to': ['http://orig/recipient'],
|
||||
'to': ['http://orig/recipient', AS2_PUBLIC_AUDIENCE],
|
||||
'cc': ['http://orig/bystander', AS2_PUBLIC_AUDIENCE],
|
||||
}
|
||||
self.orig_as2 = requests_response(
|
||||
|
@ -168,10 +169,11 @@ class WebmentionTest(testutil.TestCase):
|
|||
<a class="u-in-reply-to" href="http://orig/post">foo ☕ bar</a>
|
||||
<a href="http://localhost/"></a>""",
|
||||
'inReplyTo': 'tag:orig,2017:as2',
|
||||
'to': [AS2_PUBLIC_AUDIENCE],
|
||||
'cc': [
|
||||
AS2_PUBLIC_AUDIENCE,
|
||||
'http://orig/author',
|
||||
'http://orig/recipient',
|
||||
AS2_PUBLIC_AUDIENCE,
|
||||
'http://orig/bystander',
|
||||
],
|
||||
'attributedTo': [{
|
||||
|
@ -216,7 +218,7 @@ class WebmentionTest(testutil.TestCase):
|
|||
'type': 'Person',
|
||||
'url': 'http://localhost/r/https://orig',
|
||||
},
|
||||
'cc': ['https://www.w3.org/ns/activitystreams#Public'],
|
||||
'to': [AS2_PUBLIC_AUDIENCE],
|
||||
}
|
||||
|
||||
self.create_html = """\
|
||||
|
@ -252,7 +254,7 @@ class WebmentionTest(testutil.TestCase):
|
|||
'name': 'Ms. ☕ Baz',
|
||||
'preferredUsername': 'orig',
|
||||
}],
|
||||
'cc': ['https://www.w3.org/ns/activitystreams#Public'],
|
||||
'to': [AS2_PUBLIC_AUDIENCE],
|
||||
},
|
||||
}
|
||||
self.update_as2 = copy.deepcopy(self.create_as2)
|
||||
|
|
Ładowanie…
Reference in New Issue