actor: add follow_remote_actor()

This commit is contained in:
William Pitcock 2018-08-17 18:09:24 -05:00
parent fd171fb52c
commit b702d9a947

View file

@ -27,10 +27,12 @@ PRIVKEY = RSA.importKey(DATABASE["actorKeys"]["privateKey"])
PUBKEY = PRIVKEY.publickey() PUBKEY = PRIVKEY.publickey()
from . import app from . import app, CONFIG
from .remote_actor import fetch_actor from .remote_actor import fetch_actor
AP_CONFIG = CONFIG.get('ap', {'host': 'localhost'})
async def actor(request): async def actor(request):
data = { data = {
@ -79,6 +81,20 @@ async def push_message_to_actor(actor, message, our_key_id):
pass pass
async def follow_remote_actor(actor_uri):
actor = await fetch_actor(actor_uri)
message = {
"@context": "https://www.w3.org/ns/activitystreams",
"type": "Follow",
"to": [actor['id']],
"object": [actor['id']],
"id": "https://{}/activities/{}".format(AP_CONFIG['host'], uuid.uuid4()),
"actor": "https://{}/actor".format(AP_CONFIG['host'])
}
await push_message_to_actor(actor, message, "https://{}/actor#main-key".format(AP_CONFIG['host']))
tag_re = re.compile(r'(<!--.*?-->|<[^>]*>)') tag_re = re.compile(r'(<!--.*?-->|<[^>]*>)')
def strip_html(data): def strip_html(data):
no_tags = tag_re.sub('', data) no_tags = tag_re.sub('', data)
@ -111,6 +127,7 @@ async def handle_follow(actor, data, request):
"@context": "https://www.w3.org/ns/activitystreams", "@context": "https://www.w3.org/ns/activitystreams",
"type": "Accept", "type": "Accept",
"to": [actor["id"]], "to": [actor["id"]],
"actor": "https://{}/actor".format(request.host),
# this is wrong per litepub, but mastodon < 2.4 is not compliant with that profile. # this is wrong per litepub, but mastodon < 2.4 is not compliant with that profile.
"object": { "object": {