kopia lustrzana https://github.com/snarfed/bridgy-fed
render notifications feeds as snippets, not whole activities
rodzic
ff168231d6
commit
215578f33f
16
pages.py
16
pages.py
|
@ -136,7 +136,7 @@ def notifications(protocol, id):
|
|||
|
||||
format = request.args.get('format')
|
||||
if format:
|
||||
return serve_feed(objects=objects, format=format,
|
||||
return serve_feed(objects=objects, format=format, as_snippets=True,
|
||||
title=f'Bridgy Fed notifications for {id}')
|
||||
|
||||
# notifications tab UI page
|
||||
|
@ -181,13 +181,15 @@ def feed(protocol, id):
|
|||
title=f'Bridgy Fed feed for {id}')
|
||||
|
||||
|
||||
def serve_feed(*, objects, format, title):
|
||||
def serve_feed(*, objects, format, title, as_snippets=False):
|
||||
"""Generates a feed based on :class:`Object`s.
|
||||
|
||||
Args:
|
||||
objects (sequence of models.Object)
|
||||
format (str): ``html``, ``atom``, or ``rss``
|
||||
title (str)
|
||||
as_snippets (bool): if True, render short snippets for objects instead of
|
||||
full contents
|
||||
|
||||
Returns:
|
||||
str or (str, dict) tuple: Flask response
|
||||
|
@ -195,7 +197,15 @@ def serve_feed(*, objects, format, title):
|
|||
if format not in ('html', 'atom', 'rss'):
|
||||
error(f'format {format} not supported; expected html, atom, or rss')
|
||||
|
||||
activities = [obj.as1 for obj in objects if not obj.deleted]
|
||||
if as_snippets:
|
||||
activities = [{
|
||||
'objectType': 'note',
|
||||
'content': f'{obj.actor_link(image=False)} {obj.phrase} {obj.content}',
|
||||
'content_is_html': True,
|
||||
'updated': obj.updated.isoformat(),
|
||||
} for obj in objects if not obj.deleted]
|
||||
else:
|
||||
activities = [obj.as1 for obj in objects if not obj.deleted]
|
||||
|
||||
# hydrate authors, actors, objects from stored Objects
|
||||
fields = 'author', 'actor', 'object'
|
||||
|
|
|
@ -34,6 +34,11 @@ def contents(activities):
|
|||
|
||||
class PagesTest(TestCase):
|
||||
EXPECTED = contents([COMMENT, MENTION, NOTE])
|
||||
EXPECTED_SNIPPETS = [
|
||||
'Dr. Eve replied a comment',
|
||||
'tag:fake.com:44... posted a mention',
|
||||
'tag:fake.com:44... posted my note',
|
||||
]
|
||||
|
||||
def setUp(self):
|
||||
super().setUp()
|
||||
|
@ -196,20 +201,22 @@ class PagesTest(TestCase):
|
|||
got = self.client.get('/web/user.com/notifications?format=rss')
|
||||
self.assert_equals(200, got.status_code)
|
||||
self.assert_equals(rss.CONTENT_TYPE, got.headers['Content-Type'])
|
||||
self.assert_equals(self.EXPECTED, contents(rss.to_activities(got.text)))
|
||||
self.assert_equals(self.EXPECTED_SNIPPETS,
|
||||
contents(rss.to_activities(got.text)))
|
||||
|
||||
def test_notifications_atom(self):
|
||||
self.add_objects()
|
||||
got = self.client.get('/web/user.com/notifications?format=atom')
|
||||
self.assert_equals(200, got.status_code)
|
||||
self.assert_equals(atom.CONTENT_TYPE, got.headers['Content-Type'])
|
||||
self.assert_equals(self.EXPECTED, contents(atom.atom_to_activities(got.text)))
|
||||
self.assert_equals(self.EXPECTED_SNIPPETS,
|
||||
contents(atom.atom_to_activities(got.text)))
|
||||
|
||||
def test_notifications_html(self):
|
||||
self.add_objects()
|
||||
got = self.client.get('/web/user.com/notifications?format=html')
|
||||
self.assert_equals(200, got.status_code)
|
||||
self.assert_equals(self.EXPECTED,
|
||||
self.assert_equals(self.EXPECTED_SNIPPETS,
|
||||
contents(microformats2.html_to_activities(got.text)))
|
||||
|
||||
def test_followers_fake(self):
|
||||
|
|
Ładowanie…
Reference in New Issue