moviewyrm/fedireads/activitypub/follow.py

45 lines
1.2 KiB
Python
Raw Normal View History

''' 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,
}
2020-02-19 06:44:13 +00:00
def get_unfollow(relationship):
''' undo that precious bond of friendship '''
return {
'@context': 'https://www.w3.org/ns/activitystreams',
'id': '%s/undo' % relationship.absolute_id,
'type': 'Undo',
'actor': relationship.user_subject.actor,
'object': {
'id': relationship.relationship_id,
'type': 'Follow',
'actor': relationship.user_subject.actor,
'object': relationship.user_object.actor,
}
}
2020-02-18 04:52:14 +00:00
def get_accept(user, request_activity):
''' accept a follow request '''
return {
'@context': 'https://www.w3.org/ns/activitystreams',
2020-02-18 04:52:14 +00:00
'id': '%s#accepts/follows/' % user.absolute_id,
'type': 'Accept',
2020-02-18 04:52:14 +00:00
'actor': user.actor,
'object': request_activity,
}