kopia lustrzana https://github.com/snarfed/bridgy-fed
AP: strip Link attachments since fedi instances generate their own link previews
hopefully fixes #958pull/984/head
rodzic
b6be345921
commit
c8ca31554b
|
@ -664,12 +664,18 @@ def postprocess_as2(activity, orig_obj=None, wrap=True):
|
|||
# https://chrisbeckstrom.com/2018/12/27/32551/
|
||||
# assert activity.get('id') or (isinstance(obj, dict) and obj.get('id'))
|
||||
|
||||
# drop Link attachments since fediverse instances generate their own link previews
|
||||
# https://github.com/snarfed/bridgy-fed/issues/958
|
||||
obj_or_activity = obj if obj.keys() > set(['id']) else activity
|
||||
obj_or_activity['attachment'] = [
|
||||
a for a in as1.get_objects(obj_or_activity, 'attachment')
|
||||
if a.get('type') != 'Link']
|
||||
|
||||
# copy image(s) into attachment(s). may be Mastodon-specific.
|
||||
# https://github.com/snarfed/bridgy-fed/issues/33#issuecomment-440965618
|
||||
obj_or_activity = obj if obj.keys() > set(['id']) else activity
|
||||
imgs = util.get_list(obj_or_activity, 'image')
|
||||
atts = obj_or_activity.setdefault('attachment', [])
|
||||
if imgs:
|
||||
atts = obj_or_activity['attachment']
|
||||
atts.extend(img for img in imgs if img not in atts)
|
||||
|
||||
# cc target's author(s), recipients, mentions
|
||||
|
|
|
@ -1960,6 +1960,15 @@ class ActivityPubUtilsTest(TestCase):
|
|||
],
|
||||
}))
|
||||
|
||||
def test_postprocess_as2_strips_link_attachment(self):
|
||||
self.assertNotIn('attachment', postprocess_as2({
|
||||
'type': 'Note',
|
||||
'attachment': [{
|
||||
'type': 'Link',
|
||||
'url': 'http://a/link',
|
||||
}],
|
||||
}))
|
||||
|
||||
def test_postprocess_as2_actor_url_attachments(self):
|
||||
got = postprocess_as2_actor(as2.from_as1({
|
||||
'objectType': 'person',
|
||||
|
@ -2279,13 +2288,6 @@ class ActivityPubUtilsTest(TestCase):
|
|||
'object': ACTOR,
|
||||
}, ActivityPub.convert(obj))
|
||||
|
||||
# TODO: remove
|
||||
@skip
|
||||
def test_convert_protocols_not_enabled(self):
|
||||
obj = Object(our_as1={'foo': 'bar'}, source_protocol='atproto')
|
||||
with self.assertRaises(BadRequest):
|
||||
ActivityPub.convert(obj)
|
||||
|
||||
def test_postprocess_as2_idempotent(self):
|
||||
for obj in (ACTOR, REPLY_OBJECT, REPLY_OBJECT_WRAPPED, REPLY,
|
||||
NOTE_OBJECT, NOTE, MENTION_OBJECT, MENTION, LIKE,
|
||||
|
|
Ładowanie…
Reference in New Issue