/feed: load author/actor if it's in a separate Object

fixes #419. thanks again @gRegorLove!
pull/595/head
Ryan Barrett 2023-07-19 19:39:22 -10:00
rodzic 14ee9c1516
commit 47b90c890e
Nie znaleziono w bazie danych klucza dla tego podpisu
ID klucza GPG: 6BE31FDF4776E9D4
2 zmienionych plików z 30 dodań i 1 usunięć

Wyświetl plik

@ -4,6 +4,7 @@ import logging
import os
from flask import g, render_template, request
from google.cloud import ndb
from google.cloud.ndb.query import AND, OR
from google.cloud.ndb.stats import KindStat
from granary import as1, as2, atom, microformats2, rss
@ -145,6 +146,18 @@ 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)
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 = {
'displayName': id,
'url': g.user.web_url(),

Wyświetl plik

@ -1,4 +1,5 @@
"""Unit tests for pages.py."""
from google.cloud import ndb
from granary import atom, microformats2, rss
from granary.tests.test_as1 import (
ACTOR,
@ -12,6 +13,7 @@ from .testutil import Fake, TestCase
from activitypub import ActivityPub
from models import Object, Follower
from web import Web
from .test_web import ACTOR_AS2, REPOST_AS2
@ -251,10 +253,24 @@ class PagesTest(TestCase):
def test_feed_html(self):
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')
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)))
self.assertIn('Ms Alice Macbeth', got.text)
def test_feed_atom_empty(self):
got = self.client.get('/web/user.com/feed?format=atom')