kopia lustrzana https://github.com/snarfed/bridgy-fed
rodzic
56ebdba049
commit
2c861dbbf4
16
models.py
16
models.py
|
@ -397,14 +397,20 @@ class Object(StringIdModel):
|
|||
# logger.warning(f'{self.key} has multiple! {bool(self.as2)} {bool(self.bsky)} {bool(self.mf2)}')
|
||||
|
||||
if self.our_as1:
|
||||
return redirect_unwrap(self.our_as1)
|
||||
obj = redirect_unwrap(self.our_as1)
|
||||
elif self.as2:
|
||||
return as2.to_as1(redirect_unwrap(self.as2))
|
||||
obj = as2.to_as1(redirect_unwrap(self.as2))
|
||||
elif self.bsky:
|
||||
return bluesky.to_as1(self.bsky)
|
||||
obj = bluesky.to_as1(self.bsky)
|
||||
elif self.mf2:
|
||||
return microformats2.json_to_object(self.mf2,
|
||||
rel_urls=self.mf2.get('rel-urls'))
|
||||
obj = microformats2.json_to_object(self.mf2,
|
||||
rel_urls=self.mf2.get('rel-urls'))
|
||||
else:
|
||||
return None
|
||||
|
||||
if self.key:
|
||||
obj.setdefault('id', self.key.id())
|
||||
return obj
|
||||
|
||||
@ndb.ComputedProperty
|
||||
def type(self): # AS1 objectType, or verb if it's an activity
|
||||
|
|
|
@ -597,7 +597,6 @@ class Protocol:
|
|||
if obj.changed:
|
||||
logger.info(f'Content has changed from last time at {obj.updated}! Redelivering to all inboxes')
|
||||
id = f'{obj.key.id()}#bridgy-fed-update-{now}'
|
||||
logger.info(f'Wrapping in update activity {id}')
|
||||
update_as1 = {
|
||||
'objectType': 'activity',
|
||||
'verb': 'update',
|
||||
|
@ -613,6 +612,7 @@ class Protocol:
|
|||
**obj.as1,
|
||||
},
|
||||
}
|
||||
logger.info(f'Wrapping in update: {json_dumps(update_as1, indent=2)}')
|
||||
obj = Object(id=id, our_as1=update_as1,
|
||||
source_protocol=obj.source_protocol)
|
||||
|
||||
|
@ -620,7 +620,6 @@ class Protocol:
|
|||
elif obj.new or 'force' in request.form:
|
||||
logger.info(f'New Object {obj.key.id()}')
|
||||
id = f'{obj.key.id()}#bridgy-fed-create'
|
||||
logger.info(f'Wrapping in post activity {id}')
|
||||
create_as1 = {
|
||||
'objectType': 'activity',
|
||||
'verb': 'post',
|
||||
|
@ -629,9 +628,9 @@ class Protocol:
|
|||
'object': obj.as1,
|
||||
'published': now,
|
||||
}
|
||||
source_protocol = obj.source_protocol
|
||||
logger.info(f'Wrapping in post: {json_dumps(create_as1, indent=2)}')
|
||||
obj = Object.get_or_create(id, our_as1=create_as1,
|
||||
source_protocol=source_protocol)
|
||||
source_protocol=obj.source_protocol)
|
||||
else:
|
||||
error(f'{obj.key.id()} is unchanged, nothing to do', status=204)
|
||||
|
||||
|
@ -881,6 +880,7 @@ class Protocol:
|
|||
obj.changed = obj.activity_changed(orig_as1)
|
||||
|
||||
obj.source_protocol = cls.LABEL
|
||||
# TODO: drop this?
|
||||
obj.put()
|
||||
|
||||
with objects_cache_lock:
|
||||
|
|
|
@ -1734,7 +1734,8 @@ class ActivityPubUtilsTest(TestCase):
|
|||
mock_get.assert_has_calls([self.as2_req(id)])
|
||||
|
||||
self.assert_object(id,
|
||||
as2=AS2_OBJ, as1=AS2_OBJ,
|
||||
as2=AS2_OBJ,
|
||||
as1={**AS2_OBJ, 'id': id},
|
||||
source_protocol='activitypub',
|
||||
# check that it reused our original Object
|
||||
status='in progress')
|
||||
|
|
|
@ -355,7 +355,7 @@ class ObjectTest(TestCase):
|
|||
obj.put()
|
||||
self.assertEqual(['user'], obj.labels)
|
||||
|
||||
def test_as2(self):
|
||||
def test_as_as2(self):
|
||||
obj = Object(id='foo')
|
||||
self.assertEqual({}, obj.as_as2())
|
||||
|
||||
|
@ -375,6 +375,19 @@ class ObjectTest(TestCase):
|
|||
obj.as2 = {'baz': 'biff'}
|
||||
self.assertEqual({'baz': 'biff'}, obj.as_as2())
|
||||
|
||||
def test_as1(self):
|
||||
self.assertEqual({
|
||||
'objectType': 'person',
|
||||
'id': 'https://mas.to/users/swentel',
|
||||
'displayName': 'Mrs. ☕ Foo',
|
||||
'image': [{'url': 'https://user.com/me.jpg'}],
|
||||
'inbox': 'http://mas.to/inbox',
|
||||
}, Object(as2=ACTOR).as1)
|
||||
|
||||
self.assertEqual({'foo': 'bar'}, Object(our_as1={'foo': 'bar'}).as1)
|
||||
self.assertEqual({'id': 'x', 'foo': 'bar'},
|
||||
Object(id='x', our_as1={'foo': 'bar'}).as1)
|
||||
|
||||
|
||||
class FollowerTest(TestCase):
|
||||
|
||||
|
|
|
@ -171,7 +171,7 @@ class ProtocolTest(TestCase):
|
|||
Object(id='foo').put()
|
||||
|
||||
loaded = Fake.load('foo', remote=True)
|
||||
self.assertEqual({'x': 'y'}, loaded.as1)
|
||||
self.assertEqual({'id': 'foo', 'x': 'y'}, loaded.as1)
|
||||
self.assertTrue(loaded.changed)
|
||||
self.assertFalse(loaded.new)
|
||||
self.assertEqual(['foo'], Fake.fetched)
|
||||
|
@ -202,7 +202,7 @@ class ProtocolTest(TestCase):
|
|||
Fake.fetchable['foo'] = our_as1={'x': 'y'}
|
||||
|
||||
loaded = Fake.load('foo', local=False, remote=True)
|
||||
self.assertEqual({'x': 'y'}, loaded.as1)
|
||||
self.assertEqual({'id': 'foo', 'x': 'y'}, loaded.as1)
|
||||
self.assertIsNone(loaded.changed)
|
||||
self.assertIsNone(loaded.new)
|
||||
self.assertEqual(['foo'], Fake.fetched)
|
||||
|
|
|
@ -368,6 +368,7 @@ UPDATE_AS2.update({
|
|||
'type': 'Update',
|
||||
'id': 'http://localhost/r/https://user.com/post#bridgy-fed-update-2022-01-02T03:04:05+00:00',
|
||||
})
|
||||
del UPDATE_AS2['published']
|
||||
UPDATE_AS2['object']['updated'] = NOW.isoformat()
|
||||
|
||||
NOT_FEDIVERSE = requests_response("""\
|
||||
|
@ -1072,7 +1073,7 @@ class WebTest(TestCase):
|
|||
'objectType': 'activity',
|
||||
'verb': 'update',
|
||||
'id': 'https://user.com/post#bridgy-fed-update-2022-01-02T03:04:05+00:00',
|
||||
'actor': 'http://localhost/user.com',
|
||||
'actor': ACTOR_AS1_UNWRAPPED,
|
||||
'object': {
|
||||
**NOTE_AS1,
|
||||
'updated': '2022-01-02T03:04:05+00:00',
|
||||
|
@ -1083,7 +1084,6 @@ class WebTest(TestCase):
|
|||
users=[g.user.key],
|
||||
source_protocol='web',
|
||||
status='complete',
|
||||
mf2=NOTE_MF2,
|
||||
our_as1=update_as1,
|
||||
delivered=inboxes,
|
||||
type='update',
|
||||
|
|
Ładowanie…
Reference in New Issue