kopia lustrzana https://github.com/snarfed/bridgy-fed
rodzic
36d020eb77
commit
ca1d0dcc01
23
pages.py
23
pages.py
|
@ -1,5 +1,6 @@
|
|||
"""UI pages."""
|
||||
import datetime
|
||||
import itertools
|
||||
import logging
|
||||
import os
|
||||
|
||||
|
@ -146,17 +147,19 @@ def feed(protocol, id):
|
|||
.fetch(PAGE_SIZE)
|
||||
activities = [obj.as1 for obj in objects if not obj.deleted]
|
||||
|
||||
# fill in authors/actors stored in their own Objects
|
||||
owners = list(filter(lambda o: isinstance(o, str),
|
||||
[as1.get_owner(a) for a in activities]))
|
||||
if owners:
|
||||
keys = [ndb.Key(Object, id) for id in owners]
|
||||
owner_objs = ndb.get_multi(keys)
|
||||
# fill in authors, actors, objects stored in their own Objects
|
||||
fields = 'author', 'actor', 'object'
|
||||
hydrate_ids = [id for id in itertools.chain(
|
||||
*[[a[f] for f in fields if isinstance(a.get(f), str)]
|
||||
for a in activities])]
|
||||
if hydrate_ids:
|
||||
keys = [ndb.Key(Object, id) for id in hydrate_ids]
|
||||
hydrated = {o.key.id(): o.as1 for o in ndb.get_multi(keys) if o}
|
||||
for a in activities:
|
||||
if as1.get_owner(a) == owner_objs[0].key.id():
|
||||
a['author'] = a['actor'] = owner_objs.pop(0).as1
|
||||
if not owner_objs:
|
||||
break
|
||||
for field in fields:
|
||||
id = a.get(field)
|
||||
if isinstance(id, str) and hydrated.get(id):
|
||||
a[field] = hydrated[id]
|
||||
|
||||
actor = {
|
||||
'displayName': id,
|
||||
|
|
|
@ -263,14 +263,29 @@ class PagesTest(TestCase):
|
|||
alice = {
|
||||
'displayName': 'Ms Alice Macbeth',
|
||||
}
|
||||
self.store_object(id='z', feed=[ndb.Key(Web, 'user.com')], our_as1=note_2)
|
||||
user = ndb.Key(Web, 'user.com')
|
||||
self.store_object(id='fake:note_2', feed=[user], our_as1=note_2)
|
||||
self.store_object(id='fake:alice', our_as1=alice)
|
||||
|
||||
# repost with object (original post) in separate Object
|
||||
repost = {
|
||||
'objectType': 'activity',
|
||||
'verb': 'share',
|
||||
'object': 'fake:orig',
|
||||
}
|
||||
orig = {
|
||||
'objectType': 'note',
|
||||
'content': 'biff',
|
||||
}
|
||||
self.store_object(id='fake:repost', feed=[user], our_as1=repost)
|
||||
self.store_object(id='fake:orig', our_as1=orig)
|
||||
|
||||
got = self.client.get('/web/user.com/feed')
|
||||
self.assert_equals(200, got.status_code)
|
||||
self.assert_equals(self.EXPECTED + ['foo'],
|
||||
self.assert_equals(self.EXPECTED + ['foo', 'biff'],
|
||||
contents(microformats2.html_to_activities(got.text)))
|
||||
self.assertIn('Ms Alice Macbeth', got.text)
|
||||
self.assertIn('biff', got.text)
|
||||
|
||||
def test_feed_atom_empty(self):
|
||||
got = self.client.get('/web/user.com/feed?format=atom')
|
||||
|
|
Ładowanie…
Reference in New Issue