From 01b8eb1409fab5f693ae933676019e603eade5de Mon Sep 17 00:00:00 2001 From: Bob Mottram Date: Tue, 2 Jul 2019 12:31:26 +0100 Subject: [PATCH] Accept or reject --- acceptreject.py | 48 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100644 acceptreject.py diff --git a/acceptreject.py b/acceptreject.py new file mode 100644 index 00000000..596e7250 --- /dev/null +++ b/acceptreject.py @@ -0,0 +1,48 @@ +__filename__ = "acceptreject.py" +__author__ = "Bob Mottram" +__license__ = "AGPL3+" +__version__ = "0.0.1" +__maintainer__ = "Bob Mottram" +__email__ = "bob@freedombone.net" +__status__ = "Production" + +import json +import commentjson +from utils import getStatusNumber +from utils import createOutboxDir +from utils import urlPermitted + +def createAcceptReject(baseDir: str,federationList: [],username: str,domain: str,port: int,toUrl: str,ccUrl: str,https: bool,objectUrl: str,acceptType: str) -> {}: + """Accepts or rejects something (eg. a follow request) + Typically toUrl will be https://www.w3.org/ns/activitystreams#Public + and ccUrl might be a specific person favorited or repeated and the followers url + objectUrl is typically the url of the message, corresponding to url or atomUri in createPostBase + """ + if not urlPermitted(objectUrl,federationList): + return None + + prefix='https' + if not https: + prefix='http' + + if port!=80 and port!=443: + domain=domain+':'+str(port) + + newAccept = { + 'type': acceptType, + 'actor': prefix+'://'+domain+'/users/'+username, + 'to': [toUrl], + 'cc': [], + 'object': objectUrl, + 'published': published + } + if ccUrl: + if len(ccUrl)>0: + newAccept['cc']=ccUrl + return newAccept + +def createAccept(baseDir: str,federationList: [],username: str,domain: str,port: int,toUrl: str,ccUrl: str,https: bool,objectUrl: str) -> {}: + return createAcceptReject(baseDir,federationList,username,domain,port,toUrl,ccUrl,https,objectUrl,'Accept') + +def createReject(baseDir: str,federationList: [],username: str,domain: str,port: int,toUrl: str,ccUrl: str,https: bool,objectUrl: str) -> {}: + return createAcceptReject(baseDir,federationList,username,domain,port,toUrl,ccUrl,https,objectUrl,'Reject')