kopia lustrzana https://github.com/snarfed/bridgy-fed
/feed: load author/actor if it's in a separate Object
fixes #419. thanks again @gRegorLove!pull/595/head
rodzic
14ee9c1516
commit
47b90c890e
13
pages.py
13
pages.py
|
@ -4,6 +4,7 @@ import logging
|
||||||
import os
|
import os
|
||||||
|
|
||||||
from flask import g, render_template, request
|
from flask import g, render_template, request
|
||||||
|
from google.cloud import ndb
|
||||||
from google.cloud.ndb.query import AND, OR
|
from google.cloud.ndb.query import AND, OR
|
||||||
from google.cloud.ndb.stats import KindStat
|
from google.cloud.ndb.stats import KindStat
|
||||||
from granary import as1, as2, atom, microformats2, rss
|
from granary import as1, as2, atom, microformats2, rss
|
||||||
|
@ -145,6 +146,18 @@ def feed(protocol, id):
|
||||||
.fetch(PAGE_SIZE)
|
.fetch(PAGE_SIZE)
|
||||||
activities = [obj.as1 for obj in objects if not obj.deleted]
|
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)
|
||||||
|
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
|
||||||
|
|
||||||
actor = {
|
actor = {
|
||||||
'displayName': id,
|
'displayName': id,
|
||||||
'url': g.user.web_url(),
|
'url': g.user.web_url(),
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
"""Unit tests for pages.py."""
|
"""Unit tests for pages.py."""
|
||||||
|
from google.cloud import ndb
|
||||||
from granary import atom, microformats2, rss
|
from granary import atom, microformats2, rss
|
||||||
from granary.tests.test_as1 import (
|
from granary.tests.test_as1 import (
|
||||||
ACTOR,
|
ACTOR,
|
||||||
|
@ -12,6 +13,7 @@ from .testutil import Fake, TestCase
|
||||||
|
|
||||||
from activitypub import ActivityPub
|
from activitypub import ActivityPub
|
||||||
from models import Object, Follower
|
from models import Object, Follower
|
||||||
|
from web import Web
|
||||||
|
|
||||||
from .test_web import ACTOR_AS2, REPOST_AS2
|
from .test_web import ACTOR_AS2, REPOST_AS2
|
||||||
|
|
||||||
|
@ -251,10 +253,24 @@ class PagesTest(TestCase):
|
||||||
|
|
||||||
def test_feed_html(self):
|
def test_feed_html(self):
|
||||||
self.add_objects()
|
self.add_objects()
|
||||||
|
|
||||||
|
# note with author in separate Object
|
||||||
|
note_2 = {
|
||||||
|
'objectType': 'note',
|
||||||
|
'content': 'foo',
|
||||||
|
'author': 'fake:alice',
|
||||||
|
}
|
||||||
|
alice = {
|
||||||
|
'displayName': 'Ms Alice Macbeth',
|
||||||
|
}
|
||||||
|
self.store_object(id='z', feed=[ndb.Key(Web, 'user.com')], our_as1=note_2)
|
||||||
|
self.store_object(id='fake:alice', our_as1=alice)
|
||||||
|
|
||||||
got = self.client.get('/web/user.com/feed')
|
got = self.client.get('/web/user.com/feed')
|
||||||
self.assert_equals(200, got.status_code)
|
self.assert_equals(200, got.status_code)
|
||||||
self.assert_equals(self.EXPECTED,
|
self.assert_equals(self.EXPECTED + ['foo'],
|
||||||
contents(microformats2.html_to_activities(got.text)))
|
contents(microformats2.html_to_activities(got.text)))
|
||||||
|
self.assertIn('Ms Alice Macbeth', got.text)
|
||||||
|
|
||||||
def test_feed_atom_empty(self):
|
def test_feed_atom_empty(self):
|
||||||
got = self.client.get('/web/user.com/feed?format=atom')
|
got = self.client.get('/web/user.com/feed?format=atom')
|
||||||
|
|
Ładowanie…
Reference in New Issue