main
Bob Mottram 2020-03-31 11:07:58 +00:00
parent acc1361c4d
commit df5effc3c5
1 changed files with 37 additions and 26 deletions

View File

@ -413,7 +413,8 @@ def getPosts(session,outboxUrl: str,maxPosts: int, \
break break
return personPosts return personPosts
def deleteAllPosts(baseDir: str,nickname: str, domain: str,boxname: str) -> None: def deleteAllPosts(baseDir: str, \
nickname: str, domain: str,boxname: str) -> None:
"""Deletes all posts for a person from inbox or outbox """Deletes all posts for a person from inbox or outbox
""" """
if boxname!='inbox' and boxname!='outbox' and boxname!='tlblogs': if boxname!='inbox' and boxname!='outbox' and boxname!='tlblogs':
@ -430,7 +431,7 @@ def deleteAllPosts(baseDir: str,nickname: str, domain: str,boxname: str) -> None
print(e) print(e)
def savePostToBox(baseDir: str,httpPrefix: str,postId: str, \ def savePostToBox(baseDir: str,httpPrefix: str,postId: str, \
nickname: str, domain: str,postJsonObject: {}, \ nickname: str,domain: str,postJsonObject: {}, \
boxname: str) -> str: boxname: str) -> str:
"""Saves the give json to the give box """Saves the give json to the give box
Returns the filename Returns the filename
@ -569,7 +570,8 @@ def createPostBase(baseDir: str,nickname: str,domain: str,port: int, \
if followersOnly: if followersOnly:
postTo=postCC postTo=postCC
postCC='' postCC=''
newPostId=httpPrefix+'://'+domain+'/users/'+nickname+'/statuses/'+statusNumber newPostId= \
httpPrefix+'://'+domain+'/users/'+nickname+'/statuses/'+statusNumber
sensitive=False sensitive=False
summary=None summary=None
@ -803,7 +805,8 @@ def outboxMessageCreateWrap(httpPrefix: str, \
statusNumber,published=getStatusNumber() statusNumber,published=getStatusNumber()
if messageJson.get('published'): if messageJson.get('published'):
published=messageJson['published'] published=messageJson['published']
newPostId=httpPrefix+'://'+domain+'/users/'+nickname+'/statuses/'+statusNumber newPostId= \
httpPrefix+'://'+domain+'/users/'+nickname+'/statuses/'+statusNumber
cc=[] cc=[]
if messageJson.get('cc'): if messageJson.get('cc'):
cc=messageJson['cc'] cc=messageJson['cc']
@ -1103,8 +1106,8 @@ def createDirectMessagePost(baseDir: str,
return messageJson return messageJson
def createReportPost(baseDir: str, def createReportPost(baseDir: str,
nickname: str, domain: str, port: int,httpPrefix: str, \ nickname: str,domain: str,port: int,httpPrefix: str, \
content: str, followersOnly: bool, saveToFile: bool, content: str,followersOnly: bool,saveToFile: bool,
clientToServer: bool,\ clientToServer: bool,\
attachImageFilename: str,mediaType: str, \ attachImageFilename: str,mediaType: str, \
imageDescription: str,useBlurhash: bool, \ imageDescription: str,useBlurhash: bool, \
@ -1208,7 +1211,7 @@ def createReportPost(baseDir: str,
return postJsonObject return postJsonObject
def threadSendPost(session,postJsonStr: str,federationList: [],\ def threadSendPost(session,postJsonStr: str,federationList: [],\
inboxUrl: str, baseDir: str, \ inboxUrl: str,baseDir: str, \
signatureHeaderJson: {},postLog: [], \ signatureHeaderJson: {},postLog: [], \
debug :bool) -> None: debug :bool) -> None:
"""Sends a with retries """Sends a with retries
@ -1257,14 +1260,14 @@ def threadSendPost(session,postJsonStr: str,federationList: [],\
tries+=1 tries+=1
def sendPost(projectVersion: str, \ def sendPost(projectVersion: str, \
session,baseDir: str,nickname: str, domain: str, port: int, \ session,baseDir: str,nickname: str,domain: str,port: int, \
toNickname: str, toDomain: str, toPort: int, cc: str, \ toNickname: str,toDomain: str,toPort: int,cc: str, \
httpPrefix: str, content: str, followersOnly: bool, \ httpPrefix: str,content: str,followersOnly: bool, \
saveToFile: bool, clientToServer: bool, \ saveToFile: bool,clientToServer: bool, \
attachImageFilename: str,mediaType: str, \ attachImageFilename: str,mediaType: str, \
imageDescription: str,useBlurhash: bool, \ imageDescription: str,useBlurhash: bool, \
federationList: [],\ federationList: [],\
sendThreads: [], postLog: [], cachedWebfingers: {},personCache: {}, \ sendThreads: [],postLog: [],cachedWebfingers: {},personCache: {}, \
isArticle: bool, \ isArticle: bool, \
debug=False,inReplyTo=None,inReplyToAtomUri=None,subject=None) -> int: debug=False,inReplyTo=None,inReplyToAtomUri=None,subject=None) -> int:
"""Post to another inbox """Post to another inbox
@ -1366,9 +1369,9 @@ def sendPost(projectVersion: str, \
def sendPostViaServer(projectVersion: str, \ def sendPostViaServer(projectVersion: str, \
baseDir: str,session,fromNickname: str,password: str, \ baseDir: str,session,fromNickname: str,password: str, \
fromDomain: str, fromPort: int, \ fromDomain: str,fromPort: int, \
toNickname: str, toDomain: str, toPort: int, cc: str, \ toNickname: str,toDomain: str,toPort: int,cc: str, \
httpPrefix: str, content: str, followersOnly: bool, \ httpPrefix: str,content: str,followersOnly: bool, \
attachImageFilename: str,mediaType: str, \ attachImageFilename: str,mediaType: str, \
imageDescription: str,useBlurhash: bool, \ imageDescription: str,useBlurhash: bool, \
cachedWebfingers: {},personCache: {}, \ cachedWebfingers: {},personCache: {}, \
@ -1536,12 +1539,12 @@ def addFollowersToPublicPost(postJsonObject: {}) -> None:
postJsonObject['object']['cc']=postJsonObject['actor']+'/followers' postJsonObject['object']['cc']=postJsonObject['actor']+'/followers'
def sendSignedJson(postJsonObject: {},session,baseDir: str, \ def sendSignedJson(postJsonObject: {},session,baseDir: str, \
nickname: str, domain: str, port: int, \ nickname: str,domain: str,port: int, \
toNickname: str, toDomain: str, toPort: int, cc: str, \ toNickname: str,toDomain: str,toPort: int,cc: str, \
httpPrefix: str, saveToFile: bool, clientToServer: bool, \ httpPrefix: str,saveToFile: bool,clientToServer: bool, \
federationList: [], \ federationList: [], \
sendThreads: [], postLog: [], cachedWebfingers: {}, \ sendThreads: [],postLog: [],cachedWebfingers: {}, \
personCache: {}, debug: bool,projectVersion: str) -> int: personCache: {},debug: bool,projectVersion: str) -> int:
"""Sends a signed json object to an inbox/outbox """Sends a signed json object to an inbox/outbox
""" """
if debug: if debug:
@ -2809,9 +2812,13 @@ def downloadAnnounce(session,baseDir: str,httpPrefix: str, \
if postJsonObject: if postJsonObject:
return postJsonObject return postJsonObject
else: else:
asHeader={'Accept': 'application/activity+json; profile="https://www.w3.org/ns/activitystreams"'} asHeader={
'Accept': 'application/activity+json; profile="https://www.w3.org/ns/activitystreams"'
}
if '/channel/' in postJsonObject['actor']: if '/channel/' in postJsonObject['actor']:
asHeader={'Accept': 'application/ld+json; profile="https://www.w3.org/ns/activitystreams"'} asHeader={
'Accept': 'application/ld+json; profile="https://www.w3.org/ns/activitystreams"'
}
actorNickname=getNicknameFromActor(postJsonObject['actor']) actorNickname=getNicknameFromActor(postJsonObject['actor'])
actorDomain,actorPort=getDomainFromActor(postJsonObject['actor']) actorDomain,actorPort=getDomainFromActor(postJsonObject['actor'])
if not actorDomain: if not actorDomain:
@ -2819,7 +2826,8 @@ def downloadAnnounce(session,baseDir: str,httpPrefix: str, \
str(postJsonObject['actor'])) str(postJsonObject['actor']))
return None return None
if isBlocked(baseDir,nickname,domain,actorNickname,actorDomain): if isBlocked(baseDir,nickname,domain,actorNickname,actorDomain):
print('Announce download blocked actor: '+actorNickname+'@'+actorDomain) print('Announce download blocked actor: '+ \
actorNickname+'@'+actorDomain)
return None return None
objectNickname=getNicknameFromActor(postJsonObject['object']) objectNickname=getNicknameFromActor(postJsonObject['object'])
objectDomain,objectPort=getDomainFromActor(postJsonObject['object']) objectDomain,objectPort=getDomainFromActor(postJsonObject['object'])
@ -2829,9 +2837,11 @@ def downloadAnnounce(session,baseDir: str,httpPrefix: str, \
return None return None
if isBlocked(baseDir,nickname,domain,objectNickname,objectDomain): if isBlocked(baseDir,nickname,domain,objectNickname,objectDomain):
if objectNickname and objectDomain: if objectNickname and objectDomain:
print('Announce download blocked object: '+objectNickname+'@'+objectDomain) print('Announce download blocked object: '+ \
objectNickname+'@'+objectDomain)
else: else:
print('Announce download blocked object: '+str(postJsonObject['object'])) print('Announce download blocked object: '+ \
str(postJsonObject['object']))
return None return None
print('Downloading Announce content for '+postJsonObject['object']) print('Downloading Announce content for '+postJsonObject['object'])
announcedJson= \ announcedJson= \
@ -2842,7 +2852,8 @@ def downloadAnnounce(session,baseDir: str,httpPrefix: str, \
return None return None
if not isinstance(announcedJson, dict): if not isinstance(announcedJson, dict):
print('WARN: announce json is not a dict - '+postJsonObject['object']) print('WARN: announce json is not a dict - '+ \
postJsonObject['object'])
rejectAnnounce(announceFilename) rejectAnnounce(announceFilename)
return None return None
if not announcedJson.get('id'): if not announcedJson.get('id'):