From 4166ce5b70cdde07299e54fa3dfe2298834c5793 Mon Sep 17 00:00:00 2001 From: Bob Mottram Date: Tue, 2 Jul 2019 19:38:51 +0100 Subject: [PATCH] follow request and receive --- acceptreject.py | 3 +-- follow.py | 31 +++++++++++++++++++++++++++++++ like.py | 3 +-- 3 files changed, 33 insertions(+), 4 deletions(-) diff --git a/acceptreject.py b/acceptreject.py index 596e7250..7fdaaa4b 100644 --- a/acceptreject.py +++ b/acceptreject.py @@ -33,8 +33,7 @@ def createAcceptReject(baseDir: str,federationList: [],username: str,domain: str 'actor': prefix+'://'+domain+'/users/'+username, 'to': [toUrl], 'cc': [], - 'object': objectUrl, - 'published': published + 'object': objectUrl } if ccUrl: if len(ccUrl)>0: diff --git a/follow.py b/follow.py index 44aa6b8d..fe9fba48 100644 --- a/follow.py +++ b/follow.py @@ -200,6 +200,8 @@ def getFollowingFeed(baseDir: str,domain: str,port: int,path: str,https: bool,fo return following def receiveFollowRequest(baseDir: str,messageJson: {},federationList: []) -> bool: + """Receives a follow request within the POST section of HTTPServer + """ if not messageJson['type'].startswith('Follow'): return False if '/users/' not in messageJson['actor']: @@ -222,3 +224,32 @@ def receiveFollowRequest(baseDir: str,messageJson: {},federationList: []) -> boo if not os.path.isdir(baseDir+'/accounts/'+handleToFollow): return False return followerOfPerson(baseDir,username,domain,usernameToFollow,domainToFollow,federationList) + +def sendFollowRequest(baseDir: str,username: str, domain: str, port: int,https: bool,followUsername: str, followDomain: str, followPort: bool,followHttps: bool,federationList: []): + if not domainPermitted(followDomain,federationList): + return None + + prefix='https' + if not https: + prefix='http' + + followPrefix='https' + if not followHttps: + followPrefix='http' + + if port!=80 and port!=443: + domain=domain+':'+str(port) + + if followPort!=80 and followPort!=443: + followDomain=followDomain+':'+str(followPort) + + newFollow = { + 'type': 'Follow', + 'actor': prefix+'://'+domain+'/users/'+username, + 'object': followPrefix+'://'+followDomain+'/users/'+followUsername, + 'to': [toUrl], + 'cc': [] + } + if ccUrl: + if len(ccUrl)>0: + newFollow['cc']=ccUrl diff --git a/like.py b/like.py index 625acb84..0d276f23 100644 --- a/like.py +++ b/like.py @@ -31,8 +31,7 @@ def like(baseDir: str,federationList: [],username: str,domain: str,port: int,toU 'actor': prefix+'://'+domain+'/users/'+username, 'object': objectUrl, 'to': [toUrl], - 'cc': [], - 'published': published + 'cc': [] } if ccUrl: if len(ccUrl)>0: