move outgoing activitypub json into ap module
This commit is contained in:
@ -1,5 +1,6 @@
|
||||
''' bring activitypub functions into the namespace '''
|
||||
from .actor import get_actor
|
||||
from .collection import get_add, get_remove
|
||||
from .collection import get_outbox, get_outbox_page, get_add, get_remove
|
||||
from .create import get_create
|
||||
from .follow import get_follow_request, get_accept
|
||||
from .status import get_review, get_status
|
||||
|
@ -1,5 +1,49 @@
|
||||
''' activitypub json for collections '''
|
||||
from uuid import uuid4
|
||||
from urllib.parse import urlencode
|
||||
|
||||
from .status import get_status
|
||||
|
||||
def get_outbox(user, size):
|
||||
''' helper function for creating an outbox '''
|
||||
return get_ordered_collection(user.outbox, size)
|
||||
|
||||
|
||||
def get_outbox_page(user, page_id, statuses, max_id, min_id):
|
||||
''' helper for formatting outbox pages '''
|
||||
# not generalizing this more because the format varies for some reason
|
||||
page = {
|
||||
'@context': 'https://www.w3.org/ns/activitystreams',
|
||||
'id': page_id,
|
||||
'type': 'OrderedCollectionPage',
|
||||
'partOf': user.outbox,
|
||||
'orderedItems': [],
|
||||
}
|
||||
|
||||
for status in statuses:
|
||||
page['orderedItems'].append(get_status(status))
|
||||
|
||||
if max_id:
|
||||
page['next'] = user.outbox + '?' + \
|
||||
urlencode({'min_id': max_id, 'page': 'true'})
|
||||
if min_id:
|
||||
page['prev'] = user.outbox + '?' + \
|
||||
urlencode({'max_id': min_id, 'page': 'true'})
|
||||
|
||||
return page
|
||||
|
||||
|
||||
def get_ordered_collection(path, size):
|
||||
''' create an ordered collection '''
|
||||
return {
|
||||
'@context': 'https://www.w3.org/ns/activitystreams',
|
||||
'id': path,
|
||||
'type': 'OrderedCollection',
|
||||
'totalItems': size,
|
||||
'first': '%s?page=true' % path,
|
||||
'last': '%s?min_id=0&page=true' % path
|
||||
}
|
||||
|
||||
|
||||
def get_add(*args):
|
||||
''' activitypub Add activity '''
|
||||
|
28
fedireads/activitypub/follow.py
Normal file
28
fedireads/activitypub/follow.py
Normal file
@ -0,0 +1,28 @@
|
||||
''' makin' freinds inthe ap json format '''
|
||||
from uuid import uuid4
|
||||
|
||||
from fedireads.settings import DOMAIN
|
||||
|
||||
|
||||
def get_follow_request(user, to_follow):
|
||||
''' a local user wants to follow someone '''
|
||||
uuid = uuid4()
|
||||
return {
|
||||
'@context': 'https://www.w3.org/ns/activitystreams',
|
||||
'id': 'https://%s/%s' % (DOMAIN, str(uuid)),
|
||||
'summary': '',
|
||||
'type': 'Follow',
|
||||
'actor': user.actor,
|
||||
'object': to_follow.actor,
|
||||
}
|
||||
|
||||
|
||||
def get_accept(user, to_follow, request_activity):
|
||||
return {
|
||||
'@context': 'https://www.w3.org/ns/activitystreams',
|
||||
'id': '%s#accepts/follows/' % to_follow.absolute_id,
|
||||
'type': 'Accept',
|
||||
'actor': to_follow.actor,
|
||||
'object': activity,
|
||||
}
|
||||
|
Reference in New Issue
Block a user