kopia lustrzana https://github.com/snarfed/bridgy-fed
rodzic
f8b7d0c283
commit
e5abdc097f
|
@ -33,7 +33,7 @@ from common import (
|
||||||
subdomain_wrap,
|
subdomain_wrap,
|
||||||
unwrap,
|
unwrap,
|
||||||
)
|
)
|
||||||
from models import Follower, Object, User
|
from models import fetch_objects, Follower, Object, User
|
||||||
from protocol import Protocol
|
from protocol import Protocol
|
||||||
import webfinger
|
import webfinger
|
||||||
|
|
||||||
|
@ -932,18 +932,29 @@ def follower_collection(id, collection):
|
||||||
@app.get(f'/ap/web/<regex("{DOMAIN_RE}"):id>/outbox')
|
@app.get(f'/ap/web/<regex("{DOMAIN_RE}"):id>/outbox')
|
||||||
# special case Web users without /ap/web/ prefix, for backward compatibility
|
# special case Web users without /ap/web/ prefix, for backward compatibility
|
||||||
@app.get(f'/<regex("{DOMAIN_RE}"):id>/outbox')
|
@app.get(f'/<regex("{DOMAIN_RE}"):id>/outbox')
|
||||||
|
@flask_util.cached(cache, CACHE_TIME)
|
||||||
def outbox(id):
|
def outbox(id):
|
||||||
protocol = Protocol.for_request(fed='web')
|
protocol = Protocol.for_request(fed='web')
|
||||||
assert protocol
|
if not protocol:
|
||||||
|
error(f"Couldn't determine protocol", status=404)
|
||||||
|
|
||||||
|
user = protocol.get_by_id(id)
|
||||||
|
if not user:
|
||||||
|
error(f'User {id} not found', status=404)
|
||||||
|
|
||||||
|
query = Object.query(Object.users == user.key)
|
||||||
|
objects, before, after = fetch_objects(query, by=Object.updated, user=user)
|
||||||
|
|
||||||
return {
|
return {
|
||||||
'@context': 'https://www.w3.org/ns/activitystreams',
|
'@context': 'https://www.w3.org/ns/activitystreams',
|
||||||
'id': request.url,
|
'id': request.url,
|
||||||
'summary': f"{id}'s outbox",
|
'summary': f"{id}'s outbox",
|
||||||
'type': 'OrderedCollection',
|
'type': 'OrderedCollection',
|
||||||
'totalItems': 0,
|
# TODO. needs to handle deleted
|
||||||
|
# 'totalItems': query.count(),
|
||||||
'first': {
|
'first': {
|
||||||
'type': 'CollectionPage',
|
'type': 'CollectionPage',
|
||||||
'partOf': request.base_url,
|
'partOf': request.base_url,
|
||||||
'items': [],
|
'items': [ActivityPub.convert(obj) for obj in objects],
|
||||||
},
|
},
|
||||||
}, {'Content-Type': as2.CONTENT_TYPE}
|
}, {'Content-Type': as2.CONTENT_TYPE}
|
||||||
|
|
|
@ -1550,25 +1550,44 @@ class ActivityPubTest(TestCase):
|
||||||
'items': [ACTOR],
|
'items': [ACTOR],
|
||||||
}, resp.json)
|
}, resp.json)
|
||||||
|
|
||||||
def test_outbox_fake(self, *_):
|
def test_outbox_fake_empty(self, *_):
|
||||||
self.make_user('foo.com', cls=Fake)
|
self.make_user('fake:foo', cls=Fake)
|
||||||
resp = self.client.get(f'/ap/foo.com/outbox',
|
resp = self.client.get(f'/ap/fake:foo/outbox',
|
||||||
base_url='https://fa.brid.gy')
|
base_url='https://fa.brid.gy')
|
||||||
self.assertEqual(200, resp.status_code)
|
self.assertEqual(200, resp.status_code)
|
||||||
self.assertEqual({
|
self.assertEqual({
|
||||||
'@context': 'https://www.w3.org/ns/activitystreams',
|
'@context': 'https://www.w3.org/ns/activitystreams',
|
||||||
'id': 'https://fa.brid.gy/ap/foo.com/outbox',
|
'id': 'https://fa.brid.gy/ap/fake:foo/outbox',
|
||||||
'summary': "foo.com's outbox",
|
'summary': "fake:foo's outbox",
|
||||||
'type': 'OrderedCollection',
|
'type': 'OrderedCollection',
|
||||||
'totalItems': 0,
|
|
||||||
'first': {
|
'first': {
|
||||||
'type': 'CollectionPage',
|
'type': 'CollectionPage',
|
||||||
'partOf': 'https://fa.brid.gy/ap/foo.com/outbox',
|
'partOf': 'https://fa.brid.gy/ap/fake:foo/outbox',
|
||||||
'items': [],
|
'items': [],
|
||||||
},
|
},
|
||||||
}, resp.json)
|
}, resp.json)
|
||||||
|
|
||||||
def test_outbox_web(self, *_):
|
def test_outbox_fake_objects(self, *_):
|
||||||
|
user = self.make_user('fake:foo', cls=Fake)
|
||||||
|
for i, obj in enumerate([REPLY, MENTION, LIKE, DELETE]):
|
||||||
|
self.store_object(id=str(i), users=[user.key], as2=obj)
|
||||||
|
|
||||||
|
resp = self.client.get(f'/ap/fake:foo/outbox',
|
||||||
|
base_url='https://fa.brid.gy')
|
||||||
|
self.assertEqual(200, resp.status_code)
|
||||||
|
self.assertEqual({
|
||||||
|
'@context': 'https://www.w3.org/ns/activitystreams',
|
||||||
|
'id': 'https://fa.brid.gy/ap/fake:foo/outbox',
|
||||||
|
'summary': "fake:foo's outbox",
|
||||||
|
'type': 'OrderedCollection',
|
||||||
|
'first': {
|
||||||
|
'type': 'CollectionPage',
|
||||||
|
'partOf': 'https://fa.brid.gy/ap/fake:foo/outbox',
|
||||||
|
'items': [DELETE, LIKE, MENTION, REPLY],
|
||||||
|
},
|
||||||
|
}, resp.json)
|
||||||
|
|
||||||
|
def test_outbox_web_empty(self, *_):
|
||||||
resp = self.client.get(f'/user.com/outbox')
|
resp = self.client.get(f'/user.com/outbox')
|
||||||
self.assertEqual(200, resp.status_code)
|
self.assertEqual(200, resp.status_code)
|
||||||
self.assertEqual({
|
self.assertEqual({
|
||||||
|
@ -1576,7 +1595,6 @@ class ActivityPubTest(TestCase):
|
||||||
'id': 'http://localhost/user.com/outbox',
|
'id': 'http://localhost/user.com/outbox',
|
||||||
'summary': "user.com's outbox",
|
'summary': "user.com's outbox",
|
||||||
'type': 'OrderedCollection',
|
'type': 'OrderedCollection',
|
||||||
'totalItems': 0,
|
|
||||||
'first': {
|
'first': {
|
||||||
'type': 'CollectionPage',
|
'type': 'CollectionPage',
|
||||||
'partOf': 'http://localhost/user.com/outbox',
|
'partOf': 'http://localhost/user.com/outbox',
|
||||||
|
|
Ładowanie…
Reference in New Issue